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}
     extra_specs = vm_util.ExtraSpecs()
     result = vm_util.get_vm_create_spec(fake.FakeFactory(),
                                         fake_instance, instance_uuid,
                                         'fake-datastore', [],
                                         extra_specs)
     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,
         'managedBy':  {'extensionKey': 'org.openstack.compute',
                        'type': 'instance',
                        'obj_name': 'ns0:ManagedByInfo'},
         '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_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.º 3
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.º 4
0
 def test_get_network_detach_config_spec(self):
     result = vm_util.get_network_detach_config_spec(
             fake.FakeFactory(), 'fake-device', 2)
     expected = """{
         'extraConfig': [{'value': 'free',
                          'key': 'nvp.iface-id.2',
                          'obj_name': 'ns0:OptionValue'}],
         'deviceChange': [{'device': 'fake-device',
                           'operation': 'remove',
                           '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.º 5
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.º 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",
                                             200, 0)
        expected = """{
    'deviceChange': [
        {
            'device': {
                'connectable': {
                    'allowGuestControl': False,
                    'startConnected': True,
                    'connected': True,
                    'obj_name': 'ns0: VirtualDeviceConnectInfo'
                },
                'backing': {
                    'datastore': {
                        "summary.maintenanceMode": "normal",
                        "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_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.º 8
0
 def test_get_network_attach_config_spec_dvs(self):
     vif_info = {'network_name': 'br100',
         'mac_address': '00:00:00:ca:fe:01',
         'network_ref': {'type': 'DistributedVirtualPortgroup',
                         'dvsw': 'fake-network-id',
                         'dvpg': 'fake-group'},
         'iface_id': 7,
         'vif_model': 'VirtualE1000'}
     result = vm_util.get_network_attach_config_spec(
             fake.FakeFactory(), vif_info, 1)
     port = 'ns0:DistributedVirtualSwitchPortConnection'
     backing = 'ns0:VirtualEthernetCardDistributedVirtualPortBackingInfo'
     expected = """{
         'extraConfig': [{'value': 7,
                          'key': 'nvp.iface-id.1',
                          'obj_name': 'ns0:OptionValue'}],
         'deviceChange': [
             {'device': {'macAddress': '00:00:00:ca:fe:01',
                         'addressType': 'manual',
                         'connectable': {
                             'allowGuestControl': True,
                             'startConnected': True,
                             'connected': True,
                             'obj_name': 'ns0:VirtualDeviceConnectInfo'},
              'backing': {
                  'port': {
                      'portgroupKey': 'fake-group',
                      'switchUuid': 'fake-network-id',
                      'obj_name': '%(obj_name_port)s'},
                  'obj_name': '%(obj_name_backing)s'},
                  'key': -47,
                  'obj_name': 'ns0:VirtualE1000',
                  'wakeOnLanEnabled': True},
              'operation': 'add',
              'obj_name': 'ns0:VirtualDeviceConfigSpec'}],
         'obj_name':'ns0:VirtualMachineConfigSpec'}""" % {
                 'obj_name_backing': backing,
                 'obj_name_port': port}
     expected = re.sub(r'\s+', '', expected)
     result = re.sub(r'\s+', '', repr(result))
     self.assertEqual(expected, result)
Exemplo n.º 9
0
 def test_get_network_attach_config_spec_opaque(self):
     vif_info = {'network_name': 'br-int',
         'mac_address': '00:00:00:ca:fe:01',
         'network_ref': {'type': 'OpaqueNetwork',
                         'network-id': 'fake-network-id',
                         'network-type': 'opaque'},
         'iface_id': 7,
         'vif_model': 'VirtualE1000'}
     result = vm_util.get_network_attach_config_spec(
             fake.FakeFactory(), vif_info, 1)
     card = 'ns0:VirtualEthernetCardOpaqueNetworkBackingInfo'
     expected = """{
         'extraConfig': [{'value': 7,
                          'key': 'nvp.iface-id.1',
                          'obj_name':'ns0:OptionValue'}],
         'deviceChange': [
             {'device': {
                  'macAddress':'00:00:00:ca:fe:01',
                  'addressType': 'manual',
                  'connectable': {
                      'allowGuestControl':True,
                      'startConnected': True,
                      'connected': True,
                      'obj_name':'ns0:VirtualDeviceConnectInfo'},
                  'backing': {
                      'opaqueNetworkType': 'opaque',
                      'opaqueNetworkId': 'fake-network-id',
                      'obj_name': '%(card)s'},
                  'key': -47,
                  'obj_name': 'ns0:VirtualE1000',
                  'wakeOnLanEnabled': True},
              'operation': 'add',
              'obj_name': 'ns0:VirtualDeviceConfigSpec'}],
         'obj_name':'ns0:VirtualMachineConfigSpec'}""" % {'card': card}
     expected = re.sub(r'\s+', '', expected)
     result = re.sub(r'\s+', '', repr(result))
     self.assertEqual(expected, result)
Exemplo n.º 10
0
    def _test_get_vnc_config_spec(self, port):

        result = vm_util.get_vnc_config_spec(fake.FakeFactory(),
                                             port)
        return result
Exemplo n.º 11
0
 def test_paravirtual_controller_spec(self):
     # Test controller spec returned for paraVirtual adapter type
     config_spec = vm_util.create_controller_spec(fake.FakeFactory(), -101,
                       adapter_type="paraVirtual")
     self.assertEqual("ns0:ParaVirtualSCSIController",
                      config_spec.device.obj_name)
Exemplo n.º 12
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)