Exemple #1
0
 def test_get_guest_cpu_config_mode_is_none(self, mock_conf):
   mock_conf.libvirt_cpu_mode = None
   mock_conf.libvirt_cpu_model = None
   qemuwindriver = QemuWinDriver()
   expected_result = 'fakecpu'
   actual_result = qemuwindriver.get_guest_cpu_config()
   self.assertEqual(expected_result, actual_result)
Exemple #2
0
 def test_create_local(self, mock_conf):
   target = 'faketarget'
   local_size = 5
   mock_conf.default_ephemeral_format = 'fakeformat'
   QemuWinDriver._create_local(target, local_size)
   QemuWinDriver._utils_mkfs.assert_called_with('fakeformat', target, None)
   QemuWinDriver._create_raw_image.assert_called_with(target, 5, 'G')
Exemple #3
0
 def test_set_cache_mode(self, mock_conf):
   mock_conf.source_type = 'fakesourcetype'
   mock_conf.driver_cache = 'fakedrivercache'
   qemuwindriver = QemuWinDriver()
   qemuwindriver.disk_cachemodes = {'fakemode' : 'fakecachemode'}
   qemuwindriver.set_cache_mode(mock_conf)
   self.assertEqual('fakedrivercache', mock_conf.driver_cache)
Exemple #4
0
 def test_start_qemu_instance_smooth_run(self):
   instance = {'project_id':'fakeprojectid', 'name':'fakename'}
   qemuwindriver = QemuWinDriver()
   qemuwindriver.start_qemu_instance(instance)
   QemuWinDriver._create_qemu_machine.assert_called_with(instance, 'fakemetadataport', 'fakemetadatapid', 'i386')
   qemuwindriver._create_subproccess.assert_called_with('fakecmdline')
   qemuwindriver._check_machine_started.assert_called_with(instance)
Exemple #5
0
 def test_qemuCommandAddArg(self, mock_conf):
   qemuwindriver = QemuWinDriver()
   command = ['fakecommand']
   arg = 'fakearg'
   val = 'fakevalue'
   qemuwindriver.qemuCommandAddArg(command, arg, val)
   expected_command = ['fakecommand', arg, val]
   self.assertEqual(command, expected_command)
Exemple #6
0
 def test_create_image_configdrive_required(self, mock_conf):
   mock_conf.libvirt_images_type = 'fakeimagetype'
   context = 'fakecontext'
   instance = {'image_ref' : 'True', 'kernel_id': 'fakekernelid', 'ramdisk_id': None, 'user_id': 'fakeuserid', 'project_id': 'fakeprojectid', 'root_gb' : 1, 'os_type': 'fakeostype', 'ephemeral_gb': 1, 'metadata': 'fakemetadata', 'name': 'fakename', 'uuid': 'fakeuuid', 'host': 'fakehost'}
   disk_mapping = {'disk': 'fakediskinfo', 'disk.local': 'fakedisklocalinfo', 'disk.swap': {'dev': 'fakediskswapinfo', 'device_name': 'fakedevicename', 'swap_size': 'fakeswapsize'}}
   qemuwindriver = QemuWinDriver()
   qemuwindriver.image_backend = mock.Mock()
   qemuwindriver._create_image(context, instance, disk_mapping)
Exemple #7
0
 def test_create_ephemeral(self):
   qemuwindriver = QemuWinDriver()
   target = 'faketarget'
   ephemeral_size = 'fakeephemeralsize'
   fs_label = 'fakefs_label'
   os_type = 'fakeos_type'
   qemuwindriver._create_ephemeral(target, ephemeral_size, fs_label, os_type)
   qemuwindriver._create_local.assert_called_with(target, ephemeral_size)
Exemple #8
0
 def test_getEl(self, mock_conf, mock_minidom):
   qemuwindriver = QemuWinDriver()
   elName = 'cpu'
   fakevalue = 'fakevalue'
   mock_minidom.getElementsByTagName.return_value = [fakevalue]
   element = qemuwindriver.getEl(mock_minidom, elName)
   self.assertEqual(element, fakevalue)
   mock_minidom.getElementsByTagName.return_value = []
   self.assertRaises(IndexError, qemuwindriver.getEl, mock_minidom, elName)
Exemple #9
0
 def test_get_host_cpu_for_guest(self):
   qemuwindriver = QemuWinDriver()
   expected_model = 'fakemodel'
   expected_vendor = 'fakevendor'
   expected_arch = 'i386'
   actual_result = qemuwindriver.get_host_cpu_for_guest()
   self.assertEqual(expected_model, actual_result.model)
   self.assertEqual(expected_vendor, actual_result.vendor)
   self.assertEqual(expected_arch, actual_result.arch)
