Merge "Skip libvirt tests when libvirt not present."
This commit is contained in:
		| @@ -43,7 +43,21 @@ from nova.virt.libvirt import volume | |||||||
| from nova.volume import driver as volume_driver | from nova.volume import driver as volume_driver | ||||||
| from nova.tests import fake_network | from nova.tests import fake_network | ||||||
|  |  | ||||||
|  |  | ||||||
|  | try: | ||||||
|  |     import libvirt | ||||||
|  |     connection.libvirt = libvirt | ||||||
|  | except ImportError: | ||||||
|     libvirt = None |     libvirt = None | ||||||
|  |  | ||||||
|  |  | ||||||
|  | try: | ||||||
|  |     import libxml2 | ||||||
|  |     connection.libxml2 = libxml2 | ||||||
|  | except ImportError: | ||||||
|  |     libxml2 = None | ||||||
|  |  | ||||||
|  |  | ||||||
| FLAGS = flags.FLAGS | FLAGS = flags.FLAGS | ||||||
| LOG = logging.getLogger('nova.tests.test_libvirt') | LOG = logging.getLogger('nova.tests.test_libvirt') | ||||||
|  |  | ||||||
| @@ -228,6 +242,10 @@ class FakeVolumeDriver(object): | |||||||
|         return "" |         return "" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def missing_libvirt(): | ||||||
|  |     return libvirt is None or libxml2 is None | ||||||
|  |  | ||||||
|  |  | ||||||
| class LibvirtConnTestCase(test.TestCase): | class LibvirtConnTestCase(test.TestCase): | ||||||
|  |  | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
| @@ -252,20 +270,6 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|                      'local_gb': 20, |                      'local_gb': 20, | ||||||
|                      'instance_type_id': '5'}  # m1.small |                      'instance_type_id': '5'}  # m1.small | ||||||
|  |  | ||||||
|     def lazy_load_library_exists(self): |  | ||||||
|         """check if libvirt is available.""" |  | ||||||
|         # try to connect libvirt. if fail, skip test. |  | ||||||
|         try: |  | ||||||
|             import libvirt |  | ||||||
|             import libxml2 |  | ||||||
|         except ImportError: |  | ||||||
|             return False |  | ||||||
|         global libvirt |  | ||||||
|         libvirt = __import__('libvirt') |  | ||||||
|         connection.libvirt = __import__('libvirt') |  | ||||||
|         connection.libxml2 = __import__('libxml2') |  | ||||||
|         return True |  | ||||||
|  |  | ||||||
|     def create_fake_libvirt_mock(self, **kwargs): |     def create_fake_libvirt_mock(self, **kwargs): | ||||||
|         """Defining mocks for LibvirtConnection(libvirt is not used).""" |         """Defining mocks for LibvirtConnection(libvirt is not used).""" | ||||||
|  |  | ||||||
| @@ -352,10 +356,8 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|         instance_data = dict(self.test_instance) |         instance_data = dict(self.test_instance) | ||||||
|         self._check_xml_and_container(instance_data) |         self._check_xml_and_container(instance_data) | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_snapshot_in_ami_format(self): |     def test_snapshot_in_ami_format(self): | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         self.flags(image_service='nova.image.fake.FakeImageService') |         self.flags(image_service='nova.image.fake.FakeImageService') | ||||||
|  |  | ||||||
|         # Start test |         # Start test | ||||||
| @@ -392,10 +394,8 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|         self.assertEquals(snapshot['disk_format'], 'ami') |         self.assertEquals(snapshot['disk_format'], 'ami') | ||||||
|         self.assertEquals(snapshot['name'], snapshot_name) |         self.assertEquals(snapshot['name'], snapshot_name) | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_snapshot_in_raw_format(self): |     def test_snapshot_in_raw_format(self): | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         self.flags(image_service='nova.image.fake.FakeImageService') |         self.flags(image_service='nova.image.fake.FakeImageService') | ||||||
|  |  | ||||||
|         # Start test |         # Start test | ||||||
| @@ -428,10 +428,8 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|         self.assertEquals(snapshot['disk_format'], 'raw') |         self.assertEquals(snapshot['disk_format'], 'raw') | ||||||
|         self.assertEquals(snapshot['name'], snapshot_name) |         self.assertEquals(snapshot['name'], snapshot_name) | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_snapshot_in_qcow2_format(self): |     def test_snapshot_in_qcow2_format(self): | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         self.flags(image_service='nova.image.fake.FakeImageService') |         self.flags(image_service='nova.image.fake.FakeImageService') | ||||||
|         self.flags(snapshot_image_format='qcow2') |         self.flags(snapshot_image_format='qcow2') | ||||||
|  |  | ||||||
| @@ -465,10 +463,8 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|         self.assertEquals(snapshot['disk_format'], 'qcow2') |         self.assertEquals(snapshot['disk_format'], 'qcow2') | ||||||
|         self.assertEquals(snapshot['name'], snapshot_name) |         self.assertEquals(snapshot['name'], snapshot_name) | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_snapshot_no_image_architecture(self): |     def test_snapshot_no_image_architecture(self): | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         self.flags(image_service='nova.image.fake.FakeImageService') |         self.flags(image_service='nova.image.fake.FakeImageService') | ||||||
|  |  | ||||||
|         # Start test |         # Start test | ||||||
| @@ -732,12 +728,9 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|                           conn.update_available_resource, |                           conn.update_available_resource, | ||||||
|                           self.context, 'dummy') |                           self.context, 'dummy') | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_ensure_filtering_rules_for_instance_timeout(self): |     def test_ensure_filtering_rules_for_instance_timeout(self): | ||||||
|         """ensure_filtering_fules_for_instance() finishes with timeout.""" |         """ensure_filtering_fules_for_instance() finishes with timeout.""" | ||||||
|         # Skip if non-libvirt environment |  | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         # Preparing mocks |         # Preparing mocks | ||||||
|         def fake_none(self, *args): |         def fake_none(self, *args): | ||||||
|             return |             return | ||||||
| @@ -786,12 +779,9 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|  |  | ||||||
|         db.instance_destroy(self.context, instance_ref['id']) |         db.instance_destroy(self.context, instance_ref['id']) | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_live_migration_raises_exception(self): |     def test_live_migration_raises_exception(self): | ||||||
|         """Confirms recover method is called when exceptions are raised.""" |         """Confirms recover method is called when exceptions are raised.""" | ||||||
|         # Skip if non-libvirt environment |  | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         # Preparing data |         # Preparing data | ||||||
|         self.compute = utils.import_object(FLAGS.compute_manager) |         self.compute = utils.import_object(FLAGS.compute_manager) | ||||||
|         instance_dict = {'host': 'fake', |         instance_dict = {'host': 'fake', | ||||||
| @@ -860,13 +850,9 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|         self.mox.ReplayAll() |         self.mox.ReplayAll() | ||||||
|         self.assertEqual(conn.pre_live_migration(vol), None) |         self.assertEqual(conn.pre_live_migration(vol), None) | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_pre_block_migration_works_correctly(self): |     def test_pre_block_migration_works_correctly(self): | ||||||
|         """Confirms pre_block_migration works correctly.""" |         """Confirms pre_block_migration works correctly.""" | ||||||
|  |  | ||||||
|         # Skip if non-libvirt environment |  | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         # Replace instances_path since this testcase creates tmpfile |         # Replace instances_path since this testcase creates tmpfile | ||||||
|         tmpdir = tempfile.mkdtemp() |         tmpdir = tempfile.mkdtemp() | ||||||
|         store = FLAGS.instances_path |         store = FLAGS.instances_path | ||||||
| @@ -897,12 +883,9 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|         # Restore FLAGS.instances_path |         # Restore FLAGS.instances_path | ||||||
|         FLAGS.instances_path = store |         FLAGS.instances_path = store | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_get_instance_disk_info_works_correctly(self): |     def test_get_instance_disk_info_works_correctly(self): | ||||||
|         """Confirms pre_block_migration works correctly.""" |         """Confirms pre_block_migration works correctly.""" | ||||||
|         # Skip if non-libvirt environment |  | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         # Test data |         # Test data | ||||||
|         instance_ref = db.instance_create(self.context, self.test_instance) |         instance_ref = db.instance_create(self.context, self.test_instance) | ||||||
|         dummyxml = ("<domain type='kvm'><name>instance-0000000a</name>" |         dummyxml = ("<domain type='kvm'><name>instance-0000000a</name>" | ||||||
| @@ -955,11 +938,8 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|  |  | ||||||
|         db.instance_destroy(self.context, instance_ref['id']) |         db.instance_destroy(self.context, instance_ref['id']) | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_spawn_with_network_info(self): |     def test_spawn_with_network_info(self): | ||||||
|         # Skip if non-libvirt environment |  | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         # Preparing mocks |         # Preparing mocks | ||||||
|         def fake_none(self, instance): |         def fake_none(self, instance): | ||||||
|             return |             return | ||||||
| @@ -1074,11 +1054,8 @@ class LibvirtConnTestCase(test.TestCase): | |||||||
|         compute_driver = driver.ComputeDriver() |         compute_driver = driver.ComputeDriver() | ||||||
|         self.assertRaises(NotImplementedError, compute_driver.reboot, *args) |         self.assertRaises(NotImplementedError, compute_driver.reboot, *args) | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_immediate_delete(self): |     def test_immediate_delete(self): | ||||||
|         # Skip if non-libvirt environment |  | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         conn = connection.LibvirtConnection(False) |         conn = connection.LibvirtConnection(False) | ||||||
|         self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn') |         self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn') | ||||||
|         connection.LibvirtConnection._conn.lookupByName = lambda x: None |         connection.LibvirtConnection._conn.lookupByName = lambda x: None | ||||||
| @@ -1191,20 +1168,6 @@ class IptablesFirewallTestCase(test.TestCase): | |||||||
|         self.fw = firewall.IptablesFirewallDriver( |         self.fw = firewall.IptablesFirewallDriver( | ||||||
|                       get_connection=lambda: self.fake_libvirt_connection) |                       get_connection=lambda: self.fake_libvirt_connection) | ||||||
|  |  | ||||||
|     def lazy_load_library_exists(self): |  | ||||||
|         """check if libvirt is available.""" |  | ||||||
|         # try to connect libvirt. if fail, skip test. |  | ||||||
|         try: |  | ||||||
|             import libvirt |  | ||||||
|             import libxml2 |  | ||||||
|         except ImportError: |  | ||||||
|             return False |  | ||||||
|         global libvirt |  | ||||||
|         libvirt = __import__('libvirt') |  | ||||||
|         connection.libvirt = __import__('libvirt') |  | ||||||
|         connection.libxml2 = __import__('libxml2') |  | ||||||
|         return True |  | ||||||
|  |  | ||||||
|     in_nat_rules = [ |     in_nat_rules = [ | ||||||
|       '# Generated by iptables-save v1.4.10 on Sat Feb 19 00:03:19 2011', |       '# Generated by iptables-save v1.4.10 on Sat Feb 19 00:03:19 2011', | ||||||
|       '*nat', |       '*nat', | ||||||
| @@ -1428,11 +1391,8 @@ class IptablesFirewallTestCase(test.TestCase): | |||||||
|         self.mox.ReplayAll() |         self.mox.ReplayAll() | ||||||
|         self.fw.do_refresh_security_group_rules("fake") |         self.fw.do_refresh_security_group_rules("fake") | ||||||
|  |  | ||||||
|  |     @test.skip_if(missing_libvirt(), "Test requires libvirt") | ||||||
|     def test_unfilter_instance_undefines_nwfilter(self): |     def test_unfilter_instance_undefines_nwfilter(self): | ||||||
|         # Skip if non-libvirt environment |  | ||||||
|         if not self.lazy_load_library_exists(): |  | ||||||
|             return |  | ||||||
|  |  | ||||||
|         admin_ctxt = context.get_admin_context() |         admin_ctxt = context.get_admin_context() | ||||||
|  |  | ||||||
|         fakefilter = NWFilterFakes() |         fakefilter = NWFilterFakes() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jenkins
					Jenkins