Merge "vmware tests: Support different moref backend representations"

This commit is contained in:
Zuul 2021-06-16 07:02:02 +00:00 committed by Gerrit Code Review
commit 7df88b8c8d
3 changed files with 45 additions and 15 deletions

View File

@ -0,0 +1,29 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
class ManagedObjectReference(object):
"""A managed object reference is a remote identifier."""
def __init__(self, name="ManagedObject", value=None, propSetVal=None):
super(ManagedObjectReference, self)
# Managed Object Reference value attributes
# typically have values like vm-123 or
# host-232 and not UUID.
self.value = value
self._value_1 = value
# Managed Object Reference type
# attributes hold the name of the type
# of the vCenter object the value
# attribute is the identifier for
self.type = name
self._type = name

View File

@ -24,6 +24,7 @@ from oslotest import base
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.compute.virt.vmware import inspector as vsphere_inspector
from ceilometer import service
from ceilometer.tests.unit.compute.virt.vmware import fake as vmware_fake
class TestVsphereInspection(base.BaseTestCase):
@ -49,8 +50,8 @@ class TestVsphereInspection(base.BaseTestCase):
mock.MagicMock())
def test_instance_poweredOff(self):
test_vm_mobj = mock.MagicMock()
test_vm_mobj.value = "vm-21"
test_vm_mobj = vmware_fake.ManagedObjectReference('VirtualMachine',
value='vm-21')
test_vm_mobj_powerState = "poweredOff"
ops_mock = self._inspector._ops
@ -61,8 +62,8 @@ class TestVsphereInspection(base.BaseTestCase):
mock.MagicMock())
def test_instance_poweredOn(self):
test_vm_mobj = mock.MagicMock()
test_vm_mobj.value = "vm-21"
test_vm_mobj = vmware_fake.ManagedObjectReference('VirtualMachine',
value='vm-21')
test_vm_mobj_powerState = "poweredOn"
ops_mock = self._inspector._ops
@ -73,8 +74,8 @@ class TestVsphereInspection(base.BaseTestCase):
self.assertEqual(test_vm_mobj.value, vm_mobj.value)
def test_inspect_memory_usage(self):
test_vm_mobj = mock.MagicMock()
test_vm_mobj.value = "vm-21"
test_vm_mobj = vmware_fake.ManagedObjectReference('VirtualMachine',
value='vm-21')
fake_perf_counter_id = 'fake_perf_counter_id'
fake_memory_value = 1024.0
@ -89,8 +90,8 @@ class TestVsphereInspection(base.BaseTestCase):
self.assertEqual(1.0, stats.memory_usage)
def test_inspect_cpu_util(self):
test_vm_mobj = mock.MagicMock()
test_vm_mobj.value = "vm-21"
test_vm_mobj = vmware_fake.ManagedObjectReference('VirtualMachine',
value='vm-21')
fake_perf_counter_id = 'fake_perf_counter_id'
fake_cpu_util_value = 60.0

View File

@ -19,6 +19,7 @@ from oslo_vmware import api
from oslotest import base
from ceilometer.compute.virt.vmware import vsphere_operations
from ceilometer.tests.unit.compute.virt.vmware import fake as vmware_fake
class VsphereOperationsTest(base.BaseTestCase):
@ -41,8 +42,8 @@ class VsphereOperationsTest(base.BaseTestCase):
def construct_mock_vm_object(vm_moid, vm_instance):
vm_object = mock.MagicMock()
vm_object.obj.value = vm_moid
vm_object.obj._type = "VirtualMachine"
vm_object.obj = vmware_fake.ManagedObjectReference(
'VirtualMachine', value=vm_moid)
vm_object.propSet[0].val = vm_instance
return vm_object
@ -74,8 +75,8 @@ class VsphereOperationsTest(base.BaseTestCase):
self.assertEqual("VirtualMachine", vm_object._type)
def test_query_vm_property(self):
vm_object = mock.MagicMock()
vm_object.value = "vm-21"
vm_object = vmware_fake.ManagedObjectReference('VirtualMachine',
value='vm-21')
vm_property_name = "runtime.powerState"
vm_property_val = "poweredON"
@ -131,9 +132,8 @@ class VsphereOperationsTest(base.BaseTestCase):
self.assertEqual(2, counter_id)
def test_query_vm_stats(self):
vm_object = mock.MagicMock()
vm_object.value = "vm-21"
vm_object = vmware_fake.ManagedObjectReference('VirtualMachine',
value='vm-21')
device1 = "device-1"
device2 = "device-2"
device3 = "device-3"