def test_reboot_required(self): """ Test that reboot required flag is set when all the required agent parameters are set. """ self.agent._parse_options(["--config-path", self.agent_conf_dir]) # Check that reboot required is false until we set all the params self.assertFalse(self.agent.reboot_required) req = ProvisionRequest() req.datastores = ["ds3", "ds4"] req.stats_plugin_config = StatsPluginConfig() req.stats_plugin_config.enabled = False addr = ServerAddress(host="localhost", port=2345) req.address = addr self.agent.provision(req) # Verify that the bootstrap is still false as zk config is not # specified. self.assertFalse(self.agent.bootstrap_ready) self.assertTrue(self.agent.reboot_required) req = ProvisionRequest() req.datastores = ["ds3", "ds4"] addr = ServerAddress(host="localhost", port=2345) req.address = addr self.agent.provision(req) self.assertTrue(self.agent.reboot_required)
def test_agent_config_update(self): """ Test that updating the config using the RPC struct works """ self.agent._parse_options(["--config-path", self.agent_conf_dir, "--hostname", "localhost", "--port", "1234", "--datastores", "ds1, ds2"]) expected_image_ds = [{"name": "ds3", "used_for_vms": True}] self.assertFalse(self.agent.bootstrap_ready) self.assertTrue(self.agent.provision_ready) self.assertFalse(self.agent.reboot_required) req = ProvisionRequest() req.datastores = ["ds3", "ds4"] req.memory_overcommit = 1.5 req.image_datastores = set([ImageDatastore("ds3", True)]) addr = ServerAddress(host="localhost", port=2345) req.address = addr stats_plugin_config = StatsPluginConfig( stats_store_endpoint="10.0.0.100", stats_store_port=8081, stats_enabled=True) req.stats_plugin_config = stats_plugin_config req.host_id = "host1" req.deployment_id = "deployment1" self.agent.provision(req) assert_that(self.agent.stats_store_endpoint, equal_to("10.0.0.100")) assert_that(self.agent.stats_store_port, equal_to(8081)) assert_that(self.agent.stats_enabled, equal_to(True)) assert_that(self.agent.hostname, equal_to("localhost")) assert_that(self.agent.host_port, equal_to(2345)) assert_that(self.agent.datastores, equal_to(["ds3", "ds4"])) assert_that(self.agent.memory_overcommit, equal_to(1.5)) assert_that(self.agent.image_datastores, equal_to(expected_image_ds)) assert_that(self.agent.host_id, equal_to("host1")) assert_that(self.agent.deployment_id, equal_to("deployment1")) self.assertTrue(self.agent.bootstrap_ready) self.assertTrue(self.agent.reboot_required) # Verify we are able to unset all the configuration. req = ProvisionRequest() self.agent.provision(req) assert_that(self.agent.hostname, equal_to(None)) assert_that(self.agent.host_port, equal_to(8835)) assert_that(self.agent.datastores, equal_to([])) # Unsetting memory overcommit should set it to the default value. self.assertEqual(self.agent.memory_overcommit, 1.0) self.assertFalse(self.agent.bootstrap_ready) assert_that(self.agent.image_datastores, equal_to(expected_image_ds)) assert_that(self.agent.host_id, equal_to(None)) # Test an invalid update and verify the update doesn't have any side # effects. req = ProvisionRequest() req.datastores = ["ds3", "ds4"] req.memory_overcommit = 0.5 addr = ServerAddress(host="localhost", port=2345) req.address = addr # Verify an exception is raised. self.assertRaises(InvalidConfig, self.agent.provision, req) assert_that(self.agent.hostname, equal_to(None)) assert_that(self.agent.host_port, equal_to(8835)) assert_that(self.agent.datastores, equal_to([])) self.assertFalse(self.agent.bootstrap_ready) self.assertEqual(self.agent.memory_overcommit, 1.0)