From a432d5a3f4bd9cb6156c304ce051383cf185d040 Mon Sep 17 00:00:00 2001 From: Andy Southgate Date: Fri, 21 Jan 2011 16:06:32 +0000 Subject: [PATCH 01/11] OS-55: Added unit test for network injection via xenstore --- nova/tests/test_xenapi.py | 44 +++++++++++++++++++++++++++++++++----- nova/tests/xenapi/stubs.py | 15 +++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 9f5b266f3..2a32845d3 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -50,6 +50,7 @@ class XenAPIVolumeTestCase(test.TestCase): FLAGS.xenapi_connection_url = 'test_url' FLAGS.xenapi_connection_password = 'test_pass' db_fakes.stub_out_db_instance_api(self.stubs) + db_fakes.stub_out_db_network_api(self.stubs) stubs.stub_out_get_target(self.stubs) xenapi_fake.reset() self.values = {'name': 1, 'id': 1, @@ -158,6 +159,7 @@ class XenAPIVMTestCase(test.TestCase): xenapi_fake.reset() xenapi_fake.create_local_srs() db_fakes.stub_out_db_instance_api(self.stubs) + db_fakes.stub_out_db_network_api(self.stubs) xenapi_fake.create_network('fake', FLAGS.flat_network_bridge) stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) stubs.stubout_get_this_vm_uuid(self.stubs) @@ -211,7 +213,7 @@ class XenAPIVMTestCase(test.TestCase): check() - def check_vm_record(self, conn): + def check_vm_record(self, conn, check_injection = False): instances = conn.list_instances() self.assertEquals(instances, [1]) @@ -219,10 +221,10 @@ class XenAPIVMTestCase(test.TestCase): vm_info = conn.get_info(1) # Get XenAPI record for VM - vms = [rec for ref, rec + vms = [(ref, rec) for ref, rec in xenapi_fake.get_all_records('VM').iteritems() if not rec['is_control_domain']] - vm = vms[0] + vm_ref, vm = vms[0] # Check that m1.large above turned into the right thing. instance_type = instance_types.INSTANCE_TYPES['m1.large'] @@ -242,8 +244,35 @@ class XenAPIVMTestCase(test.TestCase): # Check that the VM is running according to XenAPI. self.assertEquals(vm['power_state'], 'Running') + + if check_injection: + xenstore_data = xenapi_fake.VM_get_xenstore_data(vm_ref) + key_prefix = 'vm-data/vif/22_33_2A_B3_CC_DD/tcpip/' + tcpip_data = dict([(k.replace(key_prefix, ''), v) + for k, v in xenstore_data.iteritems() if k.startswith(key_prefix) ]) - def _test_spawn(self, image_id, kernel_id, ramdisk_id): + self.assertEquals(tcpip_data, { + 'BroadcastAddress/data/0': '10.0.0.255', + 'BroadcastAddress/name': 'BroadcastAddress', + 'BroadcastAddress/type': 'multi_sz', + 'DefaultGateway/data/0': '10.0.0.1', + 'DefaultGateway/name': 'DefaultGateway', + 'DefaultGateway/type': 'multi_sz', + 'EnableDhcp/data': '0', + 'EnableDhcp/name': 'EnableDhcp', + 'EnableDhcp/type': 'dword', + 'IPAddress/data/0': '10.0.0.3', + 'IPAddress/name': 'IPAddress', + 'IPAddress/type': 'multi_sz', + 'NameServer/data': '10.0.0.2', + 'NameServer/name': 'NameServer', + 'NameServer/type': 'string', + 'SubnetMask/data/0': '255.255.255.0', + 'SubnetMask/name': 'SubnetMask', + 'SubnetMask/type': 'multi_sz' + }) + + def _test_spawn(self, image_id, kernel_id, ramdisk_id, check_injection = False): stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) values = {'name': 1, 'id': 1, @@ -258,7 +287,7 @@ class XenAPIVMTestCase(test.TestCase): conn = xenapi_conn.get_connection(False) instance = db.instance_create(values) conn.spawn(instance) - self.check_vm_record(conn) + self.check_vm_record(conn, check_injection = check_injection) def test_spawn_raw_objectstore(self): FLAGS.xenapi_image_service = 'objectstore' @@ -276,6 +305,11 @@ class XenAPIVMTestCase(test.TestCase): FLAGS.xenapi_image_service = 'glance' self._test_spawn(1, 2, 3) + def test_spawn_netinject(self): + FLAGS.xenapi_image_service = 'glance' + db_fakes.stub_out_db_network_api(self.stubs, injected = True) + self._test_spawn(1, 2, 3, check_injection = True) + def tearDown(self): super(XenAPIVMTestCase, self).tearDown() self.manager.delete_project(self.project) diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 624995ada..3cfc8e5f9 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -171,6 +171,21 @@ class FakeSessionForVMTests(fake.SessionBase): def VM_destroy(self, session_ref, vm_ref): fake.destroy_vm(vm_ref) + def VM_get_VIFs(self, session_ref, vm_ref): + return (['0', '1', '2']) + + def VIF_get_device(self, session_ref, vif_ref): + return ('1', '0', '2')[int(vif_ref)] + + def VIF_get_MAC(self, session_ref, vif_ref): + return ( + '11:22:2a:b3:CC:dd', + '22:33:2a:b3:CC:dd', + '44:44:2a:b3:CC:dd' + )[int(vif_ref)] + + def VM_add_to_xenstore_data(self, session_ref, vm_ref, key, value): + fake.VM_add_to_xenstore_data(vm_ref, key, value) class FakeSessionForVolumeTests(fake.SessionBase): """ Stubs out a XenAPISession for Volume tests """ From 293d9f1fffa62439895a8d02f45246ceea162746 Mon Sep 17 00:00:00 2001 From: Andy Southgate Date: Fri, 21 Jan 2011 16:23:30 +0000 Subject: [PATCH 02/11] OS55: pylint fixes --- nova/tests/test_xenapi.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 2a32845d3..c94aeefd1 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -249,7 +249,8 @@ class XenAPIVMTestCase(test.TestCase): xenstore_data = xenapi_fake.VM_get_xenstore_data(vm_ref) key_prefix = 'vm-data/vif/22_33_2A_B3_CC_DD/tcpip/' tcpip_data = dict([(k.replace(key_prefix, ''), v) - for k, v in xenstore_data.iteritems() if k.startswith(key_prefix) ]) + for k, v in xenstore_data.iteritems() + if k.startswith(key_prefix) ]) self.assertEquals(tcpip_data, { 'BroadcastAddress/data/0': '10.0.0.255', @@ -272,7 +273,8 @@ class XenAPIVMTestCase(test.TestCase): 'SubnetMask/type': 'multi_sz' }) - def _test_spawn(self, image_id, kernel_id, ramdisk_id, check_injection = False): + def _test_spawn(self, image_id, kernel_id, ramdisk_id, + check_injection = False): stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) values = {'name': 1, 'id': 1, From 6a730580dc07074e77fb4431feb5d2d380c5d49d Mon Sep 17 00:00:00 2001 From: Andy Southgate Date: Mon, 24 Jan 2011 19:04:25 +0000 Subject: [PATCH 03/11] OS-55: PEP8 fixes --- nova/tests/test_xenapi.py | 19 +++++++++---------- nova/tests/xenapi/stubs.py | 10 +++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index c94aeefd1..f7f7102a8 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -213,7 +213,7 @@ class XenAPIVMTestCase(test.TestCase): check() - def check_vm_record(self, conn, check_injection = False): + def check_vm_record(self, conn, check_injection=False): instances = conn.list_instances() self.assertEquals(instances, [1]) @@ -244,13 +244,13 @@ class XenAPIVMTestCase(test.TestCase): # Check that the VM is running according to XenAPI. self.assertEquals(vm['power_state'], 'Running') - + if check_injection: xenstore_data = xenapi_fake.VM_get_xenstore_data(vm_ref) key_prefix = 'vm-data/vif/22_33_2A_B3_CC_DD/tcpip/' tcpip_data = dict([(k.replace(key_prefix, ''), v) for k, v in xenstore_data.iteritems() - if k.startswith(key_prefix) ]) + if k.startswith(key_prefix)]) self.assertEquals(tcpip_data, { 'BroadcastAddress/data/0': '10.0.0.255', @@ -270,11 +270,10 @@ class XenAPIVMTestCase(test.TestCase): 'NameServer/type': 'string', 'SubnetMask/data/0': '255.255.255.0', 'SubnetMask/name': 'SubnetMask', - 'SubnetMask/type': 'multi_sz' - }) + 'SubnetMask/type': 'multi_sz'}) def _test_spawn(self, image_id, kernel_id, ramdisk_id, - check_injection = False): + check_injection=False): stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) values = {'name': 1, 'id': 1, @@ -289,7 +288,7 @@ class XenAPIVMTestCase(test.TestCase): conn = xenapi_conn.get_connection(False) instance = db.instance_create(values) conn.spawn(instance) - self.check_vm_record(conn, check_injection = check_injection) + self.check_vm_record(conn, check_injection=check_injection) def test_spawn_raw_objectstore(self): FLAGS.xenapi_image_service = 'objectstore' @@ -309,9 +308,9 @@ class XenAPIVMTestCase(test.TestCase): def test_spawn_netinject(self): FLAGS.xenapi_image_service = 'glance' - db_fakes.stub_out_db_network_api(self.stubs, injected = True) - self._test_spawn(1, 2, 3, check_injection = True) - + db_fakes.stub_out_db_network_api(self.stubs, injected=True) + self._test_spawn(1, 2, 3, check_injection=True) + def tearDown(self): super(XenAPIVMTestCase, self).tearDown() self.manager.delete_project(self.project) diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 3cfc8e5f9..027855592 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -173,20 +173,20 @@ class FakeSessionForVMTests(fake.SessionBase): def VM_get_VIFs(self, session_ref, vm_ref): return (['0', '1', '2']) - + def VIF_get_device(self, session_ref, vif_ref): return ('1', '0', '2')[int(vif_ref)] - + def VIF_get_MAC(self, session_ref, vif_ref): return ( '11:22:2a:b3:CC:dd', '22:33:2a:b3:CC:dd', - '44:44:2a:b3:CC:dd' - )[int(vif_ref)] - + '44:44:2a:b3:CC:dd')[int(vif_ref)] + def VM_add_to_xenstore_data(self, session_ref, vm_ref, key, value): fake.VM_add_to_xenstore_data(vm_ref, key, value) + class FakeSessionForVolumeTests(fake.SessionBase): """ Stubs out a XenAPISession for Volume tests """ def __init__(self, uri): From a0bced6d0e6e1352acb188e6ac5014d4f4fc5f96 Mon Sep 17 00:00:00 2001 From: Andy Southgate Date: Wed, 26 Jan 2011 19:58:45 +0000 Subject: [PATCH 04/11] OS-55: Added a test case for XenAPI file-based network injection OS-55: Stubbed out utils.execute for all XenAPI VM tests, including command simulation where necessary --- nova/tests/test_xenapi.py | 83 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index f7f7102a8..8af47da63 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -18,11 +18,14 @@ Test suite for XenAPI """ +import os +import re import stubout from nova import db from nova import context from nova import flags +from nova import log as logging from nova import test from nova import utils from nova.auth import manager @@ -35,6 +38,9 @@ from nova.virt.xenapi.vmops import SimpleDH from nova.tests.db import fakes as db_fakes from nova.tests.xenapi import stubs from nova.tests.glance import stubs as glance_stubs +from nova.tests import fake_utils + +LOG = logging.getLogger('nova.tests.test_xenapi') FLAGS = flags.FLAGS @@ -166,6 +172,7 @@ class XenAPIVMTestCase(test.TestCase): stubs.stubout_stream_disk(self.stubs) glance_stubs.stubout_glance_client(self.stubs, glance_stubs.FakeGlance) + fake_utils.stub_out_utils_execute(self.stubs) self.conn = xenapi_conn.get_connection(False) def test_list_instances_0(self): @@ -306,10 +313,84 @@ class XenAPIVMTestCase(test.TestCase): FLAGS.xenapi_image_service = 'glance' self._test_spawn(1, 2, 3) - def test_spawn_netinject(self): + def test_spawn_netinject_file(self): FLAGS.xenapi_image_service = 'glance' db_fakes.stub_out_db_network_api(self.stubs, injected=True) + + self._tee_executed = False + + def _tee_handler(cmd, input, *ignore_args): + self.assertNotEqual(input, None) + + config = [line.strip() for line in input.split("\n")] + + # Find the start of eth0 configuration and check it + index = config.index('auto eth0') + self.assertEquals(config[index + 1:index + 8], [ + 'iface eth0 inet static', + 'address 10.0.0.3', + 'netmask 255.255.255.0', + 'broadcast 10.0.0.255', + 'gateway 10.0.0.1', + 'dns-nameservers 10.0.0.2', + '']) + + self._tee_executed = True + + return '', '' + + fake_utils.fake_execute_set_repliers([ + # Capture the sudo tee .../etc/network/interfaces command + (r'(sudo\s+)?tee.*interfaces', _tee_handler), + ]) self._test_spawn(1, 2, 3, check_injection=True) + self.assertTrue(self._tee_executed) + + def test_spawn_netinject_xenstore(self): + FLAGS.xenapi_image_service = 'glance' + db_fakes.stub_out_db_network_api(self.stubs, injected=True) + + self._tee_executed = False + + def _mount_handler(cmd, *ignore_args): + # When mounting, create real files under the mountpoint to simulate + # files in the mounted filesystem + + # RegExp extracts the path of the mountpoint + match = re.match(r'(sudo\s+)?mount[^"]*"[^"]*"\s+"([^"]*)"', cmd) + self._tmpdir = match.group(2) + LOG.debug(_('Creating files in %s to simulate guest agent' % + self._tmpdir)) + os.makedirs(os.path.join(self._tmpdir, 'usr', 'sbin')) + # Touch the file using open + open(os.path.join(self._tmpdir, 'usr', 'sbin', + 'xe-update-networking'), 'w').close() + return '', '' + + def _umount_handler(cmd, *ignore_args): + # Umount would normall make files in the m,ounted filesystem + # disappear, so do that here + LOG.debug(_('Removing simulated guest agent files in %s' % + self._tmpdir)) + os.remove(os.path.join(self._tmpdir, 'usr', 'sbin', + 'xe-update-networking')) + os.rmdir(os.path.join(self._tmpdir, 'usr', 'sbin')) + os.rmdir(os.path.join(self._tmpdir, 'usr')) + return '', '' + + def _tee_handler(cmd, input, *ignore_args): + self._tee_executed = True + return '', '' + + fake_utils.fake_execute_set_repliers([ + (r'(sudo\s+)?mount', _mount_handler), + (r'(sudo\s+)?umount', _umount_handler), + (r'(sudo\s+)?tee.*interfaces', _tee_handler)]) + self._test_spawn(1, 2, 3, check_injection=True) + + # tee must not run in this case, where an injection-capable + # guest agent is detected + self.assertFalse(self._tee_executed) def tearDown(self): super(XenAPIVMTestCase, self).tearDown() From 3ea17fbda38af0e186d5b51c89a1b47e303bb623 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Tue, 22 Feb 2011 20:28:31 +0000 Subject: [PATCH 05/11] Added Andy Southgate to the Authors file. --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 494e614a0..f638c3c09 100644 --- a/Authors +++ b/Authors @@ -1,4 +1,5 @@ Andy Smith +Andy Southgate Anne Gentle Anthony Young Antony Messerli From 6cc92a65cf8ebad23896ce5e735ef6fa61136f16 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Tue, 1 Mar 2011 00:28:59 +0000 Subject: [PATCH 06/11] Units tests fixed partially. Still need to address checking data injected into xenstore need to convert string into dict or similar. Also todo PEP8 fixes --- nova/tests/test_xenapi.py | 42 ++++++++++++++++---------------------- nova/tests/xenapi/stubs.py | 3 +++ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index ce89a53c8..10a1b6c11 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -261,30 +261,21 @@ class XenAPIVMTestCase(test.TestCase): if check_injection: xenstore_data = xenapi_fake.VM_get_xenstore_data(vm_ref) - key_prefix = 'vm-data/vif/22_33_2A_B3_CC_DD/tcpip/' - tcpip_data = dict([(k.replace(key_prefix, ''), v) - for k, v in xenstore_data.iteritems() - if k.startswith(key_prefix)]) - - self.assertEquals(tcpip_data, { - 'BroadcastAddress/data/0': '10.0.0.255', - 'BroadcastAddress/name': 'BroadcastAddress', - 'BroadcastAddress/type': 'multi_sz', - 'DefaultGateway/data/0': '10.0.0.1', - 'DefaultGateway/name': 'DefaultGateway', - 'DefaultGateway/type': 'multi_sz', - 'EnableDhcp/data': '0', - 'EnableDhcp/name': 'EnableDhcp', - 'EnableDhcp/type': 'dword', - 'IPAddress/data/0': '10.0.0.3', - 'IPAddress/name': 'IPAddress', - 'IPAddress/type': 'multi_sz', - 'NameServer/data': '10.0.0.2', - 'NameServer/name': 'NameServer', - 'NameServer/type': 'string', - 'SubnetMask/data/0': '255.255.255.0', - 'SubnetMask/name': 'SubnetMask', - 'SubnetMask/type': 'multi_sz'}) + key = 'vm-data/networking/aabbccddeeff' + LOG.debug("Xenstore data: %s",xenstore_data) + xenstore_value=xenstore_data[key] + #tcpip_data = dict([(k, v) + # for k, v in xenstore_value.iteritems() + # if k.startswith(key_prefix)]) + #LOG.debug("tcpip data: %s",tcpip_data) + #self.assertEquals(tcpip_data['label'],'test_network') + #self.assertEquals(tcpip_data, { + # 'label': 'test_network', + # 'broadcast': '10.0.0.255', + # 'ips': [{'ip': '10.0.0.3', 'netmask':'255.255.255.0', 'enabled':'1'}], + # 'mac': 'aa:bb:cc:dd:ee:ff', + # 'dns': ['10.0.0.2'], + # 'gateway': '10.0.0.1'}) def _test_spawn(self, image_id, kernel_id, ramdisk_id, instance_type="m1.large", check_injection=False): @@ -340,6 +331,9 @@ class XenAPIVMTestCase(test.TestCase): # Find the start of eth0 configuration and check it index = config.index('auto eth0') + LOG.debug("CONFIG") + LOG.debug(config) + self.assertEquals(config[index + 1:index + 8], [ 'iface eth0 inet static', 'address 10.0.0.3', diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 6981b4f7a..551d326a4 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -191,6 +191,9 @@ class FakeSessionForVMTests(fake.SessionBase): def VM_add_to_xenstore_data(self, session_ref, vm_ref, key, value): fake.VM_add_to_xenstore_data(vm_ref, key, value) + + def VM_remove_from_xenstore_data(self, session_ref, vm_ref, key): + fake.VM_remove_from_xenstore_data(vm_ref, key) class FakeSessionForVolumeTests(fake.SessionBase): From 371d22760859d2f3cd4ffae1a8e375e40d355572 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Tue, 1 Mar 2011 01:10:38 +0000 Subject: [PATCH 07/11] Fixed xenapi tests Gave up on clever things with map stored as string in xenstore. Used ast.liteeral_eval instead. Changed instance ID and names in tests from in to string (1 => '1') This simplified VMOps._get_vm_opaqueref Changed VMOps._get_vm_opaqueref as references returned by fake xenapi do not start with "OpaqueRef:" prefix. Fixed PEP8 Errors --- nova/tests/test_xenapi.py | 46 +++++++++++++++++--------------------- nova/tests/xenapi/stubs.py | 2 +- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 10a1b6c11..a3d3371a1 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -21,6 +21,7 @@ Test suite for XenAPI import os import re import stubout +import ast from nova import db from nova import context @@ -204,7 +205,7 @@ class XenAPIVMTestCase(test.TestCase): if not vm_rec["is_control_domain"]: vm_labels.append(vm_rec["name_label"]) - self.assertEquals(vm_labels, [1]) + self.assertEquals(vm_labels, ['1']) def ensure_vbd_was_torn_down(): vbd_labels = [] @@ -212,7 +213,7 @@ class XenAPIVMTestCase(test.TestCase): vbd_rec = xenapi_fake.get_record('VBD', vbd_ref) vbd_labels.append(vbd_rec["vm_name_label"]) - self.assertEquals(vbd_labels, [1]) + self.assertEquals(vbd_labels, ['1']) def ensure_vdi_was_torn_down(): for vdi_ref in xenapi_fake.get_all('VDI'): @@ -229,10 +230,10 @@ class XenAPIVMTestCase(test.TestCase): def check_vm_record(self, conn, check_injection=False): instances = conn.list_instances() - self.assertEquals(instances, [1]) + self.assertEquals(instances, ['1']) # Get Nova record for VM - vm_info = conn.get_info(1) + vm_info = conn.get_info('1') # Get XenAPI record for VM vms = [(ref, rec) for ref, rec @@ -262,27 +263,24 @@ class XenAPIVMTestCase(test.TestCase): if check_injection: xenstore_data = xenapi_fake.VM_get_xenstore_data(vm_ref) key = 'vm-data/networking/aabbccddeeff' - LOG.debug("Xenstore data: %s",xenstore_data) - xenstore_value=xenstore_data[key] - #tcpip_data = dict([(k, v) - # for k, v in xenstore_value.iteritems() - # if k.startswith(key_prefix)]) - #LOG.debug("tcpip data: %s",tcpip_data) - #self.assertEquals(tcpip_data['label'],'test_network') - #self.assertEquals(tcpip_data, { - # 'label': 'test_network', - # 'broadcast': '10.0.0.255', - # 'ips': [{'ip': '10.0.0.3', 'netmask':'255.255.255.0', 'enabled':'1'}], - # 'mac': 'aa:bb:cc:dd:ee:ff', - # 'dns': ['10.0.0.2'], - # 'gateway': '10.0.0.1'}) + xenstore_value = xenstore_data[key] + tcpip_data = ast.literal_eval(xenstore_value) + self.assertEquals(tcpip_data, { + 'label': 'test_network', + 'broadcast': '10.0.0.255', + 'ips': [{'ip': '10.0.0.3', + 'netmask':'255.255.255.0', + 'enabled':'1'}], + 'mac': 'aa:bb:cc:dd:ee:ff', + 'dns': ['10.0.0.2'], + 'gateway': '10.0.0.1'}) def _test_spawn(self, image_id, kernel_id, ramdisk_id, instance_type="m1.large", check_injection=False): stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) - values = {'name': 1, - 'id': 1, + values = {'name': "1", + 'id': "1", 'project_id': self.project.id, 'user_id': self.user.id, 'image_id': image_id, @@ -331,9 +329,7 @@ class XenAPIVMTestCase(test.TestCase): # Find the start of eth0 configuration and check it index = config.index('auto eth0') - LOG.debug("CONFIG") - LOG.debug(config) - + self.assertEquals(config[index + 1:index + 8], [ 'iface eth0 inet static', 'address 10.0.0.3', @@ -409,8 +405,8 @@ class XenAPIVMTestCase(test.TestCase): def _create_instance(self): """Creates and spawns a test instance""" values = { - 'name': 1, - 'id': 1, + 'name': '1', + 'id': '1', 'project_id': self.project.id, 'user_id': self.user.id, 'image_id': 1, diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 551d326a4..2392a97b3 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -191,7 +191,7 @@ class FakeSessionForVMTests(fake.SessionBase): def VM_add_to_xenstore_data(self, session_ref, vm_ref, key, value): fake.VM_add_to_xenstore_data(vm_ref, key, value) - + def VM_remove_from_xenstore_data(self, session_ref, vm_ref, key): fake.VM_remove_from_xenstore_data(vm_ref, key) From f8f23299577e5efcd07ccd16ceecb99d8fdc0e32 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Sun, 13 Mar 2011 23:35:30 +0000 Subject: [PATCH 08/11] Removed excess LOG.debug line --- nova/tests/test_xenapi.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 85d804ebd..def37b377 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -268,7 +268,6 @@ class XenAPIVMTestCase(test.TestCase): mem_kib = long(instance_type['memory_mb']) << 10 mem_bytes = str(mem_kib << 10) vcpus = instance_type['vcpus'] - LOG.debug("VM:%s", self.vm) self.assertEquals(self.vm_info['max_mem'], mem_kib) self.assertEquals(self.vm_info['mem'], mem_kib) self.assertEquals(self.vm['memory_static_max'], mem_bytes) From 3de0c0b9e8823981f79d969a7dd7c954e07da0fc Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Thu, 24 Mar 2011 02:01:46 +0000 Subject: [PATCH 09/11] Addressing Rick Clark's comments. --- nova/tests/test_xenapi.py | 4 ++-- nova/tests/xenapi/stubs.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index b22163e9b..d31fa27ac 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -76,7 +76,6 @@ class XenAPIVolumeTestCase(test.TestCase): FLAGS.xenapi_connection_url = 'test_url' FLAGS.xenapi_connection_password = 'test_pass' db_fakes.stub_out_db_instance_api(self.stubs) - #db_fakes.stub_out_db_network_api(self.stubs) stubs.stub_out_get_target(self.stubs) xenapi_fake.reset() self.values = {'id': 1, @@ -333,7 +332,8 @@ class XenAPIVMTestCase(test.TestCase): self.assertEquals(self.vm['HVM_boot_policy'], '') def _test_spawn(self, image_id, kernel_id, ramdisk_id, - instance_type="m1.large", os_type="linux", check_injection=False): + instance_type="m1.large", os_type="linux", + check_injection=False): stubs.stubout_loopingcall_start(self.stubs) values = {'id': 1, 'project_id': self.project.id, diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index d278934c6..0f559b7f9 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -139,9 +139,9 @@ def stubout_is_vdi_pv(stubs): def stubout_loopingcall_start(stubs): - def f_1(self, interval, now=True): + def fake_start(self, interval, now=True): self.f(*self.args, **self.kw) - stubs.Set(utils.LoopingCall, 'start', f_1) + stubs.Set(utils.LoopingCall, 'start', fake_start) class FakeSessionForVMTests(fake.SessionBase): From 5bd1475a2a971d1fb0b47b9f46026b33bbc730a4 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Thu, 24 Mar 2011 10:32:22 +0000 Subject: [PATCH 10/11] Sorted out a problem occurred with units tests for VM migration --- nova/tests/test_xenapi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index d31fa27ac..fd8ed39d8 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -553,6 +553,7 @@ class XenAPIMigrateInstance(test.TestCase): 'image_id': 1, 'kernel_id': None, 'ramdisk_id': None, + 'local_gb': 5, 'instance_type': 'm1.large', 'mac_address': 'aa:bb:cc:dd:ee:ff', 'os_type': 'linux'} From c2f85f734ffaee68cc2f6b00e357e4d863ec9ce7 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Thu, 24 Mar 2011 16:36:37 +0000 Subject: [PATCH 11/11] Stubbing out utils.execute for migrate tests --- nova/tests/test_xenapi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index fd8ed39d8..2ee385cff 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -558,6 +558,7 @@ class XenAPIMigrateInstance(test.TestCase): 'mac_address': 'aa:bb:cc:dd:ee:ff', 'os_type': 'linux'} + 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,