Esempio n. 1
0
    def test_build_virtual_machine(self, mock_get_vim_object):
        mock_get_vim_object.return_value = vmwareapi_fake.FakeVim()

        fake_session = driver.VMwareAPISession()
        fake_vmops = vmops.VMwareVCVMOps(fake_session, None, None)

        image_id = nova.tests.image.fake.get_valid_image_id()
        image = vmware_images.VMwareImage(image_id=image_id)

        vm_ref = fake_vmops.build_virtual_machine(self._instance,
                                                  'fake-instance-name', image,
                                                  self._dc_info, self._ds,
                                                  self.network_info)

        vm = vmwareapi_fake._get_object(vm_ref)

        # Test basic VM parameters
        self.assertEqual('fake-instance-name', vm.name)
        # NOTE(mdbooth): The instanceUuid behaviour below is apparently
        # deliberate.
        self.assertEqual('fake-instance-name',
                         vm.get('summary.config.instanceUuid'))
        self.assertEqual(self._instance_values['vcpus'],
                         vm.get('summary.config.numCpu'))
        self.assertEqual(self._instance_values['memory_mb'],
                         vm.get('summary.config.memorySizeMB'))

        # Test NSX config
        for optval in vm.get('config.extraConfig').OptionValue:
            if optval.key == 'nvp.vm-uuid':
                self.assertEqual(self._instance_values['uuid'], optval.value)
                break
        else:
            self.fail('nvp.vm-uuid not found in extraConfig')

        # Test that the VM is associated with the specified datastore
        datastores = vm.datastore.ManagedObjectReference
        self.assertEqual(1, len(datastores))

        datastore = vmwareapi_fake._get_object(datastores[0])
        self.assertEqual(self._ds.name, datastore.get('summary.name'))

        # Test that the VM's network is configured as specified
        devices = vm.get('config.hardware.device').VirtualDevice
        for device in devices:
            if device.obj_name != 'ns0:VirtualE1000':
                continue
            self.assertEqual(self._network_values['address'],
                             device.macAddress)
            break
        else:
            self.fail('NIC not configured')
Esempio n. 2
0
def fake_get_vim_object(arg):
    """Stubs out the VMwareAPISession's get_vim_object method."""
    return fake.FakeVim()
Esempio n. 3
0
    def setUp(self):
        super(ConfigDriveTestCase, self).setUp()
        vm_util.vm_refs_cache_reset()
        self.context = context.RequestContext('fake', 'fake', is_admin=False)
        cluster_name = 'test_cluster'
        self.flags(cluster_name=[cluster_name],
                   host_ip='test_url',
                   host_username='******',
                   host_password='******',
                   use_linked_clone=False,
                   group='vmware')
        self.flags(vnc_enabled=False)
        vmwareapi_fake.reset()
        stubs.set_stubs(self.stubs)
        nova.tests.image.fake.stub_out_image_service(self.stubs)
        self.conn = driver.VMwareVCDriver(fake.FakeVirtAPI)
        self.network_info = utils.get_test_network_info()
        self.vim = vmwareapi_fake.FakeVim()
        self.node_name = '%s(%s)' % (self.conn.dict_mors.keys()[0],
                                     cluster_name)
        image_ref = nova.tests.image.fake.get_valid_image_id()
        instance_values = {
            'vm_state': 'building',
            'project_id': 'fake',
            'user_id': 'fake',
            'name': '1',
            'kernel_id': '1',
            'ramdisk_id': '1',
            'mac_addresses': [{
                'address': 'de:ad:be:ef:be:ef'
            }],
            'memory_mb': 8192,
            'flavor': 'm1.large',
            'vcpus': 4,
            'root_gb': 80,
            'image_ref': image_ref,
            'host': 'fake_host',
            'task_state': 'scheduling',
            'reservation_id': 'r-3t8muvr0',
            'id': 1,
            'uuid': 'fake-uuid',
            'node': self.node_name,
            'metadata': []
        }
        self.test_instance = fake_instance.fake_instance_obj(
            self.context, **instance_values)

        (image_service,
         image_id) = glance.get_remote_image_service(context, image_ref)
        metadata = image_service.show(context, image_id)
        self.image = {
            'id': image_ref,
            'disk_format': 'vmdk',
            'size': int(metadata['size']),
        }

        class FakeInstanceMetadata(object):
            def __init__(self, instance, content=None, extra_md=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(
            fixtures.MonkeyPatch('nova.api.metadata.base.InstanceMetadata',
                                 FakeInstanceMetadata))

        def fake_make_drive(_self, _path):
            pass

        # We can't actually make a config drive v2 because ensure_tree has
        # been faked out
        self.stubs.Set(nova.virt.configdrive.ConfigDriveBuilder, 'make_drive',
                       fake_make_drive)

        def fake_upload_iso_to_datastore(iso_path, instance, **kwargs):
            pass

        self.stubs.Set(vmware_images, 'upload_iso_to_datastore',
                       fake_upload_iso_to_datastore)
Esempio n. 4
0
 def setUp(self):
     super(VMwareVIMUtilTestCase, self).setUp()
     fake.reset()
     self.vim = fake.FakeVim()
     self.vim._login()