summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJohn Garbutt <john@johngarbutt.com>2013-05-13 15:53:22 +0100
committerGerrit Code Review <review@openstack.org>2013-05-30 08:40:11 +0000
commitde2da83cfb895febcef58b972ed3ed0dff9ac064 (patch)
tree3b8f6f9bfe5752fb3348acbbe7d83c333514fd91 /nova/tests
parent783b0e836d9ba0630d4745a6457144fac6dfa9f0 (diff)
downloadnova-de2da83cfb895febcef58b972ed3ed0dff9ac064.tar.gz
nova-de2da83cfb895febcef58b972ed3ed0dff9ac064.tar.xz
nova-de2da83cfb895febcef58b972ed3ed0dff9ac064.zip
compute.api call conductor ComputeTaskManager for live-migrate
Before the compute api called the scheduler to perform live migrate. This change makes the compute api call the conductor, which in turn calls the scheduler. For those not using the conductor service, this does not add any extra rpc calls. This change in control flow means we can look to move live-migrate more related rpc calls into the conductor from both schduler driver and compute manager. part of blueprint live-migration-to-conductor Change-Id: I081c5e090921d69878d044839616a48f198ecb7d
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_admin_actions.py67
-rw-r--r--nova/tests/conductor/test_conductor.py68
2 files changed, 99 insertions, 36 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py
index 2efb6fe5a..5e64bdf94 100644
--- a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py
+++ b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py
@@ -22,10 +22,10 @@ from nova.api.openstack import compute
from nova.api.openstack.compute.contrib import admin_actions
from nova.compute import api as compute_api
from nova.compute import vm_states
+from nova.conductor import api as conductor_api
from nova import context
from nova import exception
from nova.openstack.common import jsonutils
-from nova.scheduler import rpcapi as scheduler_rpcapi
from nova import test
from nova.tests.api.openstack import fakes
@@ -140,16 +140,15 @@ class AdminActionsTest(test.TestCase):
task_state, expected_task_state):
return None
- def fake_scheduler_api_live_migration(self, context, dest,
- block_migration=False,
- disk_over_commit=False, instance=None,
- instance_id=None, topic=None):
+ def fake_migrate_server(self, context, instance,
+ scheduler_hint, live, rebuild, flavor,
+ block_migration, disk_over_commit):
return None
self.stubs.Set(compute_api.API, 'update', fake_update)
- self.stubs.Set(scheduler_rpcapi.SchedulerAPI,
- 'live_migration',
- fake_scheduler_api_live_migration)
+ self.stubs.Set(conductor_api.ComputeTaskAPI,
+ 'migrate_server',
+ fake_migrate_server)
res = req.get_response(app)
self.assertEqual(res.status_int, 202)
@@ -194,16 +193,15 @@ class AdminActionsTest(test.TestCase):
task_state, expected_task_state):
return None
- def fake_scheduler_api_live_migration(context, dest,
- block_migration=False,
- disk_over_commit=False, instance=None,
- instance_id=None, topic=None):
+ def fake_migrate_server(self, context, instance,
+ scheduler_hint, live, rebuild, flavor,
+ block_migration, disk_over_commit):
raise exception.ComputeServiceUnavailable(host='host')
self.stubs.Set(compute_api.API, 'update', fake_update)
- self.stubs.Set(scheduler_rpcapi.SchedulerAPI,
- 'live_migration',
- fake_scheduler_api_live_migration)
+ self.stubs.Set(conductor_api.ComputeTaskAPI,
+ 'migrate_server',
+ fake_migrate_server)
res = req.get_response(app)
self.assertEqual(res.status_int, 400)
@@ -232,16 +230,15 @@ class AdminActionsTest(test.TestCase):
task_state, expected_task_state):
return None
- def fake_scheduler_api_live_migration(context, dest,
- block_migration=False,
- disk_over_commit=False, instance=None,
- instance_id=None, topic=None):
+ def fake_migrate_server(self, context, instance,
+ scheduler_hint, live, rebuild, flavor,
+ block_migration, disk_over_commit):
raise exception.InvalidHypervisorType()
self.stubs.Set(compute_api.API, 'update', fake_update)
- self.stubs.Set(scheduler_rpcapi.SchedulerAPI,
- 'live_migration',
- fake_scheduler_api_live_migration)
+ self.stubs.Set(conductor_api.ComputeTaskAPI,
+ 'migrate_server',
+ fake_migrate_server)
res = req.get_response(app)
self.assertEqual(res.status_int, 400)
@@ -270,16 +267,15 @@ class AdminActionsTest(test.TestCase):
task_state, expected_task_state):
return None
- def fake_scheduler_api_live_migration(context, dest,
- block_migration=False,
- disk_over_commit=False, instance=None,
- instance_id=None, topic=None):
+ def fake_migrate_server(self, context, instance,
+ scheduler_hint, live, rebuild, flavor,
+ block_migration, disk_over_commit):
raise exception.UnableToMigrateToSelf(self.UUID, host='host')
self.stubs.Set(compute_api.API, 'update', fake_update)
- self.stubs.Set(scheduler_rpcapi.SchedulerAPI,
- 'live_migration',
- fake_scheduler_api_live_migration)
+ self.stubs.Set(conductor_api.ComputeTaskAPI,
+ 'migrate_server',
+ fake_migrate_server)
res = req.get_response(app)
self.assertEqual(res.status_int, 400)
@@ -308,16 +304,15 @@ class AdminActionsTest(test.TestCase):
task_state, expected_task_state):
return None
- def fake_scheduler_api_live_migration(context, dest,
- block_migration=False,
- disk_over_commit=False, instance=None,
- instance_id=None, topic=None):
+ def fake_migrate_server(self, context, instance,
+ scheduler_hint, live, rebuild, flavor,
+ block_migration, disk_over_commit):
raise exception.DestinationHypervisorTooOld()
self.stubs.Set(compute_api.API, 'update', fake_update)
- self.stubs.Set(scheduler_rpcapi.SchedulerAPI,
- 'live_migration',
- fake_scheduler_api_live_migration)
+ self.stubs.Set(conductor_api.ComputeTaskAPI,
+ 'migrate_server',
+ fake_migrate_server)
res = req.get_response(app)
self.assertEqual(res.status_int, 400)
diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py
index c578e6de2..28d0074f2 100644
--- a/nova/tests/conductor/test_conductor.py
+++ b/nova/tests/conductor/test_conductor.py
@@ -1166,3 +1166,71 @@ class ConductorPolicyTest(test.TestCase):
for key in keys:
self.assertTrue(hasattr(instance, key))
+
+
+class _BaseTaskTestCase(object):
+ def setUp(self):
+ super(_BaseTaskTestCase, self).setUp()
+ self.user_id = 'fake'
+ self.project_id = 'fake'
+ self.context = FakeContext(self.user_id, self.project_id)
+
+ def test_migrate_server(self):
+ self.mox.StubOutWithMock(self.conductor_manager.scheduler_rpcapi,
+ 'live_migration')
+ self.conductor_manager.scheduler_rpcapi.live_migration(self.context,
+ 'block_migration', 'disk_over_commit', 'instance', 'destination')
+ self.mox.ReplayAll()
+ self.conductor.migrate_server(self.context, 'instance',
+ {'host': 'destination'}, True, False, None, 'block_migration',
+ 'disk_over_commit')
+
+ def test_migrate_server_fails_with_non_live(self):
+ self.assertRaises(NotImplementedError, self.conductor.migrate_server,
+ self.context, None, None, False, False, None, None, None)
+
+ def test_migrate_server_fails_with_rebuild(self):
+ self.assertRaises(NotImplementedError, self.conductor.migrate_server,
+ self.context, None, None, True, True, None, None, None)
+
+ def test_migrate_server_fails_with_flavor(self):
+ self.assertRaises(NotImplementedError, self.conductor.migrate_server,
+ self.context, None, None, True, False, "dummy", None, None)
+
+
+class ConductorTaskTestCase(_BaseTaskTestCase, test.TestCase):
+ """ComputeTaskManager Tests."""
+ def setUp(self):
+ super(ConductorTaskTestCase, self).setUp()
+ self.conductor = conductor_manager.ComputeTaskManager()
+ self.conductor_manager = self.conductor
+
+
+class ConductorTaskRPCAPITestCase(_BaseTaskTestCase, test.TestCase):
+ """Conductor compute_task RPC namespace Tests."""
+ def setUp(self):
+ super(ConductorTaskRPCAPITestCase, self).setUp()
+ self.conductor_service = self.start_service(
+ 'conductor', manager='nova.conductor.manager.ConductorManager')
+ self.conductor = conductor_rpcapi.ComputeTaskAPI()
+ service_manager = self.conductor_service.manager
+ self.conductor_manager = service_manager.compute_task_mgr
+
+
+class ConductorTaskAPITestCase(_BaseTaskTestCase, test.TestCase):
+ """Compute task API Tests."""
+ def setUp(self):
+ super(ConductorTaskAPITestCase, self).setUp()
+ self.conductor_service = self.start_service(
+ 'conductor', manager='nova.conductor.manager.ConductorManager')
+ self.conductor = conductor_api.ComputeTaskAPI()
+ service_manager = self.conductor_service.manager
+ self.conductor_manager = service_manager.compute_task_mgr
+
+
+class ConductorLocalComputeTaskAPITestCase(ConductorTaskAPITestCase):
+ """Conductor LocalComputeTaskAPI Tests."""
+ def setUp(self):
+ super(ConductorLocalComputeTaskAPITestCase, self).setUp()
+ self.conductor = conductor_api.LocalComputeTaskAPI()
+ self.conductor_manager = self.conductor._manager._target