summaryrefslogtreecommitdiff
path: root/ceilometer/tests
diff options
context:
space:
mode:
authorkpdev <kinpaa@gmail.com>2021-04-30 09:15:13 +0200
committerkpdev <kinpaa@gmail.com>2021-05-10 12:44:01 +0200
commit044282d453e302a5690de12b679721d290368c0a (patch)
tree3e972ec358d9f31ce5aebff6b220da036a0fa412 /ceilometer/tests
parent122c55591fa90989e66fb803d9a5aac2db8a7211 (diff)
downloadceilometer-044282d453e302a5690de12b679721d290368c0a.tar.gz
vmware tests: Support different moref backend representations
We want to switch the SOAP library backing oslo.vmware [1], which changes how a ManagedObjectReference's attributes look like. To handle the two representations in the tests - especially for the transition period - we will set both attributes on fake.ManagedObjectReference. Therefore, we have to use fake.ManagedObjectReference everywhere instead of using manual Mock objects lacking one of the attributes. [1] https://specs.openstack.org/openstack/oslo-specs/specs/victoria/oslo-vmware-soap-library-switch.html Change-Id: I449e045e948ad543c4d046b6449094c7617ce78f
Diffstat (limited to 'ceilometer/tests')
-rw-r--r--ceilometer/tests/unit/compute/virt/vmware/fake.py29
-rw-r--r--ceilometer/tests/unit/compute/virt/vmware/test_inspector.py17
-rw-r--r--ceilometer/tests/unit/compute/virt/vmware/test_vsphere_operations.py14
3 files changed, 45 insertions, 15 deletions
diff --git a/ceilometer/tests/unit/compute/virt/vmware/fake.py b/ceilometer/tests/unit/compute/virt/vmware/fake.py
new file mode 100644
index 00000000..1c6eca1c
--- /dev/null
+++ b/ceilometer/tests/unit/compute/virt/vmware/fake.py
@@ -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
diff --git a/ceilometer/tests/unit/compute/virt/vmware/test_inspector.py b/ceilometer/tests/unit/compute/virt/vmware/test_inspector.py
index e6af461b..37b63dd7 100644
--- a/ceilometer/tests/unit/compute/virt/vmware/test_inspector.py
+++ b/ceilometer/tests/unit/compute/virt/vmware/test_inspector.py
@@ -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
diff --git a/ceilometer/tests/unit/compute/virt/vmware/test_vsphere_operations.py b/ceilometer/tests/unit/compute/virt/vmware/test_vsphere_operations.py
index 8f93cd46..dad45a49 100644
--- a/ceilometer/tests/unit/compute/virt/vmware/test_vsphere_operations.py
+++ b/ceilometer/tests/unit/compute/virt/vmware/test_vsphere_operations.py
@@ -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"