summaryrefslogtreecommitdiff
path: root/openstackclient/tests/compute/v2/fakes.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-02-23 00:59:08 +0000
committerGerrit Code Review <review@openstack.org>2016-02-23 00:59:08 +0000
commit37f96c2c47e97eb630ef1a7086fc33712616fcc0 (patch)
treeb75adc88d711241d71b0ab971f1ab7a8e02e224e /openstackclient/tests/compute/v2/fakes.py
parent7c9bb377c1d9be92af676a06959f7ddc86403491 (diff)
parent8825f0d8f36f46eaa4aae121ba49c0f8fe6e1026 (diff)
downloadpython-openstackclient-37f96c2c47e97eb630ef1a7086fc33712616fcc0.tar.gz
Merge "Add unit tests for 'hypervisor stats' command"
Diffstat (limited to 'openstackclient/tests/compute/v2/fakes.py')
-rw-r--r--openstackclient/tests/compute/v2/fakes.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py
index c0db9b24..d2341ccc 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -121,6 +121,9 @@ class FakeComputev2Client(object):
self.hypervisors = mock.Mock()
self.hypervisors.resource_class = fakes.FakeResource(None, {})
+ self.hypervisors_stats = mock.Mock()
+ self.hypervisors_stats.resource_class = fakes.FakeResource(None, {})
+
self.security_groups = mock.Mock()
self.security_groups.resource_class = fakes.FakeResource(None, {})
@@ -235,6 +238,64 @@ class FakeHypervisor(object):
return hypervisors
+class FakehypervisorStats(object):
+ """Fake one or more hypervisor stats."""
+
+ @staticmethod
+ def create_one_hypervisor_stats(attrs={}, methods={}):
+ """Create a fake hypervisor stats.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object, with id, hypervisor_hostname, and so on
+ """
+ # Set default attributes.
+ stats_info = {
+ 'count': 2,
+ 'current_workload': 0,
+ 'disk_available_least': 50,
+ 'free_disk_gb': 100,
+ 'free_ram_mb': 23000,
+ 'local_gb': 100,
+ 'local_gb_used': 0,
+ 'memory_mb': 23800,
+ 'memory_mb_used': 1400,
+ 'running_vms': 3,
+ 'vcpus': 8,
+ 'vcpus_used': 3,
+ }
+ stats_info.update(attrs)
+
+ # Set default method.
+ hypervisor_stats_method = {'to_dict': stats_info}
+ hypervisor_stats_method.update(methods)
+
+ hypervisor_stats = fakes.FakeResource(
+ info=copy.deepcopy(stats_info),
+ methods=copy.deepcopy(hypervisor_stats_method),
+ loaded=True)
+ return hypervisor_stats
+
+ @staticmethod
+ def create_hypervisors_stats(attrs={}, count=2):
+ """Create multiple fake hypervisors stats.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of hypervisors to fake
+ :return:
+ A list of FakeResource objects faking the hypervisors
+ """
+ hypervisors = []
+ for i in range(0, count):
+ hypervisors.append(
+ FakehypervisorStats.create_one_hypervisor_stats(attrs))
+
+ return hypervisors
+
+
class FakeSecurityGroupRule(object):
"""Fake one or more security group rules."""