Exemple #10
0
 def test_getEls(self, mock_conf, mock_minidom):
   qemuwindriver = QemuWinDriver()
   elName = 'cpu'
   fakevalue = 'fakevalue'
   mock_minidom.getElementsByTagName.return_value = [fakevalue]
   element = qemuwindriver.getEls(mock_minidom, elName)
   self.assertEqual(element, [fakevalue])
   mock_minidom.getElementsByTagName.return_value = []
   element = qemuwindriver.getEls(mock_minidom, elName)
   self.assertEqual(element, [])
Exemple #11
0
 def test_qemuCommandStr(self, mock_conf):
   qemuwindriver = QemuWinDriver()
   command = ['fakecommand', 'fakearg', 'fakevalue']
   command_str = qemuwindriver.qemuCommandStr(command)
   command_str_expected = 'fakecommand fakearg fakevalue'
   self.assertEqual(command_str, command_str_expected)
   command = ['fakecommand']
   command_str = qemuwindriver.qemuCommandStr(command)
   command_str_expected = 'fakecommand'
   self.assertEqual(command_str, command_str_expected)
Exemple #12
0
 def test_start_metadata_proxy_no_pid_information(self, mock_conf, mock_path):
   instance = {'uuid':'fakeuuid'}
   tenant_id = 'faketenantid'
   qemuwindriver = QemuWinDriver()
   mock_path.dirname = INSTANCE_TEST_PATH
   mock_conf.nova_metadata_host = 'fakemetadatahost'
   mock_conf.nova_metadata_port = 'fakemetadataport'
   mock_conf.nova_metadata_shared_secret = 'fakemetadatasharedsecret'
   expected_return = 'fakeport' , ''
   method_return = qemuwindriver._start_metadata_proxy(instance, tenant_id)
Exemple #13
0
 def test_get_guest_storage_config_rescue(self):
   qemuwindriver = QemuWinDriver()
   instance = 'fakeinstance'
   image_meta = 'fakeimagemeta'
   disk_info = {'mapping': ['disk.config']}
   rescue = True
   block_device_info = 'fakeblockdeviceinfo'
   inst_type = 'fakeinsttype'
   expected_result = ['fakediskrescueconfig', 'fakediskosconfig', 'fakediskconfigconfig']
   actual_result = qemuwindriver.get_guest_storage_config(instance, image_meta, disk_info, rescue, block_device_info, inst_type)
   assert qemuwindriver.set_cache_mode.called
   self.assertEqual(expected_result, actual_result)
Exemple #14
0
 def test_spawn_smooth_run(self):
   qemuwindriver = QemuWinDriver()
   qemuwindriver._socket_locks = {}
   context = 'fakecontext'
   instance = {'uuid': 'fakeuuid', 'name':'fakename'}
   image_meta = 'fakeimagemeta'
   injectedfiles = 'fakeinjectedfiles'
   adminpassword = '******'
   qemuwindriver.spawn(context, instance, image_meta, injectedfiles, adminpassword)
   QemuWinDriver._get_disk_info.assert_called_with('qemu', instance, None, image_meta)
   QemuWinDriver._create_image.assert_called_with(context, instance, 'fakemapping', network_info =None,block_device_info = None,files = injectedfiles,admin_pass = adminpassword)
   QemuWinDriver.to_xml.assert_called_with(context, instance, None, {'mapping': 'fakemapping'}, image_meta, block_device_info = None, write_to_disk = True)
Exemple #15
0
 def test_qemuCommandNew(self, mock_conf):
   qemuwindriver = QemuWinDriver()
   mock_conf.qemu_home = INSTANCE_TEST_PATH
   arch = 'x64'
   qemu_command = qemuwindriver.qemuCommandNew(arch)
   qemu_command_expected = ['"%s"' % os.path.join(INSTANCE_TEST_PATH, 'qemu-system-x64.exe')]
   self.assertEqual(qemu_command, qemu_command_expected)
   mock_conf.qemu_home = None
   arch = 'x86'
   qemu_command = qemuwindriver.qemuCommandNew(arch)
   qemu_command_expected = ['qemu-system-x86.exe']
   self.assertEqual(qemu_command, qemu_command_expected)
