1818from openstackclient .tests .compute .v2 import fakes as compute_fakes
1919from openstackclient .tests import fakes
2020from openstackclient .tests .identity .v2_0 import fakes as identity_fakes
21+ from openstackclient .tests import utils
2122
2223
2324security_group_id = '11'
2425security_group_name = 'wide-open'
2526security_group_description = 'nothing but net'
2627
2728security_group_rule_id = '1'
29+ security_group_rule_cidr = '0.0.0.0/0'
2830
2931SECURITY_GROUP = {
3032 'id' : security_group_id ,
3739 'id' : security_group_rule_id ,
3840 'group' : {},
3941 'ip_protocol' : 'tcp' ,
40- 'ip_range' : '0.0.0.0/0' ,
42+ 'ip_range' : { 'cidr' : security_group_rule_cidr } ,
4143 'parent_group_id' : security_group_id ,
4244 'from_port' : 0 ,
4345 'to_port' : 0 ,
4749 'id' : security_group_rule_id ,
4850 'group' : {},
4951 'ip_protocol' : 'icmp' ,
50- 'ip_range' : '0.0.0.0/0' ,
52+ 'ip_range' : { 'cidr' : security_group_rule_cidr } ,
5153 'parent_group_id' : security_group_id ,
5254 'from_port' : - 1 ,
5355 'to_port' : - 1 ,
@@ -115,7 +117,8 @@ def test_security_group_rule_create_no_options(self):
115117 'tcp' ,
116118 0 ,
117119 0 ,
118- '0.0.0.0/0' ,
120+ security_group_rule_cidr ,
121+ None ,
119122 )
120123
121124 collist = (
@@ -131,7 +134,7 @@ def test_security_group_rule_create_no_options(self):
131134 {},
132135 security_group_rule_id ,
133136 'tcp' ,
134- '' ,
137+ security_group_rule_cidr ,
135138 security_group_id ,
136139 '0:0' ,
137140 )
@@ -166,7 +169,8 @@ def test_security_group_rule_create_ftp(self):
166169 'tcp' ,
167170 20 ,
168171 21 ,
169- '0.0.0.0/0' ,
172+ security_group_rule_cidr ,
173+ None ,
170174 )
171175
172176 collist = (
@@ -182,7 +186,7 @@ def test_security_group_rule_create_ftp(self):
182186 {},
183187 security_group_rule_id ,
184188 'tcp' ,
185- '' ,
189+ security_group_rule_cidr ,
186190 security_group_id ,
187191 '20:21' ,
188192 )
@@ -192,6 +196,7 @@ def test_security_group_rule_create_ssh(self):
192196 sg_rule = copy .deepcopy (SECURITY_GROUP_RULE )
193197 sg_rule ['from_port' ] = 22
194198 sg_rule ['to_port' ] = 22
199+ sg_rule ['group' ] = {'name' : security_group_name }
195200 self .sg_rules_mock .create .return_value = FakeSecurityGroupRuleResource (
196201 None ,
197202 sg_rule ,
@@ -201,10 +206,12 @@ def test_security_group_rule_create_ssh(self):
201206 arglist = [
202207 security_group_name ,
203208 '--dst-port' , '22' ,
209+ '--src-group' , security_group_id ,
204210 ]
205211 verifylist = [
206212 ('group' , security_group_name ),
207213 ('dst_port' , (22 , 22 )),
214+ ('src_group' , security_group_id ),
208215 ]
209216 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
210217
@@ -217,7 +224,8 @@ def test_security_group_rule_create_ssh(self):
217224 'tcp' ,
218225 22 ,
219226 22 ,
220- '0.0.0.0/0' ,
227+ security_group_rule_cidr ,
228+ security_group_id ,
221229 )
222230
223231 collist = (
@@ -230,10 +238,10 @@ def test_security_group_rule_create_ssh(self):
230238 )
231239 self .assertEqual (collist , columns )
232240 datalist = (
233- {},
241+ {'name' : security_group_name },
234242 security_group_rule_id ,
235243 'tcp' ,
236- '' ,
244+ security_group_rule_cidr ,
237245 security_group_id ,
238246 '22:22' ,
239247 )
@@ -267,7 +275,8 @@ def test_security_group_rule_create_udp(self):
267275 'udp' ,
268276 0 ,
269277 0 ,
270- '0.0.0.0/0' ,
278+ security_group_rule_cidr ,
279+ None ,
271280 )
272281
273282 collist = (
@@ -283,26 +292,31 @@ def test_security_group_rule_create_udp(self):
283292 {},
284293 security_group_rule_id ,
285294 'udp' ,
286- '' ,
295+ security_group_rule_cidr ,
287296 security_group_id ,
288297 '0:0' ,
289298 )
290299 self .assertEqual (datalist , data )
291300
292301 def test_security_group_rule_create_icmp (self ):
302+ sg_rule_cidr = '10.0.2.0/24'
303+ sg_rule = copy .deepcopy (SECURITY_GROUP_RULE_ICMP )
304+ sg_rule ['ip_range' ] = {'cidr' : sg_rule_cidr }
293305 self .sg_rules_mock .create .return_value = FakeSecurityGroupRuleResource (
294306 None ,
295- copy . deepcopy ( SECURITY_GROUP_RULE_ICMP ) ,
307+ sg_rule ,
296308 loaded = True ,
297309 )
298310
299311 arglist = [
300312 security_group_name ,
301313 '--proto' , 'ICMP' ,
314+ '--src-ip' , sg_rule_cidr ,
302315 ]
303316 verifylist = [
304317 ('group' , security_group_name ),
305318 ('proto' , 'ICMP' ),
319+ ('src_ip' , sg_rule_cidr )
306320 ]
307321 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
308322
@@ -315,7 +329,8 @@ def test_security_group_rule_create_icmp(self):
315329 'ICMP' ,
316330 - 1 ,
317331 - 1 ,
318- '0.0.0.0/0' ,
332+ sg_rule_cidr ,
333+ None ,
319334 )
320335
321336 collist = (
@@ -331,8 +346,19 @@ def test_security_group_rule_create_icmp(self):
331346 {},
332347 security_group_rule_id ,
333348 'icmp' ,
334- '' ,
349+ sg_rule_cidr ,
335350 security_group_id ,
336351 '' ,
337352 )
338353 self .assertEqual (datalist , data )
354+
355+ def test_security_group_rule_create_src_invalid (self ):
356+ arglist = [
357+ security_group_name ,
358+ '--proto' , 'ICMP' ,
359+ '--src-ip' , security_group_rule_cidr ,
360+ '--src-group' , security_group_id ,
361+ ]
362+
363+ self .assertRaises (utils .ParserException ,
364+ self .check_parser , self .cmd , arglist , [])
0 commit comments