示例#1
0
    def _get_base_class(self):
        # We do this because it has the side-effect of loading all the
        # volume drivers
        self.useFixture(nova_fixtures.LibvirtFixture())
        driver.LibvirtDriver(fake.FakeVirtAPI(), False)

        return volume.LibvirtBaseVolumeDriver
示例#2
0
 def setUp(self):
     super(LibvirtProviderUsageBaseTestCase, self).setUp()
     self.useFixture(nova_fixtures.LibvirtFixture(stub_os_vif=False))
     if self.STUB_INIT_HOST:
         self.useFixture(
             fixtures.MockPatch(
                 'nova.virt.libvirt.driver.LibvirtDriver.init_host'))
     self.useFixture(
         fixtures.MockPatch('nova.virt.libvirt.driver.LibvirtDriver.spawn'))
示例#3
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)
示例#4
0
    def setUp(self):
        super(GuestBlockTestCase, self).setUp()

        self.useFixture(nova_fixtures.LibvirtFixture())
        self.host = host.Host("qemu:///system")
        self.context = context.get_admin_context()

        self.domain = mock.Mock(spec=fakelibvirt.virDomain)
        self.guest = libvirt_guest.Guest(self.domain)
        self.gblock = self.guest.get_block_device('vda')
示例#5
0
    def setUp(self):
        super(JobInfoTestCase, self).setUp()

        self.useFixture(nova_fixtures.LibvirtFixture())

        self.conn = fakelibvirt.openAuth("qemu:///system", [[], lambda: True])
        xml = ("<domain type='kvm'>"
               "  <name>instance-0000000a</name>"
               "</domain>")
        self.dom = self.conn.createXML(xml, 0)
        self.guest = libvirt_guest.Guest(self.dom)
        libvirt_guest.JobInfo._have_job_stats = True
示例#6
0
    def setUp(self):
        super(GuestTestCase, self).setUp()

        self.useFixture(nova_fixtures.LibvirtFixture())
        self.host = host.Host("qemu:///system")
        self.context = context.get_admin_context()

        self.domain = mock.Mock(spec=fakelibvirt.virDomain)
        self.guest = libvirt_guest.Guest(self.domain)

        # Make RetryDecorator not actually sleep on retries
        self.useFixture(service_fixture.SleepFixture())
示例#7
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)
示例#8
0
 def test_find_disk_lxc(self):
     self.useFixture(nova_fixtures.LibvirtFixture())
     xml = """
       <domain type='lxc'>
         <os>
           <type>exe</type>
         </os>
         <devices>
           <filesystem type="mount">
             <source dir="/myhome/rootfs"/>
             <target dir="/"/>
           </filesystem>
         </devices>
       </domain>
     """
     virt_dom = mock.Mock(XMLDesc=mock.Mock(return_value=xml))
     guest = libvirt_guest.Guest(virt_dom)
     disk_path, format = libvirt_utils.find_disk(guest)
     self.assertEqual('/myhome/disk', disk_path)
     self.assertIsNone(format)
示例#9
0
 def test_find_disk_parallels(self):
     self.useFixture(nova_fixtures.LibvirtFixture())
     xml = """
       <domain type='parallels'>
         <os>
           <type>exe</type>
         </os>
         <devices>
           <filesystem type='file'>"
             <driver format='ploop' type='ploop'/>"
             <source file='/test/disk'/>"
             <target dir='/'/>
           </filesystem>"
         </devices>
       </domain>
     """
     virt_dom = mock.Mock(XMLDesc=mock.Mock(return_value=xml))
     guest = libvirt_guest.Guest(virt_dom)
     disk_path, format = libvirt_utils.find_disk(guest)
     self.assertEqual('/test/disk', disk_path)
     self.assertEqual('ploop', format)
示例#10
0
 def test_find_disk_block_device(self):
     self.useFixture(nova_fixtures.LibvirtFixture())
     xml = """
       <domain type='kvm'>
         <os>
           <type>linux</type>
         </os>
         <devices>
           <disk type="block" device="disk">
             <driver name="qemu" type="raw"/>
             <source dev="/dev/nova-vg/hello"/>
             <target bus="ide" dev="/dev/hda"/>
           </disk>
         </devices>
       </domain>
     """
     virt_dom = mock.Mock(XMLDesc=mock.Mock(return_value=xml))
     guest = libvirt_guest.Guest(virt_dom)
     disk_path, format = libvirt_utils.find_disk(guest)
     self.assertEqual('/dev/nova-vg/hello', disk_path)
     self.assertEqual('raw', format)
示例#11
0
 def test_find_disk_file_device(self):
     self.useFixture(nova_fixtures.LibvirtFixture())
     xml = """
       <domain type='kvm'>
         <os>
           <type>linux</type>
         </os>
         <devices>
           <disk type="file" device="disk">
             <driver name="qemu" type="qcow2" cache="none" io="native"/>
             <source file="/tmp/hello"/>
             <target bus="ide" dev="/dev/hda"/>
           </disk>
         </devices>
       </domain>
     """
     virt_dom = mock.Mock(XMLDesc=mock.Mock(return_value=xml))
     guest = libvirt_guest.Guest(virt_dom)
     disk_path, format = libvirt_utils.find_disk(guest)
     self.assertEqual('/tmp/hello', disk_path)
     self.assertEqual('qcow2', format)
