예제 #1
0
    def test_create_vm_invalid_guestid(self, mock_log_warn):
        """Ensure we warn when create_vm() fails after we passed an
        unrecognised guestId
        """

        found = [False]

        def fake_log_warn(msg, values):
            if not isinstance(values, dict):
                return
            if values.get('ostype') == 'invalid_os_type':
                found[0] = True
        mock_log_warn.side_effect = fake_log_warn

        instance_values = {'id': 7, 'name': 'fake-name',
                           'uuid': uuidutils.generate_uuid(),
                           'vcpus': 2, 'memory_mb': 2048}
        instance = fake_instance.fake_instance_obj(
            context.RequestContext('fake', 'fake', is_admin=False),
            **instance_values)

        session = driver.VMwareAPISession()

        config_spec = vm_util.get_vm_create_spec(
            session.vim.client.factory,
            instance, instance.name, 'fake-datastore', [],
            vm_util.ExtraSpecs(),
            os_type='invalid_os_type')

        self.assertRaises(vexc.VMwareDriverException,
                          vm_util.create_vm, session, instance, 'folder',
                          config_spec, 'res-pool')
        self.assertTrue(found[0])
예제 #2
0
 def setUp(self):
     super(GetNetworkWithTheNameTestCase, self).setUp()
     fake.reset()
     self.stubs.Set(driver.VMwareAPISession, "vim", stubs.fake_vim_prop)
     self.stubs.Set(driver.VMwareAPISession, "_is_vim_object",
                    stubs.fake_is_vim_object)
     self._session = driver.VMwareAPISession()
예제 #3
0
    def test_get_dynamic_properties_with_token(self):
        ObjectContent = collections.namedtuple('ObjectContent', ['propSet'])
        DynamicProperty = collections.namedtuple('Property', ['name', 'val'])

        # Add a token to our results, indicating that more are available
        result = fake.FakeRetrieveResult(token='fake_token')

        # We expect these properties to be returned
        result.add_object(
            ObjectContent(propSet=[
                DynamicProperty(name='name1', val='value1'),
                DynamicProperty(name='name2', val='value2')
            ]))

        # These properties should be ignored
        result.add_object(
            ObjectContent(
                propSet=[DynamicProperty(name='name3', val='value3')]))

        retrievePropertiesEx = mock.MagicMock(name='RetrievePropertiesEx')
        retrievePropertiesEx.return_value = result

        calls = {'RetrievePropertiesEx': retrievePropertiesEx}
        with stubs.fake_suds_context(calls):
            session = driver.VMwareAPISession(host_ip='localhost')

            service_content = session.vim.service_content
            props = session._call_method(vim_util, "get_dynamic_properties",
                                         service_content.propertyCollector,
                                         'fake_type', None)

            self.assertEqual(props, {'name1': 'value1', 'name2': 'value2'})
예제 #4
0
    def setUp(self):
        super(OVSvAppVMOpsTestCase, self).setUp()
        fake_ds_ref = vmwareapi_fake.ManagedObjectReference('fake-ds')
        vmwareapi_fake.reset()
        cluster = vmwareapi_fake.create_cluster('fake_cluster', fake_ds_ref)
        self.flags(enabled=True, group='vnc')
        self.flags(image_cache_subdirectory_name='vmware_base',
                   my_ip='',
                   flat_injected=True)
        self._context = context.RequestContext('fake_user', 'fake_project')
        self._session = driver.VMwareAPISession()

        self._virtapi = mock.Mock()
        self._image_id = nova.tests.unit.image.fake.get_valid_image_id()
        self._instance_values = {
            'name': 'fake_name',
            'display_name': 'fake_display_name',
            'uuid': self._uuid,
            'vcpus': 1,
            'memory_mb': 512,
            'image_ref': self._image_id,
            'root_gb': 10,
            'node': '%s(%s)' % (cluster.mo_id, cluster.name),
            'expected_attrs': ['system_metadata'],
        }
        self._instance = fake_instance.fake_instance_obj(
            self._context, **self._instance_values)
        self._image_meta = objects.ImageMeta.from_dict({'id': self._image_id})
        self._flavor = objects.Flavor(name='m1.small', memory_mb=512, vcpus=1,
                                      root_gb=10, ephemeral_gb=0, swap=0,
                                      extra_specs={})
        self._instance.flavor = self._flavor
        self._vmops = ovsvapp_vmops.OVSvAppVMOps(self._session, self._virtapi,
                                                 None, cluster=cluster.obj)
