summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/network/v2/fakes.py
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2016-08-02 09:42:21 +0100
committerDean Troyer <dtroyer@gmail.com>2016-10-11 15:08:36 +0000
commit3205dad161c6c7bcaf16f985121217b8cf320af0 (patch)
treee7f332fc10903866bb897f0c08af116a3841a674 /openstackclient/tests/unit/network/v2/fakes.py
parent762f2f2c34814b8bfc615696918d8cb49b93a1dd (diff)
downloadpython-openstackclient-3205dad161c6c7bcaf16f985121217b8cf320af0.tar.gz
Add network support for Network QoS policies
Added following commands: - network qos policy create - network qos policy delete - network qos policy set - network qos policy show - network qos policy list Closes-Bug: 1609037 Depends-On: I33bafeca979410d329ae10a82772ccdb48c10daa Change-Id: I63a8f63702514ff5814481bb021e2aa9d5f3d4b1
Diffstat (limited to 'openstackclient/tests/unit/network/v2/fakes.py')
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py150
1 files changed, 150 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index cea00282..94727ae3 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -633,6 +633,156 @@ class FakeNetworkRBAC(object):
return mock.Mock(side_effect=rbac_policies)
+class FakeNetworkQosBandwidthLimitRule(object):
+ """Fake one or more QoS bandwidth limit rules."""
+
+ @staticmethod
+ def create_one_qos_bandwidth_limit_rule(attrs=None):
+ """Create a fake QoS bandwidth limit rule.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object with id, qos_policy_id, max_kbps and
+ max_burst_kbps attributes.
+ """
+ attrs = attrs or {}
+
+ # 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,
+ }
+
+ # Overwrite default attributes.
+ qos_bandwidth_limit_rule_attrs.update(attrs)
+
+ qos_bandwidth_limit_rule = fakes.FakeResource(
+ info=copy.deepcopy(qos_bandwidth_limit_rule_attrs),
+ loaded=True)
+
+ return qos_bandwidth_limit_rule
+
+ @staticmethod
+ def create_qos_bandwidth_limit_rules(attrs=None, count=2):
+ """Create multiple fake QoS bandwidth limit rules.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of QoS bandwidth limit rules to fake
+ :return:
+ A list of FakeResource objects faking the QoS bandwidth limit rules
+ """
+ qos_policies = []
+ for i in range(0, count):
+ qos_policies.append(FakeNetworkQosBandwidthLimitRule.
+ create_one_qos_bandwidth_limit_rule(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.
+
+ If QoS bandwidth limit 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 bandwidth limit rules
+ :param int count:
+ The number of QoS bandwidth limit rules to fake
+ :return:
+ An iterable Mock object with side_effect set to a list of faked
+ qos bandwidth limit rules
+ """
+ if qos_rules is None:
+ qos_rules = (FakeNetworkQosBandwidthLimitRule.
+ create_qos_bandwidth_limit_rules(count))
+ return mock.Mock(side_effect=qos_rules)
+
+
+class FakeNetworkQosPolicy(object):
+ """Fake one or more QoS policies."""
+
+ @staticmethod
+ 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 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,
+ 'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ 'shared': False,
+ 'description': 'qos-policy-description-' + uuid.uuid4().hex,
+ 'rules': rules,
+ }
+
+ # Overwrite default attributes.
+ qos_policy_attrs.update(attrs)
+
+ qos_policy = fakes.FakeResource(
+ info=copy.deepcopy(qos_policy_attrs),
+ loaded=True)
+
+ # Set attributes with special mapping in OpenStack SDK.
+ qos_policy.project_id = qos_policy_attrs['tenant_id']
+
+ return qos_policy
+
+ @staticmethod
+ 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 policies to fake
+ :return:
+ A list of FakeResource objects faking the QoS policies
+ """
+ qos_policies = []
+ for i in range(0, count):
+ qos_policies.append(
+ FakeNetworkQosPolicy.create_one_qos_policy(attrs))
+
+ return qos_policies
+
+ @staticmethod
+ def get_qos_policies(qos_policies=None, count=2):
+ """Get an iterable MagicMock object with a list of faked QoS policies.
+
+ 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 policies
+ :param int count:
+ The number of QoS policies to fake
+ :return:
+ An iterable Mock object with side_effect set to a list of faked
+ QoS policies
+ """
+ if qos_policies is None:
+ qos_policies = FakeNetworkQosPolicy.create_qos_policies(count)
+ return mock.Mock(side_effect=qos_policies)
+
+
class FakeRouter(object):
"""Fake one or more routers."""