From 6ba35582eec774253d725ab7a6959fdc12cea215 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Tue, 11 Jan 2011 01:50:14 +0000 Subject: Now removing kernel/ramdisk VDI after copy Code tested with PV and HVM guests Fixed pep8 errors Could not run tests - test environment broken on dev machine --- nova/tests/test_xenapi.py | 81 ++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 32 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index ec9462ada..7c256968f 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -206,40 +206,57 @@ class XenAPIVMTestCase(test.TestCase): check() - def test_spawn(self): - instance = self._create_instance() - - def check(): - instances = self.conn.list_instances() - self.assertEquals(instances, [1]) - - # Get Nova record for VM - vm_info = self.conn.get_info(1) + def check_vm_record(self, conn): + instances = conn.list_instances() + self.assertEquals(instances, [1]) + + # Get Nova record for VM + vm_info = conn.get_info(1) + + # Get XenAPI record for VM + vms = fake.get_all('VM') + vm = fake.get_record('VM', vms[0]) + + # Check that m1.large above turned into the right thing. + instance_type = instance_types.INSTANCE_TYPES['m1.large'] + mem_kib = long(instance_type['memory_mb']) << 10 + mem_bytes = str(mem_kib << 10) + vcpus = instance_type['vcpus'] + self.assertEquals(vm_info['max_mem'], mem_kib) + self.assertEquals(vm_info['mem'], mem_kib) + self.assertEquals(vm['memory_static_max'], mem_bytes) + self.assertEquals(vm['memory_dynamic_max'], mem_bytes) + self.assertEquals(vm['memory_dynamic_min'], mem_bytes) + self.assertEquals(vm['VCPUs_max'], str(vcpus)) + self.assertEquals(vm['VCPUs_at_startup'], str(vcpus)) + + # Check that the VM is running according to Nova + self.assertEquals(vm_info['state'], power_state.RUNNING) + + # Check that the VM is running according to XenAPI. + self.assertEquals(vm['power_state'], 'Running') + + def _test_spawn(self, image_id, kernel_id, ramdisk_id): + stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) + values = {'name': 1, + 'project_id': self.project.id, + 'user_id': self.user.id, + 'image_id': image_id, + 'kernel_id': kernel_id, + 'ramdisk_id': ramdisk_id, + 'instance_type': 'm1.large', + 'mac_address': 'aa:bb:cc:dd:ee:ff', + } + conn = xenapi_conn.get_connection(False) + instance = db.instance_create(values) + conn.spawn(instance) + self.check_vm_record(conn) - # Get XenAPI record for VM - vms = xenapi_fake.get_all('VM') - vm = xenapi_fake.get_record('VM', vms[0]) - - # Check that m1.large above turned into the right thing. - instance_type = instance_types.INSTANCE_TYPES['m1.large'] - mem_kib = long(instance_type['memory_mb']) << 10 - mem_bytes = str(mem_kib << 10) - vcpus = instance_type['vcpus'] - self.assertEquals(vm_info['max_mem'], mem_kib) - self.assertEquals(vm_info['mem'], mem_kib) - self.assertEquals(vm['memory_static_max'], mem_bytes) - self.assertEquals(vm['memory_dynamic_max'], mem_bytes) - self.assertEquals(vm['memory_dynamic_min'], mem_bytes) - self.assertEquals(vm['VCPUs_max'], str(vcpus)) - self.assertEquals(vm['VCPUs_at_startup'], str(vcpus)) - - # Check that the VM is running according to Nova - self.assertEquals(vm_info['state'], power_state.RUNNING) - - # Check that the VM is running according to XenAPI. - self.assertEquals(vm['power_state'], 'Running') + def test_spawn_raw(self): + self._test_spawn(1, None, None) - check() + def test_spawn(self): + self._test_spawn(1, 2, 3) def tearDown(self): super(XenAPIVMTestCase, self).tearDown() -- cgit From 2f9ac0fd02115ff9af2e96f5a92f3442d273c6b0 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Wed, 12 Jan 2011 02:41:44 +0000 Subject: Fixed test environments. Fixed bugs in _fetch_image_objecstore and _lookup_image_objcestore (objectstore was broken!) Added tests for glance NEED TO: - add SR & PBD records to fake xenapi session for find_sr to work - fake somehow stream in _fetch_image_glance --- nova/tests/test_xenapi.py | 26 ++++++++++++++++++++++---- nova/tests/xenapi/stubs.py | 11 +++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 7c256968f..5829fa452 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -48,6 +48,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) + stubs.stubout_glance_client(self.stubs) stubs.stub_out_get_target(self.stubs) xenapi_fake.reset() self.values = {'name': 1, 'id': 1, @@ -104,6 +105,7 @@ class XenAPIVolumeTestCase(test.TestCase): def test_attach_volume(self): """ This shows how to test Ops classes' methods """ stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests) + stubs.stubout_glance_client(self.stubs) conn = xenapi_conn.get_connection(False) volume = self._create_volume() instance = db.instance_create(self.values) @@ -126,6 +128,7 @@ class XenAPIVolumeTestCase(test.TestCase): """ This shows how to test when exceptions are raised """ stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeFailedTests) + stubs.stubout_glance_client(self.stubs) conn = xenapi_conn.get_connection(False) volume = self._create_volume() instance = db.instance_create(self.values) @@ -159,6 +162,7 @@ class XenAPIVMTestCase(test.TestCase): db_fakes.stub_out_db_instance_api(self.stubs) xenapi_fake.create_network('fake', FLAGS.flat_network_bridge) stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) + stubs.stubout_glance_client(self.stubs) self.conn = xenapi_conn.get_connection(False) def test_list_instances_0(self): @@ -214,8 +218,8 @@ class XenAPIVMTestCase(test.TestCase): vm_info = conn.get_info(1) # Get XenAPI record for VM - vms = fake.get_all('VM') - vm = fake.get_record('VM', vms[0]) + vms = xenapi_fake.get_all('VM') + vm = xenapi_fake.get_record('VM', vms[0]) # Check that m1.large above turned into the right thing. instance_type = instance_types.INSTANCE_TYPES['m1.large'] @@ -238,7 +242,9 @@ class XenAPIVMTestCase(test.TestCase): def _test_spawn(self, image_id, kernel_id, ramdisk_id): stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) + stubs.stubout_glance_client(self.stubs) values = {'name': 1, + 'id':1, 'project_id': self.project.id, 'user_id': self.user.id, 'image_id': image_id, @@ -252,12 +258,24 @@ class XenAPIVMTestCase(test.TestCase): conn.spawn(instance) self.check_vm_record(conn) - def test_spawn_raw(self): + def test_spawn_raw_objectstore(self): + FLAGS.xenapi_image_service='objectstore' self._test_spawn(1, None, None) - def test_spawn(self): + def test_spawn_objectstore(self): + FLAGS.xenapi_image_service='objectstore' self._test_spawn(1, 2, 3) + def test_spawn_raw_glance(self): + xenapi_fake._create_sr('SR',['','',{'other_config':{'i18n-key':'local-storage'}},'', + '','','iscsi']) + FLAGS.xenapi_image_service='glance' + self._test_spawn(1, None, None) + + def test_spawn_glance(self): + FLAGS.xenapi_image_service='glance' + self._test_spawn(1, 2, 3) + 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 55f751f11..1b6cf1182 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -17,6 +17,7 @@ """Stubouts, mocks and fixtures for the test suite""" from nova.virt import xenapi_conn +from nova.virt.xenapi import vmops from nova.virt.xenapi import fake from nova.virt.xenapi import volume_utils from nova.virt.xenapi import vm_utils @@ -69,6 +70,16 @@ def stubout_instance_snapshot(stubs): stubs.Set(vm_utils, 'wait_for_vhd_coalesce', fake_wait_for_vhd_coalesce) +def stubout_glance_client(stubs): + """Stubs out glance import method for importing fake client""" + def fake_import(self): + """Stubs out get_imported_xenapi of XenAPISession""" + fake_module = 'nova.tests.glance.fake_client' + from_list = ['fake_client'] + return __import__(fake_module, globals(), locals(), from_list, -1) + + stubs.Set(vmops.VMOps, '_get_imported_glance',fake_import) + def stubout_session(stubs, cls): """Stubs out two methods from XenAPISession""" def fake_import(self): -- cgit From 6f9408d7ac38d5c857e1e1cdd92c49e000742734 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Wed, 12 Jan 2011 11:08:08 +0000 Subject: Added unit tests for the xenapi-glance integration. This adds a glance simulator that can stub in place of glance.client.Client, and enhances the xapi simulator to add the additional calls that the Glance-specific path requires. The test itself is just the spawn test, but now we run through with xenapi_image_service set to "objectstore", and then again set to "glance". --- nova/tests/glance/__init__.py | 20 ++++++++++++++++++++ nova/tests/glance/stubs.py | 37 +++++++++++++++++++++++++++++++++++++ nova/tests/test_xenapi.py | 28 +++++++++++++++++++++------- nova/tests/xenapi/stubs.py | 24 +++++++++++++++++++----- 4 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 nova/tests/glance/__init__.py create mode 100644 nova/tests/glance/stubs.py (limited to 'nova/tests') diff --git a/nova/tests/glance/__init__.py b/nova/tests/glance/__init__.py new file mode 100644 index 000000000..ef9fa05a7 --- /dev/null +++ b/nova/tests/glance/__init__.py @@ -0,0 +1,20 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2011 Citrix Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +:mod:`glance` -- Stubs for Glance +================================= +""" diff --git a/nova/tests/glance/stubs.py b/nova/tests/glance/stubs.py new file mode 100644 index 000000000..2ac5653bb --- /dev/null +++ b/nova/tests/glance/stubs.py @@ -0,0 +1,37 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2011 Citrix Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import StringIO + +import glance.client + + +def stubout_glance_client(stubs, cls): + """Stubs out glance.client.Client""" + stubs.Set(glance.client, 'Client', + lambda *args, **kwargs: cls(*args, **kwargs)) + + +class FakeGlance(object): + def __init__(self, host, port=None, use_ssl=False): + pass + + def get_image(self, image): + meta = { + 'size': 0, + } + image_file = StringIO.StringIO('') + return meta, image_file diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index ec9462ada..4ddfe6829 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -33,6 +33,7 @@ from nova.virt.xenapi import fake as xenapi_fake from nova.virt.xenapi import volume_utils from nova.tests.db import fakes as db_fakes from nova.tests.xenapi import stubs +from nova.tests.glance import stubs as glance_stubs FLAGS = flags.FLAGS @@ -107,18 +108,16 @@ class XenAPIVolumeTestCase(test.TestCase): conn = xenapi_conn.get_connection(False) volume = self._create_volume() instance = db.instance_create(self.values) - xenapi_fake.create_vm(instance.name, 'Running') + vm = xenapi_fake.create_vm(instance.name, 'Running') result = conn.attach_volume(instance.name, volume['id'], '/dev/sdc') def check(): # check that the VM has a VBD attached to it - # Get XenAPI reference for the VM - vms = xenapi_fake.get_all('VM') # Get XenAPI record for VBD vbds = xenapi_fake.get_all('VBD') vbd = xenapi_fake.get_record('VBD', vbds[0]) vm_ref = vbd['VM'] - self.assertEqual(vm_ref, vms[0]) + self.assertEqual(vm_ref, vm) check() @@ -156,9 +155,14 @@ class XenAPIVMTestCase(test.TestCase): FLAGS.xenapi_connection_url = 'test_url' FLAGS.xenapi_connection_password = 'test_pass' xenapi_fake.reset() + xenapi_fake.create_local_srs() db_fakes.stub_out_db_instance_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) + stubs.stubout_stream_disk(self.stubs) + glance_stubs.stubout_glance_client(self.stubs, + glance_stubs.FakeGlance) self.conn = xenapi_conn.get_connection(False) def test_list_instances_0(self): @@ -206,7 +210,15 @@ class XenAPIVMTestCase(test.TestCase): check() - def test_spawn(self): + def test_spawn_glance(self): + FLAGS.xenapi_image_service = 'glance' + self._test_spawn() + + def test_spawn_objectstore(self): + FLAGS.xenapi_image_service = 'objectstore' + self._test_spawn() + + def _test_spawn(self): instance = self._create_instance() def check(): @@ -217,8 +229,10 @@ class XenAPIVMTestCase(test.TestCase): vm_info = self.conn.get_info(1) # Get XenAPI record for VM - vms = xenapi_fake.get_all('VM') - vm = xenapi_fake.get_record('VM', vms[0]) + vms = [rec for ref, rec + in xenapi_fake.get_all_records('VM').iteritems() + if not rec['is_control_domain']] + vm = vms[0] # Check that m1.large above turned into the right thing. instance_type = instance_types.INSTANCE_TYPES['m1.large'] diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 55f751f11..ffbca9560 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -91,6 +91,21 @@ def stub_out_get_target(stubs): stubs.Set(volume_utils, '_get_target', fake_get_target) +def stubout_get_this_vm_uuid(stubs): + def f(): + vms = [rec['uuid'] for ref, rec + in fake.get_all_records('VM').iteritems() + if rec['is_control_domain']] + return vms[0] + stubs.Set(vm_utils, 'get_this_vm_uuid', f) + + +def stubout_stream_disk(stubs): + def f(_): + pass + stubs.Set(vm_utils, '_stream_disk', f) + + class FakeSessionForVMTests(fake.SessionBase): """ Stubs out a XenAPISession for VM tests """ def __init__(self, uri): @@ -100,7 +115,10 @@ class FakeSessionForVMTests(fake.SessionBase): return self.xenapi.network.get_all_records() def host_call_plugin(self, _1, _2, _3, _4, _5): - return '' + sr_ref = fake.get_all('SR')[0] + vdi_ref = fake.create_vdi('', False, sr_ref, False) + vdi_rec = fake.get_record('VDI', vdi_ref) + return '%s' % vdi_rec['uuid'] def VM_start(self, _1, ref, _2, _3): vm = fake.get_record('VM', ref) @@ -135,10 +153,6 @@ class FakeSessionForVolumeTests(fake.SessionBase): def __init__(self, uri): super(FakeSessionForVolumeTests, self).__init__(uri) - def VBD_plug(self, _1, ref): - rec = fake.get_record('VBD', ref) - rec['currently-attached'] = True - def VDI_introduce(self, _1, uuid, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11): valid_vdi = False -- cgit From ba0f974c126c2a24ca6b1464ccc4a06be071b04e Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Wed, 12 Jan 2011 11:54:58 +0000 Subject: PEP8 fixes, and switch to using the new LOG in vm_utils, matching what's just come in from trunk. --- nova/tests/glance/stubs.py | 2 +- nova/tests/test_xenapi.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/glance/stubs.py b/nova/tests/glance/stubs.py index 2ac5653bb..f182b857a 100644 --- a/nova/tests/glance/stubs.py +++ b/nova/tests/glance/stubs.py @@ -28,7 +28,7 @@ def stubout_glance_client(stubs, cls): class FakeGlance(object): def __init__(self, host, port=None, use_ssl=False): pass - + def get_image(self, image): meta = { 'size': 0, diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 19e550636..ce0bc002a 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -245,7 +245,7 @@ class XenAPIVMTestCase(test.TestCase): def _test_spawn(self, image_id, kernel_id, ramdisk_id): stubs.stubout_session(self.stubs, stubs.FakeSessionForVMTests) values = {'name': 1, - 'id':1, + 'id': 1, 'project_id': self.project.id, 'user_id': self.user.id, 'image_id': image_id, @@ -260,23 +260,21 @@ class XenAPIVMTestCase(test.TestCase): self.check_vm_record(conn) def test_spawn_raw_objectstore(self): - FLAGS.xenapi_image_service='objectstore' + FLAGS.xenapi_image_service = 'objectstore' self._test_spawn(1, None, None) def test_spawn_objectstore(self): - FLAGS.xenapi_image_service='objectstore' + FLAGS.xenapi_image_service = 'objectstore' self._test_spawn(1, 2, 3) def test_spawn_raw_glance(self): - xenapi_fake._create_sr('SR',['','',{'other_config':{'i18n-key':'local-storage'}},'', - '','','iscsi']) - FLAGS.xenapi_image_service='glance' + FLAGS.xenapi_image_service = 'glance' self._test_spawn(1, None, None) def test_spawn_glance(self): - FLAGS.xenapi_image_service='glance' + FLAGS.xenapi_image_service = 'glance' self._test_spawn(1, 2, 3) - + def tearDown(self): super(XenAPIVMTestCase, self).tearDown() self.manager.delete_project(self.project) -- cgit From 32eac05776d18dcbde49aa022f149fd597907cbe Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Wed, 12 Jan 2011 14:28:50 +0000 Subject: Fixing the stub for _stream_disk as well --- nova/tests/xenapi/stubs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 36a984f0e..9add7e592 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -125,7 +125,7 @@ def stubout_get_this_vm_uuid(stubs): def stubout_stream_disk(stubs): - def f(_): + def f(_1,_2): pass stubs.Set(vm_utils, '_stream_disk', f) -- cgit From f3dba791b9f10fec759dce0fe4e2abc214e3fd61 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Wed, 12 Jan 2011 14:37:03 +0000 Subject: pep8 fixes --- nova/tests/xenapi/stubs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 9add7e592..0c0fe5bc9 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -125,7 +125,7 @@ def stubout_get_this_vm_uuid(stubs): def stubout_stream_disk(stubs): - def f(_1,_2): + def f(_1, _2): pass stubs.Set(vm_utils, '_stream_disk', f) -- cgit From c71d5d41bb6e5d7a046a76563eed75a4d6e77e90 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Wed, 12 Jan 2011 17:05:40 +0000 Subject: Fixed another issue in _stream_disk, as it did never execute _write_partition. Fixed fake method accordingly. Fixed pep8 errors. --- nova/tests/xenapi/stubs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 0c0fe5bc9..624995ada 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -125,7 +125,7 @@ def stubout_get_this_vm_uuid(stubs): def stubout_stream_disk(stubs): - def f(_1, _2): + def f(_1, _2, _3, _4): pass stubs.Set(vm_utils, '_stream_disk', f) -- cgit From 6bef91e9fe67a893bd2a1ba0ef8ef56d4b2bb72d Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 18 Jan 2011 12:42:20 -0800 Subject: fix test to respect xml changes --- nova/tests/test_virt.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index afdc89ba2..556fe561c 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -122,10 +122,10 @@ class LibvirtConnTestCase(test.TestCase): if rescue: check = (lambda t: t.find('./os/kernel').text.split('/')[1], - 'rescue-kernel') + 'kernel.rescue') check_list.append(check) check = (lambda t: t.find('./os/initrd').text.split('/')[1], - 'rescue-ramdisk') + 'ramdisk.rescue') check_list.append(check) else: if expect_kernel: @@ -161,13 +161,16 @@ class LibvirtConnTestCase(test.TestCase): if rescue: common_checks += [ (lambda t: t.findall('./devices/disk/source')[0].get( - 'file').split('/')[1], 'rescue-disk'), + 'file').split('/')[1], 'disk.rescue'), (lambda t: t.findall('./devices/disk/source')[1].get( 'file').split('/')[1], 'disk')] else: common_checks += [(lambda t: t.findall( './devices/disk/source')[0].get('file').split('/')[1], 'disk')] + common_checks += [(lambda t: t.findall( + './devices/disk/source')[1].get('file').split('/')[1], + 'disk.local')] for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems(): FLAGS.libvirt_type = libvirt_type -- cgit From b6ad755dcb495743c9137b0da441d264420b02b6 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Wed, 19 Jan 2011 00:31:51 +0100 Subject: Add an apply_instance_filter method to NWFilter driver. Adjust unit tests for both firewall drivers to actually exercise these code paths. --- nova/tests/test_virt.py | 53 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index 556fe561c..39dc91df8 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -228,12 +228,6 @@ class IptablesFirewallTestCase(test.TestCase): self.manager.delete_user(self.user) super(IptablesFirewallTestCase, self).tearDown() - def _p(self, *args, **kwargs): - if 'iptables-restore' in args: - print ' '.join(args), kwargs['stdin'] - if 'iptables-save' in args: - return - in_rules = [ '# Generated by iptables-save v1.4.4 on Mon Dec 6 11:54:13 2010', '*filter', @@ -255,11 +249,21 @@ class IptablesFirewallTestCase(test.TestCase): '# Completed on Mon Dec 6 11:54:13 2010', ] + in6_rules = [ + '# Generated by ip6tables-save v1.4.4 on Tue Jan 18 23:47:56 2011', + '*filter', + ':INPUT ACCEPT [349155:75810423]', + ':FORWARD ACCEPT [0:0]', + ':OUTPUT ACCEPT [349256:75777230]', + 'COMMIT', + '# Completed on Tue Jan 18 23:47:56 2011' + ] + def test_static_filters(self): - self.fw.execute = self._p instance_ref = db.instance_create(self.context, {'user_id': 'fake', - 'project_id': 'fake'}) + 'project_id': 'fake', + 'mac_address': '56:12:12:12:12:12'}) ip = '10.11.12.13' network_ref = db.project_get_network(self.context, @@ -304,18 +308,31 @@ class IptablesFirewallTestCase(test.TestCase): secgroup['id']) instance_ref = db.instance_get(admin_ctxt, instance_ref['id']) - self.fw.add_instance(instance_ref) - - out_rules = self.fw.modify_rules(self.in_rules) +# self.fw.add_instance(instance_ref) + def fake_iptables_execute(cmd, process_input=None): + if cmd == 'sudo ip6tables-save -t filter': + return '\n'.join(self.in6_rules), None + if cmd == 'sudo iptables-save -t filter': + return '\n'.join(self.in_rules), None + if cmd == 'sudo iptables-restore': + self.out_rules = process_input.split('\n') + return '', '' + if cmd == 'sudo ip6tables-restore': + self.out6_rules = process_input.split('\n') + return '', '' + self.fw.execute = fake_iptables_execute + + self.fw.prepare_instance_filter(instance_ref) + self.fw.apply_instance_filter(instance_ref) in_rules = filter(lambda l: not l.startswith('#'), self.in_rules) for rule in in_rules: if not 'nova' in rule: - self.assertTrue(rule in out_rules, + self.assertTrue(rule in self.out_rules, 'Rule went missing: %s' % rule) instance_chain = None - for rule in out_rules: + for rule in self.out_rules: # This is pretty crude, but it'll do for now if '-d 10.11.12.13 -j' in rule: instance_chain = rule.split(' ')[-1] @@ -323,7 +340,7 @@ class IptablesFirewallTestCase(test.TestCase): self.assertTrue(instance_chain, "The instance chain wasn't added") security_group_chain = None - for rule in out_rules: + for rule in self.out_rules: # This is pretty crude, but it'll do for now if '-A %s -j' % instance_chain in rule: security_group_chain = rule.split(' ')[-1] @@ -332,16 +349,16 @@ class IptablesFirewallTestCase(test.TestCase): "The security group chain wasn't added") self.assertTrue('-A %s -p icmp -s 192.168.11.0/24 -j ACCEPT' % \ - security_group_chain in out_rules, + security_group_chain in self.out_rules, "ICMP acceptance rule wasn't added") self.assertTrue('-A %s -p icmp -s 192.168.11.0/24 -m icmp --icmp-type' - ' 8 -j ACCEPT' % security_group_chain in out_rules, + ' 8 -j ACCEPT' % security_group_chain in self.out_rules, "ICMP Echo Request acceptance rule wasn't added") self.assertTrue('-A %s -p tcp -s 192.168.10.0/24 -m multiport ' '--dports 80:81 -j ACCEPT' % security_group_chain \ - in out_rules, + in self.out_rules, "TCP port 80/81 acceptance rule wasn't added") @@ -476,5 +493,7 @@ class NWFilterTestCase(test.TestCase): self.fw.setup_basic_filtering(instance) self.fw.prepare_instance_filter(instance) + self.fw.apply_instance_filter(instance) _ensure_all_called() self.teardown_security_group() + -- cgit From 87cca15270e29666cf46adb5ea72e103c284d525 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Wed, 19 Jan 2011 00:39:24 +0100 Subject: Enable the use_ipv6 flag in unit tests by default. --- nova/tests/fake_flags.py | 1 + 1 file changed, 1 insertion(+) (limited to 'nova/tests') diff --git a/nova/tests/fake_flags.py b/nova/tests/fake_flags.py index 7376a11dd..1097488ec 100644 --- a/nova/tests/fake_flags.py +++ b/nova/tests/fake_flags.py @@ -40,3 +40,4 @@ FLAGS.blades_per_shelf = 4 FLAGS.iscsi_num_targets = 8 FLAGS.verbose = True FLAGS.sql_connection = 'sqlite:///nova.sqlite' +FLAGS.use_ipv6 = True -- cgit From 7f352a72333e94c642d8288638c73a166cfb2943 Mon Sep 17 00:00:00 2001 From: Andy Smith Date: Tue, 18 Jan 2011 17:32:54 -0800 Subject: move db sync into nosetests package-level fixtures so that the existing nosetests attempt in hudson will pass --- nova/tests/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/__init__.py b/nova/tests/__init__.py index 8dc87d0e2..592d5bea9 100644 --- a/nova/tests/__init__.py +++ b/nova/tests/__init__.py @@ -34,3 +34,8 @@ # The code below enables nosetests to work with i18n _() blocks import __builtin__ setattr(__builtin__, '_', lambda x: x) + + +def setup(): + from nova.db import migration + migration.db_sync() -- cgit From c79e72b2a14b5e231724a1e187bf7effe5c64fc4 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Wed, 19 Jan 2011 10:11:55 +0100 Subject: PEP-8 fixes --- nova/tests/test_virt.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index 39dc91df8..f6800e3d9 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -352,8 +352,8 @@ class IptablesFirewallTestCase(test.TestCase): security_group_chain in self.out_rules, "ICMP acceptance rule wasn't added") - self.assertTrue('-A %s -p icmp -s 192.168.11.0/24 -m icmp --icmp-type' - ' 8 -j ACCEPT' % security_group_chain in self.out_rules, + self.assertTrue('-A %s -p icmp -s 192.168.11.0/24 -m icmp --icmp-type ' + '8 -j ACCEPT' % security_group_chain in self.out_rules, "ICMP Echo Request acceptance rule wasn't added") self.assertTrue('-A %s -p tcp -s 192.168.10.0/24 -m multiport ' @@ -496,4 +496,3 @@ class NWFilterTestCase(test.TestCase): self.fw.apply_instance_filter(instance) _ensure_all_called() self.teardown_security_group() - -- cgit