@@ -38,6 +38,8 @@ class TestCreateSubnetPool(TestSubnetPool):
3838 # The new subnet pool to create.
3939 _subnet_pool = network_fakes .FakeSubnetPool .create_one_subnet_pool ()
4040
41+ _address_scope = network_fakes .FakeAddressScope .create_one_address_scope ()
42+
4143 columns = (
4244 'address_scope_id' ,
4345 'default_prefixlen' ,
@@ -76,6 +78,9 @@ def setUp(self):
7678 # Get the command object to test
7779 self .cmd = subnet_pool .CreateSubnetPool (self .app , self .namespace )
7880
81+ self .network .find_address_scope = mock .Mock (
82+ return_value = self ._address_scope )
83+
7984 # Set identity client. And get a shortcut to Identity client.
8085 identity_client = identity_fakes_v3 .FakeIdentityv3Client (
8186 endpoint = fakes .AUTH_URL ,
@@ -193,6 +198,29 @@ def test_create_project_domain(self):
193198 self .assertEqual (self .columns , columns )
194199 self .assertEqual (self .data , data )
195200
201+ def test_create_address_scope_option (self ):
202+ arglist = [
203+ '--pool-prefix' , '10.0.10.0/24' ,
204+ '--address-scope' , self ._address_scope .id ,
205+ self ._subnet_pool .name ,
206+ ]
207+ verifylist = [
208+ ('prefixes' , ['10.0.10.0/24' ]),
209+ ('address_scope' , self ._address_scope .id ),
210+ ('name' , self ._subnet_pool .name ),
211+ ]
212+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
213+
214+ columns , data = (self .cmd .take_action (parsed_args ))
215+
216+ self .network .create_subnet_pool .assert_called_once_with (** {
217+ 'prefixes' : ['10.0.10.0/24' ],
218+ 'address_scope_id' : self ._address_scope .id ,
219+ 'name' : self ._subnet_pool .name ,
220+ })
221+ self .assertEqual (self .columns , columns )
222+ self .assertEqual (self .data , data )
223+
196224
197225class TestDeleteSubnetPool (TestSubnetPool ):
198226
@@ -301,6 +329,8 @@ class TestSetSubnetPool(TestSubnetPool):
301329 # The subnet_pool to set.
302330 _subnet_pool = network_fakes .FakeSubnetPool .create_one_subnet_pool ()
303331
332+ _address_scope = network_fakes .FakeAddressScope .create_one_address_scope ()
333+
304334 def setUp (self ):
305335 super (TestSetSubnetPool , self ).setUp ()
306336
@@ -309,21 +339,24 @@ def setUp(self):
309339 self .network .find_subnet_pool = mock .Mock (
310340 return_value = self ._subnet_pool )
311341
342+ self .network .find_address_scope = mock .Mock (
343+ return_value = self ._address_scope )
344+
312345 # Get the command object to test
313346 self .cmd = subnet_pool .SetSubnetPool (self .app , self .namespace )
314347
315348 def test_set_this (self ):
316349 arglist = [
317- self ._subnet_pool .name ,
318350 '--name' , 'noob' ,
319351 '--default-prefix-length' , '8' ,
320352 '--min-prefix-length' , '8' ,
353+ self ._subnet_pool .name ,
321354 ]
322355 verifylist = [
323- ('subnet_pool' , self ._subnet_pool .name ),
324356 ('name' , 'noob' ),
325357 ('default_prefix_length' , '8' ),
326358 ('min_prefix_length' , '8' ),
359+ ('subnet_pool' , self ._subnet_pool .name ),
327360 ]
328361 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
329362
@@ -340,15 +373,15 @@ def test_set_this(self):
340373
341374 def test_set_that (self ):
342375 arglist = [
343- self ._subnet_pool .name ,
344376 '--pool-prefix' , '10.0.1.0/24' ,
345377 '--pool-prefix' , '10.0.2.0/24' ,
346378 '--max-prefix-length' , '16' ,
379+ self ._subnet_pool .name ,
347380 ]
348381 verifylist = [
349- ('subnet_pool' , self ._subnet_pool .name ),
350382 ('prefixes' , ['10.0.1.0/24' , '10.0.2.0/24' ]),
351383 ('max_prefix_length' , '16' ),
384+ ('subnet_pool' , self ._subnet_pool .name ),
352385 ]
353386 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
354387
@@ -374,17 +407,73 @@ def test_set_nothing(self):
374407
375408 def test_set_len_negative (self ):
376409 arglist = [
377- self ._subnet_pool .name ,
378410 '--max-prefix-length' , '-16' ,
411+ self ._subnet_pool .name ,
379412 ]
380413 verifylist = [
381- ('subnet_pool' , self ._subnet_pool .name ),
382414 ('max_prefix_length' , '-16' ),
415+ ('subnet_pool' , self ._subnet_pool .name ),
383416 ]
384417
385418 self .assertRaises (argparse .ArgumentTypeError , self .check_parser ,
386419 self .cmd , arglist , verifylist )
387420
421+ def test_set_address_scope (self ):
422+ arglist = [
423+ '--address-scope' , self ._address_scope .id ,
424+ self ._subnet_pool .name ,
425+ ]
426+ verifylist = [
427+ ('address_scope' , self ._address_scope .id ),
428+ ('subnet_pool' , self ._subnet_pool .name ),
429+ ]
430+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
431+
432+ result = self .cmd .take_action (parsed_args )
433+
434+ attrs = {
435+ 'address_scope_id' : self ._address_scope .id ,
436+ }
437+ self .network .update_subnet_pool .assert_called_once_with (
438+ self ._subnet_pool , ** attrs )
439+ self .assertIsNone (result )
440+
441+ def test_set_no_address_scope (self ):
442+ arglist = [
443+ '--no-address-scope' ,
444+ self ._subnet_pool .name ,
445+ ]
446+ verifylist = [
447+ ('no_address_scope' , True ),
448+ ('subnet_pool' , self ._subnet_pool .name ),
449+ ]
450+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
451+
452+ result = self .cmd .take_action (parsed_args )
453+
454+ attrs = {
455+ 'address_scope_id' : None ,
456+ }
457+ self .network .update_subnet_pool .assert_called_once_with (
458+ self ._subnet_pool , ** attrs )
459+ self .assertIsNone (result )
460+
461+ def test_set_no_address_scope_conflict (self ):
462+ arglist = [
463+ '--address-scope' , self ._address_scope .id ,
464+ '--no-address-scope' ,
465+ self ._subnet_pool .name ,
466+ ]
467+ verifylist = [
468+ ('address_scope' , self ._address_scope .id ),
469+ ('no_address_scope' , True ),
470+ ('subnet_pool' , self ._subnet_pool .name ),
471+ ]
472+
473+ # Exclusive arguments will conflict here.
474+ self .assertRaises (tests_utils .ParserException , self .check_parser ,
475+ self .cmd , arglist , verifylist )
476+
388477
389478class TestShowSubnetPool (TestSubnetPool ):
390479
0 commit comments