summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/network/v2/fakes.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests/unit/network/v2/fakes.py')
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py107
1 files changed, 100 insertions, 7 deletions
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index 4d029a0e..6d922008 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -34,6 +34,7 @@ from openstack.network.v2 import port as _port
from openstack.network.v2 import rbac_policy as network_rbac
from openstack.network.v2 import segment as _segment
from openstack.network.v2 import service_profile as _flavor_profile
+from openstack.network.v2 import trunk as _trunk
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes_v3
@@ -1065,11 +1066,13 @@ class FakeFloatingIPPortForwarding(object):
""""Fake one or more Port forwarding"""
@staticmethod
- def create_one_port_forwarding(attrs=None):
+ def create_one_port_forwarding(attrs=None, use_range=False):
"""Create a fake Port Forwarding.
:param Dictionary attrs:
A dictionary with all attributes
+ :param Boolean use_range:
+ A boolean which defines if we will use ranges or not
:return:
A FakeResource object with name, id, etc.
"""
@@ -1083,13 +1086,29 @@ class FakeFloatingIPPortForwarding(object):
'floatingip_id': floatingip_id,
'internal_port_id': 'internal-port-id-' + uuid.uuid4().hex,
'internal_ip_address': '192.168.1.2',
- 'internal_port': randint(1, 65535),
- 'external_port': randint(1, 65535),
'protocol': 'tcp',
'description': 'some description',
'location': 'MUNCHMUNCHMUNCH',
}
+ if use_range:
+ port_range = randint(0, 100)
+ internal_start = randint(1, 65535 - port_range)
+ internal_end = internal_start + port_range
+ internal_range = ':'.join(map(str, [internal_start, internal_end]))
+ external_start = randint(1, 65535 - port_range)
+ external_end = external_start + port_range
+ external_range = ':'.join(map(str, [external_start, external_end]))
+ port_forwarding_attrs['internal_port_range'] = internal_range
+ port_forwarding_attrs['external_port_range'] = external_range
+ port_forwarding_attrs['internal_port'] = None
+ port_forwarding_attrs['external_port'] = None
+ else:
+ port_forwarding_attrs['internal_port'] = randint(1, 65535)
+ port_forwarding_attrs['external_port'] = randint(1, 65535)
+ port_forwarding_attrs['internal_port_range'] = ''
+ port_forwarding_attrs['external_port_range'] = ''
+
# Overwrite default attributes.
port_forwarding_attrs.update(attrs)
@@ -1100,25 +1119,28 @@ class FakeFloatingIPPortForwarding(object):
return port_forwarding
@staticmethod
- def create_port_forwardings(attrs=None, count=2):
+ def create_port_forwardings(attrs=None, count=2, use_range=False):
"""Create multiple fake Port Forwarding.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
The number of Port Forwarding rule to fake
+ :param Boolean use_range:
+ A boolean which defines if we will use ranges or not
:return:
A list of FakeResource objects faking the Port Forwardings
"""
port_forwardings = []
for i in range(0, count):
port_forwardings.append(
- FakeFloatingIPPortForwarding.create_one_port_forwarding(attrs)
+ FakeFloatingIPPortForwarding.create_one_port_forwarding(
+ attrs, use_range=use_range)
)
return port_forwardings
@staticmethod
- def get_port_forwardings(port_forwardings=None, count=2):
+ def get_port_forwardings(port_forwardings=None, count=2, use_range=False):
"""Get a list of faked Port Forwardings.
If port forwardings list is provided, then initialize the Mock object
@@ -1128,13 +1150,16 @@ class FakeFloatingIPPortForwarding(object):
A list of FakeResource objects faking port forwardings
:param int count:
The number of Port Forwardings to fake
+ :param Boolean use_range:
+ A boolean which defines if we will use ranges or not
:return:
An iterable Mock object with side_effect set to a list of faked
Port Forwardings
"""
if port_forwardings is None:
port_forwardings = (
- FakeFloatingIPPortForwarding.create_port_forwardings(count)
+ FakeFloatingIPPortForwarding.create_port_forwardings(
+ count, use_range=use_range)
)
return mock.Mock(side_effect=port_forwardings)
@@ -2152,3 +2177,71 @@ def get_ndp_proxies(ndp_proxies=None, count=2):
create_ndp_proxies(count)
)
return mock.Mock(side_effect=ndp_proxies)
+
+
+def create_one_trunk(attrs=None):
+ """Create a fake trunk.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with name, id, etc.
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ trunk_attrs = {
+ 'id': 'trunk-id-' + uuid.uuid4().hex,
+ 'name': 'trunk-name-' + uuid.uuid4().hex,
+ 'description': '',
+ 'port_id': 'port-' + uuid.uuid4().hex,
+ 'admin_state_up': True,
+ 'project_id': 'project-id-' + uuid.uuid4().hex,
+ 'status': 'ACTIVE',
+ 'sub_ports': [{'port_id': 'subport-' +
+ uuid.uuid4().hex,
+ 'segmentation_type': 'vlan',
+ 'segmentation_id': 100}],
+ }
+ # Overwrite default attributes.
+ trunk_attrs.update(attrs)
+
+ trunk = _trunk.Trunk(**trunk_attrs)
+
+ return trunk
+
+
+def create_trunks(attrs=None, count=2):
+ """Create multiple fake trunks.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of trunks to fake
+ :return:
+ A list of FakeResource objects faking the trunks
+ """
+ trunks = []
+ for i in range(0, count):
+ trunks.append(create_one_trunk(attrs))
+
+ return trunks
+
+
+def get_trunks(trunks=None, count=2):
+ """Get an iterable Mock object with a list of faked trunks.
+
+ If trunk list is provided, then initialize the Mock object
+ with the list. Otherwise create one.
+
+ :param List trunks:
+ A list of FakeResource objects faking trunks
+ :param int count:
+ The number of trunks to fake
+ :return:
+ An iterable Mock object with side_effect set to a list of faked
+ trunks
+ """
+ if trunks is None:
+ trunks = create_trunks(count)
+ return mock.Mock(side_effect=trunks)