Ejemplo n.º 1
0
    def setUp(self):
        super(ServersTestBase, self).setUp()

        # Replace libvirt with fakelibvirt
        self.useFixture(fake_imagebackend.ImageBackendFixture())
        self.useFixture(fixtures.MonkeyPatch(
            'nova.virt.libvirt.driver.libvirt',
            fakelibvirt))
        self.useFixture(fixtures.MonkeyPatch(
            'nova.virt.libvirt.host.libvirt',
            fakelibvirt))
        self.useFixture(fixtures.MonkeyPatch(
            'nova.virt.libvirt.guest.libvirt',
            fakelibvirt))
        self.useFixture(fakelibvirt.FakeLibvirtFixture())
        self.useFixture(func_fixtures.PlacementFixture())

        self.stub_out('nova.privsep.utils.supports_direct_io', lambda _: True)

        # Mock the 'get_connection' function, as we're going to need to provide
        # custom capabilities for each test
        _p = mock.patch('nova.virt.libvirt.host.Host.get_connection')
        self.mock_conn = _p.start()
        self.addCleanup(_p.stop)
        # As above, mock the 'get_arch' function as we may need to provide
        # different host architectures during some tests.
        _a = mock.patch('nova.virt.libvirt.utils.get_arch')
        self.mock_arch = _a.start()
        # Default to X86_64
        self.mock_arch.return_value = obj_fields.Architecture.X86_64
        self.addCleanup(_a.stop)
Ejemplo n.º 2
0
    def setUp(self):
        super(ServersTestBase, self).setUp()

        # Replace libvirt with fakelibvirt
        self.useFixture(fake_imagebackend.ImageBackendFixture())
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.driver.libvirt_utils',
                                 fake_libvirt_utils))
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.driver.libvirt',
                                 fakelibvirt))
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.host.libvirt',
                                 fakelibvirt))
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.guest.libvirt',
                                 fakelibvirt))
        self.useFixture(fakelibvirt.FakeLibvirtFixture())
        self.useFixture(func_fixtures.PlacementFixture())

        self.stub_out('nova.privsep.utils.supports_direct_io', lambda _: True)

        # Mock the 'get_connection' function, as we're going to need to provide
        # custom capabilities for each test
        _p = mock.patch('nova.virt.libvirt.host.Host.get_connection')
        self.mock_conn = _p.start()
        self.addCleanup(_p.stop)
