@@ -30,16 +30,11 @@ def __init__(self, chassis_gateway_mapping, gateway):
3030 None ))
3131
3232
33- class FakeOVNGatewaySchedulerSbOvnIdl (object ):
34- def __init__ (self , chassis_gateway_mapping ):
35- self .get_all_chassis = mock .Mock (
36- return_value = chassis_gateway_mapping ['Chassis' ])
37-
38-
3933class TestOVNGatewayScheduler (base .BaseTestCase ):
4034
4135 def setUp (self ):
4236 super (TestOVNGatewayScheduler , self ).setUp ()
37+ self .mock_log = mock .patch .object (l3_ovn_scheduler , 'LOG' ).start ()
4338
4439 # Overwritten by derived classes
4540 self .l3_scheduler = None
@@ -82,12 +77,11 @@ def setUp(self):
8277 if chassis in details ['Chassis_Bindings' ]:
8378 details ['Chassis_Bindings' ][chassis ].append ((gw , 0 ))
8479
85- def select (self , chassis_gateway_mapping , gateway_name ):
80+ def select (self , chassis_gateway_mapping , gateway_name , candidates = None ):
8681 nb_idl = FakeOVNGatewaySchedulerNbOvnIdl (chassis_gateway_mapping ,
8782 gateway_name )
88- sb_idl = FakeOVNGatewaySchedulerSbOvnIdl (chassis_gateway_mapping )
89- return self .l3_scheduler .select (nb_idl , sb_idl ,
90- gateway_name )
83+ return self .l3_scheduler .select (nb_idl , gateway_name ,
84+ candidates = candidates )
9185
9286 def filter_existing_chassis (self , * args , ** kwargs ):
9387 return self .l3_scheduler .filter_existing_chassis (
@@ -108,21 +102,33 @@ def setUp(self):
108102 def test_no_chassis_available_for_existing_gateway (self ):
109103 mapping = self .fake_chassis_gateway_mappings ['None' ]
110104 gateway_name = random .choice (list (mapping ['Gateways' ].keys ()))
111- chassis = self .select (mapping , gateway_name )
105+ chassis = self .select (mapping , gateway_name ,
106+ candidates = mapping ['Chassis' ])
112107 self .assertEqual ([ovn_const .OVN_GATEWAY_INVALID_CHASSIS ], chassis )
113108
114109 def test_no_chassis_available_for_new_gateway (self ):
115110 mapping = self .fake_chassis_gateway_mappings ['None' ]
116111 gateway_name = self .new_gateway_name
117- chassis = self .select (mapping , gateway_name )
112+ chassis = self .select (mapping , gateway_name ,
113+ candidates = mapping ['Chassis' ])
118114 self .assertEqual ([ovn_const .OVN_GATEWAY_INVALID_CHASSIS ], chassis )
119115
120116 def test_random_chassis_available_for_new_gateway (self ):
121117 mapping = self .fake_chassis_gateway_mappings ['Multiple1' ]
122118 gateway_name = self .new_gateway_name
123- chassis = self .select (mapping , gateway_name )
119+ chassis = self .select (mapping , gateway_name ,
120+ candidates = mapping ['Chassis' ])
124121 self .assertCountEqual (chassis , mapping .get ('Chassis' ))
125122
123+ def test_no_candidates_provided (self ):
124+ mapping = self .fake_chassis_gateway_mappings ['None' ]
125+ gateway_name = self .new_gateway_name
126+ chassis = self .select (mapping , gateway_name )
127+ self .assertEqual ([ovn_const .OVN_GATEWAY_INVALID_CHASSIS ], chassis )
128+ self .mock_log .warning .assert_called_once_with (
129+ 'Gateway %s was not scheduled on any chassis, no candidates are '
130+ 'available' , gateway_name )
131+
126132 def test_filter_existing_chassis (self ):
127133 # filter_existing_chassis is scheduler independent, but calling
128134 # it from Base class didnt seem right. Also, there is no need to have
@@ -171,19 +177,22 @@ def setUp(self):
171177 def test_no_chassis_available_for_existing_gateway (self ):
172178 mapping = self .fake_chassis_gateway_mappings ['None' ]
173179 gateway_name = random .choice (list (mapping ['Gateways' ].keys ()))
174- chassis = self .select (mapping , gateway_name )
180+ chassis = self .select (mapping , gateway_name ,
181+ candidates = mapping ['Chassis' ])
175182 self .assertEqual ([ovn_const .OVN_GATEWAY_INVALID_CHASSIS ], chassis )
176183
177184 def test_no_chassis_available_for_new_gateway (self ):
178185 mapping = self .fake_chassis_gateway_mappings ['None' ]
179186 gateway_name = self .new_gateway_name
180- chassis = self .select (mapping , gateway_name )
187+ chassis = self .select (mapping , gateway_name ,
188+ candidates = mapping ['Chassis' ])
181189 self .assertEqual ([ovn_const .OVN_GATEWAY_INVALID_CHASSIS ], chassis )
182190
183191 def test_least_loaded_chassis_available_for_new_gateway1 (self ):
184192 mapping = self .fake_chassis_gateway_mappings ['Multiple1' ]
185193 gateway_name = self .new_gateway_name
186- chassis = self .select (mapping , gateway_name )
194+ chassis = self .select (mapping , gateway_name ,
195+ candidates = mapping ['Chassis' ])
187196 self .assertCountEqual (chassis , mapping .get ('Chassis' ))
188197 # least loaded will be the first one in the list,
189198 # networking-ovn will assign highest priority to this first element
@@ -192,28 +201,32 @@ def test_least_loaded_chassis_available_for_new_gateway1(self):
192201 def test_least_loaded_chassis_available_for_new_gateway2 (self ):
193202 mapping = self .fake_chassis_gateway_mappings ['Multiple2' ]
194203 gateway_name = self .new_gateway_name
195- chassis = self .select (mapping , gateway_name )
204+ chassis = self .select (mapping , gateway_name ,
205+ candidates = mapping ['Chassis' ])
196206 # hv1 will have least priority
197207 self .assertEqual (chassis [2 ], 'hv1' )
198208
199209 def test_least_loaded_chassis_available_for_new_gateway3 (self ):
200210 mapping = self .fake_chassis_gateway_mappings ['Multiple3' ]
201211 gateway_name = self .new_gateway_name
202- chassis = self .select (mapping , gateway_name )
212+ chassis = self .select (mapping , gateway_name ,
213+ candidates = mapping ['Chassis' ])
203214 # least loaded chassis will be in the front of the list
204215 self .assertEqual (['hv1' , 'hv3' , 'hv2' ], chassis )
205216
206217 def test_least_loaded_chassis_with_rebalance (self ):
207218 mapping = self .fake_chassis_gateway_mappings ['Multiple4' ]
208219 gateway_name = self .new_gateway_name
209- chassis = self .select (mapping , gateway_name )
220+ chassis = self .select (mapping , gateway_name ,
221+ candidates = mapping ['Chassis' ])
210222 # least loaded chassis will be in the front of the list
211223 self .assertEqual (['hv2' , 'hv1' ], chassis )
212224
213225 def test_existing_chassis_available_for_existing_gateway (self ):
214226 mapping = self .fake_chassis_gateway_mappings ['Multiple1' ]
215227 gateway_name = random .choice (list (mapping ['Gateways' ].keys ()))
216- chassis = self .select (mapping , gateway_name )
228+ chassis = self .select (mapping , gateway_name ,
229+ candidates = mapping ['Chassis' ])
217230 self .assertEqual (ovn_const .MAX_GW_CHASSIS , len (chassis ))
218231
219232 def test__get_chassis_load_by_prios_several_ports (self ):
0 commit comments