@@ -6,11 +6,108 @@ import (
66
77 golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
88 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
9+ "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto"
910 "github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/extensions/secgroups"
1011 "github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v2/extensions/security/rules"
1112 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
1213)
1314
15+ func TestICMPSecurityGroupRules (t * testing.T ) {
16+ clientNetworking , err := clients .NewNetworkV2Client ()
17+ if err != nil {
18+ t .Fatalf ("Unable to create a networking client: %v" , err )
19+ }
20+ clientCompute , err := clients .NewComputeV2Client ()
21+ if err != nil {
22+ t .Fatalf ("Unable to create a networking client: %v" , err )
23+ }
24+
25+ createSGOpts := secgroups.CreateOpts {
26+ Name : "sg-test-01" ,
27+ Description : "desc" ,
28+ }
29+ t .Logf ("Attempting to create sg: %s" , createSGOpts .Name )
30+
31+ sg , err := secgroups .Create (clientCompute , createSGOpts ).Extract ()
32+ th .AssertNoErr (t , err )
33+
34+ optsEchoReply := rules.CreateOpts {
35+ Description : "ICMP echo reply" ,
36+ SecGroupID : sg .ID ,
37+ PortRangeMin : pointerto .Int (0 ),
38+ PortRangeMax : pointerto .Int (0 ),
39+ Direction : "ingress" ,
40+ EtherType : "IPv4" ,
41+ Protocol : "ICMP" ,
42+ }
43+ log .Print ("[DEBUG] Create OpenTelekomCloud Neutron ICMP echo reply Security Group Rule" )
44+ echoReply , err := rules .Create (clientNetworking , optsEchoReply ).Extract ()
45+ th .AssertNoErr (t , err )
46+
47+ getEchoReply , err := rules .Get (clientNetworking , echoReply .ID ).Extract ()
48+ th .AssertNoErr (t , err )
49+ th .AssertEquals (t , * getEchoReply .PortRangeMin , 0 )
50+ th .AssertEquals (t , * getEchoReply .PortRangeMax , 0 )
51+
52+ optsAll := rules.CreateOpts {
53+ Description : "ICMP all" ,
54+ SecGroupID : sg .ID ,
55+ PortRangeMin : nil ,
56+ PortRangeMax : nil ,
57+ Direction : "ingress" ,
58+ EtherType : "IPv4" ,
59+ Protocol : "ICMP" ,
60+ }
61+ log .Print ("[DEBUG] Create OpenTelekomCloud Neutron ICMP All Security Group Rule" )
62+ all , err := rules .Create (clientNetworking , optsAll ).Extract ()
63+ th .AssertNoErr (t , err )
64+
65+ getAll , err := rules .Get (clientNetworking , all .ID ).Extract ()
66+ th .AssertNoErr (t , err )
67+ th .AssertEquals (t , getAll .PortRangeMin , (* int )(nil ))
68+ th .AssertEquals (t , getAll .PortRangeMax , (* int )(nil ))
69+
70+ optsEcho := rules.CreateOpts {
71+ Description : "ICMP echo" ,
72+ SecGroupID : sg .ID ,
73+ PortRangeMin : pointerto .Int (8 ),
74+ PortRangeMax : pointerto .Int (0 ),
75+ Direction : "ingress" ,
76+ EtherType : "IPv4" ,
77+ Protocol : "ICMP" ,
78+ }
79+ log .Print ("[DEBUG] Create OpenTelekomCloud Neutron ICMP Echo Security Group Rule" )
80+ echo , err := rules .Create (clientNetworking , optsEcho ).Extract ()
81+ th .AssertNoErr (t , err )
82+
83+ getEcho , err := rules .Get (clientNetworking , echo .ID ).Extract ()
84+ th .AssertNoErr (t , err )
85+ th .AssertEquals (t , * getEcho .PortRangeMin , 8 )
86+ th .AssertEquals (t , * getEcho .PortRangeMax , 0 )
87+
88+ optsFragment := rules.CreateOpts {
89+ Description : "ICMP Fragment need DF set" ,
90+ SecGroupID : sg .ID ,
91+ PortRangeMin : pointerto .Int (3 ),
92+ PortRangeMax : pointerto .Int (4 ),
93+ Direction : "ingress" ,
94+ EtherType : "IPv4" ,
95+ Protocol : "ICMP" ,
96+ }
97+ log .Print ("[DEBUG] Create OpenTelekomCloud Neutron ICMP Fragment need DF set Security Group Rule" )
98+ fragment , err := rules .Create (clientNetworking , optsFragment ).Extract ()
99+ th .AssertNoErr (t , err )
100+
101+ getFragment , err := rules .Get (clientNetworking , fragment .ID ).Extract ()
102+ th .AssertNoErr (t , err )
103+ th .AssertEquals (t , * getFragment .PortRangeMin , 3 )
104+ th .AssertEquals (t , * getFragment .PortRangeMax , 4 )
105+
106+ t .Cleanup (func () {
107+ secgroups .Delete (clientCompute , sg .ID )
108+ })
109+ }
110+
14111func TestThrottlingSgs (t * testing.T ) {
15112 t .Skip ("please run only manually, long test" )
16113 clientNetworking , err := clients .NewNetworkV2Client ()
0 commit comments