2014-07-11 09:05:37 -06:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2015-12-01 16:27:40 +08:00
|
|
|
import copy
|
2016-08-05 09:57:24 +01:00
|
|
|
from random import choice
|
|
|
|
from random import randint
|
2020-01-10 14:21:47 -06:00
|
|
|
from unittest import mock
|
2015-12-01 16:27:40 +08:00
|
|
|
import uuid
|
2014-07-11 09:05:37 -06:00
|
|
|
|
2023-06-07 11:09:09 +01:00
|
|
|
from openstack.network.v2 import _proxy
|
2022-02-18 15:01:12 +03:00
|
|
|
from openstack.network.v2 import address_group as _address_group
|
|
|
|
from openstack.network.v2 import address_scope as _address_scope
|
2022-03-16 15:29:47 +03:00
|
|
|
from openstack.network.v2 import agent as network_agent
|
2022-02-18 15:01:12 +03:00
|
|
|
from openstack.network.v2 import auto_allocated_topology as allocated_topology
|
|
|
|
from openstack.network.v2 import availability_zone as _availability_zone
|
2023-06-02 13:17:29 +01:00
|
|
|
from openstack.network.v2 import extension as _extension
|
2022-03-16 12:14:08 +03:00
|
|
|
from openstack.network.v2 import flavor as _flavor
|
2021-08-23 14:41:47 +03:00
|
|
|
from openstack.network.v2 import local_ip as _local_ip
|
|
|
|
from openstack.network.v2 import local_ip_association as _local_ip_association
|
2020-08-31 11:39:48 +00:00
|
|
|
from openstack.network.v2 import ndp_proxy as _ndp_proxy
|
2022-03-15 10:53:49 +03:00
|
|
|
from openstack.network.v2 import network as _network
|
|
|
|
from openstack.network.v2 import network_ip_availability as _ip_availability
|
2022-03-16 12:14:08 +03:00
|
|
|
from openstack.network.v2 import network_segment_range as _segment_range
|
2022-03-16 15:29:47 +03:00
|
|
|
from openstack.network.v2 import port as _port
|
|
|
|
from openstack.network.v2 import rbac_policy as network_rbac
|
2024-07-09 14:37:07 +01:00
|
|
|
from openstack.network.v2 import security_group as _security_group
|
2022-03-16 12:14:08 +03:00
|
|
|
from openstack.network.v2 import segment as _segment
|
2024-07-09 14:37:07 +01:00
|
|
|
from openstack.network.v2 import service_profile as _service_profile
|
2023-01-06 09:10:00 +01:00
|
|
|
from openstack.network.v2 import trunk as _trunk
|
2021-08-23 14:41:47 +03:00
|
|
|
|
2016-09-05 22:14:33 -07:00
|
|
|
from openstackclient.tests.unit import fakes
|
2024-02-14 17:44:04 +00:00
|
|
|
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
2016-09-05 22:14:33 -07:00
|
|
|
from openstackclient.tests.unit import utils
|
2015-12-01 18:05:52 +08:00
|
|
|
|
2014-07-11 09:05:37 -06:00
|
|
|
|
2015-12-21 16:17:34 -06:00
|
|
|
QUOTA = {
|
|
|
|
"subnet": 10,
|
|
|
|
"network": 10,
|
|
|
|
"floatingip": 50,
|
|
|
|
"subnetpool": -1,
|
|
|
|
"security_group_rule": 100,
|
|
|
|
"security_group": 10,
|
|
|
|
"router": 10,
|
|
|
|
"rbac_policy": -1,
|
|
|
|
"port": 50,
|
2016-03-14 19:27:36 +08:00
|
|
|
"vip": 10,
|
|
|
|
"member": 10,
|
2016-09-16 12:46:45 +05:30
|
|
|
"healthmonitor": 10,
|
2016-09-16 13:39:54 +05:30
|
|
|
"l7policy": 5,
|
2015-12-21 16:17:34 -06:00
|
|
|
}
|
|
|
|
|
2016-08-05 09:57:24 +01:00
|
|
|
RULE_TYPE_BANDWIDTH_LIMIT = 'bandwidth-limit'
|
|
|
|
RULE_TYPE_DSCP_MARKING = 'dscp-marking'
|
|
|
|
RULE_TYPE_MINIMUM_BANDWIDTH = 'minimum-bandwidth'
|
2021-09-21 13:16:10 +02:00
|
|
|
RULE_TYPE_MINIMUM_PACKET_RATE = 'minimum-packet-rate'
|
2023-05-08 11:03:05 +01:00
|
|
|
VALID_QOS_RULES = [
|
|
|
|
RULE_TYPE_BANDWIDTH_LIMIT,
|
|
|
|
RULE_TYPE_DSCP_MARKING,
|
|
|
|
RULE_TYPE_MINIMUM_BANDWIDTH,
|
|
|
|
RULE_TYPE_MINIMUM_PACKET_RATE,
|
|
|
|
]
|
|
|
|
VALID_DSCP_MARKS = [
|
|
|
|
0,
|
|
|
|
8,
|
|
|
|
10,
|
|
|
|
12,
|
|
|
|
14,
|
|
|
|
16,
|
|
|
|
18,
|
|
|
|
20,
|
|
|
|
22,
|
|
|
|
24,
|
|
|
|
26,
|
|
|
|
28,
|
|
|
|
30,
|
|
|
|
32,
|
|
|
|
34,
|
|
|
|
36,
|
|
|
|
38,
|
|
|
|
40,
|
|
|
|
46,
|
|
|
|
48,
|
|
|
|
56,
|
|
|
|
]
|
2016-08-05 09:57:24 +01:00
|
|
|
|
2015-12-09 11:38:31 -07:00
|
|
|
|
2023-06-07 11:09:09 +01:00
|
|
|
class FakeClientMixin:
|
2015-12-01 18:05:52 +08:00
|
|
|
def setUp(self):
|
2023-06-02 13:17:29 +01:00
|
|
|
super().setUp()
|
2015-12-01 18:05:52 +08:00
|
|
|
|
2023-06-07 11:09:09 +01:00
|
|
|
self.app.client_manager.network = mock.Mock(spec=_proxy.Proxy)
|
|
|
|
self.network_client = self.app.client_manager.network
|
2015-12-01 18:05:52 +08:00
|
|
|
|
2023-06-07 11:09:09 +01:00
|
|
|
|
2024-02-14 17:44:04 +00:00
|
|
|
class TestNetworkV2(
|
|
|
|
identity_fakes.FakeClientMixin,
|
|
|
|
FakeClientMixin,
|
|
|
|
utils.TestCommand,
|
2024-04-23 12:22:26 +01:00
|
|
|
): ...
|
2017-02-18 15:46:43 -06:00
|
|
|
|
2015-12-01 16:27:40 +08:00
|
|
|
|
2023-06-02 13:17:29 +01:00
|
|
|
def create_one_extension(attrs=None):
|
|
|
|
"""Create a fake extension.
|
2016-06-03 20:58:23 +08:00
|
|
|
|
2023-06-02 13:17:29 +01:00
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
An Extension object with name, namespace, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
2016-06-03 20:58:23 +08:00
|
|
|
|
2023-06-02 13:17:29 +01:00
|
|
|
# Set default attributes.
|
|
|
|
extension_info = {
|
|
|
|
'name': 'name-' + uuid.uuid4().hex,
|
|
|
|
'description': 'description-' + uuid.uuid4().hex,
|
|
|
|
'alias': 'Dystopian',
|
|
|
|
'links': [],
|
|
|
|
'updated_at': '2013-07-09T12:00:0-00:00',
|
|
|
|
}
|
2016-06-03 20:58:23 +08:00
|
|
|
|
2023-06-02 13:17:29 +01:00
|
|
|
# Overwrite default attributes.
|
|
|
|
extension_info.update(attrs)
|
|
|
|
|
|
|
|
extension = _extension.Extension(**extension_info)
|
|
|
|
return extension
|
2016-06-03 20:58:23 +08:00
|
|
|
|
|
|
|
|
2016-08-05 09:57:24 +01:00
|
|
|
class FakeNetworkQosPolicy:
|
|
|
|
"""Fake one or more QoS policies."""
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2016-08-05 09:57:24 +01:00
|
|
|
def create_one_qos_policy(attrs=None):
|
|
|
|
"""Create a fake QoS policy.
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
2016-08-05 09:57:24 +01:00
|
|
|
A FakeResource object with name, id, etc.
|
2016-08-02 09:42:21 +01:00
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
2016-08-05 09:57:24 +01:00
|
|
|
qos_id = attrs.get('id') or 'qos-policy-id-' + uuid.uuid4().hex
|
|
|
|
rule_attrs = {'qos_policy_id': qos_id}
|
|
|
|
rules = [FakeNetworkQosRule.create_one_qos_rule(rule_attrs)]
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
# Set default attributes.
|
2016-08-05 09:57:24 +01:00
|
|
|
qos_policy_attrs = {
|
|
|
|
'name': 'qos-policy-name-' + uuid.uuid4().hex,
|
|
|
|
'id': qos_id,
|
2017-02-16 18:55:02 +00:00
|
|
|
'is_default': False,
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2016-08-05 09:57:24 +01:00
|
|
|
'shared': False,
|
|
|
|
'description': 'qos-policy-description-' + uuid.uuid4().hex,
|
|
|
|
'rules': rules,
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2016-08-02 09:42:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
2016-08-05 09:57:24 +01:00
|
|
|
qos_policy_attrs.update(attrs)
|
2016-08-02 09:42:21 +01:00
|
|
|
|
2016-08-05 09:57:24 +01:00
|
|
|
qos_policy = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(qos_policy_attrs), loaded=True
|
|
|
|
)
|
2016-08-02 09:42:21 +01:00
|
|
|
|
2016-08-05 09:57:24 +01:00
|
|
|
# Set attributes with special mapping in OpenStack SDK.
|
|
|
|
qos_policy.is_shared = qos_policy_attrs['shared']
|
|
|
|
|
|
|
|
return qos_policy
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2016-08-05 09:57:24 +01:00
|
|
|
def create_qos_policies(attrs=None, count=2):
|
|
|
|
"""Create multiple fake QoS policies.
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
2016-08-05 09:57:24 +01:00
|
|
|
The number of QoS policies to fake
|
2016-08-02 09:42:21 +01:00
|
|
|
:return:
|
2016-08-05 09:57:24 +01:00
|
|
|
A list of FakeResource objects faking the QoS policies
|
2016-08-02 09:42:21 +01:00
|
|
|
"""
|
|
|
|
qos_policies = []
|
|
|
|
for i in range(0, count):
|
2016-08-05 09:57:24 +01:00
|
|
|
qos_policies.append(
|
2023-05-08 11:03:05 +01:00
|
|
|
FakeNetworkQosPolicy.create_one_qos_policy(attrs)
|
|
|
|
)
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
return qos_policies
|
|
|
|
|
|
|
|
@staticmethod
|
2016-08-05 09:57:24 +01:00
|
|
|
def get_qos_policies(qos_policies=None, count=2):
|
|
|
|
"""Get an iterable MagicMock object with a list of faked QoS policies.
|
2016-08-02 09:42:21 +01:00
|
|
|
|
2016-08-05 09:57:24 +01:00
|
|
|
If qos policies list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
2016-08-02 09:42:21 +01:00
|
|
|
|
2017-05-30 16:37:01 +07:00
|
|
|
:param List qos_policies:
|
2016-08-05 09:57:24 +01:00
|
|
|
A list of FakeResource objects faking qos policies
|
2016-08-02 09:42:21 +01:00
|
|
|
:param int count:
|
2016-08-05 09:57:24 +01:00
|
|
|
The number of QoS policies to fake
|
2016-08-02 09:42:21 +01:00
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
2016-08-05 09:57:24 +01:00
|
|
|
QoS policies
|
2016-08-02 09:42:21 +01:00
|
|
|
"""
|
2016-08-05 09:57:24 +01:00
|
|
|
if qos_policies is None:
|
|
|
|
qos_policies = FakeNetworkQosPolicy.create_qos_policies(count)
|
|
|
|
return mock.Mock(side_effect=qos_policies)
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
|
2019-02-13 14:17:33 -07:00
|
|
|
class FakeNetworkSecGroup:
|
|
|
|
"""Fake one security group."""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_one_security_group(attrs=None):
|
|
|
|
"""Create a fake security group.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object with name, id, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
sg_id = attrs.get('id') or 'security-group-id-' + uuid.uuid4().hex
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
security_group_attrs = {
|
|
|
|
'name': 'security-group-name-' + uuid.uuid4().hex,
|
|
|
|
'id': sg_id,
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2021-12-16 16:21:58 +01:00
|
|
|
'description': 'security-group-description-' + uuid.uuid4().hex,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2019-02-13 14:17:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
security_group = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(security_group_attrs), loaded=True
|
|
|
|
)
|
2019-02-13 14:17:33 -07:00
|
|
|
|
|
|
|
return security_group
|
|
|
|
|
|
|
|
|
2016-08-05 09:57:24 +01:00
|
|
|
class FakeNetworkQosRule:
|
|
|
|
"""Fake one or more Network QoS rules."""
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2016-08-05 09:57:24 +01:00
|
|
|
def create_one_qos_rule(attrs=None):
|
|
|
|
"""Create a fake Network QoS rule.
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object with name, id, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
2016-08-05 09:57:24 +01:00
|
|
|
type = attrs.get('type') or choice(VALID_QOS_RULES)
|
|
|
|
qos_rule_attrs = {
|
|
|
|
'id': 'qos-rule-id-' + uuid.uuid4().hex,
|
|
|
|
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2016-08-05 09:57:24 +01:00
|
|
|
'type': type,
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2016-08-02 09:42:21 +01:00
|
|
|
}
|
2016-08-05 09:57:24 +01:00
|
|
|
if type == RULE_TYPE_BANDWIDTH_LIMIT:
|
|
|
|
qos_rule_attrs['max_kbps'] = randint(1, 10000)
|
|
|
|
qos_rule_attrs['max_burst_kbits'] = randint(1, 10000)
|
2017-04-19 10:07:40 +00:00
|
|
|
qos_rule_attrs['direction'] = 'egress'
|
2016-08-05 09:57:24 +01:00
|
|
|
elif type == RULE_TYPE_DSCP_MARKING:
|
|
|
|
qos_rule_attrs['dscp_mark'] = choice(VALID_DSCP_MARKS)
|
|
|
|
elif type == RULE_TYPE_MINIMUM_BANDWIDTH:
|
|
|
|
qos_rule_attrs['min_kbps'] = randint(1, 10000)
|
|
|
|
qos_rule_attrs['direction'] = 'egress'
|
2021-09-21 13:16:10 +02:00
|
|
|
elif type == RULE_TYPE_MINIMUM_PACKET_RATE:
|
|
|
|
qos_rule_attrs['min_kpps'] = randint(1, 10000)
|
|
|
|
qos_rule_attrs['direction'] = 'egress'
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
# Overwrite default attributes.
|
2016-08-05 09:57:24 +01:00
|
|
|
qos_rule_attrs.update(attrs)
|
2016-08-02 09:42:21 +01:00
|
|
|
|
2023-05-08 11:03:05 +01:00
|
|
|
qos_rule = fakes.FakeResource(
|
|
|
|
info=copy.deepcopy(qos_rule_attrs), loaded=True
|
|
|
|
)
|
2016-08-02 09:42:21 +01:00
|
|
|
|
2016-08-05 09:57:24 +01:00
|
|
|
return qos_rule
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2016-08-05 09:57:24 +01:00
|
|
|
def create_qos_rules(attrs=None, count=2):
|
|
|
|
"""Create multiple fake Network QoS rules.
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
2016-08-05 09:57:24 +01:00
|
|
|
The number of Network QoS rule to fake
|
2016-08-02 09:42:21 +01:00
|
|
|
:return:
|
2016-08-05 09:57:24 +01:00
|
|
|
A list of FakeResource objects faking the Network QoS rules
|
2016-08-02 09:42:21 +01:00
|
|
|
"""
|
2016-08-05 09:57:24 +01:00
|
|
|
qos_rules = []
|
2016-08-02 09:42:21 +01:00
|
|
|
for i in range(0, count):
|
2016-08-05 09:57:24 +01:00
|
|
|
qos_rules.append(FakeNetworkQosRule.create_one_qos_rule(attrs))
|
|
|
|
return qos_rules
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2016-08-05 09:57:24 +01:00
|
|
|
def get_qos_rules(qos_rules=None, count=2):
|
|
|
|
"""Get a list of faked Network QoS rules.
|
2016-08-02 09:42:21 +01:00
|
|
|
|
2016-08-05 09:57:24 +01:00
|
|
|
If Network QoS rules list is provided, then initialize the Mock
|
|
|
|
object with the list. Otherwise create one.
|
2016-08-02 09:42:21 +01:00
|
|
|
|
2017-05-30 16:37:01 +07:00
|
|
|
:param List qos_rules:
|
2016-08-05 09:57:24 +01:00
|
|
|
A list of FakeResource objects faking Network QoS rules
|
2016-08-02 09:42:21 +01:00
|
|
|
:param int count:
|
2016-08-05 09:57:24 +01:00
|
|
|
The number of QoS minimum bandwidth rules to fake
|
2016-08-02 09:42:21 +01:00
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
2016-08-05 09:57:24 +01:00
|
|
|
qos minimum bandwidth rules
|
2016-08-02 09:42:21 +01:00
|
|
|
"""
|
2016-08-05 09:57:24 +01:00
|
|
|
if qos_rules is None:
|
2023-05-08 11:03:05 +01:00
|
|
|
qos_rules = FakeNetworkQosRule.create_qos_rules(count)
|
2016-08-05 09:57:24 +01:00
|
|
|
return mock.Mock(side_effect=qos_rules)
|
2016-08-02 09:42:21 +01:00
|
|
|
|
|
|
|
|
2016-08-12 16:51:35 +01:00
|
|
|
class FakeNetworkQosRuleType:
|
|
|
|
"""Fake one or more Network QoS rule types."""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_one_qos_rule_type(attrs=None):
|
|
|
|
"""Create a fake Network QoS rule type.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object with name, id, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
qos_rule_type_attrs = {
|
|
|
|
'type': 'rule-type-' + uuid.uuid4().hex,
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2016-08-12 16:51:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
qos_rule_type_attrs.update(attrs)
|
|
|
|
|
|
|
|
return fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(qos_rule_type_attrs), loaded=True
|
|
|
|
)
|
2016-08-12 16:51:35 +01:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_qos_rule_types(attrs=None, count=2):
|
|
|
|
"""Create multiple fake Network QoS rule types.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of QoS rule types to fake
|
|
|
|
:return:
|
|
|
|
A list of FakeResource objects faking the QoS rule types
|
|
|
|
"""
|
|
|
|
qos_rule_types = []
|
|
|
|
for i in range(0, count):
|
|
|
|
qos_rule_types.append(
|
2023-05-08 11:03:05 +01:00
|
|
|
FakeNetworkQosRuleType.create_one_qos_rule_type(attrs)
|
|
|
|
)
|
2016-08-12 16:51:35 +01:00
|
|
|
|
|
|
|
return qos_rule_types
|
|
|
|
|
|
|
|
|
2015-12-12 17:19:10 +08:00
|
|
|
class FakeRouter:
|
|
|
|
"""Fake one or more routers."""
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-15 15:46:19 +08:00
|
|
|
def create_one_router(attrs=None):
|
2015-12-12 17:19:10 +08:00
|
|
|
"""Create a fake router.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object, with id, name, admin_state_up,
|
2022-01-14 18:51:56 +01:00
|
|
|
status, project_id
|
2015-12-12 17:19:10 +08:00
|
|
|
"""
|
2016-04-15 15:46:19 +08:00
|
|
|
attrs = attrs or {}
|
|
|
|
|
2015-12-12 17:19:10 +08:00
|
|
|
# Set default attributes.
|
|
|
|
router_attrs = {
|
|
|
|
'id': 'router-id-' + uuid.uuid4().hex,
|
|
|
|
'name': 'router-name-' + uuid.uuid4().hex,
|
|
|
|
'status': 'ACTIVE',
|
|
|
|
'admin_state_up': True,
|
2016-09-20 12:29:08 -05:00
|
|
|
'description': 'router-description-' + uuid.uuid4().hex,
|
2015-12-12 17:19:10 +08:00
|
|
|
'distributed': False,
|
|
|
|
'ha': False,
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2015-12-12 17:19:10 +08:00
|
|
|
'routes': [],
|
|
|
|
'external_gateway_info': {},
|
2016-01-21 04:19:48 -06:00
|
|
|
'availability_zone_hints': [],
|
|
|
|
'availability_zones': [],
|
2017-04-29 00:32:32 +00:00
|
|
|
'tags': [],
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2015-12-12 17:19:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
router_attrs.update(attrs)
|
|
|
|
|
2023-05-08 11:03:05 +01:00
|
|
|
router = fakes.FakeResource(
|
|
|
|
info=copy.deepcopy(router_attrs), loaded=True
|
|
|
|
)
|
2016-03-03 20:50:17 +08:00
|
|
|
|
|
|
|
# Set attributes with special mapping in OpenStack SDK.
|
2016-11-14 01:23:39 -08:00
|
|
|
router.is_admin_state_up = router_attrs['admin_state_up']
|
|
|
|
router.is_distributed = router_attrs['distributed']
|
|
|
|
router.is_ha = router_attrs['ha']
|
2016-03-03 20:50:17 +08:00
|
|
|
|
2015-12-12 17:19:10 +08:00
|
|
|
return router
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-15 15:46:19 +08:00
|
|
|
def create_routers(attrs=None, count=2):
|
2015-12-12 17:19:10 +08:00
|
|
|
"""Create multiple fake routers.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of routers to fake
|
|
|
|
:return:
|
|
|
|
A list of FakeResource objects faking the routers
|
|
|
|
"""
|
|
|
|
routers = []
|
|
|
|
for i in range(0, count):
|
2016-04-11 16:32:58 +08:00
|
|
|
routers.append(FakeRouter.create_one_router(attrs))
|
2015-12-12 17:19:10 +08:00
|
|
|
|
|
|
|
return routers
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_routers(routers=None, count=2):
|
2016-09-27 09:52:41 +07:00
|
|
|
"""Get an iterable Mock object with a list of faked routers.
|
2015-12-12 17:19:10 +08:00
|
|
|
|
|
|
|
If routers list is provided, then initialize the Mock object with the
|
|
|
|
list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List routers:
|
|
|
|
A list of FakeResource objects faking routers
|
|
|
|
:param int count:
|
|
|
|
The number of routers to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
routers
|
|
|
|
"""
|
|
|
|
if routers is None:
|
|
|
|
routers = FakeRouter.create_routers(count)
|
2016-09-14 13:27:31 +08:00
|
|
|
return mock.Mock(side_effect=routers)
|
2014-08-13 13:13:51 -06:00
|
|
|
|
|
|
|
|
2015-12-14 13:29:43 -06:00
|
|
|
class FakeSecurityGroup:
|
|
|
|
"""Fake one or more security groups."""
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-11 16:32:58 +08:00
|
|
|
def create_one_security_group(attrs=None):
|
2015-12-14 13:29:43 -06:00
|
|
|
"""Create a fake security group.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object, with id, name, etc.
|
|
|
|
"""
|
2016-04-15 15:46:19 +08:00
|
|
|
attrs = attrs or {}
|
2016-02-26 11:33:45 -06:00
|
|
|
|
2015-12-14 13:29:43 -06:00
|
|
|
# Set default attributes.
|
|
|
|
security_group_attrs = {
|
|
|
|
'id': 'security-group-id-' + uuid.uuid4().hex,
|
|
|
|
'name': 'security-group-name-' + uuid.uuid4().hex,
|
|
|
|
'description': 'security-group-description-' + uuid.uuid4().hex,
|
2020-03-05 17:54:55 +01:00
|
|
|
'stateful': True,
|
2017-02-16 18:43:31 +08:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2015-12-14 13:29:43 -06:00
|
|
|
'security_group_rules': [],
|
2021-12-16 16:21:58 +01:00
|
|
|
'tags': [],
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2015-12-14 13:29:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
security_group_attrs.update(attrs)
|
|
|
|
|
|
|
|
security_group = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(security_group_attrs), loaded=True
|
|
|
|
)
|
2016-02-26 11:33:45 -06:00
|
|
|
|
2015-12-14 13:29:43 -06:00
|
|
|
return security_group
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-11 16:32:58 +08:00
|
|
|
def create_security_groups(attrs=None, count=2):
|
2015-12-14 13:29:43 -06:00
|
|
|
"""Create multiple fake security groups.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of security groups to fake
|
|
|
|
:return:
|
|
|
|
A list of FakeResource objects faking the security groups
|
|
|
|
"""
|
|
|
|
security_groups = []
|
|
|
|
for i in range(0, count):
|
|
|
|
security_groups.append(
|
2023-05-08 11:03:05 +01:00
|
|
|
FakeSecurityGroup.create_one_security_group(attrs)
|
|
|
|
)
|
2015-12-14 13:29:43 -06:00
|
|
|
|
|
|
|
return security_groups
|
|
|
|
|
2016-06-12 12:50:30 +08:00
|
|
|
@staticmethod
|
|
|
|
def get_security_groups(security_groups=None, count=2):
|
2016-09-27 09:52:41 +07:00
|
|
|
"""Get an iterable Mock object with a list of faked security groups.
|
2016-06-12 12:50:30 +08:00
|
|
|
|
|
|
|
If security groups list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
2017-05-30 16:37:01 +07:00
|
|
|
:param List security_groups:
|
2016-06-12 12:50:30 +08:00
|
|
|
A list of FakeResource objects faking security groups
|
|
|
|
:param int count:
|
|
|
|
The number of security groups to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
security groups
|
|
|
|
"""
|
|
|
|
if security_groups is None:
|
|
|
|
security_groups = FakeSecurityGroup.create_security_groups(count)
|
2016-09-14 13:27:31 +08:00
|
|
|
return mock.Mock(side_effect=security_groups)
|
2016-06-12 12:50:30 +08:00
|
|
|
|
2016-02-05 09:02:27 -06:00
|
|
|
|
|
|
|
class FakeSecurityGroupRule:
|
|
|
|
"""Fake one or more security group rules."""
|
|
|
|
|
2015-12-14 13:29:43 -06:00
|
|
|
@staticmethod
|
2016-04-11 16:32:58 +08:00
|
|
|
def create_one_security_group_rule(attrs=None):
|
2016-02-05 09:02:27 -06:00
|
|
|
"""Create a fake security group rule.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
2016-02-19 10:19:28 -06:00
|
|
|
A FakeResource object, with id, etc.
|
2016-02-05 09:02:27 -06:00
|
|
|
"""
|
2016-04-15 15:46:19 +08:00
|
|
|
attrs = attrs or {}
|
2016-02-26 11:33:45 -06:00
|
|
|
|
2016-02-05 09:02:27 -06:00
|
|
|
# Set default attributes.
|
|
|
|
security_group_rule_attrs = {
|
2023-05-08 11:03:05 +01:00
|
|
|
'description': 'security-group-rule-description-'
|
|
|
|
+ uuid.uuid4().hex,
|
2016-02-05 09:02:27 -06:00
|
|
|
'direction': 'ingress',
|
2017-02-24 16:04:43 +01:00
|
|
|
'ether_type': 'IPv4',
|
2016-02-05 09:02:27 -06:00
|
|
|
'id': 'security-group-rule-id-' + uuid.uuid4().hex,
|
Additional network protocol support
Add the following network protocol support to the
"os security group rule create" command:
- Add "--icmp-type" and "--icmp-code" options
for Network v2 only. These options can be used to set
the ICMP type and code for ICMP IP protocols.
- Change the "--proto" option to "--protocol". Using the
"--proto" option is still supported, but is no longer
documented and may be deprecated in a future release.
- Add the following Network v2 IP protocols to the
"--protocol" option: "ah", "dccp", "egp", "esp", "gre",
"igmp", "ipv6-encap", "ipv6-frag", "ipv6-icmp",
"ipv6-nonxt", "ipv6-opts", "ipv6-route", "ospf", "pgm",
"rsvp", "sctp", "udplite", "vrrp" and integer
representations [0-255].
The "os security group rule list" command now supports
displaying the ICMP type and code for security group rules
with the ICMP IP protocols.
Change-Id: Ic84bc92bc7aa5ac08f6ef91660eb6c125a200eb3
Closes-Bug: #1519512
Implements: blueprint neutron-client
2016-04-15 07:36:43 -05:00
|
|
|
'port_range_max': None,
|
|
|
|
'port_range_min': None,
|
2017-11-10 10:58:58 -05:00
|
|
|
'protocol': None,
|
2016-03-11 15:30:47 -06:00
|
|
|
'remote_group_id': None,
|
2020-10-14 11:35:22 -05:00
|
|
|
'remote_address_group_id': None,
|
2016-03-11 15:30:47 -06:00
|
|
|
'remote_ip_prefix': '0.0.0.0/0',
|
2016-02-05 09:02:27 -06:00
|
|
|
'security_group_id': 'security-group-id-' + uuid.uuid4().hex,
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2016-02-05 09:02:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
security_group_rule_attrs.update(attrs)
|
2015-12-14 13:29:43 -06:00
|
|
|
|
2016-02-05 09:02:27 -06:00
|
|
|
security_group_rule = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(security_group_rule_attrs), loaded=True
|
|
|
|
)
|
2016-02-19 10:19:28 -06:00
|
|
|
|
2016-02-05 09:02:27 -06:00
|
|
|
return security_group_rule
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-11 16:32:58 +08:00
|
|
|
def create_security_group_rules(attrs=None, count=2):
|
2016-02-05 09:02:27 -06:00
|
|
|
"""Create multiple fake security group rules.
|
2015-12-14 13:29:43 -06:00
|
|
|
|
2016-02-05 09:02:27 -06:00
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
2015-12-14 13:29:43 -06:00
|
|
|
:param int count:
|
2016-02-05 09:02:27 -06:00
|
|
|
The number of security group rules to fake
|
2015-12-14 13:29:43 -06:00
|
|
|
:return:
|
2016-02-05 09:02:27 -06:00
|
|
|
A list of FakeResource objects faking the security group rules
|
2015-12-14 13:29:43 -06:00
|
|
|
"""
|
2016-02-05 09:02:27 -06:00
|
|
|
security_group_rules = []
|
|
|
|
for i in range(0, count):
|
|
|
|
security_group_rules.append(
|
2023-05-08 11:03:05 +01:00
|
|
|
FakeSecurityGroupRule.create_one_security_group_rule(attrs)
|
|
|
|
)
|
2016-02-05 09:02:27 -06:00
|
|
|
|
|
|
|
return security_group_rules
|
2015-12-14 13:29:43 -06:00
|
|
|
|
2016-06-12 12:50:30 +08:00
|
|
|
@staticmethod
|
|
|
|
def get_security_group_rules(security_group_rules=None, count=2):
|
2019-06-14 11:51:52 +01:00
|
|
|
"""Get an iterable Mock with a list of faked security group rules.
|
2016-06-12 12:50:30 +08:00
|
|
|
|
|
|
|
If security group rules list is provided, then initialize the Mock
|
|
|
|
object with the list. Otherwise create one.
|
|
|
|
|
2017-05-30 16:37:01 +07:00
|
|
|
:param List security_group_rules:
|
2016-06-12 12:50:30 +08:00
|
|
|
A list of FakeResource objects faking security group rules
|
|
|
|
:param int count:
|
|
|
|
The number of security group rules to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
security group rules
|
|
|
|
"""
|
|
|
|
if security_group_rules is None:
|
|
|
|
security_group_rules = (
|
2023-05-08 11:03:05 +01:00
|
|
|
FakeSecurityGroupRule.create_security_group_rules(count)
|
|
|
|
)
|
2016-09-14 13:27:31 +08:00
|
|
|
return mock.Mock(side_effect=security_group_rules)
|
2016-06-12 12:50:30 +08:00
|
|
|
|
2015-12-14 13:29:43 -06:00
|
|
|
|
2014-08-13 13:13:51 -06:00
|
|
|
class FakeSubnet:
|
|
|
|
"""Fake one or more subnets."""
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-15 15:46:19 +08:00
|
|
|
def create_one_subnet(attrs=None):
|
2014-08-13 13:13:51 -06:00
|
|
|
"""Create a fake subnet.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object faking the subnet
|
|
|
|
"""
|
2016-04-15 15:46:19 +08:00
|
|
|
attrs = attrs or {}
|
|
|
|
|
2014-08-13 13:13:51 -06:00
|
|
|
# Set default attributes.
|
2016-02-04 17:19:37 -06:00
|
|
|
project_id = 'project-id-' + uuid.uuid4().hex
|
2014-08-13 13:13:51 -06:00
|
|
|
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',
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': project_id,
|
2014-08-13 13:13:51 -06:00
|
|
|
'enable_dhcp': True,
|
|
|
|
'dns_nameservers': [],
|
|
|
|
'allocation_pools': [],
|
|
|
|
'host_routes': [],
|
2016-02-11 15:20:27 -06:00
|
|
|
'ip_version': 4,
|
2014-08-13 13:13:51 -06:00
|
|
|
'gateway_ip': '10.10.10.1',
|
2016-06-10 16:01:31 -05:00
|
|
|
'ipv6_address_mode': None,
|
|
|
|
'ipv6_ra_mode': None,
|
|
|
|
'segment_id': None,
|
2016-07-15 13:20:10 -04:00
|
|
|
'service_types': [],
|
2016-06-10 16:01:31 -05:00
|
|
|
'subnetpool_id': None,
|
2016-08-18 16:50:52 +07:00
|
|
|
'description': 'subnet-description-' + uuid.uuid4().hex,
|
2017-04-29 00:32:32 +00:00
|
|
|
'tags': [],
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2014-08-13 13:13:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
subnet_attrs.update(attrs)
|
|
|
|
|
2023-05-08 11:03:05 +01:00
|
|
|
subnet = fakes.FakeResource(
|
|
|
|
info=copy.deepcopy(subnet_attrs), loaded=True
|
|
|
|
)
|
2016-04-15 15:46:19 +08:00
|
|
|
|
2016-02-04 17:19:37 -06:00
|
|
|
# Set attributes with special mappings in OpenStack SDK.
|
2016-11-17 16:14:40 -08:00
|
|
|
subnet.is_dhcp_enabled = subnet_attrs['enable_dhcp']
|
|
|
|
subnet.subnet_pool_id = subnet_attrs['subnetpool_id']
|
2014-08-13 13:13:51 -06:00
|
|
|
|
|
|
|
return subnet
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-15 15:46:19 +08:00
|
|
|
def create_subnets(attrs=None, count=2):
|
2014-08-13 13:13:51 -06:00
|
|
|
"""Create multiple fake subnets.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
: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):
|
2016-04-11 16:32:58 +08:00
|
|
|
subnets.append(FakeSubnet.create_one_subnet(attrs))
|
2014-08-13 13:13:51 -06:00
|
|
|
|
|
|
|
return subnets
|
2016-02-02 09:35:38 +05:30
|
|
|
|
2016-06-16 13:09:27 +08:00
|
|
|
@staticmethod
|
|
|
|
def get_subnets(subnets=None, count=2):
|
2016-09-27 09:52:41 +07:00
|
|
|
"""Get an iterable Mock object with a list of faked subnets.
|
2016-06-16 13:09:27 +08:00
|
|
|
|
|
|
|
If subnets list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List subnets:
|
|
|
|
A list of FakeResource objects faking subnets
|
|
|
|
:param int count:
|
|
|
|
The number of subnets to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
subnets
|
|
|
|
"""
|
|
|
|
if subnets is None:
|
|
|
|
subnets = FakeSubnet.create_subnets(count)
|
2016-09-14 13:27:31 +08:00
|
|
|
return mock.Mock(side_effect=subnets)
|
2016-06-16 13:09:27 +08:00
|
|
|
|
2016-02-02 09:35:38 +05:30
|
|
|
|
|
|
|
class FakeFloatingIP:
|
|
|
|
"""Fake one or more floating ip."""
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-15 15:46:19 +08:00
|
|
|
def create_one_floating_ip(attrs=None):
|
2016-02-02 09:35:38 +05:30
|
|
|
"""Create a fake floating ip.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
2016-02-09 14:23:28 +08:00
|
|
|
A FakeResource object, with id, ip, and so on
|
2016-02-02 09:35:38 +05:30
|
|
|
"""
|
2016-04-15 15:46:19 +08:00
|
|
|
attrs = attrs or {}
|
|
|
|
|
2016-02-02 09:35:38 +05:30
|
|
|
# Set default attributes.
|
|
|
|
floating_ip_attrs = {
|
|
|
|
'id': 'floating-ip-id-' + uuid.uuid4().hex,
|
2016-02-16 14:33:31 +08:00
|
|
|
'floating_ip_address': '1.0.9.0',
|
|
|
|
'fixed_ip_address': '2.0.9.0',
|
2016-02-24 17:26:13 +08:00
|
|
|
'dns_domain': None,
|
|
|
|
'dns_name': None,
|
|
|
|
'status': 'DOWN',
|
|
|
|
'floating_network_id': 'network-id-' + uuid.uuid4().hex,
|
|
|
|
'router_id': 'router-id-' + uuid.uuid4().hex,
|
2016-02-16 14:33:31 +08:00
|
|
|
'port_id': 'port-id-' + uuid.uuid4().hex,
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2016-09-20 12:29:08 -05:00
|
|
|
'description': 'floating-ip-description-' + uuid.uuid4().hex,
|
2017-11-05 12:05:09 +08:00
|
|
|
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
|
2018-02-23 08:03:12 +00:00
|
|
|
'tags': [],
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2016-02-02 09:35:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
floating_ip_attrs.update(attrs)
|
|
|
|
|
|
|
|
floating_ip = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(floating_ip_attrs), loaded=True
|
2016-02-24 17:26:13 +08:00
|
|
|
)
|
|
|
|
|
2016-02-02 09:35:38 +05:30
|
|
|
return floating_ip
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-15 15:46:19 +08:00
|
|
|
def create_floating_ips(attrs=None, count=2):
|
2016-02-02 09:35:38 +05:30
|
|
|
"""Create multiple fake floating ips.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of floating ips to fake
|
|
|
|
:return:
|
|
|
|
A list of FakeResource objects faking the floating ips
|
|
|
|
"""
|
|
|
|
floating_ips = []
|
|
|
|
for i in range(0, count):
|
2016-04-11 16:32:58 +08:00
|
|
|
floating_ips.append(FakeFloatingIP.create_one_floating_ip(attrs))
|
2016-02-02 09:35:38 +05:30
|
|
|
return floating_ips
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_floating_ips(floating_ips=None, count=2):
|
2016-09-27 09:52:41 +07:00
|
|
|
"""Get an iterable Mock object with a list of faked floating ips.
|
2016-02-02 09:35:38 +05:30
|
|
|
|
|
|
|
If floating_ips list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
2017-05-30 16:37:01 +07:00
|
|
|
:param List floating_ips:
|
2016-02-02 09:35:38 +05:30
|
|
|
A list of FakeResource objects faking floating ips
|
|
|
|
:param int count:
|
|
|
|
The number of floating ips to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
floating ips
|
|
|
|
"""
|
|
|
|
if floating_ips is None:
|
|
|
|
floating_ips = FakeFloatingIP.create_floating_ips(count)
|
2016-09-14 13:27:31 +08:00
|
|
|
return mock.Mock(side_effect=floating_ips)
|
2016-02-12 13:31:15 +08:00
|
|
|
|
|
|
|
|
2016-09-23 14:59:51 -05:00
|
|
|
class FakeNetworkMeter:
|
|
|
|
"""Fake network meter"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_one_meter(attrs=None):
|
|
|
|
"""Create metering pool"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
meter_attrs = {
|
|
|
|
'id': 'meter-id-' + uuid.uuid4().hex,
|
|
|
|
'name': 'meter-name-' + uuid.uuid4().hex,
|
|
|
|
'description': 'meter-description-' + uuid.uuid4().hex,
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2021-12-16 16:21:58 +01:00
|
|
|
'shared': False,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2016-09-23 14:59:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
meter_attrs.update(attrs)
|
|
|
|
|
|
|
|
meter = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(meter_attrs), loaded=True
|
|
|
|
)
|
2016-09-23 14:59:51 -05:00
|
|
|
|
|
|
|
return meter
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_meter(attrs=None, count=2):
|
|
|
|
"""Create multiple meters"""
|
|
|
|
|
|
|
|
meters = []
|
|
|
|
for i in range(0, count):
|
2023-05-08 11:03:05 +01:00
|
|
|
meters.append(FakeNetworkMeter.create_one_meter(attrs))
|
2016-09-23 14:59:51 -05:00
|
|
|
return meters
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_meter(meter=None, count=2):
|
|
|
|
"""Get a list of meters"""
|
|
|
|
if meter is None:
|
2023-05-08 11:03:05 +01:00
|
|
|
meter = FakeNetworkMeter.create_meter(count)
|
2016-09-23 14:59:51 -05:00
|
|
|
return mock.Mock(side_effect=meter)
|
|
|
|
|
|
|
|
|
2016-09-27 17:00:43 -05:00
|
|
|
class FakeNetworkMeterRule:
|
|
|
|
"""Fake metering rule"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_one_rule(attrs=None):
|
|
|
|
"""Create one meter rule"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
meter_rule_attrs = {
|
|
|
|
'id': 'meter-label-rule-id-' + uuid.uuid4().hex,
|
|
|
|
'direction': 'ingress',
|
|
|
|
'excluded': False,
|
|
|
|
'metering_label_id': 'meter-label-id-' + uuid.uuid4().hex,
|
|
|
|
'remote_ip_prefix': '10.0.0.0/24',
|
2020-09-02 17:26:00 -03:00
|
|
|
'source_ip_prefix': '8.8.8.8/32',
|
|
|
|
'destination_ip_prefix': '10.0.0.0/24',
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2016-09-27 17:00:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
meter_rule_attrs.update(attrs)
|
|
|
|
|
|
|
|
meter_rule = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(meter_rule_attrs), loaded=True
|
|
|
|
)
|
2016-09-27 17:00:43 -05:00
|
|
|
|
|
|
|
return meter_rule
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_meter_rule(attrs=None, count=2):
|
|
|
|
"""Create multiple meter rules"""
|
|
|
|
|
|
|
|
meter_rules = []
|
|
|
|
for i in range(0, count):
|
2023-05-08 11:03:05 +01:00
|
|
|
meter_rules.append(FakeNetworkMeterRule.create_one_rule(attrs))
|
2016-09-27 17:00:43 -05:00
|
|
|
return meter_rules
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_meter_rule(meter_rule=None, count=2):
|
|
|
|
"""Get a list of meter rules"""
|
|
|
|
if meter_rule is None:
|
2023-05-08 11:03:05 +01:00
|
|
|
meter_rule = FakeNetworkMeterRule.create_meter_rule(count)
|
2016-09-27 17:00:43 -05:00
|
|
|
return mock.Mock(side_effect=meter_rule)
|
|
|
|
|
|
|
|
|
2016-02-12 13:31:15 +08:00
|
|
|
class FakeSubnetPool:
|
|
|
|
"""Fake one or more subnet pools."""
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-15 15:46:19 +08:00
|
|
|
def create_one_subnet_pool(attrs=None):
|
2016-02-12 13:31:15 +08:00
|
|
|
"""Create a fake subnet pool.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object faking the subnet pool
|
|
|
|
"""
|
2016-04-15 15:46:19 +08:00
|
|
|
attrs = attrs or {}
|
|
|
|
|
2016-02-12 13:31:15 +08:00
|
|
|
# Set default attributes.
|
|
|
|
subnet_pool_attrs = {
|
|
|
|
'id': 'subnet-pool-id-' + uuid.uuid4().hex,
|
|
|
|
'name': 'subnet-pool-name-' + uuid.uuid4().hex,
|
2016-02-13 09:49:46 +08:00
|
|
|
'prefixes': ['10.0.0.0/24', '10.1.0.0/24'],
|
2016-03-07 20:48:03 +08:00
|
|
|
'default_prefixlen': '8',
|
2016-02-13 09:49:46 +08:00
|
|
|
'address_scope_id': 'address-scope-id-' + uuid.uuid4().hex,
|
2022-01-14 18:51:56 +01:00
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
2016-02-13 10:13:14 +08:00
|
|
|
'is_default': False,
|
|
|
|
'shared': False,
|
2016-03-07 20:48:03 +08:00
|
|
|
'max_prefixlen': '32',
|
|
|
|
'min_prefixlen': '8',
|
2016-02-13 10:13:14 +08:00
|
|
|
'default_quota': None,
|
2016-03-07 20:48:03 +08:00
|
|
|
'ip_version': '4',
|
2016-08-18 16:50:52 +07:00
|
|
|
'description': 'subnet-pool-description-' + uuid.uuid4().hex,
|
2017-04-29 00:32:32 +00:00
|
|
|
'tags': [],
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2016-02-12 13:31:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
subnet_pool_attrs.update(attrs)
|
|
|
|
|
|
|
|
subnet_pool = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(subnet_pool_attrs), loaded=True
|
2016-02-12 13:31:15 +08:00
|
|
|
)
|
|
|
|
|
2016-02-20 16:39:06 +08:00
|
|
|
# Set attributes with special mapping in OpenStack SDK.
|
2023-05-08 11:03:05 +01:00
|
|
|
subnet_pool.default_prefix_length = subnet_pool_attrs[
|
|
|
|
'default_prefixlen'
|
|
|
|
]
|
2016-10-05 08:09:16 -05:00
|
|
|
subnet_pool.is_shared = subnet_pool_attrs['shared']
|
|
|
|
subnet_pool.maximum_prefix_length = subnet_pool_attrs['max_prefixlen']
|
|
|
|
subnet_pool.minimum_prefix_length = subnet_pool_attrs['min_prefixlen']
|
2016-02-20 16:39:06 +08:00
|
|
|
|
2016-02-12 13:31:15 +08:00
|
|
|
return subnet_pool
|
|
|
|
|
|
|
|
@staticmethod
|
2016-04-15 15:46:19 +08:00
|
|
|
def create_subnet_pools(attrs=None, count=2):
|
2016-02-12 13:31:15 +08:00
|
|
|
"""Create multiple fake subnet pools.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of subnet pools to fake
|
|
|
|
:return:
|
|
|
|
A list of FakeResource objects faking the subnet pools
|
|
|
|
"""
|
|
|
|
subnet_pools = []
|
|
|
|
for i in range(0, count):
|
2023-05-08 11:03:05 +01:00
|
|
|
subnet_pools.append(FakeSubnetPool.create_one_subnet_pool(attrs))
|
2016-02-12 13:31:15 +08:00
|
|
|
|
|
|
|
return subnet_pools
|
2016-06-16 13:09:27 +08:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_subnet_pools(subnet_pools=None, count=2):
|
2016-09-27 09:52:41 +07:00
|
|
|
"""Get an iterable Mock object with a list of faked subnet pools.
|
2016-06-16 13:09:27 +08:00
|
|
|
|
|
|
|
If subnet_pools list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
2017-05-30 16:37:01 +07:00
|
|
|
:param List subnet_pools:
|
2016-06-16 13:09:27 +08:00
|
|
|
A list of FakeResource objects faking subnet pools
|
|
|
|
:param int count:
|
|
|
|
The number of subnet pools to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
subnet pools
|
|
|
|
"""
|
|
|
|
if subnet_pools is None:
|
|
|
|
subnet_pools = FakeSubnetPool.create_subnet_pools(count)
|
2016-09-14 13:27:31 +08:00
|
|
|
return mock.Mock(side_effect=subnet_pools)
|
2016-10-03 18:39:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
class FakeNetworkServiceProvider:
|
|
|
|
"""Fake Network Service Providers"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_one_network_service_provider(attrs=None):
|
|
|
|
"""Create service provider"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
service_provider = {
|
|
|
|
'name': 'provider-name-' + uuid.uuid4().hex,
|
|
|
|
'service_type': 'service-type-' + uuid.uuid4().hex,
|
|
|
|
'default': False,
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2016-10-03 18:39:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
service_provider.update(attrs)
|
|
|
|
|
|
|
|
provider = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(service_provider), loaded=True
|
|
|
|
)
|
2016-10-03 18:39:00 -05:00
|
|
|
provider.is_default = service_provider['default']
|
|
|
|
|
|
|
|
return provider
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_network_service_providers(attrs=None, count=2):
|
|
|
|
"""Create multiple service providers"""
|
|
|
|
|
|
|
|
service_providers = []
|
|
|
|
for i in range(0, count):
|
2023-05-08 11:03:05 +01:00
|
|
|
service_providers.append(
|
|
|
|
FakeNetworkServiceProvider.create_one_network_service_provider(
|
|
|
|
attrs
|
|
|
|
)
|
|
|
|
)
|
2016-10-03 18:39:00 -05:00
|
|
|
return service_providers
|
2016-09-29 15:32:51 -05:00
|
|
|
|
|
|
|
|
|
|
|
class FakeQuota:
|
|
|
|
"""Fake quota"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_one_net_quota(attrs=None):
|
|
|
|
"""Create one quota"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
quota_attrs = {
|
|
|
|
'floating_ips': 20,
|
|
|
|
'networks': 25,
|
|
|
|
'ports': 11,
|
|
|
|
'rbac_policies': 15,
|
|
|
|
'routers': 40,
|
|
|
|
'security_groups': 10,
|
|
|
|
'security_group_rules': 100,
|
|
|
|
'subnets': 20,
|
2023-05-08 11:03:05 +01:00
|
|
|
'subnet_pools': 30,
|
|
|
|
}
|
2016-09-29 15:32:51 -05:00
|
|
|
|
|
|
|
quota_attrs.update(attrs)
|
|
|
|
|
|
|
|
quota = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(quota_attrs), loaded=True
|
|
|
|
)
|
2016-09-29 15:32:51 -05:00
|
|
|
return quota
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_one_default_net_quota(attrs=None):
|
|
|
|
"""Create one quota"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
quota_attrs = {
|
|
|
|
'floatingip': 30,
|
|
|
|
'network': 20,
|
|
|
|
'port': 10,
|
|
|
|
'rbac_policy': 25,
|
|
|
|
'router': 30,
|
|
|
|
'security_group': 30,
|
|
|
|
'security_group_rule': 200,
|
|
|
|
'subnet': 10,
|
2023-05-08 11:03:05 +01:00
|
|
|
'subnetpool': 20,
|
|
|
|
}
|
2016-09-29 15:32:51 -05:00
|
|
|
|
|
|
|
quota_attrs.update(attrs)
|
|
|
|
|
|
|
|
quota = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(quota_attrs), loaded=True
|
|
|
|
)
|
2016-09-29 15:32:51 -05:00
|
|
|
return quota
|
2018-10-19 12:46:21 +03:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_one_net_detailed_quota(attrs=None):
|
|
|
|
"""Create one quota"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
quota_attrs = {
|
|
|
|
'floating_ips': {'used': 0, 'reserved': 0, 'limit': 20},
|
|
|
|
'networks': {'used': 0, 'reserved': 0, 'limit': 25},
|
|
|
|
'ports': {'used': 0, 'reserved': 0, 'limit': 11},
|
|
|
|
'rbac_policies': {'used': 0, 'reserved': 0, 'limit': 15},
|
|
|
|
'routers': {'used': 0, 'reserved': 0, 'limit': 40},
|
|
|
|
'security_groups': {'used': 0, 'reserved': 0, 'limit': 10},
|
|
|
|
'security_group_rules': {'used': 0, 'reserved': 0, 'limit': 100},
|
|
|
|
'subnets': {'used': 0, 'reserved': 0, 'limit': 20},
|
2023-05-08 11:03:05 +01:00
|
|
|
'subnet_pools': {'used': 0, 'reserved': 0, 'limit': 30},
|
|
|
|
}
|
2018-10-19 12:46:21 +03:00
|
|
|
|
|
|
|
quota_attrs.update(attrs)
|
|
|
|
|
|
|
|
quota = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(quota_attrs), loaded=True
|
|
|
|
)
|
2018-10-19 12:46:21 +03:00
|
|
|
return quota
|
2018-09-12 06:18:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
class FakeFloatingIPPortForwarding:
|
2023-05-08 11:03:05 +01:00
|
|
|
"""Fake one or more Port forwarding"""
|
2018-09-12 06:18:04 +08:00
|
|
|
|
|
|
|
@staticmethod
|
2019-08-31 20:10:47 -03:00
|
|
|
def create_one_port_forwarding(attrs=None, use_range=False):
|
2018-09-12 06:18:04 +08:00
|
|
|
"""Create a fake Port Forwarding.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
2019-08-31 20:10:47 -03:00
|
|
|
:param Boolean use_range:
|
|
|
|
A boolean which defines if we will use ranges or not
|
2018-09-12 06:18:04 +08:00
|
|
|
:return:
|
|
|
|
A FakeResource object with name, id, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
floatingip_id = (
|
2020-05-14 13:53:38 -05:00
|
|
|
attrs.get('floatingip_id') or 'floating-ip-id-' + uuid.uuid4().hex
|
2018-09-12 06:18:04 +08:00
|
|
|
)
|
|
|
|
# Set default attributes.
|
|
|
|
port_forwarding_attrs = {
|
|
|
|
'id': uuid.uuid4().hex,
|
|
|
|
'floatingip_id': floatingip_id,
|
|
|
|
'internal_port_id': 'internal-port-id-' + uuid.uuid4().hex,
|
|
|
|
'internal_ip_address': '192.168.1.2',
|
|
|
|
'protocol': 'tcp',
|
2020-03-23 15:15:59 -03:00
|
|
|
'description': 'some description',
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2018-09-12 06:18:04 +08:00
|
|
|
}
|
|
|
|
|
2019-08-31 20:10:47 -03:00
|
|
|
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'] = ''
|
|
|
|
|
2018-09-12 06:18:04 +08:00
|
|
|
# Overwrite default attributes.
|
|
|
|
port_forwarding_attrs.update(attrs)
|
|
|
|
|
|
|
|
port_forwarding = fakes.FakeResource(
|
2023-05-08 11:03:05 +01:00
|
|
|
info=copy.deepcopy(port_forwarding_attrs), loaded=True
|
2018-09-12 06:18:04 +08:00
|
|
|
)
|
|
|
|
return port_forwarding
|
|
|
|
|
|
|
|
@staticmethod
|
2019-08-31 20:10:47 -03:00
|
|
|
def create_port_forwardings(attrs=None, count=2, use_range=False):
|
2018-09-12 06:18:04 +08:00
|
|
|
"""Create multiple fake Port Forwarding.
|
|
|
|
|
2023-05-08 11:03:05 +01:00
|
|
|
: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
|
|
|
|
"""
|
2018-09-12 06:18:04 +08:00
|
|
|
port_forwardings = []
|
|
|
|
for i in range(0, count):
|
|
|
|
port_forwardings.append(
|
2019-08-31 20:10:47 -03:00
|
|
|
FakeFloatingIPPortForwarding.create_one_port_forwarding(
|
2023-05-08 11:03:05 +01:00
|
|
|
attrs, use_range=use_range
|
|
|
|
)
|
2018-09-12 06:18:04 +08:00
|
|
|
)
|
|
|
|
return port_forwardings
|
|
|
|
|
|
|
|
@staticmethod
|
2019-08-31 20:10:47 -03:00
|
|
|
def get_port_forwardings(port_forwardings=None, count=2, use_range=False):
|
2018-09-12 06:18:04 +08:00
|
|
|
"""Get a list of faked Port Forwardings.
|
|
|
|
|
|
|
|
If port forwardings list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List port forwardings:
|
|
|
|
A list of FakeResource objects faking port forwardings
|
|
|
|
:param int count:
|
|
|
|
The number of Port Forwardings to fake
|
2019-08-31 20:10:47 -03:00
|
|
|
:param Boolean use_range:
|
|
|
|
A boolean which defines if we will use ranges or not
|
2018-09-12 06:18:04 +08:00
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
Port Forwardings
|
|
|
|
"""
|
|
|
|
if port_forwardings is None:
|
|
|
|
port_forwardings = (
|
2019-08-31 20:10:47 -03:00
|
|
|
FakeFloatingIPPortForwarding.create_port_forwardings(
|
2023-05-08 11:03:05 +01:00
|
|
|
count, use_range=use_range
|
|
|
|
)
|
2018-09-12 06:18:04 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
return mock.Mock(side_effect=port_forwardings)
|
2021-04-07 23:40:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
class FakeL3ConntrackHelper:
|
2023-05-08 11:03:05 +01:00
|
|
|
"""Fake one or more L3 conntrack helper"""
|
2021-04-07 23:40:16 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_one_l3_conntrack_helper(attrs=None):
|
|
|
|
"""Create a fake L3 conntrack helper.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object with protocol, port, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
2023-05-08 11:03:05 +01:00
|
|
|
router_id = attrs.get('router_id') or 'router-id-' + uuid.uuid4().hex
|
2021-04-07 23:40:16 +02:00
|
|
|
# Set default attributes.
|
|
|
|
ct_attrs = {
|
|
|
|
'id': uuid.uuid4().hex,
|
|
|
|
'router_id': router_id,
|
|
|
|
'helper': 'tftp',
|
|
|
|
'protocol': 'tcp',
|
|
|
|
'port': randint(1, 65535),
|
2021-12-16 16:21:58 +01:00
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
2021-04-07 23:40:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
ct_attrs.update(attrs)
|
|
|
|
|
2023-05-08 11:03:05 +01:00
|
|
|
ct = fakes.FakeResource(info=copy.deepcopy(ct_attrs), loaded=True)
|
2021-04-07 23:40:16 +02:00
|
|
|
return ct
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create_l3_conntrack_helpers(attrs=None, count=2):
|
|
|
|
"""Create multiple fake L3 Conntrack helpers.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of L3 Conntrack helper rule to fake
|
|
|
|
:return:
|
|
|
|
A list of FakeResource objects faking the Conntrack helpers
|
|
|
|
"""
|
|
|
|
ct_helpers = []
|
|
|
|
for i in range(0, count):
|
|
|
|
ct_helpers.append(
|
|
|
|
FakeL3ConntrackHelper.create_one_l3_conntrack_helper(attrs)
|
|
|
|
)
|
|
|
|
return ct_helpers
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_l3_conntrack_helpers(ct_helpers=None, count=2):
|
|
|
|
"""Get a list of faked L3 Conntrack helpers.
|
|
|
|
|
|
|
|
If ct_helpers list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List ct_helpers:
|
|
|
|
A list of FakeResource objects faking conntrack helpers
|
|
|
|
:param int count:
|
|
|
|
The number of L3 conntrack helpers to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
L3 conntrack helpers
|
|
|
|
"""
|
|
|
|
if ct_helpers is None:
|
2023-05-08 11:03:05 +01:00
|
|
|
ct_helpers = FakeL3ConntrackHelper.create_l3_conntrack_helpers(
|
|
|
|
count
|
2021-04-07 23:40:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
return mock.Mock(side_effect=ct_helpers)
|
2021-08-23 14:41:47 +03:00
|
|
|
|
|
|
|
|
2022-02-18 15:01:12 +03:00
|
|
|
def create_one_address_group(attrs=None):
|
|
|
|
"""Create a fake address group.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
An AddressGroup object with name, id, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
address_group_attrs = {
|
|
|
|
'name': 'address-group-name-' + uuid.uuid4().hex,
|
|
|
|
'description': 'address-group-description-' + uuid.uuid4().hex,
|
|
|
|
'id': 'address-group-id-' + uuid.uuid4().hex,
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
'addresses': ['10.0.0.1/32'],
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
address_group_attrs.update(attrs)
|
|
|
|
|
|
|
|
address_group = _address_group.AddressGroup(**address_group_attrs)
|
|
|
|
|
|
|
|
return address_group
|
|
|
|
|
|
|
|
|
|
|
|
def create_address_groups(attrs=None, count=2):
|
|
|
|
"""Create multiple fake address groups.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of address groups to fake
|
|
|
|
:return:
|
|
|
|
A list of AddressGroup objects faking the address groups
|
|
|
|
"""
|
|
|
|
address_groups = []
|
|
|
|
for i in range(0, count):
|
|
|
|
address_groups.append(create_one_address_group(attrs))
|
|
|
|
|
|
|
|
return address_groups
|
|
|
|
|
|
|
|
|
|
|
|
def get_address_groups(address_groups=None, count=2):
|
|
|
|
"""Get an iterable Mock object with a list of faked address groups.
|
|
|
|
|
|
|
|
If address groups list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List address_groups:
|
|
|
|
A list of FakeResource objects faking address groups
|
|
|
|
:param int count:
|
|
|
|
The number of address groups to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
AddressGroup objects
|
|
|
|
"""
|
|
|
|
if address_groups is None:
|
|
|
|
address_groups = create_address_groups(count)
|
|
|
|
return mock.Mock(side_effect=address_groups)
|
|
|
|
|
|
|
|
|
|
|
|
def create_one_address_scope(attrs=None):
|
|
|
|
"""Create a fake address scope.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
An AddressScope object with name, id, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
address_scope_attrs = {
|
|
|
|
'name': 'address-scope-name-' + uuid.uuid4().hex,
|
|
|
|
'id': 'address-scope-id-' + uuid.uuid4().hex,
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
'shared': False,
|
|
|
|
'ip_version': 4,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
address_scope_attrs.update(attrs)
|
|
|
|
|
|
|
|
address_scope = _address_scope.AddressScope(**address_scope_attrs)
|
|
|
|
|
|
|
|
# Set attributes with special mapping in OpenStack SDK.
|
|
|
|
address_scope.is_shared = address_scope_attrs['shared']
|
|
|
|
|
|
|
|
return address_scope
|
|
|
|
|
|
|
|
|
|
|
|
def create_address_scopes(attrs=None, count=2):
|
|
|
|
"""Create multiple fake address scopes.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of address scopes to fake
|
|
|
|
:return:
|
|
|
|
A list of AddressScope objects faking the address scopes
|
|
|
|
"""
|
|
|
|
address_scopes = []
|
|
|
|
for i in range(0, count):
|
|
|
|
address_scopes.append(create_one_address_scope(attrs))
|
|
|
|
|
|
|
|
return address_scopes
|
|
|
|
|
|
|
|
|
|
|
|
def get_address_scopes(address_scopes=None, count=2):
|
|
|
|
"""Get an iterable Mock object with a list of faked address scopes.
|
|
|
|
|
|
|
|
If address scopes list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List address_scopes:
|
|
|
|
A list of FakeResource objects faking address scopes
|
|
|
|
:param int count:
|
|
|
|
The number of address scopes to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
AddressScope objects
|
|
|
|
"""
|
|
|
|
if address_scopes is None:
|
|
|
|
address_scopes = create_address_scopes(count)
|
|
|
|
return mock.Mock(side_effect=address_scopes)
|
|
|
|
|
|
|
|
|
|
|
|
def create_one_topology(attrs=None):
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
auto_allocated_topology_attrs = {
|
|
|
|
'id': 'network-id-' + uuid.uuid4().hex,
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
}
|
|
|
|
|
|
|
|
auto_allocated_topology_attrs.update(attrs)
|
|
|
|
|
|
|
|
auto_allocated_topology = allocated_topology.AutoAllocatedTopology(
|
|
|
|
**auto_allocated_topology_attrs
|
|
|
|
)
|
|
|
|
|
|
|
|
return auto_allocated_topology
|
|
|
|
|
|
|
|
|
|
|
|
def create_one_availability_zone(attrs=None):
|
|
|
|
"""Create a fake AZ.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
An AvailabilityZone object with name, state, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
availability_zone = {
|
|
|
|
'name': uuid.uuid4().hex,
|
|
|
|
'state': 'available',
|
|
|
|
'resource': 'network',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
availability_zone.update(attrs)
|
|
|
|
|
|
|
|
availability_zone = _availability_zone.AvailabilityZone(
|
|
|
|
**availability_zone
|
|
|
|
)
|
|
|
|
return availability_zone
|
|
|
|
|
|
|
|
|
|
|
|
def create_availability_zones(attrs=None, count=2):
|
|
|
|
"""Create multiple fake AZs.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of AZs to fake
|
|
|
|
:return:
|
|
|
|
A list of AvailabilityZone objects faking the AZs
|
|
|
|
"""
|
|
|
|
availability_zones = []
|
|
|
|
for i in range(0, count):
|
|
|
|
availability_zone = create_one_availability_zone(attrs)
|
|
|
|
availability_zones.append(availability_zone)
|
|
|
|
|
|
|
|
return availability_zones
|
|
|
|
|
|
|
|
|
2022-03-15 10:53:49 +03:00
|
|
|
def create_one_ip_availability(attrs=None):
|
|
|
|
"""Create a fake list with ip availability stats of a network.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A NetworkIPAvailability object with network_name, network_id, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
network_ip_attrs = {
|
|
|
|
'network_id': 'network-id-' + uuid.uuid4().hex,
|
|
|
|
'network_name': 'network-name-' + uuid.uuid4().hex,
|
|
|
|
'project_id': '',
|
|
|
|
'subnet_ip_availability': [],
|
|
|
|
'total_ips': 254,
|
|
|
|
'used_ips': 6,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
network_ip_attrs.update(attrs)
|
|
|
|
|
|
|
|
network_ip_availability = _ip_availability.NetworkIPAvailability(
|
2023-05-08 11:03:05 +01:00
|
|
|
**network_ip_attrs
|
|
|
|
)
|
2022-03-15 10:53:49 +03:00
|
|
|
|
|
|
|
return network_ip_availability
|
|
|
|
|
|
|
|
|
|
|
|
def create_ip_availability(count=2):
|
|
|
|
"""Create fake list of ip availability stats of multiple networks.
|
|
|
|
|
|
|
|
:param int count:
|
|
|
|
The number of networks to fake
|
|
|
|
:return:
|
|
|
|
A list of NetworkIPAvailability objects faking
|
|
|
|
network ip availability stats
|
|
|
|
"""
|
|
|
|
network_ip_availabilities = []
|
|
|
|
for i in range(0, count):
|
|
|
|
network_ip_availability = create_one_ip_availability()
|
|
|
|
network_ip_availabilities.append(network_ip_availability)
|
|
|
|
|
|
|
|
return network_ip_availabilities
|
|
|
|
|
|
|
|
|
|
|
|
def create_one_network(attrs=None):
|
|
|
|
"""Create a fake network.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
An Network object, with id, name, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
network_attrs = {
|
|
|
|
'created_at': '2021-11-29T10:10:23.000000',
|
|
|
|
'id': 'network-id-' + uuid.uuid4().hex,
|
|
|
|
'name': 'network-name-' + uuid.uuid4().hex,
|
|
|
|
'status': 'ACTIVE',
|
|
|
|
'description': 'network-description-' + uuid.uuid4().hex,
|
|
|
|
'dns_domain': 'example.org.',
|
|
|
|
'mtu': '1350',
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
'admin_state_up': True,
|
|
|
|
'shared': False,
|
|
|
|
'subnets': ['a', 'b'],
|
|
|
|
'segments': 'network-segment-' + uuid.uuid4().hex,
|
|
|
|
'provider:network_type': 'vlan',
|
|
|
|
'provider:physical_network': 'physnet1',
|
|
|
|
'provider:segmentation_id': "400",
|
|
|
|
'router:external': True,
|
|
|
|
'availability_zones': [],
|
|
|
|
'availability_zone_hints': [],
|
|
|
|
'is_default': False,
|
|
|
|
'is_vlan_transparent': True,
|
|
|
|
'port_security_enabled': True,
|
|
|
|
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
|
|
|
|
'ipv4_address_scope': 'ipv4' + uuid.uuid4().hex,
|
|
|
|
'ipv6_address_scope': 'ipv6' + uuid.uuid4().hex,
|
|
|
|
'tags': [],
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
'updated_at': '2021-11-29T10:10:25.000000',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
network_attrs.update(attrs)
|
|
|
|
|
|
|
|
network = _network.Network(**network_attrs)
|
|
|
|
|
|
|
|
return network
|
|
|
|
|
|
|
|
|
|
|
|
def create_networks(attrs=None, count=2):
|
|
|
|
"""Create multiple fake networks.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of networks to fake
|
|
|
|
:return:
|
|
|
|
A list of Network objects faking the networks
|
|
|
|
"""
|
|
|
|
networks = []
|
|
|
|
for i in range(0, count):
|
|
|
|
networks.append(create_one_network(attrs))
|
|
|
|
|
|
|
|
return networks
|
|
|
|
|
|
|
|
|
|
|
|
def get_networks(networks=None, count=2):
|
|
|
|
"""Get an iterable Mock object with a list of faked networks.
|
|
|
|
|
|
|
|
If networks list is provided, then initialize the Mock object with the
|
|
|
|
list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List networks:
|
|
|
|
A list of Network objects faking networks
|
|
|
|
:param int count:
|
|
|
|
The number of networks to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
networks
|
|
|
|
"""
|
|
|
|
if networks is None:
|
|
|
|
networks = create_networks(count)
|
|
|
|
return mock.Mock(side_effect=networks)
|
|
|
|
|
|
|
|
|
2022-03-16 12:14:08 +03:00
|
|
|
def create_one_network_flavor(attrs=None):
|
|
|
|
"""Create a fake network flavor.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A Flavor object faking the network flavor
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
fake_uuid = uuid.uuid4().hex
|
|
|
|
network_flavor_attrs = {
|
|
|
|
'description': 'network-flavor-description-' + fake_uuid,
|
|
|
|
'is_enabled': True,
|
|
|
|
'id': 'network-flavor-id-' + fake_uuid,
|
|
|
|
'name': 'network-flavor-name-' + fake_uuid,
|
|
|
|
'service_type': 'vpn',
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
network_flavor_attrs.update(attrs)
|
|
|
|
|
|
|
|
network_flavor = _flavor.Flavor(**network_flavor_attrs)
|
|
|
|
|
|
|
|
return network_flavor
|
|
|
|
|
|
|
|
|
|
|
|
def create_flavor(attrs=None, count=2):
|
|
|
|
"""Create multiple fake network flavors.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of network flavors to fake
|
|
|
|
:return:
|
|
|
|
A list of Flavor objects faking the network falvors
|
|
|
|
"""
|
|
|
|
network_flavors = []
|
|
|
|
for i in range(0, count):
|
|
|
|
network_flavors.append(create_one_network_flavor(attrs))
|
|
|
|
|
|
|
|
return network_flavors
|
|
|
|
|
|
|
|
|
|
|
|
def get_flavor(network_flavors=None, count=2):
|
|
|
|
"""Get a list of flavors."""
|
|
|
|
if network_flavors is None:
|
|
|
|
network_flavors = create_flavor(count)
|
|
|
|
return mock.Mock(side_effect=network_flavors)
|
|
|
|
|
|
|
|
|
|
|
|
def create_one_network_segment(attrs=None):
|
|
|
|
"""Create a fake network segment.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
An Segment object faking the network segment
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
fake_uuid = uuid.uuid4().hex
|
|
|
|
network_segment_attrs = {
|
|
|
|
'description': 'network-segment-description-' + fake_uuid,
|
|
|
|
'id': 'network-segment-id-' + fake_uuid,
|
|
|
|
'name': 'network-segment-name-' + fake_uuid,
|
|
|
|
'network_id': 'network-id-' + fake_uuid,
|
|
|
|
'network_type': 'vlan',
|
|
|
|
'physical_network': 'physical-network-name-' + fake_uuid,
|
|
|
|
'segmentation_id': 1024,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
network_segment_attrs.update(attrs)
|
|
|
|
|
|
|
|
network_segment = _segment.Segment(**network_segment_attrs)
|
|
|
|
|
|
|
|
return network_segment
|
|
|
|
|
|
|
|
|
|
|
|
def create_network_segments(attrs=None, count=2):
|
|
|
|
"""Create multiple fake network segments.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of network segments to fake
|
|
|
|
:return:
|
|
|
|
A list of Segment objects faking the network segments
|
|
|
|
"""
|
|
|
|
network_segments = []
|
|
|
|
for i in range(0, count):
|
|
|
|
network_segments.append(create_one_network_segment(attrs))
|
|
|
|
return network_segments
|
|
|
|
|
|
|
|
|
|
|
|
def create_one_network_segment_range(attrs=None):
|
|
|
|
"""Create a fake network segment range.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A NetworkSegmentRange object faking the network segment range
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
fake_uuid = uuid.uuid4().hex
|
|
|
|
network_segment_range_attrs = {
|
|
|
|
'id': 'network-segment-range-id-' + fake_uuid,
|
|
|
|
'name': 'network-segment-name-' + fake_uuid,
|
|
|
|
'default': False,
|
|
|
|
'shared': False,
|
|
|
|
'project_id': 'project-id-' + fake_uuid,
|
|
|
|
'network_type': 'vlan',
|
|
|
|
'physical_network': 'physical-network-name-' + fake_uuid,
|
|
|
|
'minimum': 100,
|
|
|
|
'maximum': 106,
|
2023-05-08 11:03:05 +01:00
|
|
|
'used': {
|
|
|
|
104: '3312e4ba67864b2eb53f3f41432f8efc',
|
|
|
|
106: '3312e4ba67864b2eb53f3f41432f8efc',
|
|
|
|
},
|
2022-03-16 12:14:08 +03:00
|
|
|
'available': [100, 101, 102, 103, 105],
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
network_segment_range_attrs.update(attrs)
|
|
|
|
|
2023-05-08 11:03:05 +01:00
|
|
|
network_segment_range = _segment_range.NetworkSegmentRange(
|
|
|
|
**network_segment_range_attrs
|
|
|
|
)
|
2022-03-16 12:14:08 +03:00
|
|
|
|
|
|
|
return network_segment_range
|
|
|
|
|
|
|
|
|
|
|
|
def create_network_segment_ranges(attrs=None, count=2):
|
|
|
|
"""Create multiple fake network segment ranges.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of network segment ranges to fake
|
|
|
|
:return:
|
|
|
|
A list of NetworkSegmentRange objects faking
|
|
|
|
the network segment ranges
|
|
|
|
"""
|
|
|
|
network_segment_ranges = []
|
|
|
|
for i in range(0, count):
|
|
|
|
network_segment_ranges.append(create_one_network_segment_range(attrs))
|
|
|
|
return network_segment_ranges
|
|
|
|
|
|
|
|
|
2022-03-16 15:29:47 +03:00
|
|
|
def create_one_port(attrs=None):
|
|
|
|
"""Create a fake port.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A Port object, with id, name, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
port_attrs = {
|
|
|
|
'is_admin_state_up': True,
|
|
|
|
'allowed_address_pairs': [{}],
|
|
|
|
'binding:host_id': 'binding-host-id-' + uuid.uuid4().hex,
|
|
|
|
'binding:profile': {},
|
|
|
|
'binding:vif_details': {},
|
|
|
|
'binding:vif_type': 'ovs',
|
|
|
|
'binding:vnic_type': 'normal',
|
|
|
|
'data_plane_status': None,
|
|
|
|
'description': 'description-' + uuid.uuid4().hex,
|
|
|
|
'device_id': 'device-id-' + uuid.uuid4().hex,
|
|
|
|
'device_owner': 'compute:nova',
|
|
|
|
'device_profile': 'cyborg_device_profile_1',
|
|
|
|
'dns_assignment': [{}],
|
|
|
|
'dns_domain': 'dns-domain-' + uuid.uuid4().hex,
|
|
|
|
'dns_name': 'dns-name-' + uuid.uuid4().hex,
|
|
|
|
'extra_dhcp_opts': [{}],
|
2023-05-08 11:03:05 +01:00
|
|
|
'fixed_ips': [
|
|
|
|
{
|
|
|
|
'ip_address': '10.0.0.3',
|
|
|
|
'subnet_id': 'subnet-id-' + uuid.uuid4().hex,
|
|
|
|
}
|
|
|
|
],
|
2023-08-23 16:18:04 +00:00
|
|
|
'hardware_offload_type': None,
|
2023-04-25 14:22:07 +02:00
|
|
|
'hints': {},
|
2022-03-16 15:29:47 +03:00
|
|
|
'id': 'port-id-' + uuid.uuid4().hex,
|
|
|
|
'mac_address': 'fa:16:3e:a9:4e:72',
|
|
|
|
'name': 'port-name-' + uuid.uuid4().hex,
|
|
|
|
'network_id': 'network-id-' + uuid.uuid4().hex,
|
|
|
|
'numa_affinity_policy': 'required',
|
|
|
|
'is_port_security_enabled': True,
|
|
|
|
'security_group_ids': [],
|
|
|
|
'status': 'ACTIVE',
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
'qos_network_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
|
|
|
|
'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
|
|
|
|
'tags': [],
|
|
|
|
'propagate_uplink_status': False,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
port_attrs.update(attrs)
|
|
|
|
|
|
|
|
port = _port.Port(**port_attrs)
|
|
|
|
|
|
|
|
return port
|
|
|
|
|
|
|
|
|
|
|
|
def create_ports(attrs=None, count=2):
|
|
|
|
"""Create multiple fake ports.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of ports to fake
|
|
|
|
:return:
|
|
|
|
A list of Port objects faking the ports
|
|
|
|
"""
|
|
|
|
ports = []
|
|
|
|
for i in range(0, count):
|
|
|
|
ports.append(create_one_port(attrs))
|
|
|
|
|
|
|
|
return ports
|
|
|
|
|
|
|
|
|
|
|
|
def get_ports(ports=None, count=2):
|
|
|
|
"""Get an iterable Mock object with a list of faked ports.
|
|
|
|
|
|
|
|
If ports list is provided, then initialize the Mock object with the
|
|
|
|
list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List ports:
|
|
|
|
A list of Port objects faking ports
|
|
|
|
:param int count:
|
|
|
|
The number of ports to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
ports
|
|
|
|
"""
|
|
|
|
if ports is None:
|
|
|
|
ports = create_ports(count)
|
|
|
|
return mock.Mock(side_effect=ports)
|
|
|
|
|
|
|
|
|
|
|
|
def create_one_network_agent(attrs=None):
|
|
|
|
"""Create a fake network agent
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
An Agent object, with id, agent_type, and so on.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes
|
|
|
|
agent_attrs = {
|
|
|
|
'id': 'agent-id-' + uuid.uuid4().hex,
|
|
|
|
'agent_type': 'agent-type-' + uuid.uuid4().hex,
|
|
|
|
'host': 'host-' + uuid.uuid4().hex,
|
|
|
|
'availability_zone': 'zone-' + uuid.uuid4().hex,
|
|
|
|
'alive': True,
|
|
|
|
'admin_state_up': True,
|
|
|
|
'binary': 'binary-' + uuid.uuid4().hex,
|
|
|
|
'configurations': {'subnet': 2, 'networks': 1},
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
agent_attrs.update(attrs)
|
|
|
|
agent = network_agent.Agent(**agent_attrs)
|
|
|
|
|
|
|
|
return agent
|
|
|
|
|
|
|
|
|
|
|
|
def create_network_agents(attrs=None, count=2):
|
|
|
|
"""Create multiple fake network agents.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of network agents to fake
|
|
|
|
:return:
|
|
|
|
A list of Agent objects faking the network agents
|
|
|
|
"""
|
|
|
|
agents = []
|
|
|
|
for i in range(0, count):
|
|
|
|
agents.append(create_one_network_agent(attrs))
|
|
|
|
|
|
|
|
return agents
|
|
|
|
|
|
|
|
|
|
|
|
def get_network_agents(agents=None, count=2):
|
|
|
|
"""Get an iterable Mock object with a list of faked network agents.
|
|
|
|
|
|
|
|
If network agents list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List agents:
|
|
|
|
A list of Agent objects faking network agents
|
|
|
|
:param int count:
|
|
|
|
The number of network agents to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
network agents
|
|
|
|
"""
|
|
|
|
if agents is None:
|
|
|
|
agents = create_network_agents(count)
|
|
|
|
return mock.Mock(side_effect=agents)
|
|
|
|
|
|
|
|
|
|
|
|
def create_one_network_rbac(attrs=None):
|
|
|
|
"""Create a fake network rbac
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A RBACPolicy object, with id, action, target_tenant,
|
|
|
|
project_id, type
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes
|
|
|
|
rbac_attrs = {
|
|
|
|
'id': 'rbac-id-' + uuid.uuid4().hex,
|
|
|
|
'object_type': 'network',
|
|
|
|
'object_id': 'object-id-' + uuid.uuid4().hex,
|
|
|
|
'action': 'access_as_shared',
|
|
|
|
'target_tenant': 'target-tenant-' + uuid.uuid4().hex,
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
|
|
|
rbac_attrs.update(attrs)
|
|
|
|
rbac = network_rbac.RBACPolicy(**rbac_attrs)
|
|
|
|
|
|
|
|
return rbac
|
|
|
|
|
|
|
|
|
|
|
|
def create_network_rbacs(attrs=None, count=2):
|
|
|
|
"""Create multiple fake network rbac policies.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of rbac policies to fake
|
|
|
|
:return:
|
|
|
|
A list of RBACPolicy objects faking the rbac policies
|
|
|
|
"""
|
|
|
|
rbac_policies = []
|
|
|
|
for i in range(0, count):
|
|
|
|
rbac_policies.append(create_one_network_rbac(attrs))
|
|
|
|
|
|
|
|
return rbac_policies
|
|
|
|
|
|
|
|
|
|
|
|
def get_network_rbacs(rbac_policies=None, count=2):
|
|
|
|
"""Get an iterable Mock object with a list of faked rbac policies.
|
|
|
|
|
|
|
|
If rbac policies list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List rbac_policies:
|
|
|
|
A list of RBACPolicy objects faking rbac policies
|
|
|
|
:param int count:
|
|
|
|
The number of rbac policies to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
rbac policies
|
|
|
|
"""
|
|
|
|
if rbac_policies is None:
|
|
|
|
rbac_policies = create_network_rbacs(count)
|
|
|
|
return mock.Mock(side_effect=rbac_policies)
|
|
|
|
|
|
|
|
|
2024-07-09 14:37:07 +01:00
|
|
|
def create_one_security_group(attrs=None):
|
|
|
|
"""Create a security group."""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
security_group_attrs = {
|
|
|
|
'name': 'security-group-name-' + uuid.uuid4().hex,
|
|
|
|
'id': 'security-group-id-' + uuid.uuid4().hex,
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
'description': 'security-group-description-' + uuid.uuid4().hex,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
|
|
|
security_group_attrs.update(attrs)
|
|
|
|
|
|
|
|
security_group = _security_group.SecurityGroup(**security_group_attrs)
|
|
|
|
|
|
|
|
return security_group
|
|
|
|
|
|
|
|
|
|
|
|
def create_security_groups(attrs=None, count=2):
|
|
|
|
"""Create multiple fake security groups.
|
|
|
|
|
|
|
|
:param dict attrs: A dictionary with all attributes
|
|
|
|
:param int count: The number of security groups to fake
|
|
|
|
:return: A list of fake SecurityGroup objects
|
|
|
|
"""
|
|
|
|
security_groups = []
|
|
|
|
for i in range(0, count):
|
|
|
|
security_groups.append(create_one_security_group(attrs))
|
|
|
|
|
|
|
|
return security_groups
|
|
|
|
|
|
|
|
|
2022-03-16 15:29:47 +03:00
|
|
|
def create_one_service_profile(attrs=None):
|
2024-07-09 14:37:07 +01:00
|
|
|
"""Create service profile."""
|
2022-03-16 15:29:47 +03:00
|
|
|
attrs = attrs or {}
|
|
|
|
|
2024-07-09 14:37:07 +01:00
|
|
|
service_profile_attrs = {
|
2022-03-16 15:29:47 +03:00
|
|
|
'id': 'flavor-profile-id' + uuid.uuid4().hex,
|
|
|
|
'description': 'flavor-profile-description-' + uuid.uuid4().hex,
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
'driver': 'driver-' + uuid.uuid4().hex,
|
|
|
|
'metainfo': 'metainfo-' + uuid.uuid4().hex,
|
|
|
|
'enabled': True,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
2024-07-09 14:37:07 +01:00
|
|
|
service_profile_attrs.update(attrs)
|
2022-03-16 15:29:47 +03:00
|
|
|
|
2024-07-09 14:37:07 +01:00
|
|
|
flavor_profile = _service_profile.ServiceProfile(**service_profile_attrs)
|
2022-03-16 15:29:47 +03:00
|
|
|
|
|
|
|
return flavor_profile
|
|
|
|
|
|
|
|
|
|
|
|
def create_service_profile(attrs=None, count=2):
|
2024-07-09 14:37:07 +01:00
|
|
|
"""Create multiple service profiles."""
|
2022-03-16 15:29:47 +03:00
|
|
|
|
2024-07-09 14:37:07 +01:00
|
|
|
service_profiles = []
|
2022-03-16 15:29:47 +03:00
|
|
|
for i in range(0, count):
|
2024-07-09 14:37:07 +01:00
|
|
|
service_profiles.append(create_one_service_profile(attrs))
|
|
|
|
return service_profiles
|
2022-03-16 15:29:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
def get_service_profile(flavor_profile=None, count=2):
|
|
|
|
"""Get a list of flavor profiles."""
|
|
|
|
if flavor_profile is None:
|
|
|
|
flavor_profile = create_service_profile(count)
|
|
|
|
|
|
|
|
return mock.Mock(side_effect=flavor_profile)
|
|
|
|
|
|
|
|
|
2021-08-23 14:41:47 +03:00
|
|
|
def create_one_local_ip(attrs=None):
|
|
|
|
"""Create a fake local ip.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object with name, id, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
local_ip_attrs = {
|
|
|
|
'created_at': '2021-11-29T10:10:23.000000',
|
|
|
|
'name': 'local-ip-name-' + uuid.uuid4().hex,
|
|
|
|
'description': 'local-ip-description-' + uuid.uuid4().hex,
|
|
|
|
'id': 'local-ip-id-' + uuid.uuid4().hex,
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
'local_port_id': 'local_port_id-' + uuid.uuid4().hex,
|
|
|
|
'network_id': 'network_id-' + uuid.uuid4().hex,
|
|
|
|
'local_ip_address': '10.0.0.1',
|
|
|
|
'ip_mode': 'translate',
|
|
|
|
'revision_number': 'local-ip-revision-number-' + uuid.uuid4().hex,
|
|
|
|
'updated_at': '2021-11-29T10:10:25.000000',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
local_ip_attrs.update(attrs)
|
|
|
|
|
|
|
|
local_ip = _local_ip.LocalIP(**local_ip_attrs)
|
|
|
|
|
|
|
|
return local_ip
|
|
|
|
|
|
|
|
|
|
|
|
def create_local_ips(attrs=None, count=2):
|
|
|
|
"""Create multiple fake local ips.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of local ips to fake
|
|
|
|
:return:
|
|
|
|
A list of FakeResource objects faking the local ips
|
|
|
|
"""
|
|
|
|
local_ips = []
|
|
|
|
for i in range(0, count):
|
|
|
|
local_ips.append(create_one_local_ip(attrs))
|
|
|
|
|
|
|
|
return local_ips
|
|
|
|
|
|
|
|
|
|
|
|
def get_local_ips(local_ips=None, count=2):
|
|
|
|
"""Get an iterable Mock object with a list of faked local ips.
|
|
|
|
|
|
|
|
If local ip list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List local_ips:
|
|
|
|
A list of FakeResource objects faking local ips
|
|
|
|
:param int count:
|
|
|
|
The number of local ips to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
local ips
|
|
|
|
"""
|
|
|
|
if local_ips is None:
|
|
|
|
local_ips = create_local_ips(count)
|
|
|
|
return mock.Mock(side_effect=local_ips)
|
|
|
|
|
|
|
|
|
|
|
|
def create_one_local_ip_association(attrs=None):
|
|
|
|
"""Create a fake local ip association.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object with local_ip_id, local_ip_address, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
|
|
|
|
|
|
|
# Set default attributes.
|
|
|
|
local_ip_association_attrs = {
|
|
|
|
'local_ip_id': 'local-ip-id-' + uuid.uuid4().hex,
|
|
|
|
'local_ip_address': '172.24.4.228',
|
|
|
|
'fixed_port_id': 'fixed-port-id-' + uuid.uuid4().hex,
|
|
|
|
'fixed_ip': '10.0.0.5',
|
|
|
|
'host': 'host-' + uuid.uuid4().hex,
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
local_ip_association_attrs.update(attrs)
|
|
|
|
|
2023-05-08 11:03:05 +01:00
|
|
|
local_ip_association = _local_ip_association.LocalIPAssociation(
|
|
|
|
**local_ip_association_attrs
|
|
|
|
)
|
2021-08-23 14:41:47 +03:00
|
|
|
|
|
|
|
return local_ip_association
|
|
|
|
|
|
|
|
|
|
|
|
def create_local_ip_associations(attrs=None, count=2):
|
|
|
|
"""Create multiple fake local ip associations.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
2022-02-22 12:51:08 +03:00
|
|
|
The number of local ip associations to fake
|
2021-08-23 14:41:47 +03:00
|
|
|
:return:
|
|
|
|
A list of FakeResource objects faking the local ip associations
|
|
|
|
"""
|
|
|
|
local_ip_associations = []
|
|
|
|
for i in range(0, count):
|
|
|
|
local_ip_associations.append(create_one_local_ip_association(attrs))
|
|
|
|
|
|
|
|
return local_ip_associations
|
|
|
|
|
|
|
|
|
|
|
|
def get_local_ip_associations(local_ip_associations=None, count=2):
|
|
|
|
"""Get a list of faked local ip associations
|
|
|
|
|
|
|
|
If local ip association list is provided, then initialize
|
|
|
|
the Mock object with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List local_ip_associations:
|
|
|
|
A list of FakeResource objects faking local ip associations
|
|
|
|
:param int count:
|
|
|
|
The number of local ip associations to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
local ip associations
|
|
|
|
"""
|
|
|
|
if local_ip_associations is None:
|
|
|
|
local_ip_associations = create_local_ip_associations(count)
|
|
|
|
|
|
|
|
return mock.Mock(side_effect=local_ip_associations)
|
2020-08-31 11:39:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_one_ndp_proxy(attrs=None):
|
|
|
|
"""Create a fake NDP proxy.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:return:
|
|
|
|
A FakeResource object with router_id, port_id, etc.
|
|
|
|
"""
|
|
|
|
attrs = attrs or {}
|
2023-05-08 11:03:05 +01:00
|
|
|
router_id = attrs.get('router_id') or 'router-id-' + uuid.uuid4().hex
|
|
|
|
port_id = attrs.get('port_id') or 'port-id-' + uuid.uuid4().hex
|
2020-08-31 11:39:48 +00:00
|
|
|
# Set default attributes.
|
|
|
|
np_attrs = {
|
|
|
|
'id': uuid.uuid4().hex,
|
|
|
|
'name': 'ndp-proxy-name-' + uuid.uuid4().hex,
|
|
|
|
'router_id': router_id,
|
|
|
|
'port_id': port_id,
|
|
|
|
'ip_address': '2001::1:2',
|
|
|
|
'description': 'ndp-proxy-description-' + uuid.uuid4().hex,
|
|
|
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
|
|
|
'location': 'MUNCHMUNCHMUNCH',
|
|
|
|
}
|
|
|
|
|
|
|
|
# Overwrite default attributes.
|
|
|
|
np_attrs.update(attrs)
|
|
|
|
|
|
|
|
return _ndp_proxy.NDPProxy(**np_attrs)
|
|
|
|
|
|
|
|
|
|
|
|
def create_ndp_proxies(attrs=None, count=2):
|
|
|
|
"""Create multiple fake NDP proxies.
|
|
|
|
|
|
|
|
:param Dictionary attrs:
|
|
|
|
A dictionary with all attributes
|
|
|
|
:param int count:
|
|
|
|
The number of NDP proxxy to fake
|
|
|
|
:return:
|
|
|
|
A list of FakeResource objects faking the NDP proxies
|
|
|
|
"""
|
|
|
|
ndp_proxies = []
|
|
|
|
for i in range(0, count):
|
2023-05-08 11:03:05 +01:00
|
|
|
ndp_proxies.append(create_one_ndp_proxy(attrs))
|
2020-08-31 11:39:48 +00:00
|
|
|
return ndp_proxies
|
|
|
|
|
|
|
|
|
|
|
|
def get_ndp_proxies(ndp_proxies=None, count=2):
|
|
|
|
"""Get a list of faked NDP proxies.
|
|
|
|
|
|
|
|
If ndp_proxy list is provided, then initialize the Mock object
|
|
|
|
with the list. Otherwise create one.
|
|
|
|
|
|
|
|
:param List ndp_proxies:
|
|
|
|
A list of FakeResource objects faking ndp proxy
|
|
|
|
:param int count:
|
|
|
|
The number of ndp proxy to fake
|
|
|
|
:return:
|
|
|
|
An iterable Mock object with side_effect set to a list of faked
|
|
|
|
ndp proxy
|
|
|
|
"""
|
|
|
|
if ndp_proxies is None:
|
2023-05-08 11:03:05 +01:00
|
|
|
ndp_proxies = create_ndp_proxies(count)
|
2020-08-31 11:39:48 +00:00
|
|
|
return mock.Mock(side_effect=ndp_proxies)
|
2023-01-06 09:10:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
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',
|
2023-05-08 11:03:05 +01:00
|
|
|
'sub_ports': [
|
|
|
|
{
|
|
|
|
'port_id': 'subport-' + uuid.uuid4().hex,
|
|
|
|
'segmentation_type': 'vlan',
|
|
|
|
'segmentation_id': 100,
|
|
|
|
}
|
|
|
|
],
|
2023-01-06 09:10:00 +01:00
|
|
|
}
|
|
|
|
# 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)
|