From 6e380b685bd5e6b8feb9365799da3e48867652fa Mon Sep 17 00:00:00 2001 From: Tin Lam Date: Sun, 21 Feb 2016 01:38:51 -0600 Subject: [PATCH] Update nova service state The primitive ChangeNovaServiceState allows us to change the state of the nova-compute by calling nova api. The state of a nova-compute can be ENABLED or DISABLED, however in the current implementation we use OFFLINE and ONLINE. Update the code to use ENABLED or DISABLED. Change-Id: If3d9726bc5ae980b66c7fd4c5b7986f89d8bc690 Closes-Bug: #1523891 --- watcher/applier/actions/change_nova_service_state.py | 8 ++++---- .../strategy/strategies/basic_consolidation.py | 6 +++--- .../actions/test_change_nova_service_state.py | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/watcher/applier/actions/change_nova_service_state.py b/watcher/applier/actions/change_nova_service_state.py index 5eabc494a..37ce6ab1e 100644 --- a/watcher/applier/actions/change_nova_service_state.py +++ b/watcher/applier/actions/change_nova_service_state.py @@ -52,17 +52,17 @@ class ChangeNovaServiceState(base.BaseAction): def execute(self): target_state = None - if self.state == hstate.HypervisorState.OFFLINE.value: + if self.state == hstate.HypervisorState.DISABLED.value: target_state = False - elif self.state == hstate.HypervisorState.ONLINE.value: + elif self.state == hstate.HypervisorState.ENABLED.value: target_state = True return self._nova_manage_service(target_state) def revert(self): target_state = None - if self.state == hstate.HypervisorState.OFFLINE.value: + if self.state == hstate.HypervisorState.DISABLED.value: target_state = True - elif self.state == hstate.HypervisorState.ONLINE.value: + elif self.state == hstate.HypervisorState.ENABLED.value: target_state = False return self._nova_manage_service(target_state) diff --git a/watcher/decision_engine/strategy/strategies/basic_consolidation.py b/watcher/decision_engine/strategy/strategies/basic_consolidation.py index 02887d16f..1a91962df 100644 --- a/watcher/decision_engine/strategy/strategies/basic_consolidation.py +++ b/watcher/decision_engine/strategy/strategies/basic_consolidation.py @@ -398,7 +398,7 @@ class BasicConsolidation(base.BaseStrategy): self.add_change_service_state(mig_src_hypervisor. uuid, hyper_state.HypervisorState. - OFFLINE.value) + DISABLED.value) self.number_of_released_nodes += 1 def calculate_num_migrations(self, sorted_vms, current_model, @@ -455,10 +455,10 @@ class BasicConsolidation(base.BaseStrategy): count = current_model.get_mapping(). \ get_node_vms_from_id(hypervisor_id) if len(count) == 0: - if hypervisor.state == hyper_state.HypervisorState.ONLINE: + if hypervisor.state == hyper_state.HypervisorState.ENABLED: self.add_change_service_state(hypervisor_id, hyper_state.HypervisorState. - OFFLINE.value) + DISABLED.value) while self.get_allowed_migration_attempts() >= unsuccessful_migration: if not first_migration: diff --git a/watcher/tests/applier/actions/test_change_nova_service_state.py b/watcher/tests/applier/actions/test_change_nova_service_state.py index e8810f237..4ed09b428 100644 --- a/watcher/tests/applier/actions/test_change_nova_service_state.py +++ b/watcher/tests/applier/actions/test_change_nova_service_state.py @@ -52,7 +52,7 @@ class TestChangeNovaServiceState(base.TestCase): self.input_parameters = { baction.BaseAction.RESOURCE_ID: "compute-1", - "state": hstate.HypervisorState.ONLINE.value, + "state": hstate.HypervisorState.ENABLED.value, } self.action = change_nova_service_state.ChangeNovaServiceState() self.action.input_parameters = self.input_parameters @@ -60,13 +60,13 @@ class TestChangeNovaServiceState(base.TestCase): def test_parameters_down(self): self.action.input_parameters = { baction.BaseAction.RESOURCE_ID: "compute-1", - self.action.STATE: hstate.HypervisorState.OFFLINE.value} + self.action.STATE: hstate.HypervisorState.DISABLED.value} self.assertEqual(True, self.action.validate_parameters()) def test_parameters_up(self): self.action.input_parameters = { baction.BaseAction.RESOURCE_ID: "compute-1", - self.action.STATE: hstate.HypervisorState.ONLINE.value} + self.action.STATE: hstate.HypervisorState.ENABLED.value} self.assertEqual(True, self.action.validate_parameters()) def test_parameters_exception_wrong_state(self): @@ -81,7 +81,7 @@ class TestChangeNovaServiceState(base.TestCase): def test_parameters_resource_id_empty(self): self.action.input_parameters = { - self.action.STATE: hstate.HypervisorState.ONLINE.value, + self.action.STATE: hstate.HypervisorState.ENABLED.value, } exc = self.assertRaises( voluptuous.Invalid, self.action.validate_parameters) @@ -122,7 +122,7 @@ class TestChangeNovaServiceState(base.TestCase): def test_execute_change_service_state_with_disable_target(self): self.action.input_parameters["state"] = ( - hstate.HypervisorState.OFFLINE.value) + hstate.HypervisorState.DISABLED.value) self.action.execute() self.m_helper_cls.assert_called_once_with(osc=self.m_osc) @@ -138,7 +138,7 @@ class TestChangeNovaServiceState(base.TestCase): def test_revert_change_service_state_with_disable_target(self): self.action.input_parameters["state"] = ( - hstate.HypervisorState.OFFLINE.value) + hstate.HypervisorState.DISABLED.value) self.action.revert() self.m_helper_cls.assert_called_once_with(osc=self.m_osc)