Beispiel #1
0
    def test_get_instance_info(self):
        """Check retrieval of instance info from VM instance in the system"""
        host = fake.HostSystem()
        device = fake.VirtualDisk(unitNumber=0)
        network = fake.Network()
        vm_folder = fake.Folder(name='fake-folder')
        fake._create_object('Folder', vm_folder)
        fake_folders = fake.FakeRetrieveResult()
        respool = fake.ResourcePool()
        fake._create_object('ResourcePool', respool)
        cluster = fake.ClusterComputeResource()
        cluster._add_root_resource_pool(respool.obj)
        fake._create_object('ClusterComputeResource', cluster)

        virtualMachine = fake.VirtualMachine(name="VM-1",
                                             instanceUuid="fake-uuid",
                                             runtime_host=host.obj,
                                             virtual_device=[device, network],
                                             parent=vm_folder.obj,
                                             resourcePool=respool.obj)

        fake_vms = fake.FakeRetrieveResult()
        fake_vms.add_object(virtualMachine)
        fake_pools = fake.FakeRetrieveResult()
        fake_pools.add_object(respool)
        fake_clusters = fake.FakeRetrieveResult()
        fake_clusters.add_object(cluster)
        session = fake_session(fake_virtual_machines=fake_vms,
                               fake_vm_folder=fake_folders,
                               fake_resource_pools=fake_pools)
        driver = fake_driver(session, cluster_ref=cluster.obj)

        vm_util.add_vm_to_cache(driver, 'fake-uuid', {
            'vmref': virtualMachine.obj,
            "template": "false"
        })
        instance_info = vm_util.get_instance_info(driver, 'fake-uuid')

        virtual_interfaces = instance_info['virtual_interfaces'][0]
        block_device_mapping = instance_info['block_device_mapping_v2'][0]

        self.assertEquals("123.123.123.123", instance_info['access_ip_v4'])
        self.assertEquals("fake-uuid", instance_info['instance_uuid'])
        self.assertEquals(1, instance_info['memory_mb'])
        self.assertEquals("VM-1", instance_info['name'])
        self.assertEquals(1, instance_info['power_state'])
        self.assertEquals(1, instance_info['vcpus'])
        self.assertEquals("test-mac-address",
                          virtual_interfaces['mac_address'])
        self.assertEquals("Test-Network",
                          virtual_interfaces['port_group_label'])
        self.assertEquals(0, block_device_mapping['boot_index'])
        self.assertEquals(False, block_device_mapping['delete_on_termination'])
        self.assertEquals("Test-Virtual-Disk",
                          block_device_mapping['device_name'])
        self.assertEquals("volume", block_device_mapping['guest_format'])
        self.assertEquals("blank", block_device_mapping['source_type'])
        self.assertEquals(1048576, block_device_mapping['virtual_size'])
Beispiel #2
0
    def test_list_instance_uuids_hide_vms(self):
        """
        Check list of VM instance UUIDs and make sure VMs under
        pf9_cinder_volumes are not listed
        """
        host = fake.HostSystem()
        vm_folder = fake.Folder(name='fake-folder')
        fake._create_object('Folder', vm_folder)
        ignore_folder = fake.Folder(name='pf9_cinder_volumes')
        fake._create_object('Folder', ignore_folder)
        respool = fake.ResourcePool()
        fake._create_object('ResourcePool', respool)
        cluster = fake.ClusterComputeResource()
        cluster._add_root_resource_pool(respool.obj)
        fake._create_object('ClusterComputeResource', cluster)

        virtualMachine1 = fake.VirtualMachine(name="VM-1",
                                              instanceUuid="test-uuid-1",
                                              runtime_host=host.obj,
                                              parent=vm_folder.obj,
                                              resourcePool=respool.obj)
        virtualMachine2 = fake.VirtualMachine(name="VM-2",
                                              instanceUuid="test-uuid-2",
                                              runtime_host=host.obj,
                                              parent=ignore_folder.obj,
                                              resourcePool=respool.obj)

        fake_vms = fake.FakeRetrieveResult()
        fake_vms.add_object(virtualMachine1)
        fake_vms.add_object(virtualMachine2)
        fake_folders = fake.FakeRetrieveResult()
        fake_folders.add_object(vm_folder)
        fake_folders.add_object(ignore_folder)
        fake_pools = fake.FakeRetrieveResult()
        fake_pools.add_object(respool)

        session = fake_session(fake_virtual_machines=fake_vms,
                               fake_vm_folder=fake_folders,
                               fake_resource_pools=fake_pools)
        driver = fake_driver(session, cluster_ref=cluster.obj)

        instance_uuids = vm_util.list_instance_uuids(driver)
        self.assertIn("test-uuid-1", instance_uuids)
        self.assertNotIn("test-uuid-2", instance_uuids)
        self.assertEquals(1, len(instance_uuids))
