summaryrefslogtreecommitdiff
path: root/openstackclient/tests/network/v2/fakes.py
diff options
context:
space:
mode:
authorTerry Howe <terrylhowe@gmail.com>2014-08-13 13:13:51 -0600
committerLingxian Kong <anlin.kong@gmail.com>2016-01-25 21:57:54 +1300
commitffcfff6f3eda2cc9022b7924aa1d08739d63aaa1 (patch)
treeaa6f662ce5b70baca319dc1fdf6d2d6fe63f8e10 /openstackclient/tests/network/v2/fakes.py
parenteb36df1f82e7a4d6bd2970fe39909dd3cae82ce3 (diff)
downloadpython-openstackclient-ffcfff6f3eda2cc9022b7924aa1d08739d63aaa1.tar.gz
Subnet List
Subnet list command Partially implements: blueprint neutron-client Partial-Bug: #1523258 Change-Id: I3c0748074a6511ff92500516b3129886d2476eed
Diffstat (limited to 'openstackclient/tests/network/v2/fakes.py')
-rw-r--r--openstackclient/tests/network/v2/fakes.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index de885c62..6085bfbd 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -304,3 +304,71 @@ class FakeRouter(object):
if routers is None:
routers = FakeRouter.create_routers(count)
return mock.MagicMock(side_effect=routers)
+
+
+class FakeSubnet(object):
+ """Fake one or more subnets."""
+
+ @staticmethod
+ def create_one_subnet(attrs={}, methods={}):
+ """Create a fake subnet.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :return:
+ A FakeResource object faking the subnet
+ """
+ # Set default attributes.
+ subnet_attrs = {
+ 'id': 'subnet-id-' + uuid.uuid4().hex,
+ 'name': 'subnet-name-' + uuid.uuid4().hex,
+ 'network_id': 'network-id-' + uuid.uuid4().hex,
+ 'cidr': '10.10.10.0/24',
+ 'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ 'enable_dhcp': True,
+ 'dns_nameservers': [],
+ 'allocation_pools': [],
+ 'host_routes': [],
+ 'ip_version': '4',
+ 'gateway_ip': '10.10.10.1',
+ }
+
+ # Overwrite default attributes.
+ subnet_attrs.update(attrs)
+
+ # Set default methods.
+ subnet_methods = {
+ 'keys': ['id', 'name', 'network_id', 'cidr', 'enable_dhcp',
+ 'allocation_pools', 'dns_nameservers', 'gateway_ip',
+ 'host_routes', 'ip_version', 'tenant_id']
+ }
+
+ # Overwrite default methods.
+ subnet_methods.update(methods)
+
+ subnet = fakes.FakeResource(info=copy.deepcopy(subnet_attrs),
+ methods=copy.deepcopy(subnet_methods),
+ loaded=True)
+
+ return subnet
+
+ @staticmethod
+ def create_subnets(attrs={}, methods={}, count=2):
+ """Create multiple fake subnets.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :param int count:
+ The number of subnets to fake
+ :return:
+ A list of FakeResource objects faking the subnets
+ """
+ subnets = []
+ for i in range(0, count):
+ subnets.append(FakeSubnet.create_one_subnet(attrs, methods))
+
+ return subnets