示例#12
0
 def test_find_disk_rbd(self):
     self.useFixture(nova_fixtures.LibvirtFixture())
     xml = """
       <domain type='kvm'>
         <os>
           <type>linux</type>
         </os>
         <devices>
           <disk type="network" device="disk">
             <driver name="qemu" type="raw"/>
             <source name="pool/image" protocol="rbd">
               <host name="1.2.3.4" port="456"/>
             </source>
             <target bus="virtio" dev="/dev/vda"/>
           </disk>
         </devices>
       </domain>
     """
     virt_dom = mock.Mock(XMLDesc=mock.Mock(return_value=xml))
     guest = libvirt_guest.Guest(virt_dom)
     disk_path, format = libvirt_utils.find_disk(guest)
     self.assertEqual('rbd:pool/image', disk_path)
     self.assertEqual('raw', format)
示例#13
0
    def setUp(self):
        super(LibvirtVolumeBaseTestCase, self).setUp()

        self.useFixture(nova_fixtures.LibvirtFixture())

        self.fake_host = host.Host("qemu:///system")

        self.connr = {
            'ip': '127.0.0.1',
            'initiator': 'fake_initiator',
            'host': 'fake_host'
        }
        self.disk_info = {
            "bus": "virtio",
            "dev": "vde",
            "type": "disk",
        }
        self.name = 'volume-00000001'
        self.location = '10.0.2.15:3260'
        self.iqn = 'iqn.2010-10.org.openstack:%s' % self.name
        self.vol = {'id': 1, 'name': self.name}
        self.uuid = '875a8070-d0b9-4949-8b31-104d125c9a64'
        self.user = '******'
示例#14
0
    def setUp(self):
        super(TestSerialConsoleLiveMigrate, self).setUp()
        self.useFixture(nova_fixtures.RealPolicyFixture())
        self.useFixture(nova_fixtures.NeutronFixture(self))
        self.useFixture(nova_fixtures.GlanceFixture(self))
        self.useFixture(func_fixtures.PlacementFixture())
        api_fixture = self.useFixture(
            nova_fixtures.OSAPIFixture(api_version='v2.1'))
        # Replace libvirt with fakelibvirt
        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(nova_fixtures.LibvirtFixture())

        self.admin_api = api_fixture.admin_api
        self.api = api_fixture.api

        self.flags(compute_driver='libvirt.LibvirtDriver')
        self.flags(enabled=True, group="serial_console")
        self.flags(enabled=False, group="vnc")
        self.flags(enabled=False, group="spice")

        self.start_service('conductor')
        self.start_service('scheduler')
        self.compute = self.start_service('compute', host='test_compute1')

        self.useFixture(nova_fixtures.CastAsCallFixture(self))

        self.image_id = self.api.get_images()[0]['id']
        self.flavor_id = self.api.get_flavors()[0]['id']
示例#15
0
    def setUp(self):
        super(_LibvirtEvacuateTest, self).setUp()

        self.useFixture(nova_fixtures.CinderFixture(self))
        self.useFixture(nova_fixtures.NeutronFixture(self))
        self.useFixture(nova_fixtures.GlanceFixture(self))
        self.useFixture(func_fixtures.PlacementFixture())
        fake_network.set_stub_network_methods(self)

        api_fixture = self.useFixture(
            nova_fixtures.OSAPIFixture(api_version='v2.1'))

        self.api = api_fixture.admin_api
        # force_down and evacuate without onSharedStorage
        self.api.microversion = '2.14'

        self.notifier = self.useFixture(
            nova_fixtures.NotificationFixture(self))

        self.useFixture(nova_fixtures.LibvirtFixture())

        # Fake out all the details of volume connection
        self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.driver.LibvirtDriver.get_volume_connector'))
        self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.driver.LibvirtDriver._connect_volume'))
        # For cleanup
        self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.driver.LibvirtDriver._disconnect_volume'))

        volume_config = libvirt_config.LibvirtConfigGuestDisk()
        volume_config.driver_name = 'fake-volume-driver'
        volume_config.source_path = 'fake-source-path'
        volume_config.target_dev = 'fake-target-dev'
        volume_config.target_bus = 'fake-target-bus'
        get_volume_config = self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.driver.LibvirtDriver._get_volume_config')
        ).mock
        get_volume_config.return_value = volume_config

        # Ensure our computes report lots of available disk, vcpu, and ram
        lots = 10000000
        get_local_gb_info = self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.driver.LibvirtDriver._get_local_gb_info')
        ).mock
        get_local_gb_info.return_value = {
            'total': lots,
            'free': lots,
            'used': 1
        }
        get_vcpu_available = self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.driver.LibvirtDriver._get_vcpu_available')
        ).mock
        get_vcpu_available.return_value = set(cpu for cpu in range(24))
        get_memory_mb_total = self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.host.Host.get_memory_mb_total')).mock
        get_memory_mb_total.return_value = lots

        # Mock out adding rng devices
        self.useFixture(
            fixtures.MockPatch(
                'nova.virt.libvirt.driver.LibvirtDriver._add_rng_device')).mock

        self.start_service('conductor')
        self.start_service('scheduler')

        self.flags(compute_driver='libvirt.LibvirtDriver')

        ctxt = context.get_admin_context()
        for flavor in FLAVOR_FIXTURES:
            objects.Flavor(context=ctxt, **flavor).create()
示例#16
0
 def setUp(self):
     self.flags(compute_driver='libvirt.LibvirtDriver')
     self.useFixture(nova_fixtures.LibvirtFixture())
     self.useFixture(fixtures.MockPatchObject(host.Host, 'initialize'))
     super(TestLibvirtErrorNotificationSample, self).setUp()