Beispiel #3
0
    def test_get_vm_ref(self):
        """Check retrieval of vm reference using uuid or name"""
        respool = fake.ResourcePool()
        fake._create_object('ResourcePool', respool)
        cluster = fake.ClusterComputeResource()
        cluster._add_root_resource_pool(respool.obj)
        fake._create_object('ClusterComputeResource', cluster)
        vm_folder = fake.Folder(name='fake-folder')
        fake_folders = fake.FakeRetrieveResult()
        fake_folders.add_object(vm_folder)
        fake_pools = fake.FakeRetrieveResult()
        fake_pools.add_object(respool)
        fake_clusters = fake.FakeRetrieveResult()
        fake_clusters.add_object(cluster)
        optionVal = fake.OptionValue(key="nvp.vm-uuid", value="test-uuid-1")
        virtualMachine1 = fake.VirtualMachine(name="VM-1",
                                              instanceUuid="test-uuid-1",
                                              resourcePool=respool.obj,
                                              extra_config=[optionVal])
        fake_vms = fake.FakeRetrieveResult()
        fake_vms.add_object(virtualMachine1)
        session = fake_session(fake_virtual_machines=fake_vms,
                               fake_resource_pools=fake_pools,
                               fake_cluster=fake_clusters,
                               fake_vm_folder=fake_folders)
        driver = fake_driver(session, cluster_ref=cluster.obj)

        instance = {}
        vm_util.add_vm_to_cache(driver, 'test-uuid-1', {
            'vmref': virtualMachine1.obj,
            "template": "false"
        })
        # Verify retrieval based on uuid
        instance['uuid'] = 'test-uuid-1'
        returned_vm_ref = vm_util.get_vm_ref(driver._session, instance)
        returned_vm_name = driver._session._call_method(
            None, "get_dynamic_property", returned_vm_ref, "VirtualMachine",
            "name")
        self.assertEquals(virtualMachine1.obj, returned_vm_ref)
        self.assertEquals("VM-1", returned_vm_name)

        # Verify exception for wrong uuid
        instance['uuid'] = 'non-existent-uuid'
        self.assertRaises(exception.InstanceNotFound, vm_util.get_vm_ref,
                          driver._session, instance)
Beispiel #4
0
    def test_get_instance_info_ipv6(self):
        """Check retrieval of instance info from VM instance in the system"""
        host = fake.HostSystem()
        device = fake.VirtualDisk(unitNumber=0)
        network = fake.Network()
        vm_folder = fake.Folder(name='fake-folder')
        fake._create_object('Folder', vm_folder)
        fake_folders = fake.FakeRetrieveResult()
        respool = fake.ResourcePool()
        fake._create_object('ResourcePool', respool)
        cluster = fake.ClusterComputeResource()
        cluster._add_root_resource_pool(respool.obj)
        fake._create_object('ClusterComputeResource', cluster)

        virtualMachine = fake.VirtualMachine(
            name="VM-1",
            instanceUuid="fake-uuid",
            runtime_host=host.obj,
            virtual_device=[device, network],
            ip_address="aaaa::123:aaaa:aaaa:aaaa",
            parent=vm_folder.obj,
            resourcePool=respool.obj)

        fake_vms = fake.FakeRetrieveResult()
        fake_vms.add_object(virtualMachine)
        fake_pools = fake.FakeRetrieveResult()
        fake_pools.add_object(respool)
        fake_clusters = fake.FakeRetrieveResult()
        fake_clusters.add_object(cluster)
        session = fake_session(fake_virtual_machines=fake_vms,
                               fake_vm_folder=fake_folders,
                               fake_resource_pools=fake_pools)
        driver = fake_driver(session, cluster_ref=cluster.obj)

        vm_util.add_vm_to_cache(driver, 'fake-uuid', {
            'vmref': virtualMachine.obj,
            "template": "false"
        })

        instance_info = vm_util.get_instance_info(driver, 'fake-uuid')

        self.assertIn('access_ip_v6', instance_info.keys())
        self.assertEquals("aaaa::123:aaaa:aaaa:aaaa",
                          instance_info['access_ip_v6'])