예제 #5
0
    def setUp(self):
        super(VMwareVolumeOpsTestCase, self).setUp()
        vmwareapi_fake.reset()
        stubs.set_stubs(self.stubs)

        self._session = driver.VMwareAPISession()
        self._volumeops = volumeops.VMwareVolumeOps(self._session)
        self.instance = {'name': 'fake_name', 'uuid': 'fake_uuid'}
예제 #6
0
 def _get_vim_session(self, pool):
     """Get VIM session for the pool specified."""
     vim_session = None
     if pool['id'] not in self.sessions.keys():
         vim_session = vmwareapi_conn.VMwareAPISession(
             pool['address'], pool['username'], pool['password'],
             CONF.console_vmrc_error_retries)
         self.sessions[pool['id']] = vim_session
     return self.sessions[pool['id']]
예제 #7
0
 def setUp(self):
     super(GetNetworkWithTheNameTestCase, self).setUp()
     fake.reset()
     self.stub_out('nova.virt.vmwareapi.driver.VMwareAPISession.vim',
                   stubs.fake_vim_prop)
     self.stub_out(
         'nova.virt.vmwareapi.driver.'
         'VMwareAPISession.is_vim_object', stubs.fake_is_vim_object)
     self._session = driver.VMwareAPISession()
예제 #8
0
    def setUp(self):
        super(VMwareVMUtilGetHostRefTestCase, self).setUp()
        fake.reset()
        vm_util.vm_refs_cache_reset()

        self.session = driver.VMwareAPISession()

        # Create a fake VirtualMachine running on a known host
        self.host_ref = fake._db_content['HostSystem'].keys()[0]
        self.vm_ref = fake.create_vm(host_ref=self.host_ref)
예제 #9
0
파일: test_vmops.py 프로젝트: gukai/su-nova
    def setUp(self):
        super(VMwareVMOpsTestCase, self).setUp()
        vmwareapi_fake.reset()
        stubs.set_stubs(self.stubs)
        self._session = driver.VMwareAPISession()

        self._vmops = vmops.VMwareVMOps(self._session, None, None)
        self._instance = {'name': 'fake_name', 'uuid': 'fake_uuid'}

        subnet_4 = network_model.Subnet(
            cidr='192.168.0.1/24',
            dns=[network_model.IP('192.168.0.1')],
            gateway=network_model.IP('192.168.0.1'),
            ips=[network_model.IP('192.168.0.100')],
            routes=None)
        subnet_6 = network_model.Subnet(
            cidr='dead:beef::1/64',
            dns=None,
            gateway=network_model.IP('dead:beef::1'),
            ips=[network_model.IP('dead:beef::dcad:beff:feef:0')],
            routes=None)
        network = network_model.Network(id=0,
                                        bridge='fa0',
                                        label='fake',
                                        subnets=[subnet_4, subnet_6],
                                        vlan=None,
                                        bridge_interface=None,
                                        injected=True)
        self.network_info = network_model.NetworkInfo([
            network_model.VIF(id=None,
                              address='DE:AD:BE:EF:00:00',
                              network=network,
                              type=None,
                              devname=None,
                              ovs_interfaceid=None,
                              rxtx_cap=3)
        ])
        pure_IPv6_network = network_model.Network(id=0,
                                                  bridge='fa0',
                                                  label='fake',
                                                  subnets=[subnet_6],
                                                  vlan=None,
                                                  bridge_interface=None,
                                                  injected=True)
        self.pure_IPv6_network_info = network_model.NetworkInfo([
            network_model.VIF(id=None,
                              address='DE:AD:BE:EF:00:00',
                              network=pure_IPv6_network,
                              type=None,
                              devname=None,
                              ovs_interfaceid=None,
                              rxtx_cap=3)
        ])
        utils.reset_is_neutron()
