示例#1
0
 def setUp(self):
     super(GetNetworkWithTheNameTestCase, self).setUp()
     fake.reset()
     self.stub_out('nova.virt.vmwareapi.session.VMwareAPISession.vim',
                   stubs.fake_vim_prop)
     self.stub_out(
         'nova.virt.vmwareapi.session.'
         'VMwareAPISession.is_vim_object', stubs.fake_is_vim_object)
     self._session = session.VMwareAPISession()
示例#2
0
 def test_call_method_vim(self, mock_is_vim):
     with test.nested(
             mock.patch.object(session.VMwareAPISession, '_create_session',
                               _fake_create_session),
             mock.patch.object(session.VMwareAPISession, 'invoke_api'),
     ) as (fake_create, fake_invoke):
         _session = session.VMwareAPISession()
         module = mock.Mock()
         _session._call_method(module, 'fira')
         fake_invoke.assert_called_once_with(module, 'fira')
示例#3
0
    def __init__(self, virtapi, scheme="https"):
        super(VMwareVCDriver, self).__init__(virtapi)

        if (CONF.vmware.host_ip is None or CONF.vmware.host_username is None
                or CONF.vmware.host_password is None):
            raise Exception(
                _("Must specify host_ip, host_username and "
                  "host_password to use vmwareapi.VMwareVCDriver"))

        self._datastore_regex = None
        if CONF.vmware.datastore_regex:
            try:
                self._datastore_regex = re.compile(CONF.vmware.datastore_regex)
            except re.error:
                raise exception.InvalidInput(
                    reason=_("Invalid Regular Expression %s") %
                    CONF.vmware.datastore_regex)

        self._session = session.VMwareAPISession(scheme=scheme)

        self._check_min_version()

        # Update the PBM location if necessary
        if CONF.vmware.pbm_enabled:
            self._update_pbm_location()

        self._validate_configuration()
        self._cluster_name = CONF.vmware.cluster_name
        self._cluster_ref = vm_util.get_cluster_ref_by_name(
            self._session, self._cluster_name)
        if self._cluster_ref is None:
            raise exception.NotFound(
                _("The specified cluster '%s' was not "
                  "found in vCenter") % self._cluster_name)
        self._vcenter_uuid = self._get_vcenter_uuid()
        self._nodename = \
            self._create_nodename(vim_util.get_moref_value(self._cluster_ref))
        self._volumeops = volumeops.VMwareVolumeOps(self._session,
                                                    self._cluster_ref)
        self._vmops = vmops.VMwareVMOps(self._session,
                                        virtapi,
                                        self._volumeops,
                                        self._cluster_ref,
                                        datastore_regex=self._datastore_regex)
        self._vc_state = host.VCState(self._session, self._nodename,
                                      self._cluster_ref, self._datastore_regex)

        # Register the OpenStack extension
        self._register_openstack_extension()
示例#4
0
    def test_call_method_recovery_arg_success(self, mock_is_vim):
        with test.nested(
                mock.patch.object(session.VMwareAPISession, '_create_session',
                                  _fake_create_session),
                mock.patch.object(session.VMwareAPISession, 'invoke_api'),
                mock.patch.object(FakeStableMoRefProxy, 'fetch_moref',
                                  _fake_fetch_moref_impl),
        ) as (fake_create, fake_invoke, fake_fetch_moref):
            _session = session.VMwareAPISession()
            module = mock.Mock()
            ref = FakeStableMoRefProxy()

            fake_invoke.side_effect = [
                vexec.ManagedObjectNotFoundException(
                    details=dict(obj=mock.sentinel.moref), ), None
            ]
            _session._call_method(module, mock.sentinel.method_arg, ref)
            fake_invoke.assert_called_with(module, mock.sentinel.method_arg,
                                           ref)
示例#5
0
    def test_call_method_recovery_arg_failed(self, mock_is_vim):
        with test.nested(
                mock.patch.object(session.VMwareAPISession, '_create_session',
                                  _fake_create_session),
                mock.patch.object(session.VMwareAPISession, 'invoke_api'),
                mock.patch.object(FakeStableMoRefProxy, 'fetch_moref'),
        ) as (fake_create, fake_invoke, fake_fetch_moref):
            _session = session.VMwareAPISession()
            module = mock.Mock()
            ref = FakeStableMoRefProxy()
            fake_invoke.side_effect = [vexec.ManagedObjectNotFoundException]

            self.assertRaises(vexec.ManagedObjectNotFoundException,
                              _session._call_method, module,
                              mock.sentinel.method_arg, ref)

            fake_invoke.assert_called_once_with(module,
                                                mock.sentinel.method_arg, ref)
            fake_fetch_moref.assert_not_called()
示例#6
0
    def test_call_method_no_recovery(self, mock_is_vim):
        with test.nested(
                mock.patch.object(session.VMwareAPISession, '_create_session',
                                  _fake_create_session),
                mock.patch.object(session.VMwareAPISession, 'invoke_api'),
                mock.patch.object(FakeStableMoRefProxy, 'fetch_moref'),
        ) as (fake_create, fake_invoke, fake_fetch_moref):
            _session = session.VMwareAPISession()
            module = mock.Mock()
            ref = FakeStableMoRefProxy()

            _session._call_method(module,
                                  mock.sentinel.method_arg,
                                  ref,
                                  ref=ref)

            fake_invoke.assert_called_once_with(module,
                                                mock.sentinel.method_arg,
                                                ref,
                                                ref=ref)
            fake_fetch_moref.assert_not_called()
示例#7
0
    def setUp(self):

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

        self._volumeops = volumeops.VMwareVolumeOps(self._session)
        self._image_id = uuids.image
        self._instance_values = {
            'name': 'fake_name',
            'uuid': uuids.foo,
            '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)