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.py162
1 files changed, 89 insertions, 73 deletions
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index b931cb55..fe0422fa 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -14,6 +14,8 @@
import argparse
import copy
import mock
+from random import choice
+from random import randint
import uuid
from openstackclient.tests.unit import fakes
@@ -37,6 +39,15 @@ QUOTA = {
"l7policy": 5,
}
+RULE_TYPE_BANDWIDTH_LIMIT = 'bandwidth-limit'
+RULE_TYPE_DSCP_MARKING = 'dscp-marking'
+RULE_TYPE_MINIMUM_BANDWIDTH = 'minimum-bandwidth'
+VALID_QOS_RULES = [RULE_TYPE_BANDWIDTH_LIMIT,
+ RULE_TYPE_DSCP_MARKING,
+ RULE_TYPE_MINIMUM_BANDWIDTH]
+VALID_DSCP_MARKS = [0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32,
+ 34, 36, 38, 40, 46, 48, 56]
+
class FakeNetworkV2Client(object):
@@ -662,83 +673,90 @@ class FakeNetworkRBAC(object):
return mock.Mock(side_effect=rbac_policies)
-class FakeNetworkQosBandwidthLimitRule(object):
- """Fake one or more QoS bandwidth limit rules."""
+class FakeNetworkQosPolicy(object):
+ """Fake one or more QoS policies."""
@staticmethod
- def create_one_qos_bandwidth_limit_rule(attrs=None):
- """Create a fake QoS bandwidth limit rule.
+ def create_one_qos_policy(attrs=None):
+ """Create a fake QoS policy.
:param Dictionary attrs:
A dictionary with all attributes
:return:
- A FakeResource object with id, qos_policy_id, max_kbps and
- max_burst_kbps attributes.
+ A FakeResource object with name, id, etc.
"""
attrs = attrs or {}
+ 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)]
# Set default attributes.
- qos_bandwidth_limit_rule_attrs = {
- 'id': 'qos-bandwidth-limit-rule-id-' + uuid.uuid4().hex,
- 'qos_policy_id': 'qos-policy-id-' + uuid.uuid4().hex,
- 'max_kbps': 1500,
- 'max_burst_kbps': 1200,
+ qos_policy_attrs = {
+ 'name': 'qos-policy-name-' + uuid.uuid4().hex,
+ 'id': qos_id,
+ 'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ 'shared': False,
+ 'description': 'qos-policy-description-' + uuid.uuid4().hex,
+ 'rules': rules,
}
# Overwrite default attributes.
- qos_bandwidth_limit_rule_attrs.update(attrs)
+ qos_policy_attrs.update(attrs)
- qos_bandwidth_limit_rule = fakes.FakeResource(
- info=copy.deepcopy(qos_bandwidth_limit_rule_attrs),
+ qos_policy = fakes.FakeResource(
+ info=copy.deepcopy(qos_policy_attrs),
loaded=True)
- return qos_bandwidth_limit_rule
+ # Set attributes with special mapping in OpenStack SDK.
+ qos_policy.is_shared = qos_policy_attrs['shared']
+ qos_policy.project_id = qos_policy_attrs['tenant_id']
+
+ return qos_policy
@staticmethod
- def create_qos_bandwidth_limit_rules(attrs=None, count=2):
- """Create multiple fake QoS bandwidth limit rules.
+ def create_qos_policies(attrs=None, count=2):
+ """Create multiple fake QoS policies.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
- The number of QoS bandwidth limit rules to fake
+ The number of QoS policies to fake
:return:
- A list of FakeResource objects faking the QoS bandwidth limit rules
+ A list of FakeResource objects faking the QoS policies
"""
qos_policies = []
for i in range(0, count):
- qos_policies.append(FakeNetworkQosBandwidthLimitRule.
- create_one_qos_bandwidth_limit_rule(attrs))
+ qos_policies.append(
+ FakeNetworkQosPolicy.create_one_qos_policy(attrs))
return qos_policies
@staticmethod
- def get_qos_bandwidth_limit_rules(qos_rules=None, count=2):
- """Get a list of faked QoS bandwidth limit rules.
+ def get_qos_policies(qos_policies=None, count=2):
+ """Get an iterable MagicMock object with a list of faked QoS policies.
- If QoS bandwidth limit rules list is provided, then initialize the
- Mock object with the list. Otherwise create one.
+ If qos policies list is provided, then initialize the Mock object
+ with the list. Otherwise create one.
:param List address scopes:
- A list of FakeResource objects faking QoS bandwidth limit rules
+ A list of FakeResource objects faking qos policies
:param int count:
- The number of QoS bandwidth limit rules to fake
+ The number of QoS policies to fake
:return:
An iterable Mock object with side_effect set to a list of faked
- qos bandwidth limit rules
+ QoS policies
"""
- if qos_rules is None:
- qos_rules = (FakeNetworkQosBandwidthLimitRule.
- create_qos_bandwidth_limit_rules(count))
- return mock.Mock(side_effect=qos_rules)
+ if qos_policies is None:
+ qos_policies = FakeNetworkQosPolicy.create_qos_policies(count)
+ return mock.Mock(side_effect=qos_policies)
-class FakeNetworkQosPolicy(object):
- """Fake one or more QoS policies."""
+class FakeNetworkQosRule(object):
+ """Fake one or more Network QoS rules."""
@staticmethod
- def create_one_qos_policy(attrs=None):
- """Create a fake QoS policy.
+ def create_one_qos_rule(attrs=None):
+ """Create a fake Network QoS rule.
:param Dictionary attrs:
A dictionary with all attributes
@@ -746,71 +764,69 @@ class FakeNetworkQosPolicy(object):
A FakeResource object with name, id, etc.
"""
attrs = attrs or {}
- qos_id = attrs.get('id') or 'qos-policy-id-' + uuid.uuid4().hex
- rule_attrs = {'qos_policy_id': qos_id}
- rules = [
- FakeNetworkQosBandwidthLimitRule.
- create_one_qos_bandwidth_limit_rule(rule_attrs)]
# Set default attributes.
- qos_policy_attrs = {
- 'name': 'qos-policy-name-' + uuid.uuid4().hex,
- 'id': qos_id,
+ 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,
'tenant_id': 'project-id-' + uuid.uuid4().hex,
- 'shared': False,
- 'description': 'qos-policy-description-' + uuid.uuid4().hex,
- 'rules': rules,
+ 'type': type,
}
+ if type == RULE_TYPE_BANDWIDTH_LIMIT:
+ qos_rule_attrs['max_kbps'] = randint(1, 10000)
+ qos_rule_attrs['max_burst_kbits'] = randint(1, 10000)
+ 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'
# Overwrite default attributes.
- qos_policy_attrs.update(attrs)
+ qos_rule_attrs.update(attrs)
- qos_policy = fakes.FakeResource(
- info=copy.deepcopy(qos_policy_attrs),
- loaded=True)
+ qos_rule = fakes.FakeResource(info=copy.deepcopy(qos_rule_attrs),
+ loaded=True)
# Set attributes with special mapping in OpenStack SDK.
- qos_policy.is_shared = qos_policy_attrs['shared']
- qos_policy.project_id = qos_policy_attrs['tenant_id']
+ qos_rule.project_id = qos_rule['tenant_id']
- return qos_policy
+ return qos_rule
@staticmethod
- def create_qos_policies(attrs=None, count=2):
- """Create multiple fake QoS policies.
+ def create_qos_rules(attrs=None, count=2):
+ """Create multiple fake Network QoS rules.
:param Dictionary attrs:
A dictionary with all attributes
:param int count:
- The number of QoS policies to fake
+ The number of Network QoS rule to fake
:return:
- A list of FakeResource objects faking the QoS policies
+ A list of FakeResource objects faking the Network QoS rules
"""
- qos_policies = []
+ qos_rules = []
for i in range(0, count):
- qos_policies.append(
- FakeNetworkQosPolicy.create_one_qos_policy(attrs))
-
- return qos_policies
+ qos_rules.append(FakeNetworkQosRule.create_one_qos_rule(attrs))
+ return qos_rules
@staticmethod
- def get_qos_policies(qos_policies=None, count=2):
- """Get an iterable MagicMock object with a list of faked QoS policies.
+ def get_qos_rules(qos_rules=None, count=2):
+ """Get a list of faked Network QoS rules.
- If qos policies list is provided, then initialize the Mock object
- with the list. Otherwise create one.
+ If Network QoS rules list is provided, then initialize the Mock
+ object with the list. Otherwise create one.
:param List address scopes:
- A list of FakeResource objects faking qos policies
+ A list of FakeResource objects faking Network QoS rules
:param int count:
- The number of QoS policies to fake
+ The number of QoS minimum bandwidth rules to fake
:return:
An iterable Mock object with side_effect set to a list of faked
- QoS policies
+ qos minimum bandwidth rules
"""
- if qos_policies is None:
- qos_policies = FakeNetworkQosPolicy.create_qos_policies(count)
- return mock.Mock(side_effect=qos_policies)
+ if qos_rules is None:
+ qos_rules = (FakeNetworkQosRule.create_qos_rules(count))
+ return mock.Mock(side_effect=qos_rules)
class FakeNetworkQosRuleType(object):