summaryrefslogtreecommitdiff
path: root/ceilometer
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2021-06-16 07:02:02 +0000
committerGerrit Code Review <review@openstack.org>2021-06-16 07:02:02 +0000
commit7df88b8c8d78807d6269ebdd3a7106d1f873df0e (patch)
treebb5b396fc1a4d3a9a7a87aa6dda21665a46b6b3b /ceilometer
parente396932505e5fd1589c8fea90e35d1b22de0ed67 (diff)
parent044282d453e302a5690de12b679721d290368c0a (diff)
downloadceilometer-7df88b8c8d78807d6269ebdd3a7106d1f873df0e.tar.gz
Merge "vmware tests: Support different moref backend representations"
Diffstat (limited to 'ceilometer')
-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"