Exemple #16
0
 def test_get_guest_storage_config_not_rescue(self):
   qemuwindriver = QemuWinDriver()
   qemuwindriver.virtapi = mock.Mock()
   qemuwindriver.virtapi.instance_update = mock.Mock()
   instance = {'uuid': 'fakeuuid'}
   image_meta = 'fakeimagemeta'
   disk_info = {'mapping': ['disk', 'disk.local', 'disk.swap']}
   rescue = False
   block_device_info = 'fakeblockdeviceinfo'
   inst_type = 'fakeinsttype'
   expected_result = ['fakediskosconfig', 'fakedisklocalconfig', 'fakediskephconfig', 'fakediskswapconfig', 'fakevolumedriverconfig']
   actual_result = qemuwindriver.get_guest_storage_config(instance, image_meta, disk_info, rescue, block_device_info, inst_type)
   assert qemuwindriver.set_cache_mode.called
Exemple #17
0
 def test_get_guest_pci_device(self):
   qemuwindriver = QemuWinDriver()
   pci_device = {'address' : 'fakeaddress'}
   expected_domain = 'fakedomain'
   expected_bus = 'fakebus'
   expected_slot = 'fakeslot'
   expected_function = 'fakefunction'
   expected_managed = 'yes'
   actual_result = qemuwindriver.get_guest_pci_device(pci_device)
   self.assertEqual(expected_domain, actual_result.domain)
   self.assertEqual(expected_bus, actual_result.bus)
   self.assertEqual(expected_slot, actual_result.slot)
   self.assertEqual(expected_function, actual_result.function)
   self.assertEqual(expected_managed, actual_result.managed)
Exemple #18
0
 def test_get_host_capabilities_no_existing_caps(self):
   qemuwindriver = QemuWinDriver()
   qemuwindriver._caps = None
   expected_uuid = 'fakeuuid'
   expected_arch = 'i386'
   expected_model = 'host-model'
   expected_vendor = 'Intel'
   expected_features = []
   actual_result = qemuwindriver.get_host_capabilities()
   self.assertEqual(expected_uuid, actual_result.host.uuid) 
   self.assertEqual(expected_arch, actual_result.host.cpu.arch)
   self.assertEqual(expected_model, actual_result.host.cpu.model)
   self.assertEqual(expected_vendor, actual_result.host.cpu.vendor)
   self.assertEqual(expected_features, actual_result.host.cpu.features)
Exemple #19
0
  def test_disk_cache_mode(self, mock_conf):
    qemuwindriver = QemuWinDriver()
    mock_conf.instances_path = None

    qemuwindriver._disk_cachemode = None
 #   mock_supp.return_value = False
    cachemode = qemuwindriver.disk_cachemode
    self.assertEqual(cachemode, "writethrough")

    qemuwindriver._disk_cachemode = None
    cachemode = qemuwindriver.disk_cachemode
    self.assertEqual(cachemode, 'none')

    qemuwindriver._disk_cachemode = 'none'
    cachemode = qemuwindriver.disk_cachemode
    self.assertEqual(cachemode ,'none')
Exemple #20
0
  def test_get_guest_config_sysinfo(self):
    qemuwindriver = QemuWinDriver()
    instance = {'uuid' : 'fakeuuid'}
    expected_system_manufacturer = 'fakevendorstring'
    expected_system_product = 'fakeproductstring'
    expected_system_version = 'fakeversionstring'
    expected_system_serial = 'fakehostuuid'
    expected_system_uuid = 'fakeuuid'

    actual_result = qemuwindriver.get_guest_config_sysinfo(instance)
    self.assertEqual(expected_system_manufacturer, actual_result.system_manufacturer)
    self.assertEqual(expected_system_product, actual_result.system_product)
    self.assertEqual(expected_system_version, actual_result.system_version)
    self.assertEqual(expected_system_version, actual_result.system_version)
    self.assertEqual(expected_system_serial, actual_result.system_serial)
    self.assertEqual(expected_system_uuid, actual_result.system_uuid)
Exemple #21
0
  def test_list_instance(self, mock_conf):
    # set up the mock
    qemuwindriver = QemuWinDriver()
    mock_conf.instances_path = INSTANCE_TEST_PATH
    
    #resets the test environment
    self.reset_test_environ()
    #creating two fake instances

    self.add_fake_instances()
    time.sleep(1)
    self.add_fake_instances()

    #calling the testes method

    listinstances = qemuwindriver.list_instances()

    #comparing method return to stored information

    self.assertItemsEqual(instance_tracker, listinstances)

    #comparing number of instances to expected number

    assert len(listinstances) == 2

    #removing a fake instance

    self.remove_fake_instance()

    listinstances = qemuwindriver.list_instances()

    self.assertItemsEqual(instance_tracker, listinstances)

    assert len(listinstances) == 1

    self.remove_fake_instance()

    listinstances = qemuwindriver.list_instances()

    #Expects a empty list if there are no instances

    self.assertItemsEqual([], listinstances)

    assert len(listinstances) == 0