예제 #10
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')
예제 #11
0
    def test_VC_Connection(self):
        self.attempts = 0
        self.login_session = vmwareapi_fake.FakeVim()._login()

        def _fake_login(_self):
            self.attempts += 1
            if self.attempts == 1:
                raise exception.NovaException('Here is my fake exception')
            return self.login_session

        self.stubs.Set(vmwareapi_fake.FakeVim, '_login', _fake_login)
        self.conn = driver.VMwareAPISession()
        self.assertEqual(self.attempts, 2)
예제 #12
0
    def setUp(self):

        super(VMwareVolumeOpsTestCase, self).setUp()
        vmwareapi_fake.reset()
        stubs.set_stubs(self.stubs)
        self._session = driver.VMwareAPISession()
        self._context = context.RequestContext('fake_user', 'fake_project')

        self._volumeops = volumeops.VMwareVolumeOps(self._session)
        self._image_id = image_fake.get_valid_image_id()
        self._instance_values = {
            'name': 'fake_name',
            'uuid': 'fake_uuid',
            'vcpus': 1,
            'memory_mb': 512,
            'image_ref': self._image_id,
            'root_gb': 10,
            'node': 'respool-1001(MyResPoolName)',
            'expected_attrs': ['system_metadata'],
        }
        self._instance = fake_instance.fake_instance_obj(self._context,
            **self._instance_values)
예제 #13
0
import copy

import pdb

# session = api.VMwareAPISession(
#     '172.18.211.201',
#     '*****@*****.**',
#     'Naguan.123',
#     10,
#     0.1
# )

session = driver.VMwareAPISession(host_ip='172.18.211.201',
                                  host_port=443,
                                  username='******',
                                  password='******',
                                  retry_count=10,
                                  scheme="https",
                                  cacert=None,
                                  insecure=True)

client_factory = session.vim.client.factory
# target = client_factory.create('ns0:HostSystem')
# ----------------------------------------------------------------------------------------
#   migrate vm
# ----------------------------------------------------------------------------------------
vm_ref = vm_util.get_vm_ref_from_name(session, 'shengping-test')
host_refa = session._call_method(vim_util, "get_object_property", vm_ref,
                                 "runtime.host")
target = copy.deepcopy(host_refa)
target.value = 'host-13'
pdb.set_trace()
예제 #14
0
파일: test_vmops.py 프로젝트: xzj675/nova
    def setUp(self):
        super(VMwareVMOpsTestCase, self).setUp()
        vmwareapi_fake.reset()
        stubs.set_stubs(self.stubs)
        self.flags(image_cache_subdirectory_name='vmware_base',
                   my_ip='',
                   flat_injected=True,
                   vnc_enabled=True)
        self._context = context.RequestContext('fake_user', 'fake_project')
        self._session = driver.VMwareAPISession()

        self._virtapi = mock.Mock()
        self._vmops = vmops.VMwareVCVMOps(self._session, self._virtapi, None)

        self._image_id = nova.tests.image.fake.get_valid_image_id()
        values = {
            'name': 'fake_name',
            'uuid': 'fake_uuid',
            'vcpus': 1,
            'memory_mb': 512,
            'image_ref': self._image_id,
            'root_gb': 1,
            'node': 'respool-1001(MyResPoolName)'
        }
        self._instance = fake_instance.fake_instance_obj(
                                 self._context, **values)

        fake_ds_ref = vmwareapi_fake.ManagedObjectReference('fake-ds')

        self._ds_record = vm_util.DSRecord(
                datastore=fake_ds_ref, name='fake_ds',
                capacity=10 * units.Gi,
                freespace=10 * units.Gi)
        self._dc_info = vmops.DcInfo(
                ref='fake_dc_ref', name='fake_dc',
                vmFolder='fake_vm_folder')

        subnet_4 = network_model.Subnet(cidr='192.168.0.1/24',
                                        dns=[network_model.IP('192.168.0.1')],
                                        gateway=
                                            network_model.IP('192.168.0.1'),
                                        ips=[
                                            network_model.IP('192.168.0.100')],
                                        routes=None)
        subnet_6 = network_model.Subnet(cidr='dead:beef::1/64',
                                        dns=None,
                                        gateway=
                                            network_model.IP('dead:beef::1'),
                                        ips=[network_model.IP(
                                            'dead:beef::dcad:beff:feef:0')],
                                        routes=None)
        network = network_model.Network(id=0,
                                        bridge='fa0',
                                        label='fake',
                                        subnets=[subnet_4, subnet_6],
                                        vlan=None,
                                        bridge_interface=None,
                                        injected=True)
        self.network_info = network_model.NetworkInfo([
                network_model.VIF(id=None,
                                  address='DE:AD:BE:EF:00:00',
                                  network=network,
                                  type=None,
                                  devname=None,
                                  ovs_interfaceid=None,
                                  rxtx_cap=3)
                ])
        pure_IPv6_network = network_model.Network(id=0,
                                        bridge='fa0',
                                        label='fake',
                                        subnets=[subnet_6],
                                        vlan=None,
                                        bridge_interface=None,
                                        injected=True)
        self.pure_IPv6_network_info = network_model.NetworkInfo([
                network_model.VIF(id=None,
                                  address='DE:AD:BE:EF:00:00',
                                  network=pure_IPv6_network,
                                  type=None,
                                  devname=None,
                                  ovs_interfaceid=None,
                                  rxtx_cap=3)
                ])
