Example #1
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()

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

            self.assertEqual(props, {
                'name1': 'value1',
                'name2': 'value2'
            })
Example #2
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'})