summaryrefslogtreecommitdiff
path: root/openstackclient/tests/compute
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-02-18 09:03:27 +0000
committerGerrit Code Review <review@openstack.org>2016-02-18 09:03:27 +0000
commitbb153b705a14c2fbf9b3a0936f8a7ca4c56895e3 (patch)
treea22e15cedb191346286f8c0cd01f93a65d63dabb /openstackclient/tests/compute
parent272ac55776dcc945cdad3d6d38e3356e0c099e45 (diff)
parenta29c9732d7434902fd36e0417e16bb760875591f (diff)
downloadpython-openstackclient-bb153b705a14c2fbf9b3a0936f8a7ca4c56895e3.tar.gz
Merge "Refactor security group rule delete to use SDK"
Diffstat (limited to 'openstackclient/tests/compute')
-rw-r--r--openstackclient/tests/compute/v2/fakes.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py
index 00f73748..a1c42b45 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -235,6 +235,68 @@ class FakeHypervisor(object):
return hypervisors
+class FakeSecurityGroupRule(object):
+ """Fake one or more security group rules."""
+
+ @staticmethod
+ def create_one_security_group_rule(attrs={}, methods={}):
+ """Create a fake security group rule.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :return:
+ A FakeResource object, with id, etc.
+ """
+ # Set default attributes.
+ security_group_rule_attrs = {
+ 'from_port': -1,
+ 'group': {},
+ 'id': 'security-group-rule-id-' + uuid.uuid4().hex,
+ 'ip_protocol': 'icmp',
+ 'ip_range': {'cidr': '0.0.0.0/0'},
+ 'parent_group_id': 'security-group-id-' + uuid.uuid4().hex,
+ 'to_port': -1,
+ }
+
+ # Overwrite default attributes.
+ security_group_rule_attrs.update(attrs)
+
+ # Set default methods.
+ security_group_rule_methods = {}
+
+ # Overwrite default methods.
+ security_group_rule_methods.update(methods)
+
+ security_group_rule = fakes.FakeResource(
+ info=copy.deepcopy(security_group_rule_attrs),
+ methods=copy.deepcopy(security_group_rule_methods),
+ loaded=True)
+ return security_group_rule
+
+ @staticmethod
+ def create_security_group_rules(attrs={}, methods={}, count=2):
+ """Create multiple fake security group rules.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :param int count:
+ The number of security group rules to fake
+ :return:
+ A list of FakeResource objects faking the security group rules
+ """
+ security_group_rules = []
+ for i in range(0, count):
+ security_group_rules.append(
+ FakeSecurityGroupRule.create_one_security_group_rule(
+ attrs, methods))
+
+ return security_group_rules
+
+
class FakeServer(object):
"""Fake one or more compute servers."""