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
This commit is contained in:
Tin Lam 2016-02-21 01:38:51 -06:00
parent 1ddf69a68f
commit 6e380b685b
3 changed files with 13 additions and 13 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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)