summaryrefslogtreecommitdiff
path: root/openstackclient/tests/compute/v2
diff options
context:
space:
mode:
authorRichard Theis <rtheis@us.ibm.com>2016-02-05 09:02:27 -0600
committerRichard Theis <rtheis@us.ibm.com>2016-02-10 10:38:35 -0600
commita29c9732d7434902fd36e0417e16bb760875591f (patch)
tree75ba5443bad7cf4ad4a4ad62ceac191c7fb8095d /openstackclient/tests/compute/v2
parent624c39ab1bb060e35253b78c842d41ebc1807ae5 (diff)
downloadpython-openstackclient-a29c9732d7434902fd36e0417e16bb760875591f.tar.gz
Refactor security group rule delete to use SDK
Refactored the 'os security group rule delete' command to use the SDK when neutron is enabled, but continue to use the nova client when nova network is enabled. This patch set also introduces new FakeSecurityGroupRule classes for testing network and compute security group rules. And fixes were made to the network FakeSecurityGroup class. Change-Id: I8d0917925aa464e8255defae95a2a2adfb6cfb75 Partial-Bug: #1519512 Related-to: blueprint neutron-client
Diffstat (limited to 'openstackclient/tests/compute/v2')
-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 68a66740..d2070c2f 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -228,6 +228,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."""