Ejemplo n.º 3
0
    def setUp(self):
        self.flags(instances_path=self.useFixture(fixtures.TempDir()).path)

        self.computes = {}
        self.compute_rp_uuids = {}

        super(ServersTestBase, self).setUp()

        self.useFixture(fake_imagebackend.ImageBackendFixture())
        self.useFixture(fakelibvirt.FakeLibvirtFixture())

        self.useFixture(fixtures.MockPatch(
            'nova.virt.libvirt.LibvirtDriver._create_image',
            return_value=(False, False)))
        self.useFixture(fixtures.MockPatch(
            'nova.virt.libvirt.LibvirtDriver._get_local_gb_info',
            return_value={'total': 128, 'used': 44, 'free': 84}))
        self.useFixture(fixtures.MockPatch(
            'nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname',
            return_value=True))
        self.useFixture(fixtures.MockPatch(
            'nova.virt.libvirt.driver.libvirt_utils.file_open',
            side_effect=lambda *a, **k: io.BytesIO(b'')))
        self.useFixture(fixtures.MockPatch(
            'nova.privsep.utils.supports_direct_io',
            return_value=True))
        self.useFixture(fixtures.MockPatch(
            'nova.virt.libvirt.host.Host.get_online_cpus',
            return_value=set(range(16))))

        # Mock the 'get_connection' function, as we're going to need to provide
        # custom capabilities for each test
        _p = mock.patch('nova.virt.libvirt.host.Host.get_connection')
        self.mock_conn = _p.start()
        self.addCleanup(_p.stop)
    def setUp(self):
        super(VPMEMTestBase, self).setUp()

        self.flags(pmem_namespaces="4GB:ns_0,SMALL:ns_1|ns_2", group='libvirt')
        self.fake_pmem_namespaces = '''
            [{"dev":"namespace0.0",
            "mode":"devdax",
            "map":"mem",
            "size":4292870144,
            "uuid":"24ffd5e4-2b39-4f28-88b3-d6dc1ec44863",
            "daxregion":{"id": 0, "size": 4292870144,"align": 2097152,
            "devices":[{"chardev":"dax0.0",
            "size":4292870144}]},
            "name":"ns_0",
            "numa_node":0},
            {"dev":"namespace0.1",
            "mode":"devdax",
            "map":"mem",
            "size":4292870144,
            "uuid":"ac64fe52-de38-465b-b32b-947a6773ac66",
            "daxregion":{"id": 0, "size": 4292870144,"align": 2097152,
            "devices":[{"chardev":"dax0.1",
            "size":4292870144}]},
            "name":"ns_1",
            "numa_node":0},
            {"dev":"namespace0.2",
            "mode":"devdax",
            "map":"mem",
            "size":4292870144,
            "uuid":"2ff41eba-db9c-4bb9-a959-31d992568a3e",
            "raw_uuid":"0b61823b-5668-4856-842d-c644dae83410",
            "daxregion":{"id":0, "size":4292870144, "align":2097152,
            "devices":[{"chardev":"dax0.2",
            "size":4292870144}]},
            "name":"ns_2",
            "numa_node":0}]'''

        self.useFixture(
            fixtures.MockPatch('nova.privsep.libvirt.cleanup_vpmem'))
        self.useFixture(
            fixtures.MockPatch('nova.privsep.libvirt.get_pmem_namespaces',
                               return_value=self.fake_pmem_namespaces))
        self.useFixture(fake_imagebackend.ImageBackendFixture())
        self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.LibvirtDriver._get_local_gb_info',
                return_value={
                    'total': 128,
                    'used': 44,
                    'free': 84
                }))
        self.mock_conn = self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.host.Host._get_new_connection')).mock
Ejemplo n.º 5
0
    def setUp(self):
        super(ServersTestBase, self).setUp()

        # Replace libvirt with fakelibvirt
        self.useFixture(fake_imagebackend.ImageBackendFixture())
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.driver.libvirt',
                                 fakelibvirt))
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.host.libvirt',
                                 fakelibvirt))
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.guest.libvirt',
                                 fakelibvirt))
        self.useFixture(fakelibvirt.FakeLibvirtFixture())

        self.useFixture(
            fixtures.MockPatch('nova.virt.libvirt.LibvirtDriver._create_image',
                               return_value=(False, False)))
        self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.LibvirtDriver._get_local_gb_info',
                return_value={
                    'total': 128,
                    'used': 44,
                    'free': 84
                }))
        self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.driver.libvirt_utils.is_valid_hostname',
                return_value=True))
        self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.driver.libvirt_utils.file_open',
                side_effect=lambda *a, **k: io.BytesIO(b'')))
        self.useFixture(
            fixtures.MockPatch('nova.privsep.utils.supports_direct_io',
                               return_value=True))
        self.useFixture(
            fixtures.MockPatch('nova.virt.libvirt.host.Host.get_online_cpus',
                               return_value=set(range(16))))

        # Mock the 'get_connection' function, as we're going to need to provide
        # custom capabilities for each test
        _p = mock.patch('nova.virt.libvirt.host.Host.get_connection')
        self.mock_conn = _p.start()
        self.addCleanup(_p.stop)

        # Mock the 'get_arch' function as we may need to provide different host
        # architectures during some tests. We default to x86_64
        _a = mock.patch('nova.virt.libvirt.utils.get_arch')
        self.mock_arch = _a.start()
        self.mock_arch.return_value = obj_fields.Architecture.X86_64
        self.addCleanup(_a.stop)