# session = api.VMwareAPISession(
#     '172.28.8.247',      # vSphere host endpoint
#    '*****@*****.**', # vSphere username
#     'Vcenter123.',      # vSphere password
#     10,              # Number of retries for connection failures in tasks
#    0.1              # Poll interval for async tasks (in seconds)
# )

instance = prepare_instance()

session = driver.VMwareAPISession(
    host_ip='172.28.8.247',
    host_port=443,
    username='******',
    password='******',
    retry_count=10,
    scheme="https",
    cacert=None,
    insecure=True
)

client_factory = session.vim.client.factory

# vm_ref = vm_util.get_vm_ref(session, instance)
vm_ref = vm_util.get_vm_ref_from_name(session, 'test-vm')

# get manager object from content
content = session.vim.retrieve_service_content()
# manager object for guest operation
gopmgr = content.guestOperationsManager
예제 #16
0
    def setUp(self):
        super(VMwareVMOpsTestCase, self).setUp()
        vmwareapi_fake.reset()
        stubs.set_stubs(self.stubs)
        self._session = driver.VMwareAPISession()

        self._vmops = vmops.VMwareVMOps(self._session, None, None)
        self._image_id = nova.tests.image.fake.get_valid_image_id()
        values = {
            'name': 'fake_name',
            'uuid': 'fake_uuid',
            'vcpus': 1,
            'memory_mb': 512,
            'image_ref': self._image_id,
            'root_gb': 1,
            'node': 'respool-1001(MyResPoolName)',
        }
        self._context = context.RequestContext('fake_user', 'fake_project')
        self._instance = fake_instance.fake_instance_obj(
            self._context, **values)

        subnet_4 = network_model.Subnet(
            cidr='192.168.0.1/24',
            dns=[network_model.IP('192.168.0.1')],
            gateway=network_model.IP('192.168.0.1'),
            ips=[network_model.IP('192.168.0.100')],
            routes=None)
        subnet_6 = network_model.Subnet(
            cidr='dead:beef::1/64',
            dns=None,
            gateway=network_model.IP('dead:beef::1'),
            ips=[network_model.IP('dead:beef::dcad:beff:feef:0')],
            routes=None)
        network = network_model.Network(id=0,
                                        bridge='fa0',
                                        label='fake',
                                        subnets=[subnet_4, subnet_6],
                                        vlan=None,
                                        bridge_interface=None,
                                        injected=True)
        self.network_info = network_model.NetworkInfo([
            network_model.VIF(id=None,
                              address='DE:AD:BE:EF:00:00',
                              network=network,
                              type=None,
                              devname=None,
                              ovs_interfaceid=None,
                              rxtx_cap=3)
        ])
        pure_IPv6_network = network_model.Network(id=0,
                                                  bridge='fa0',
                                                  label='fake',
                                                  subnets=[subnet_6],
                                                  vlan=None,
                                                  bridge_interface=None,
                                                  injected=True)
        self.pure_IPv6_network_info = network_model.NetworkInfo([
            network_model.VIF(id=None,
                              address='DE:AD:BE:EF:00:00',
                              network=pure_IPv6_network,
                              type=None,
                              devname=None,
                              ovs_interfaceid=None,
                              rxtx_cap=3)
        ])
        utils.reset_is_neutron()