Exemplo n.º 1
0
 def test_get_vm_create_spec(self):
     instance_uuid = uuidutils.generate_uuid()
     fake_instance = {
         'id': 7,
         'name': 'fake!',
         'uuid': instance_uuid,
         'vcpus': 2,
         'memory_mb': 2048
     }
     result = vm_util.get_vm_create_spec(fake.FakeFactory(), fake_instance,
                                         instance_uuid, 'fake-datastore',
                                         [])
     expected = """{
         'files': {'vmPathName': '[fake-datastore]',
         'obj_name': 'ns0:VirtualMachineFileInfo'},
         'instanceUuid': '%(instance_uuid)s',
         'name': '%(instance_uuid)s', 'deviceChange': [],
         'extraConfig': [{'value': '%(instance_uuid)s',
                          'key': 'nvp.vm-uuid',
                          'obj_name': 'ns0:OptionValue'}],
         'memoryMB': 2048,
         'obj_name': 'ns0:VirtualMachineConfigSpec',
         'guestId': 'otherGuest',
         'tools': {'beforeGuestStandby': True,
                   'beforeGuestReboot': True,
                   'beforeGuestShutdown': True,
                   'afterResume': True,
                   'afterPowerOn': True,
         'obj_name': 'ns0:ToolsConfigInfo'},
         'numCPUs': 2}""" % {
         'instance_uuid': instance_uuid
     }
     expected = re.sub(r'\s+', '', expected)
     result = re.sub(r'\s+', '', repr(result))
     self.assertEqual(expected, result)
Exemplo n.º 2
0
 def _test_detach_virtual_disk_spec(self, destroy_disk=False):
     virtual_device_config = vm_util.detach_virtual_disk_spec(
         fake.FakeFactory(), 'fake_device', destroy_disk)
     self.assertEqual('remove', virtual_device_config.operation)
     self.assertEqual('fake_device', virtual_device_config.device)
     self.assertEqual('ns0:VirtualDeviceConfigSpec',
                      virtual_device_config.obj_name)
     if destroy_disk:
         self.assertEqual('destroy', virtual_device_config.fileOperation)
     else:
         self.assertFalse(hasattr(virtual_device_config, 'fileOperation'))
Exemplo n.º 3
0
 def test_get_resize_spec(self):
     fake_instance = {'id': 7, 'name': 'fake!',
                      'uuid': 'bda5fb9e-b347-40e8-8256-42397848cb00',
                      'vcpus': 2, 'memory_mb': 2048}
     result = vm_util.get_vm_resize_spec(fake.FakeFactory(),
                                         fake_instance)
     expected = """{'memoryMB': 2048,
                    'numCPUs': 2,
                    'obj_name': 'ns0:VirtualMachineConfigSpec'}"""
     expected = re.sub(r'\s+', '', expected)
     result = re.sub(r'\s+', '', repr(result))
     self.assertEqual(expected, result)
Exemplo n.º 4
0
 def test_allocate_controller_key_and_unit_number_scsi(self):
     # Test that we allocate on existing SCSI controller if there is a free
     # slot on it
     devices = [fake.VirtualLsiLogicController(1000, scsiCtlrUnitNumber=7)]
     for unit_number in range(7):
         disk = fake.VirtualDisk(1000, unit_number)
         devices.append(disk)
     factory = fake.FakeFactory()
     (controller_key, unit_number,
      controller_spec) = vm_util.allocate_controller_key_and_unit_number(
          factory, devices, 'lsiLogic')
     self.assertEqual(1000, controller_key)
     self.assertEqual(8, unit_number)
     self.assertIsNone(controller_spec)
Exemplo n.º 5
0
 def test_allocate_controller_key_and_unit_number_ide(self):
     # Test that a new controller is created when there is no free slot on
     # the default IDE controllers
     ide0 = fake.VirtualIDEController(200)
     ide1 = fake.VirtualIDEController(201)
     devices = [ide0, ide1]
     for controller_key in [200, 201]:
         for unit_number in [0, 1]:
             disk = fake.VirtualDisk(controller_key, unit_number)
             devices.append(disk)
     factory = fake.FakeFactory()
     (controller_key, unit_number,
      controller_spec) = vm_util.allocate_controller_key_and_unit_number(
          factory, devices, 'ide')
     self.assertEqual(-101, controller_key)
     self.assertEqual(0, unit_number)
     self.assertIsNotNone(controller_spec)
Exemplo n.º 6
0
    def test_get_cdrom_attach_config_spec(self):

        result = vm_util.get_cdrom_attach_config_spec(fake.FakeFactory(),
                                             fake.Datastore(),
                                             "/tmp/foo.iso",
                                             0)
        expected = """{
    'deviceChange': [
        {
            'device': {
                'connectable': {
                    'allowGuestControl': False,
                    'startConnected': True,
                    'connected': True,
                    'obj_name': 'ns0: VirtualDeviceConnectInfo'
                },
                'backing': {
                    'datastore': {
                        "summary.type": "VMFS",
                        "summary.accessible":true,
                        "summary.name": "fake-ds",
                        "summary.capacity": 1099511627776,
                        "summary.freeSpace": 536870912000,
                        "browser": ""
                    },
                    'fileName': '/tmp/foo.iso',
                    'obj_name': 'ns0: VirtualCdromIsoBackingInfo'
                },
                'controllerKey': 200,
                'unitNumber': 0,
                'key': -1,
                'obj_name': 'ns0: VirtualCdrom'
            },
            'operation': 'add',
            'obj_name': 'ns0: VirtualDeviceConfigSpec'
        }
    ],
    'obj_name': 'ns0: VirtualMachineConfigSpec'
}
"""

        expected = re.sub(r'\s+', '', expected)
        result = re.sub(r'\s+', '', repr(result))
        self.assertEqual(expected, result)
Exemplo n.º 7
0
    def _test_get_vnc_config_spec(self, port):

        result = vm_util.get_vnc_config_spec(fake.FakeFactory(), port)
        return result
Exemplo n.º 8
0
 def test_lsilogic_controller_spec(self):
     # Test controller spec returned for lsiLogic sas adapter type
     config_spec = vm_util.create_controller_spec(
         fake.FakeFactory(), -101, adapter_type="lsiLogicsas")
     self.assertEqual("ns0:VirtualLsiLogicSASController",
                      config_spec.device.obj_name)