pep8 issues
This commit is contained in:
parent
9c17fad86d
commit
2cb86c56d1
@ -35,8 +35,9 @@ class SecurityGroupRule(base.Resource):
|
||||
class SecurityGroupRuleManager(base.ManagerWithFind):
|
||||
resource_class = SecurityGroupRule
|
||||
|
||||
def create(self, parent_group_id, ip_protocol=None, from_port=None, to_port=None, cidr=None, group_id=None):
|
||||
"""
|
||||
def create(self, parent_group_id, ip_protocol=None, from_port=None,
|
||||
to_port=None, cidr=None, group_id=None):
|
||||
"""
|
||||
Create a security group
|
||||
|
||||
:param ip_protocol: IP protocol, one of 'tcp', 'udp' or 'icmp'
|
||||
@ -46,22 +47,21 @@ class SecurityGroupRuleManager(base.ManagerWithFind):
|
||||
:param group_id: Security group id (int)
|
||||
:param parent_group_id: Parent security group id (int)
|
||||
"""
|
||||
body = { "security_group_rule": {
|
||||
"ip_protocol": ip_protocol,
|
||||
"from_port": from_port,
|
||||
"to_port": to_port,
|
||||
"cidr": cidr,
|
||||
"group_id": group_id,
|
||||
"parent_group_id": parent_group_id }}
|
||||
body = {"security_group_rule": {
|
||||
"ip_protocol": ip_protocol,
|
||||
"from_port": from_port,
|
||||
"to_port": to_port,
|
||||
"cidr": cidr,
|
||||
"group_id": group_id,
|
||||
"parent_group_id": parent_group_id}}
|
||||
|
||||
return self._create('/os-security-group-rules', body, "security_group_rule")
|
||||
return self._create('/os-security-group-rules', body,
|
||||
'security_group_rule')
|
||||
|
||||
def delete(self, id):
|
||||
"""
|
||||
def delete(self, rule):
|
||||
"""
|
||||
Delete a security group rule
|
||||
|
||||
:param id: The security group rule ID to delete
|
||||
:param rule: The security group rule to delete (ID or Class)
|
||||
"""
|
||||
if hasattr(id, 'id'):
|
||||
id = id.id
|
||||
return self._delete('/os-security-group-rules/%s' % id)
|
||||
return self._delete('/os-security-group-rules/%s' % base.getid(rule))
|
||||
|
@ -39,7 +39,7 @@ class SecurityGroupManager(base.ManagerWithFind):
|
||||
resource_class = SecurityGroup
|
||||
|
||||
def create(self, name, description):
|
||||
"""
|
||||
"""
|
||||
Create a security group
|
||||
|
||||
:param name: name for the security group to create
|
||||
@ -49,27 +49,24 @@ class SecurityGroupManager(base.ManagerWithFind):
|
||||
body = {"security_group": {"name": name, 'description': description}}
|
||||
return self._create('/os-security-groups', body, 'security_group')
|
||||
|
||||
def delete(self, id):
|
||||
"""
|
||||
def delete(self, group):
|
||||
"""
|
||||
Delete a security group
|
||||
|
||||
:param id: The security group ID to delete
|
||||
:param group: The security group to delete (group or ID)
|
||||
:rtype: None
|
||||
"""
|
||||
if hasattr(id, 'id'):
|
||||
id = id.id
|
||||
return self._delete('/os-security-groups/%d' % id)
|
||||
return self._delete('/os-security-groups/%s' % base.getid(group))
|
||||
|
||||
def get(self, id):
|
||||
"""
|
||||
"""
|
||||
Get a security group
|
||||
|
||||
:param id: The security group ID to get
|
||||
:param group: The security group to get by ID
|
||||
:rtype: :class:`SecurityGroup`
|
||||
"""
|
||||
if hasattr(id, 'id'):
|
||||
id = id.id
|
||||
return self._get('/os-security-groups/%s' % id, 'security_group')
|
||||
"""
|
||||
return self._get('/os-security-groups/%s' % id,
|
||||
'security_group')
|
||||
|
||||
def list(self):
|
||||
"""
|
||||
|
@ -2,8 +2,8 @@
|
||||
A fake server that "responds" to API methods with pre-canned responses.
|
||||
|
||||
All of these responses come from the spec, so if for some reason the spec's
|
||||
wrong the tests might raise AssertionError. I've indicated in comments the places where actual
|
||||
behavior differs from the spec.
|
||||
wrong the tests might raise AssertionError. I've indicated in comments the
|
||||
places where actual behavior differs from the spec.
|
||||
"""
|
||||
|
||||
import novaclient.client
|
||||
@ -17,7 +17,8 @@ def assert_has_keys(dict, required=[], optional=[]):
|
||||
except AssertionError:
|
||||
allowed_keys = set(required) | set(optional)
|
||||
extra_keys = set(keys).difference(set(required + optional))
|
||||
raise AssertionError("found unexpected keys: %s" % list(extra_keys))
|
||||
raise AssertionError("found unexpected keys: %s" %
|
||||
list(extra_keys))
|
||||
|
||||
|
||||
class FakeClient(object):
|
||||
|
@ -31,7 +31,8 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
assert 'body' in kwargs
|
||||
|
||||
# Call the method
|
||||
munged_url = url.strip('/').replace('/', '_').replace('.', '_').replace('-', '_')
|
||||
munged_url = url.strip('/').replace('/', '_') \
|
||||
.replace('.', '_').replace('-', '_')
|
||||
callback = "%s_%s" % (method.lower(), munged_url)
|
||||
if not hasattr(self, callback):
|
||||
raise AssertionError('Called unknown API method: %s %s' % (method,
|
||||
@ -383,7 +384,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
]})
|
||||
|
||||
def get_os_security_groups_1(self, **kw):
|
||||
return (200, {"security_group":
|
||||
return (200, {"security_group":
|
||||
{'id': 1, 'name': 'test', 'description': 'FAKE_SECURITY_GROUP'}
|
||||
})
|
||||
|
||||
@ -393,8 +394,9 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
def post_os_security_groups(self, body, **kw):
|
||||
assert body.keys() == ['security_group']
|
||||
fakes.assert_has_keys(body['security_group'],
|
||||
required=['name','description'])
|
||||
r = {'security_group': self.get_os_security_groups()[1]['security_groups'][0]}
|
||||
required=['name', 'description'])
|
||||
r = {'security_group':
|
||||
self.get_os_security_groups()[1]['security_groups'][0]}
|
||||
return (202, r)
|
||||
|
||||
#
|
||||
@ -402,8 +404,9 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
#
|
||||
def get_os_security_group_rules(self, **kw):
|
||||
return (200, {"security_group_rules": [
|
||||
{'id': 1, 'parent_group_id': 1, 'group_id': 2, 'ip_protocol': 'TCP',
|
||||
'from_port': '22', 'to_port': 22, 'cidr': '10.0.0.0/8'}
|
||||
{'id': 1, 'parent_group_id': 1, 'group_id': 2,
|
||||
'ip_protocol': 'TCP', 'from_port': '22', 'to_port': 22,
|
||||
'cidr': '10.0.0.0/8'}
|
||||
]})
|
||||
|
||||
def delete_os_security_group_rules_1(self, **kw):
|
||||
@ -412,8 +415,9 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
def post_os_security_group_rules(self, body, **kw):
|
||||
assert body.keys() == ['security_group_rule']
|
||||
fakes.assert_has_keys(body['security_group_rule'],
|
||||
required=['parent_group_id'],
|
||||
optional=['group_id','ip_protocol','from_port','to_port','cidr'])
|
||||
r = {'security_group_rule': self.get_os_security_group_rules()[1]['security_group_rules'][0]}
|
||||
required=['parent_group_id'],
|
||||
optional=['group_id', 'ip_protocol', 'from_port',
|
||||
'to_port', 'cidr'])
|
||||
r = {'security_group_rule':
|
||||
self.get_os_security_group_rules()[1]['security_group_rules'][0]}
|
||||
return (202, r)
|
||||
|
||||
|
@ -11,7 +11,8 @@ class SecurityGroupsTest(utils.TestCase):
|
||||
def test_list_security_groups(self):
|
||||
sgs = cs.security_groups.list()
|
||||
cs.assert_called('GET', '/os-security-groups')
|
||||
[self.assertTrue(isinstance(sg, security_groups.SecurityGroup)) for sg in sgs]
|
||||
for sg in sgs:
|
||||
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
|
||||
|
||||
def test_get_security_groups(self):
|
||||
sg = cs.security_groups.get(1)
|
||||
@ -28,6 +29,6 @@ class SecurityGroupsTest(utils.TestCase):
|
||||
cs.assert_called('DELETE', '/os-security-groups/1')
|
||||
|
||||
def test_create_security_group(self):
|
||||
sg = cs.security_groups.create("foo","foo barr")
|
||||
sg = cs.security_groups.create("foo", "foo barr")
|
||||
cs.assert_called('POST', '/os-security-groups')
|
||||
self.assertTrue(isinstance(sg, security_groups.SecurityGroup))
|
||||
|
Loading…
Reference in New Issue
Block a user