Exemple #22
0
 def test_get_guest_config(self, mock_conf):
   qemuwindriver = QemuWinDriver()
   qemuwindriver.virtapi = mock.Mock()
   qemuwindriver.virtapi.instance_type_get.return_value =  {'memory_mb': 'fakememory', 'vcpus': 'fakevcpus', 'extra_specs': {'quota:cpu_quota' : 'fake_value'}}
   qemuwindriver.virtapi.instance_update = mock.Mock()
   qemuwindriver.vif_driver = mock.Mock()
   qemuwindriver.vif_driver.get_config.return_value = 'fakevifdriverconfig '
   mock_conf.libvirt_type = 'fakevirttype'
   mock_conf.vcpu_pin_set = 'fakecpuset'
   mock_conf.vnc_enabled = 'True'
   mock_conf.use_usb_tablet = 'fakeneedusbtablet'
   mock_conf.spice = mock.Mock()
   mock_conf.spice.enable = 'fakespiceenabled'
   mock_conf.spice.agent_enabled = 'fakespiceagentenabled'
   instance = {'instance_type_id': 'fakeinstancetypeid', 'name': 'fakename', 'uuid': 'fakeuuid', 'kernel_id' : False, 'os_type' : 'windows'}
   network_info = ['fakevif']
   image_meta = {'properties': {'hw_qemu_guest_agent': 'fakehw_qga'}}
   disk_info ={'mapping': {'root': {'dev': 'fakedev'}}}
   actual_result = qemuwindriver.get_guest_config(instance, network_info, image_meta, disk_info)
Exemple #23
0
 def test_wait_for_qmp_running_on_first_try(self):
   qemuwindriver = QemuWinDriver()
   instance = {'name' : 'fakename'}
   qemuwindriver.QEMU_SPAWN_MAX_RETRIES = 1
   qemuwindriver._wait_for_qmp(instance)
Exemple #24
0
 def test_wait_for_qmp_fails(self):
   qemuwindriver = QemuWinDriver()
   instance = {'name' : 'fakename'}
   qemuwindriver.QEMU_SPAWN_MAX_RETRIES = 1
   self.assertRaises(Exception, qemuwindriver._wait_for_qmp, instance)
Exemple #25
0
 def test_chown_disk_config_for_instance_path_not_exists(self, mock_path):
   mock_path.exists.return_value = False
   instance = 'fakeinstance'
   qemuwindriver = QemuWinDriver()
   qemuwindriver._chown_disk_config_for_instance(instance)
   assert not qemuwindriver._chown.called, 'method should not have been called'
Exemple #26
0
 def test_get_host_state_file_not_exists(self, mock_conf):
   qemuwindriver = QemuWinDriver()
   mock_conf.instance_path = INSTANCE_TEST_PATH
   expected_result = 'fakestate'
   actual_result = qemuwindriver._get_host_state()
   self.assertEqual(expected_result, actual_result)
Exemple #27
0
 def test_get_guest_cpu_config_mode_is_none_model_not_none(self, mock_conf):
   mock_conf.libvirt_cpu_mode = None
   mock_conf.libvirt_cpu_model = 'Notnone'
   qemuwindriver = QemuWinDriver()
   expected_result = 'fakecpu'
   self.assertRaises(Exception, qemuwindriver.get_guest_cpu_config)
Exemple #28
0
 def test_create_host_state_file(self, mock_conf):
   mock_conf.instance_path = INSTANCE_TEST_PATH
   qemuwindriver = QemuWinDriver()
   expected_result = {'uuid': 'fakeuuid', 'arch': 'fakearch', 'next_volume_index': 0}
   actual_result = qemuwindriver._create_host_state_file()
   self.assertEqual(expected_result, actual_result)
Exemple #29
0
 def test_next_vnc_display(self):
   qemuwindriver = QemuWinDriver()
   test_result = qemuwindriver._next_vnc_display()
   expected_result = (1, 5901)
   self.assertEqual(expected_result, test_result)
Exemple #30
0
 def test_get_host_uuid(self):
   qemuwindriver = QemuWinDriver()
   expected_result = 'fakeuuid'
   actual_result= qemuwindriver.get_host_uuid()
   self.assertEqual(expected_result, actual_result)
 def test_check_machine_started_file_is_empty(self):
   instance = 'instance'
   qemuwindriver = QemuWinDriver()
   self.assertFalse(qemuwindriver._check_machine_started(instance))