Ejemplo n.º 6
0
    def setUp(self):
        super(NUMAServersTest, self).setUp()

        # Replace libvirt with fakelibvirt
        self.useFixture(fake_imagebackend.ImageBackendFixture())
        self.useFixture(fixtures.MonkeyPatch(
           'nova.virt.libvirt.driver.libvirt_utils',
           fake_libvirt_utils))
        self.useFixture(fixtures.MonkeyPatch(
           'nova.virt.libvirt.driver.libvirt',
           fakelibvirt))
        self.useFixture(fixtures.MonkeyPatch(
           'nova.virt.libvirt.host.libvirt',
           fakelibvirt))
        self.useFixture(fixtures.MonkeyPatch(
           'nova.virt.libvirt.guest.libvirt',
           fakelibvirt))
        self.useFixture(fakelibvirt.FakeLibvirtFixture())
Ejemplo n.º 7
0
    def setUp(self):
        super(RealTimeServersTest, self).setUp()

        # Replace libvirt with fakelibvirt
        self.useFixture(fake_imagebackend.ImageBackendFixture())
        self.useFixture(fixtures.MonkeyPatch(
           'nova.virt.libvirt.driver.libvirt_utils',
           fake_libvirt_utils))
        self.useFixture(fixtures.MonkeyPatch(
           'nova.virt.libvirt.driver.libvirt',
           fakelibvirt))
        self.useFixture(fixtures.MonkeyPatch(
           'nova.virt.libvirt.host.libvirt',
           fakelibvirt))
        self.useFixture(fixtures.MonkeyPatch(
           'nova.virt.libvirt.guest.libvirt',
           fakelibvirt))
        self.useFixture(fakelibvirt.FakeLibvirtFixture())
        self.flags(sysinfo_serial='none', group='libvirt')
Ejemplo n.º 8
0
    def _setup_fakelibvirt(self):
        # So that the _supports_direct_io does the test based
        # on the current working directory, instead of the
        # default instances_path which doesn't exist
        self.flags(instances_path=self.useFixture(fixtures.TempDir()).path)

        # Put fakelibvirt in place
        if 'libvirt' in sys.modules:
            self.saved_libvirt = sys.modules['libvirt']
        else:
            self.saved_libvirt = None

        from nova.tests.unit.virt.libvirt import fake_imagebackend
        from nova.tests.unit.virt.libvirt import fakelibvirt

        from nova.tests.unit.virt.libvirt import fake_os_brick_connector

        self.useFixture(fake_imagebackend.ImageBackendFixture())
        self.useFixture(fakelibvirt.FakeLibvirtFixture())

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.driver.connector',
                                 fake_os_brick_connector))

        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.virt.libvirt.host.Host._conn_event_thread',
                lambda *args: None))

        self.flags(rescue_image_id="2",
                   rescue_kernel_id="3",
                   rescue_ramdisk_id=None,
                   snapshots_directory='./',
                   sysinfo_serial='none',
                   group='libvirt')

        def fake_wait():
            pass

        def fake_detach_device_with_retry(_self, get_device_conf_func, device,
                                          live, *args, **kwargs):
            # Still calling detach, but instead of returning function
            # that actually checks if device is gone from XML, just continue
            # because XML never gets updated in these tests
            _self.detach_device(get_device_conf_func(device), live=live)
            return fake_wait

        self.stub_out(
            'nova.virt.libvirt.driver.LibvirtDriver.'
            '_get_instance_disk_info_from_config',
            lambda self, guest_config, block_device_info: [])
        self.stub_out('nova.virt.disk.api.extend', lambda image, size: None)
        self.stub_out(
            'nova.virt.libvirt.driver.LibvirtDriver.'
            'delete_instance_files', lambda self, instance: None)
        self.stub_out('nova.virt.libvirt.guest.Guest.detach_device_with_retry',
                      fake_detach_device_with_retry)
        self.stub_out('nova.virt.libvirt.guest.Guest.migrate',
                      lambda self, destination, migrate_uri=None, migrate_disks
                      =None, destination_xml=None, flags=0, bandwidth=0: None)
        # We can't actually make a config drive v2 because ensure_tree has
        # been faked out
        self.stub_out('nova.virt.configdrive.ConfigDriveBuilder.make_drive',
                      lambda self, path: None)
