From e0cf82323ab19bbcbad88aa75045b3e55692f071 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Wed, 14 Sep 2011 23:11:03 +0000 Subject: Adding progress --- nova/tests/api/openstack/contrib/test_createserverext.py | 6 ++++-- nova/tests/api/openstack/test_server_actions.py | 1 + nova/tests/api/openstack/test_servers.py | 15 ++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/contrib/test_createserverext.py b/nova/tests/api/openstack/contrib/test_createserverext.py index 078b72d67..24f756d5b 100644 --- a/nova/tests/api/openstack/contrib/test_createserverext.py +++ b/nova/tests/api/openstack/contrib/test_createserverext.py @@ -51,7 +51,8 @@ INSTANCE = { "uuid": FAKE_UUID, "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0), "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0), - "security_groups": [{"id": 1, "name": "test"}] + "security_groups": [{"id": 1, "name": "test"}], + "progress": 0 } @@ -115,7 +116,8 @@ class CreateserverextTest(test.TestCase): 'user_id': 'fake', 'project_id': 'fake', 'created_at': "", - 'updated_at': ""}] + 'updated_at': "", + 'progress': 0}] def set_admin_password(self, *args, **kwargs): pass diff --git a/nova/tests/api/openstack/test_server_actions.py b/nova/tests/api/openstack/test_server_actions.py index b9ef41465..f6e45e9c7 100644 --- a/nova/tests/api/openstack/test_server_actions.py +++ b/nova/tests/api/openstack/test_server_actions.py @@ -91,6 +91,7 @@ def stub_instance(id, metadata=None, image_ref="10", flavor_id="1", "access_ip_v6": "", "uuid": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "virtual_interfaces": [], + "progress": 0, } instance["fixed_ips"] = { diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index f0a1c5ce5..f654bf209 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -156,7 +156,7 @@ def stub_instance(id, user_id='fake', project_id='fake', private_address=None, vm_state=None, task_state=None, reservation_id="", uuid=FAKE_UUID, image_ref="10", flavor_id="1", interfaces=None, name=None, key_name='', - access_ipv4=None, access_ipv6=None): + access_ipv4=None, access_ipv6=None, progress=0): metadata = [] metadata.append(InstanceMetadata(key='seq', value=id)) @@ -216,7 +216,8 @@ def stub_instance(id, user_id='fake', project_id='fake', private_address=None, "access_ip_v4": access_ipv4, "access_ip_v6": access_ipv6, "uuid": uuid, - "virtual_interfaces": interfaces} + "virtual_interfaces": interfaces, + "progress": progress} instance["fixed_ips"] = { "address": private_address, @@ -509,7 +510,8 @@ class ServersTest(test.TestCase): }, ] new_return_server = return_server_with_attributes( - interfaces=interfaces, vm_state=vm_states.ACTIVE) + interfaces=interfaces, vm_state=vm_states.ACTIVE, + progress=100) self.stubs.Set(nova.db.api, 'instance_get', new_return_server) req = webob.Request.blank('/v1.1/fake/servers/1') @@ -606,7 +608,7 @@ class ServersTest(test.TestCase): ] new_return_server = return_server_with_attributes( interfaces=interfaces, vm_state=vm_states.ACTIVE, - image_ref=image_ref, flavor_id=flavor_id) + image_ref=image_ref, flavor_id=flavor_id, progress=100) self.stubs.Set(nova.db.api, 'instance_get', new_return_server) req = webob.Request.blank('/v1.1/fake/servers/1') @@ -1488,6 +1490,7 @@ class ServersTest(test.TestCase): "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0), "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0), "config_drive": self.config_drive, + "progress": 0 } def server_update(context, id, params): @@ -3689,7 +3692,8 @@ class ServersViewBuilderV11Test(test.TestCase): "accessIPv6": "fead::1234", #"address": , #"floating_ips": [{"address":ip} for ip in public_addresses]} - "uuid": "deadbeef-feed-edee-beef-d0ea7beefedd"} + "uuid": "deadbeef-feed-edee-beef-d0ea7beefedd", + "progress": 0} return instance @@ -3812,6 +3816,7 @@ class ServersViewBuilderV11Test(test.TestCase): def test_build_server_detail_active_status(self): #set the power state of the instance to running self.instance['vm_state'] = vm_states.ACTIVE + self.instance['progress'] = 100 image_bookmark = "http://localhost/images/5" flavor_bookmark = "http://localhost/flavors/1" expected_server = { -- cgit From 6f3ae6e1e5453330e14807348f6e3f6587877946 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Fri, 16 Sep 2011 00:22:31 +0000 Subject: Allowing resizes to the same machine --- nova/tests/test_compute.py | 2 +- nova/tests/test_xenapi.py | 72 +++++++++++++++++++++++++++------------------- nova/tests/xenapi/stubs.py | 4 +-- 3 files changed, 45 insertions(+), 33 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 4d463572b..1ecd26ce6 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -568,7 +568,7 @@ class ComputeTestCase(test.TestCase): pass self.stubs.Set(self.compute.driver, 'finish_migration', fake) - self.stubs.Set(self.compute.driver, 'revert_migration', fake) + self.stubs.Set(self.compute.driver, 'finish_revert_migration', fake) self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake) self.compute.run_instance(self.context, instance_id) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 4a83d139e..4541a21cb 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -76,7 +76,7 @@ class XenAPIVolumeTestCase(test.TestCase): db_fakes.stub_out_db_instance_api(self.stubs) stubs.stub_out_get_target(self.stubs) xenapi_fake.reset() - self.values = {'id': 1, + self.instance_values = {'id': 1, 'project_id': self.user_id, 'user_id': 'fake', 'image_ref': 1, @@ -132,7 +132,7 @@ class XenAPIVolumeTestCase(test.TestCase): stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests) conn = xenapi_conn.get_connection(False) volume = self._create_volume() - instance = db.instance_create(self.context, self.values) + instance = db.instance_create(self.context, self.instance_values) vm = xenapi_fake.create_vm(instance.name, 'Running') result = conn.attach_volume(instance.name, volume['id'], '/dev/sdc') @@ -152,7 +152,7 @@ class XenAPIVolumeTestCase(test.TestCase): stubs.FakeSessionForVolumeFailedTests) conn = xenapi_conn.get_connection(False) volume = self._create_volume() - instance = db.instance_create(self.context, self.values) + instance = db.instance_create(self.context, self.instance_values) xenapi_fake.create_vm(instance.name, 'Running') self.assertRaises(Exception, conn.attach_volume, @@ -369,7 +369,7 @@ class XenAPIVMTestCase(test.TestCase): create_record=True, empty_dns=False): stubs.stubout_loopingcall_start(self.stubs) if create_record: - values = {'id': instance_id, + instance_values = {'id': instance_id, 'project_id': self.project_id, 'user_id': self.user_id, 'image_ref': image_ref, @@ -378,7 +378,7 @@ class XenAPIVMTestCase(test.TestCase): 'instance_type_id': instance_type_id, 'os_type': os_type, 'architecture': architecture} - instance = db.instance_create(self.context, values) + instance = db.instance_create(self.context, instance_values) else: instance = db.instance_get(self.context, instance_id) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': True}, @@ -622,28 +622,28 @@ class XenAPIVMTestCase(test.TestCase): # Ensure that it will not unrescue a non-rescued instance. self.assertRaises(Exception, conn.unrescue, instance, None) - def test_revert_migration(self): + def test_finish_revert_migration(self): instance = self._create_instance() class VMOpsMock(): def __init__(self): - self.revert_migration_called = False + self.finish_revert_migration_called = False - def revert_migration(self, instance): - self.revert_migration_called = True + def finish_revert_migration(self, instance): + self.finish_revert_migration_called = True stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) conn._vmops = VMOpsMock() - conn.revert_migration(instance) - self.assertTrue(conn._vmops.revert_migration_called) + conn.finish_revert_migration(instance) + self.assertTrue(conn._vmops.finish_revert_migration_called) def _create_instance(self, instance_id=1, spawn=True): """Creates and spawns a test instance.""" stubs.stubout_loopingcall_start(self.stubs) - values = { + instance_values = { 'id': instance_id, 'project_id': self.project_id, 'user_id': self.user_id, @@ -653,7 +653,7 @@ class XenAPIVMTestCase(test.TestCase): 'instance_type_id': '3', # m1.large 'os_type': 'linux', 'architecture': 'x86-64'} - instance = db.instance_create(self.context, values) + instance = db.instance_create(self.context, instance_values) network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False}, {'broadcast': '192.168.0.255', 'dns': ['192.168.0.1'], @@ -731,7 +731,7 @@ class XenAPIMigrateInstance(test.TestCase): self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) - self.values = {'id': 1, + self.instance_values = {'id': 1, 'project_id': self.project_id, 'user_id': self.user_id, 'image_ref': 1, @@ -742,22 +742,34 @@ class XenAPIMigrateInstance(test.TestCase): 'os_type': 'linux', 'architecture': 'x86-64'} + migration_values = { + 'source_compute': 'nova-compute', + 'dest_compute': 'nova-compute', + 'dest_host': '10.127.5.114', + 'status': 'post-migrating', + 'instance_uuid': '15f23e6a-cc6e-4d22-b651-d9bdaac316f7', + 'old_instance_type_id': 5, + 'new_instance_type_id': 1 + } + self.migration = db.migration_create( + context.get_admin_context(), migration_values) + fake_utils.stub_out_utils_execute(self.stubs) stubs.stub_out_migration_methods(self.stubs) stubs.stubout_get_this_vm_uuid(self.stubs) glance_stubs.stubout_glance_client(self.stubs) def test_migrate_disk_and_power_off(self): - instance = db.instance_create(self.context, self.values) + instance = db.instance_create(self.context, self.instance_values) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) conn.migrate_disk_and_power_off(instance, '127.0.0.1') def test_revert_migrate(self): - instance = db.instance_create(self.context, self.values) + instance = db.instance_create(self.context, self.instance_values) self.called = False self.fake_vm_start_called = False - self.fake_revert_migration_called = False + self.fake_finish_revert_migration_called = False def fake_vm_start(*args, **kwargs): self.fake_vm_start_called = True @@ -765,13 +777,13 @@ class XenAPIMigrateInstance(test.TestCase): def fake_vdi_resize(*args, **kwargs): self.called = True - def fake_revert_migration(*args, **kwargs): - self.fake_revert_migration_called = True + def fake_finish_revert_migration(*args, **kwargs): + self.fake_finish_revert_migration_called = True self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) self.stubs.Set(vmops.VMOps, '_start', fake_vm_start) - self.stubs.Set(vmops.VMOps, 'revert_migration', fake_revert_migration) + self.stubs.Set(vmops.VMOps, 'finish_revert_migration', fake_finish_revert_migration) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) @@ -790,17 +802,17 @@ class XenAPIMigrateInstance(test.TestCase): 'label': 'fake', 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3})] - conn.finish_migration(self.context, instance, + conn.finish_migration(self.context, self.migration, instance, dict(base_copy='hurr', cow='durr'), network_info, resize_instance=True) self.assertEqual(self.called, True) self.assertEqual(self.fake_vm_start_called, True) - conn.revert_migration(instance) - self.assertEqual(self.fake_revert_migration_called, True) + conn.finish_revert_migration(instance) + self.assertEqual(self.fake_finish_revert_migration_called, True) def test_finish_migrate(self): - instance = db.instance_create(self.context, self.values) + instance = db.instance_create(self.context, self.instance_values) self.called = False self.fake_vm_start_called = False @@ -831,7 +843,7 @@ class XenAPIMigrateInstance(test.TestCase): 'label': 'fake', 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3})] - conn.finish_migration(self.context, instance, + conn.finish_migration(self.context, self.migration, instance, dict(base_copy='hurr', cow='durr'), network_info, resize_instance=True) self.assertEqual(self.called, True) @@ -840,8 +852,8 @@ class XenAPIMigrateInstance(test.TestCase): def test_finish_migrate_no_local_storage(self): tiny_type_id = \ instance_types.get_instance_type_by_name('m1.tiny')['id'] - self.values.update({'instance_type_id': tiny_type_id, 'local_gb': 0}) - instance = db.instance_create(self.context, self.values) + self.instance_values.update({'instance_type_id': tiny_type_id, 'local_gb': 0}) + instance = db.instance_create(self.context, self.instance_values) def fake_vdi_resize(*args, **kwargs): raise Exception("This shouldn't be called") @@ -865,12 +877,12 @@ class XenAPIMigrateInstance(test.TestCase): 'label': 'fake', 'mac': 'DE:AD:BE:EF:00:00', 'rxtx_cap': 3})] - conn.finish_migration(self.context, instance, + conn.finish_migration(self.context, self.migration, instance, dict(base_copy='hurr', cow='durr'), network_info, resize_instance=True) def test_finish_migrate_no_resize_vdi(self): - instance = db.instance_create(self.context, self.values) + instance = db.instance_create(self.context, self.instance_values) def fake_vdi_resize(*args, **kwargs): raise Exception("This shouldn't be called") @@ -896,7 +908,7 @@ class XenAPIMigrateInstance(test.TestCase): 'rxtx_cap': 3})] # Resize instance would be determined by the compute call - conn.finish_migration(self.context, instance, + conn.finish_migration(self.context, self.migration, instance, dict(base_copy='hurr', cow='durr'), network_info, resize_instance=False) diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 647a4c1df..a1f6a7788 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -297,7 +297,7 @@ class FakeSessionForMigrationTests(fake.SessionBase): def stub_out_migration_methods(stubs): - def fake_get_snapshot(self, instance): + def fake_create_snapshot(self, instance): return 'vm_ref', dict(image='foo', snap='bar') @classmethod @@ -327,7 +327,7 @@ def stub_out_migration_methods(stubs): stubs.Set(vmops.VMOps, '_destroy', fake_destroy) stubs.Set(vm_utils.VMHelper, 'scan_default_sr', fake_sr) stubs.Set(vm_utils.VMHelper, 'scan_sr', fake_sr) - stubs.Set(vmops.VMOps, '_get_snapshot', fake_get_snapshot) + stubs.Set(vmops.VMOps, '_create_snapshot', fake_create_snapshot) stubs.Set(vm_utils.VMHelper, 'get_vdi_for_vm_safely', fake_get_vdi) stubs.Set(xenapi_conn.XenAPISession, 'wait_for_task', lambda x, y, z: None) stubs.Set(vm_utils.VMHelper, 'get_sr_path', fake_get_sr_path) -- cgit From 80462f3e446964560198e77af6903d84a05cab87 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Fri, 16 Sep 2011 11:17:44 -0500 Subject: Fixing tests, PEP8 failures --- nova/tests/test_xenapi.py | 6 ++++-- nova/tests/xenapi/stubs.py | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 4541a21cb..6b5bb240c 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -783,7 +783,8 @@ class XenAPIMigrateInstance(test.TestCase): self.stubs.Set(stubs.FakeSessionForMigrationTests, "VDI_resize_online", fake_vdi_resize) self.stubs.Set(vmops.VMOps, '_start', fake_vm_start) - self.stubs.Set(vmops.VMOps, 'finish_revert_migration', fake_finish_revert_migration) + self.stubs.Set(vmops.VMOps, 'finish_revert_migration', + fake_finish_revert_migration) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) stubs.stubout_loopingcall_start(self.stubs) @@ -852,7 +853,8 @@ class XenAPIMigrateInstance(test.TestCase): def test_finish_migrate_no_local_storage(self): tiny_type_id = \ instance_types.get_instance_type_by_name('m1.tiny')['id'] - self.instance_values.update({'instance_type_id': tiny_type_id, 'local_gb': 0}) + self.instance_values.update({'instance_type_id': tiny_type_id, + 'local_gb': 0}) instance = db.instance_create(self.context, self.instance_values) def fake_vdi_resize(*args, **kwargs): diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index a1f6a7788..aee279920 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -295,6 +295,9 @@ class FakeSessionForMigrationTests(fake.SessionBase): vm['is_control_domain'] = False vm['domid'] = random.randrange(1, 1 << 16) + def VM_set_name_label(self, *args): + pass + def stub_out_migration_methods(stubs): def fake_create_snapshot(self, instance): -- cgit From 10f7128079942b14e7627fa34b93e2e0ae05058f Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Fri, 16 Sep 2011 18:06:27 +0000 Subject: Adding migration progress --- nova/tests/test_virt_drivers.py | 3 ++- nova/tests/test_xenapi.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 440d3401b..244e4e803 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -181,7 +181,8 @@ class _VirtDriverTestCase(test.TestCase): instance_ref = test_utils.get_test_instance() network_info = test_utils.get_test_network_info() self.connection.spawn(self.ctxt, instance_ref, network_info) - self.connection.migrate_disk_and_power_off(instance_ref, 'dest_host') + self.connection.migrate_disk_and_power_off( + self.ctxt, instance_ref, 'dest_host') @catch_notimplementederror def test_pause(self): diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 6b5bb240c..a8a03b56b 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -763,7 +763,7 @@ class XenAPIMigrateInstance(test.TestCase): instance = db.instance_create(self.context, self.instance_values) stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests) conn = xenapi_conn.get_connection(False) - conn.migrate_disk_and_power_off(instance, '127.0.0.1') + conn.migrate_disk_and_power_off(self.context, instance, '127.0.0.1') def test_revert_migrate(self): instance = db.instance_create(self.context, self.instance_values) -- cgit