@@ -614,9 +614,15 @@ def setUp(self):
614
614
self .mixin = l3_attrs_db .ExtraAttributesMixin ()
615
615
directory .add_plugin (plugin_constants .L3 , self .mixin )
616
616
self .ctx = context .get_admin_context ()
617
- self .router = l3_models .Router ()
618
- with db_api .CONTEXT_WRITER .using (self .ctx ):
619
- self .ctx .session .add (self .router )
617
+ self .router = self ._new_router (self .ctx )
618
+
619
+ @staticmethod
620
+ @db_api .CONTEXT_WRITER
621
+ def _new_router (ctx ):
622
+ router = l3_models .Router ()
623
+ ctx .session .add (router )
624
+ l3_attrs_db .ExtraAttributesMixin .add_extra_attr (ctx , router )
625
+ return router
620
626
621
627
def _get_default_api_values (self ):
622
628
return {k : v .get ('transform_from_db' , lambda x : x )(v ['default' ])
@@ -625,8 +631,7 @@ def _get_default_api_values(self):
625
631
def test_set_extra_attr_key_bad (self ):
626
632
with testtools .ExpectedException (RuntimeError ):
627
633
with db_api .CONTEXT_WRITER .using (self .ctx ):
628
- self .mixin .set_extra_attr_value (self .ctx , self .router ,
629
- 'bad' , 'value' )
634
+ self .mixin .set_extra_attr_value (self .router , 'bad' , 'value' )
630
635
631
636
def test__extend_extra_router_dict_defaults (self ):
632
637
rdict = {}
@@ -635,9 +640,8 @@ def test__extend_extra_router_dict_defaults(self):
635
640
636
641
def test_set_attrs_and_extend (self ):
637
642
with db_api .CONTEXT_WRITER .using (self .ctx ):
638
- self .mixin .set_extra_attr_value (self .ctx , self .router ,
639
- 'ha_vr_id' , 99 )
640
- self .mixin .set_extra_attr_value (self .ctx , self .router ,
643
+ self .mixin .set_extra_attr_value (self .router , 'ha_vr_id' , 99 )
644
+ self .mixin .set_extra_attr_value (self .router ,
641
645
'availability_zone_hints' ,
642
646
['x' , 'y' , 'z' ])
643
647
expected = self ._get_default_api_values ()
@@ -647,7 +651,7 @@ def test_set_attrs_and_extend(self):
647
651
self .mixin ._extend_extra_router_dict (rdict , self .router )
648
652
self .assertEqual (expected , rdict )
649
653
650
- self .mixin .set_extra_attr_value (self .ctx , self . router ,
654
+ self .mixin .set_extra_attr_value (self .router ,
651
655
'availability_zone_hints' ,
652
656
['z' , 'y' , 'z' ])
653
657
expected ['availability_zone_hints' ] = ['z' , 'y' , 'z' ]
0 commit comments