23
23
from common .mode import Mode
24
24
from common .service_name import ServiceName
25
25
from common .state import State
26
- from gen .agent .ttypes import ProvisionRequest
26
+ from gen .agent .ttypes import ProvisionRequest , UpdateConfigRequest
27
27
from gen .common .ttypes import ServerAddress
28
28
from gen .resource .ttypes import ImageDatastore
29
29
from gen .stats .plugin .ttypes import StatsPluginConfig
@@ -138,7 +138,7 @@ def test_agent_config_update(self):
138
138
139
139
req .host_id = "host1"
140
140
req .deployment_id = "deployment1"
141
- self .agent .update_config (req )
141
+ self .agent .provision (req )
142
142
143
143
assert_that (self .agent .stats_store_endpoint , equal_to ("10.0.0.100" ))
144
144
assert_that (self .agent .stats_store_port , equal_to (8081 ))
@@ -158,7 +158,7 @@ def test_agent_config_update(self):
158
158
# Verify we are able to unset all the configuration.
159
159
req = ProvisionRequest ()
160
160
161
- self .agent .update_config (req )
161
+ self .agent .provision (req )
162
162
assert_that (self .agent .hostname , equal_to (None ))
163
163
assert_that (self .agent .host_port , equal_to (8835 ))
164
164
assert_that (self .agent .datastores , equal_to ([]))
@@ -178,7 +178,7 @@ def test_agent_config_update(self):
178
178
req .address = addr
179
179
180
180
# Verify an exception is raised.
181
- self .assertRaises (InvalidConfig , self .agent .update_config , req )
181
+ self .assertRaises (InvalidConfig , self .agent .provision , req )
182
182
assert_that (self .agent .hostname , equal_to (None ))
183
183
assert_that (self .agent .host_port , equal_to (8835 ))
184
184
assert_that (self .agent .datastores , equal_to ([]))
@@ -200,7 +200,7 @@ def test_reboot_required(self):
200
200
req .stats_plugin_config .enabled = False
201
201
addr = ServerAddress (host = "localhost" , port = 2345 )
202
202
req .address = addr
203
- self .agent .update_config (req )
203
+ self .agent .provision (req )
204
204
# Verify that the bootstrap is still false as zk config is not
205
205
# specified.
206
206
self .assertFalse (self .agent .bootstrap_ready )
@@ -210,7 +210,7 @@ def test_reboot_required(self):
210
210
req .datastores = ["ds3" , "ds4" ]
211
211
addr = ServerAddress (host = "localhost" , port = 2345 )
212
212
req .address = addr
213
- self .agent .update_config (req )
213
+ self .agent .provision (req )
214
214
self .assertTrue (self .agent .reboot_required )
215
215
216
216
def test_thrift_thread_settings (self ):
@@ -253,15 +253,27 @@ def test_load_image_datastores(self):
253
253
{"name" : "ds2" , "used_for_vms" : False },
254
254
]
255
255
req = ProvisionRequest ()
256
- req .datastores = ["ds1" , "ds2" , "ds3" ]
257
- req .image_datastores = set ([ImageDatastore ("ds1" , True ),
258
- ImageDatastore ("ds2" , False )])
259
- self .agent .update_config (req )
260
- self .agent ._persist_config ()
256
+ req .datastores = ["ds1" , "ds2" , "ds3" , "ds4" ]
257
+ req .image_datastores = {ImageDatastore ("ds1" , True ), ImageDatastore ("ds2" , False )}
258
+ self .agent .provision (req )
261
259
self .agent ._load_config ()
262
- assert_that (self .agent .datastores , equal_to (["ds1" , "ds2" , "ds3" ]))
263
- assert_that (self .agent .image_datastores ,
264
- contains_inanyorder (* expected_image_ds ))
260
+ assert_that (self .agent .datastores , equal_to (["ds1" , "ds2" , "ds3" , "ds4" ]))
261
+ assert_that (self .agent .image_datastores , contains_inanyorder (* expected_image_ds ))
262
+
263
+ imageds_callback = mock .MagicMock ()
264
+ self .agent .on_config_change (self .agent .IMAGE_DATASTORES , imageds_callback )
265
+ req = UpdateConfigRequest ()
266
+ req .image_datastores = {ImageDatastore ("ds1" , True ), ImageDatastore ("ds2" , False ), ImageDatastore ("ds3" , True )}
267
+ self .agent .update (req )
268
+ expected_image_ds = [
269
+ {"name" : "ds1" , "used_for_vms" : True },
270
+ {"name" : "ds2" , "used_for_vms" : False },
271
+ {"name" : "ds3" , "used_for_vms" : True },
272
+ ]
273
+ assert_that (self .agent .image_datastores , contains_inanyorder (* expected_image_ds ))
274
+ imageds_callback .assert_called_once_with (self .agent .image_datastores )
275
+ self .agent ._load_config ()
276
+ assert_that (self .agent .image_datastores , contains_inanyorder (* expected_image_ds ))
265
277
266
278
def test_config_change (self ):
267
279
# Test cpu_overcommit and memory_overcommit config change
@@ -273,10 +285,9 @@ def test_config_change(self):
273
285
provision .memory_overcommit = 6.0
274
286
self .agent .on_config_change (self .agent .CPU_OVERCOMMIT , cpu_callback )
275
287
self .agent .on_config_change (self .agent .MEMORY_OVERCOMMIT , mem_callback )
276
- self .agent .update_config (provision )
288
+ self .agent .provision (provision )
277
289
cpu_callback .assert_called_once_with (5.0 )
278
290
mem_callback .assert_called_once_with (6.0 )
279
291
280
-
281
292
if __name__ == "__main__" :
282
293
unittest .main ()
0 commit comments