summaryrefslogtreecommitdiff
path: root/openstackclient/tests/compute
diff options
context:
space:
mode:
authorTang Chen <chen.tang@easystack.cn>2016-02-10 11:49:15 +0800
committerTang Chen <chen.tang@easystack.cn>2016-02-17 17:04:43 +0800
commitddc97c6dc5bc36d678515aeb9f7b3f9e85bd70d0 (patch)
treee0adec887bccc7d3bcad6952035b389adf899859 /openstackclient/tests/compute
parent0a3ba91d53524cd0aa3a411f1f964594c8445cd3 (diff)
downloadpython-openstackclient-ddc97c6dc5bc36d678515aeb9f7b3f9e85bd70d0.tar.gz
Support "network list" command in nova network
"network list" command is not implemented in nova network. This patch implements it. The Network object in novaclient is quite different from the one in sdk. And the output of "network list" using Nova network is also quite different from using Neutron. It is like this: # openstack network list +--------------------------------------+---------+-------------+ | ID | Name | Subnet | +--------------------------------------+---------+-------------+ | 96a98ec4-31f6-45f6-99e6-9384569b3bb5 | private | 10.0.0.0/24 | +--------------------------------------+---------+-------------+ --long and --external options have not been implemented because the attrs in Network object in novaclient is too much different. This patch also introduces a new FakeNetwork class in compute/v2/fake.py to fake nova network. Change-Id: Id1fdf81fb2fa8b39f2c76b7bae37ac4fecafd0f7 Depends-On: I1b59264cd40aaf1062f4e8db233ccb7fd0e95f0e partial-Bug: 1543672
Diffstat (limited to 'openstackclient/tests/compute')
-rw-r--r--openstackclient/tests/compute/v2/fakes.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py
index 00f73748..66e488b7 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -525,3 +525,61 @@ class FakeFloatingIP(object):
if floating_ips is None:
floating_ips = FakeFloatingIP.create_floating_ips(count)
return mock.MagicMock(side_effect=floating_ips)
+
+
+class FakeNetwork(object):
+ """Fake one or more networks."""
+
+ @staticmethod
+ def create_one_network(attrs={}, methods={}):
+ """Create a fake network.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :return:
+ A FakeResource object, with id, label, cidr
+ """
+ # Set default attributes.
+ network_attrs = {
+ 'id': 'network-id-' + uuid.uuid4().hex,
+ 'label': 'network-label-' + uuid.uuid4().hex,
+ 'cidr': '10.0.0.0/24',
+ }
+
+ # Overwrite default attributes.
+ network_attrs.update(attrs)
+
+ # Set default methods.
+ network_methods = {
+ 'keys': ['id', 'label', 'cidr'],
+ }
+
+ # Overwrite default methods.
+ network_methods.update(methods)
+
+ network = fakes.FakeResource(info=copy.deepcopy(network_attrs),
+ methods=copy.deepcopy(network_methods),
+ loaded=True)
+
+ return network
+
+ @staticmethod
+ def create_networks(attrs={}, methods={}, count=2):
+ """Create multiple fake networks.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :param int count:
+ The number of networks to fake
+ :return:
+ A list of FakeResource objects faking the networks
+ """
+ networks = []
+ for i in range(0, count):
+ networks.append(FakeNetwork.create_one_network(attrs, methods))
+
+ return networks