Merge "Fix invalid vim call in vim_util.get_dynamic_properties()"

This commit is contained in:
Jenkins 2014-03-19 22:30:55 +00:00 committed by Gerrit Code Review
commit e2d6c32c6b
3 changed files with 44 additions and 2 deletions

View File

@ -12,9 +12,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
import fixtures
import mock
from nova import test
from nova.tests.virt.vmwareapi import stubs
from nova.virt.vmwareapi import driver
from nova.virt.vmwareapi import fake
from nova.virt.vmwareapi import vim_util
@ -58,6 +62,42 @@ class VMwareVIMUtilTestCase(test.NoDBTestCase):
'fake-type', 'fake-property')
self.assertIsNone(res)
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'
})
def test_get_inner_objects(self):
property = ['summary.name']
# Get the fake datastores directly from the cluster

View File

@ -115,8 +115,10 @@ def _convert_to_array_of_opt_val(optvals):
class FakeRetrieveResult(object):
"""Object to retrieve a ObjectContent list."""
def __init__(self):
def __init__(self, token=None):
self.objects = []
if token is not None:
self.token = token
def add_object(self, object):
self.objects.append(object)

View File

@ -175,7 +175,7 @@ def get_dynamic_properties(vim, mobj, type, property_names):
"""Gets the specified properties of the Managed Object."""
obj_content = get_object_properties(vim, None, mobj, type, property_names)
if hasattr(obj_content, 'token'):
vim.CancelRetrievePropertiesEx(token=obj_content.token)
cancel_retrieve(vim, obj_content.token)
property_dict = {}
if obj_content.objects:
if hasattr(obj_content.objects[0], 'propSet'):