summaryrefslogtreecommitdiff
path: root/openstackclient/tests/compute/v2
diff options
context:
space:
mode:
authorRichard Theis <rtheis@us.ibm.com>2016-01-13 11:36:49 -0600
committerRichard Theis <rtheis@us.ibm.com>2016-01-14 11:43:31 -0600
commit84174440fc9fd4679f3a72d24ed50f0b1927b91d (patch)
tree1584da96191413d4b3fdd2db4bb881348522dc48 /openstackclient/tests/compute/v2
parent9317df07a2057df8985e2882dd88633a13ba9bf3 (diff)
downloadpython-openstackclient-84174440fc9fd4679f3a72d24ed50f0b1927b91d.tar.gz
Refactor "os availability zone list"
Refactor the "os availability zone list" command to make it a common command instead of a compute-only command. Since availability zones are common to compute, volume and network (new), this refactoring allows availability zone support to be added for volume and network. In addition to the refactor, unit and functional tests were added. Change-Id: I63e9d41d229b21cd38e5a083493042c096d65e05 Partial-Bug: #1532945
Diffstat (limited to 'openstackclient/tests/compute/v2')
-rw-r--r--openstackclient/tests/compute/v2/fakes.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py
index ecf7f599..a90c9ee7 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -88,6 +88,8 @@ SERVICE = {
class FakeComputev2Client(object):
def __init__(self, **kwargs):
+ self.availability_zones = mock.Mock()
+ self.availability_zones.resource_class = fakes.FakeResource(None, {})
self.images = mock.Mock()
self.images.resource_class = fakes.FakeResource(None, {})
self.servers = mock.Mock()
@@ -289,3 +291,63 @@ class FakeFlavor(object):
if flavors is None:
flavors = FakeServer.create_flavors(count)
return mock.MagicMock(side_effect=flavors)
+
+
+class FakeAvailabilityZone(object):
+ """Fake one or more compute availability zones (AZs)."""
+
+ @staticmethod
+ def create_one_availability_zone(attrs={}, methods={}):
+ """Create a fake AZ.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :return:
+ A FakeResource object with zoneName, zoneState, etc.
+ """
+ # Set default attributes.
+ host_name = uuid.uuid4().hex
+ service_name = uuid.uuid4().hex
+ service_updated_at = uuid.uuid4().hex
+ availability_zone = {
+ 'zoneName': uuid.uuid4().hex,
+ 'zoneState': {'available': True},
+ 'hosts': {host_name: {service_name: {
+ 'available': True,
+ 'active': True,
+ 'updated_at': service_updated_at,
+ }}},
+ }
+
+ # Overwrite default attributes.
+ availability_zone.update(attrs)
+
+ availability_zone = fakes.FakeResource(
+ info=copy.deepcopy(availability_zone),
+ methods=methods,
+ loaded=True)
+ return availability_zone
+
+ @staticmethod
+ def create_availability_zones(attrs={}, methods={}, count=2):
+ """Create multiple fake AZs.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :param int count:
+ The number of AZs to fake
+ :return:
+ A list of FakeResource objects faking the AZs
+ """
+ availability_zones = []
+ for i in range(0, count):
+ availability_zone = \
+ FakeAvailabilityZone.create_one_availability_zone(
+ attrs, methods)
+ availability_zones.append(availability_zone)
+
+ return availability_zones