Check compute_nodes before live-migrate and migrate

If compute_nodes < 2, live-migrate and migrate must be fail.
So it is necessary to add the check of compute_nodes.

Change-Id: I30e16133cf45b77ab0b71bc411e67421dda31d13
This commit is contained in:
lianghao 2018-12-07 10:52:45 +08:00
parent 0779d36493
commit 172542c0b7
2 changed files with 29 additions and 4 deletions

View File

@ -773,16 +773,25 @@ class NovaScenario(scenario.OpenStackScenario):
@atomic.action_timer("nova.live_migrate")
def _live_migrate(self, server, block_migration=False,
disk_over_commit=False, skip_host_check=False):
disk_over_commit=False, skip_compute_nodes_check=False,
skip_host_check=False):
"""Run live migration of the given server.
:param server: Server object
:param block_migration: Specifies the migration type
:param disk_over_commit: Specifies whether to overcommit migrated
instance or not
:param skip_compute_nodes_check: Specifies whether to verify the number
of compute nodes
:param skip_host_check: Specifies whether to verify the targeted host
availability
"""
if not skip_compute_nodes_check:
compute_nodes = len(self._list_hypervisors())
if compute_nodes < 2:
raise exceptions.RallyException("Less than 2 compute nodes,"
" skipping Live Migration")
server_admin = self.admin_clients("nova").servers.get(server.id)
host_pre_migrate = getattr(server_admin, "OS-EXT-SRV-ATTR:host")
server_admin.live_migrate(block_migration=block_migration,
@ -804,13 +813,22 @@ class NovaScenario(scenario.OpenStackScenario):
"but instance did not change host: %s" % host_pre_migrate)
@atomic.action_timer("nova.migrate")
def _migrate(self, server, skip_host_check=False):
def _migrate(self, server, skip_compute_nodes_check=False,
skip_host_check=False):
"""Run migration of the given server.
:param server: Server object
:param skip_compute_nodes_check: Specifies whether to verify the number
of compute nodes
:param skip_host_check: Specifies whether to verify the targeted host
availability
"""
if not skip_compute_nodes_check:
compute_nodes = len(self._list_hypervisors())
if compute_nodes < 2:
raise exceptions.RallyException("Less than 2 compute nodes,"
" skipping Migration")
server_admin = self.admin_clients("nova").servers.get(server.id)
host_pre_migrate = getattr(server_admin, "OS-EXT-SRV-ATTR:host")
server_admin.migrate()

View File

@ -742,6 +742,7 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
nova_scenario._live_migrate(self.server,
block_migration=False,
disk_over_commit=False,
skip_compute_nodes_check=True,
skip_host_check=True)
self.mock_wait_for_status.mock.assert_called_once_with(
@ -760,7 +761,8 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
setattr(fake_server, "OS-EXT-SRV-ATTR:host", "a1")
self.clients("nova").servers.get(return_value=fake_server)
nova_scenario = utils.NovaScenario(context=self.context)
nova_scenario._migrate(fake_server, skip_host_check=True)
nova_scenario._migrate(fake_server, skip_compute_nodes_check=True,
skip_host_check=True)
self.mock_wait_for_status.mock.assert_called_once_with(
fake_server,
@ -774,7 +776,12 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
self.assertRaises(rally_exceptions.RallyException,
nova_scenario._migrate,
fake_server, skip_host_check=False)
fake_server, skip_compute_nodes_check=True,
skip_host_check=False)
self.assertRaises(rally_exceptions.RallyException,
nova_scenario._migrate,
fake_server, skip_compute_nodes_check=False,
skip_host_check=True)
def test__add_server_secgroups(self):
server = mock.Mock()