Ejemplo n.º 9
0
    def _setup_fakelibvirt(self):
        # So that the _supports_direct_io does the test based
        # on the current working directory, instead of the
        # default instances_path which doesn't exist
        self.flags(instances_path=self.useFixture(fixtures.TempDir()).path)

        # Put fakelibvirt in place
        if 'libvirt' in sys.modules:
            self.saved_libvirt = sys.modules['libvirt']
        else:
            self.saved_libvirt = None

        import nova.tests.unit.virt.libvirt.fake_imagebackend as \
            fake_imagebackend
        import nova.tests.unit.virt.libvirt.fake_libvirt_utils as \
            fake_libvirt_utils
        import nova.tests.unit.virt.libvirt.fakelibvirt as fakelibvirt

        import nova.tests.unit.virt.libvirt.fake_os_brick_connector as \
            fake_os_brick_connector

        self.useFixture(fake_imagebackend.ImageBackendFixture())
        self.useFixture(fakelibvirt.FakeLibvirtFixture())
        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.driver.libvirt_utils',
                                 fake_libvirt_utils))
        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.virt.libvirt.imagebackend.libvirt_utils',
                fake_libvirt_utils))

        self.useFixture(
            fixtures.MonkeyPatch('nova.virt.libvirt.driver.connector',
                                 fake_os_brick_connector))

        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.virt.libvirt.host.Host._conn_event_thread',
                lambda *args: None))

        self.flags(rescue_image_id="2",
                   rescue_kernel_id="3",
                   rescue_ramdisk_id=None,
                   snapshots_directory='./',
                   sysinfo_serial='none',
                   group='libvirt')

        def fake_extend(image, size):
            pass

        def fake_migrate(_self,
                         destination,
                         migrate_uri=None,
                         params=None,
                         flags=0,
                         domain_xml=None,
                         bandwidth=0):
            pass

        def fake_make_drive(_self, _path):
            pass

        def fake_get_instance_disk_info(_self,
                                        instance,
                                        xml=None,
                                        block_device_info=None):
            return '[]'

        def fake_delete_instance_files(_self, _instance):
            pass

        def fake_wait():
            pass

        def fake_detach_device_with_retry(_self,
                                          get_device_conf_func,
                                          device,
                                          persistent,
                                          live,
                                          max_retry_count=7,
                                          inc_sleep_time=2,
                                          max_sleep_time=30):
            # Still calling detach, but instead of returning function
            # that actually checks if device is gone from XML, just continue
            # because XML never gets updated in these tests
            _self.detach_device(get_device_conf_func(device),
                                persistent=persistent,
                                live=live)
            return fake_wait

        import nova.virt.libvirt.driver

        self.stubs.Set(nova.virt.libvirt.driver.LibvirtDriver,
                       '_get_instance_disk_info', fake_get_instance_disk_info)

        self.stubs.Set(nova.virt.libvirt.driver.disk_api, 'extend',
                       fake_extend)

        self.stubs.Set(nova.virt.libvirt.driver.LibvirtDriver,
                       'delete_instance_files', fake_delete_instance_files)

        self.stubs.Set(nova.virt.libvirt.guest.Guest,
                       'detach_device_with_retry',
                       fake_detach_device_with_retry)

        self.stubs.Set(nova.virt.libvirt.guest.Guest, 'migrate', fake_migrate)

        # We can't actually make a config drive v2 because ensure_tree has
        # been faked out
        self.stubs.Set(nova.virt.configdrive.ConfigDriveBuilder, 'make_drive',
                       fake_make_drive)