Ejemplo n.º 1
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

        self.useFixture(nova_fixtures.OSBrickFixture())
        self.useFixture(nova_fixtures.LibvirtImageBackendFixture())
        self.useFixture(nova_fixtures.LibvirtFixture())

        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.º 2
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(nova_fixtures.LibvirtImageBackendFixture())
        self.useFixture(nova_fixtures.LibvirtFixture())
        self.useFixture(nova_fixtures.OSBrickFixture())

        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)
Ejemplo n.º 3
0
    def setUp(self):
        super(NUMALiveMigrationBase, self).setUp()

        self.useFixture(nova_fixtures.OSBrickFixture())

        # NOTE(artom) There's a specific code path that we want to test.
        # There's an instance.save() call in the compute manager's
        # post_live_migration_at_destination(), and another instance.save()
        # call in the libvirt driver's cleanup(), as called from
        # _post_live_migration() in the compute manager. We want to make sure
        # the latter does not clobber any NUMA topology information saved by
        # the former. In order to trigger that code path, two things need to
        # happen. First, the do_cleanup variable needs to be True, in order for
        # driver.cleanup() to actually get called by _post_live_migration().
        # Second, destroy_disks needs to be True as well, in order for
        # cleanup() to enter the code block containing the instance.save()
        # call. Both do_cleanup and destroy_disks are set by
        # _live_migration_cleanup_flags(), so we just monkeypatch it to return
        # what we want regardless of any shared storage configuration.
        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.compute.manager.ComputeManager.'
                '_live_migration_cleanup_flags', lambda *args, **kwargs:
                (True, True)))
Ejemplo n.º 4
0
    def setUp(self):
        super().setUp()
        self.neutron.list_extensions = self.list_extensions
        self.neutron_api = neutron.API()

        self.useFixture(nova_fixtures.OSBrickFixture())

        self.start_compute(hostname='start_host',
                           host_info=fakelibvirt.HostInfo(cpu_nodes=1,
                                                          cpu_sockets=1,
                                                          cpu_cores=4,
                                                          cpu_threads=2))
        self.start_compute(hostname='end_host',
                           host_info=fakelibvirt.HostInfo(cpu_nodes=1,
                                                          cpu_sockets=1,
                                                          cpu_cores=4,
                                                          cpu_threads=2))

        self.ctxt = context.get_admin_context()
        # TODO(sean-k-mooney): remove this when it is part of ServersTestBase
        self.useFixture(
            fixtures.MonkeyPatch(
                'nova.tests.fixtures.libvirt.Domain.migrateToURI3',
                self._migrate_stub))