Merge "Return complete resp from security_groups_client"
This commit is contained in:
@@ -156,9 +156,8 @@ class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
|
||||
|
||||
s_name = data_utils.rand_name('securitygroup')
|
||||
s_description = data_utils.rand_name('description')
|
||||
securitygroup =\
|
||||
self.sg_client.create_security_group(name=s_name,
|
||||
description=s_description)
|
||||
securitygroup = self.sg_client.create_security_group(
|
||||
name=s_name, description=s_description)['security_group']
|
||||
self.addCleanup(self.sg_client.delete_security_group,
|
||||
securitygroup['id'])
|
||||
|
||||
|
||||
@@ -50,9 +50,8 @@ class SecurityGroupsTestAdminJSON(base.BaseV2ComputeAdminTest):
|
||||
for i in range(2):
|
||||
name = data_utils.rand_name('securitygroup')
|
||||
description = data_utils.rand_name('description')
|
||||
securitygroup = (self.client
|
||||
.create_security_group(name=name,
|
||||
description=description))
|
||||
securitygroup = self.client.create_security_group(
|
||||
name=name, description=description)['security_group']
|
||||
self.addCleanup(self._delete_security_group,
|
||||
securitygroup['id'], admin=False)
|
||||
security_group_list.append(securitygroup)
|
||||
@@ -63,13 +62,14 @@ class SecurityGroupsTestAdminJSON(base.BaseV2ComputeAdminTest):
|
||||
name = data_utils.rand_name('securitygroup')
|
||||
description = data_utils.rand_name('description')
|
||||
adm_securitygroup = self.adm_client.create_security_group(
|
||||
name=name, description=description)
|
||||
name=name, description=description)['security_group']
|
||||
self.addCleanup(self._delete_security_group,
|
||||
adm_securitygroup['id'])
|
||||
security_group_list.append(adm_securitygroup)
|
||||
|
||||
# Fetch all security groups based on 'all_tenants' search filter
|
||||
fetched_list = self.adm_client.list_security_groups(all_tenants='true')
|
||||
fetched_list = self.adm_client.list_security_groups(
|
||||
all_tenants='true')['security_groups']
|
||||
sec_group_id_list = map(lambda sg: sg['id'], fetched_list)
|
||||
# Now check if all created Security Groups are present in fetched list
|
||||
for sec_group in security_group_list:
|
||||
@@ -77,7 +77,8 @@ class SecurityGroupsTestAdminJSON(base.BaseV2ComputeAdminTest):
|
||||
|
||||
# Fetch all security groups for non-admin user with 'all_tenants'
|
||||
# search filter
|
||||
fetched_list = self.client.list_security_groups(all_tenants='true')
|
||||
fetched_list = (self.client.list_security_groups(all_tenants='true')
|
||||
['security_groups'])
|
||||
# Now check if all created Security Groups are present in fetched list
|
||||
for sec_group in fetched_list:
|
||||
self.assertEqual(sec_group['tenant_id'], client_tenant_id,
|
||||
|
||||
@@ -223,9 +223,8 @@ class BaseComputeTest(tempest.test.BaseTestCase):
|
||||
name = data_utils.rand_name(cls.__name__ + "-securitygroup")
|
||||
if description is None:
|
||||
description = data_utils.rand_name('description')
|
||||
body = \
|
||||
cls.security_groups_client.create_security_group(
|
||||
name=name, description=description)
|
||||
body = cls.security_groups_client.create_security_group(
|
||||
name=name, description=description)['security_group']
|
||||
cls.security_groups.append(body)
|
||||
|
||||
return body
|
||||
|
||||
@@ -40,7 +40,7 @@ class SecurityGroupsTestJSON(base.BaseSecurityGroupsTest):
|
||||
security_group_list.append(body)
|
||||
# Fetch all Security Groups and verify the list
|
||||
# has all created Security Groups
|
||||
fetched_list = self.client.list_security_groups()
|
||||
fetched_list = self.client.list_security_groups()['security_groups']
|
||||
# Now check if all the created Security Groups are in fetched list
|
||||
missing_sgs = \
|
||||
[sg for sg in security_group_list if sg not in fetched_list]
|
||||
@@ -53,7 +53,7 @@ class SecurityGroupsTestJSON(base.BaseSecurityGroupsTest):
|
||||
self.client.delete_security_group(sg['id'])
|
||||
self.client.wait_for_resource_deletion(sg['id'])
|
||||
# Now check if all the created Security Groups are deleted
|
||||
fetched_list = self.client.list_security_groups()
|
||||
fetched_list = self.client.list_security_groups()['security_groups']
|
||||
deleted_sgs = \
|
||||
[sg for sg in security_group_list if sg in fetched_list]
|
||||
self.assertFalse(deleted_sgs,
|
||||
@@ -75,8 +75,8 @@ class SecurityGroupsTestJSON(base.BaseSecurityGroupsTest):
|
||||
"The created Security Group name is "
|
||||
"not equal to the requested name")
|
||||
# Now fetch the created Security Group by its 'id'
|
||||
fetched_group = \
|
||||
self.client.show_security_group(securitygroup['id'])
|
||||
fetched_group = (self.client.show_security_group(securitygroup['id'])
|
||||
['security_group'])
|
||||
self.assertEqual(securitygroup, fetched_group,
|
||||
"The fetched Security Group is different "
|
||||
"from the created Group")
|
||||
@@ -143,7 +143,7 @@ class SecurityGroupsTestJSON(base.BaseSecurityGroupsTest):
|
||||
name=s_new_name,
|
||||
description=s_new_des)
|
||||
# get the security group
|
||||
fetched_group = \
|
||||
self.client.show_security_group(securitygroup_id)
|
||||
fetched_group = (self.client.show_security_group(securitygroup_id)
|
||||
['security_group'])
|
||||
self.assertEqual(s_new_name, fetched_group['name'])
|
||||
self.assertEqual(s_new_des, fetched_group['description'])
|
||||
|
||||
@@ -39,7 +39,7 @@ class SecurityGroupsNegativeTestJSON(base.BaseSecurityGroupsTest):
|
||||
|
||||
def _generate_a_non_existent_security_group_id(self):
|
||||
security_group_id = []
|
||||
body = self.client.list_security_groups()
|
||||
body = self.client.list_security_groups()['security_groups']
|
||||
for i in range(len(body)):
|
||||
security_group_id.append(body[i]['id'])
|
||||
# Generate a non-existent security group id
|
||||
@@ -122,7 +122,7 @@ class SecurityGroupsNegativeTestJSON(base.BaseSecurityGroupsTest):
|
||||
def test_delete_the_default_security_group(self):
|
||||
# Negative test:Deletion of the "default" Security Group should Fail
|
||||
default_security_group_id = None
|
||||
body = self.client.list_security_groups()
|
||||
body = self.client.list_security_groups()['security_groups']
|
||||
for i in range(len(body)):
|
||||
if body[i]['name'] == 'default':
|
||||
default_security_group_id = body[i]['id']
|
||||
|
||||
@@ -49,7 +49,7 @@ class ServerRescueTestJSON(base.BaseV2ComputeTest):
|
||||
cls.sg_name = data_utils.rand_name('sg')
|
||||
cls.sg_desc = data_utils.rand_name('sg-desc')
|
||||
cls.sg = cls.security_groups_client.create_security_group(
|
||||
name=cls.sg_name, description=cls.sg_desc)
|
||||
name=cls.sg_name, description=cls.sg_desc)['security_group']
|
||||
cls.sg_id = cls.sg['id']
|
||||
|
||||
# Server for positive tests
|
||||
|
||||
@@ -84,7 +84,7 @@ class AuthorizationTestJSON(base.BaseV2ComputeTest):
|
||||
name = data_utils.rand_name('security')
|
||||
description = data_utils.rand_name('description')
|
||||
cls.security_group = cls.security_client.create_security_group(
|
||||
name=name, description=description)
|
||||
name=name, description=description)['security_group']
|
||||
|
||||
parent_group_id = cls.security_group['id']
|
||||
ip_protocol = 'tcp'
|
||||
|
||||
@@ -271,7 +271,7 @@ class SecurityGroupService(BaseService):
|
||||
|
||||
def list(self):
|
||||
client = self.client
|
||||
secgrps = client.list_security_groups()
|
||||
secgrps = client.list_security_groups()['security_groups']
|
||||
secgrp_del = [grp for grp in secgrps if grp['name'] != 'default']
|
||||
LOG.debug("List count, %s Security Groups" % len(secgrp_del))
|
||||
return secgrp_del
|
||||
|
||||
@@ -909,14 +909,15 @@ def create_secgroups(secgroups):
|
||||
# only create a security group if the name isn't here
|
||||
# i.e. a security group may be used by another server
|
||||
# only create a router if the name isn't here
|
||||
body = client.secgroups.list_security_groups()
|
||||
body = client.secgroups.list_security_groups()['security_groups']
|
||||
if any(item['name'] == secgroup['name'] for item in body):
|
||||
LOG.warning("Security group '%s' already exists" %
|
||||
secgroup['name'])
|
||||
continue
|
||||
|
||||
body = client.secgroups.create_security_group(
|
||||
name=secgroup['name'], description=secgroup['description'])
|
||||
name=secgroup['name'],
|
||||
description=secgroup['description'])['security_group']
|
||||
secgroup_id = body['id']
|
||||
# for each security group, create the rules
|
||||
for rule in secgroup['rules']:
|
||||
|
||||
@@ -28,7 +28,7 @@ def create_ssh_security_group(os, add_rule=False):
|
||||
sg_name = data_utils.rand_name('securitygroup-')
|
||||
sg_description = data_utils.rand_name('description-')
|
||||
security_group = security_groups_client.create_security_group(
|
||||
name=sg_name, description=sg_description)
|
||||
name=sg_name, description=sg_description)['security_group']
|
||||
if add_rule:
|
||||
security_group_rules_client.create_security_group_rule(
|
||||
parent_group_id=security_group['id'], ip_protocol='tcp',
|
||||
|
||||
@@ -226,7 +226,7 @@ class ScenarioTest(tempest.test.BaseTestCase):
|
||||
_client = self.security_groups_client
|
||||
_client_rules = self.security_group_rules_client
|
||||
if secgroup_id is None:
|
||||
sgs = _client.list_security_groups()
|
||||
sgs = _client.list_security_groups()['security_groups']
|
||||
for sg in sgs:
|
||||
if sg['name'] == 'default':
|
||||
secgroup_id = sg['id']
|
||||
@@ -266,7 +266,7 @@ class ScenarioTest(tempest.test.BaseTestCase):
|
||||
sg_name = data_utils.rand_name(self.__class__.__name__)
|
||||
sg_desc = sg_name + " description"
|
||||
secgroup = self.security_groups_client.create_security_group(
|
||||
name=sg_name, description=sg_desc)
|
||||
name=sg_name, description=sg_desc)['security_group']
|
||||
self.assertEqual(secgroup['name'], sg_name)
|
||||
self.assertEqual(secgroup['description'], sg_desc)
|
||||
self.addCleanup(self.delete_wrapper,
|
||||
|
||||
@@ -87,7 +87,8 @@ class TestLargeOpsScenario(manager.ScenarioTest):
|
||||
# Since no traffic is tested, we don't need to actually add rules to
|
||||
# secgroup
|
||||
secgroup = self.security_groups_client.create_security_group(
|
||||
name='secgroup-%s' % name, description='secgroup-desc-%s' % name)
|
||||
name='secgroup-%s' % name,
|
||||
description='secgroup-desc-%s' % name)['security_group']
|
||||
self.addCleanupClass(self.security_groups_client.delete_security_group,
|
||||
secgroup['id'])
|
||||
create_kwargs = {
|
||||
|
||||
@@ -33,7 +33,7 @@ class SecurityGroupsClient(service_client.ServiceClient):
|
||||
resp, body = self.get(url)
|
||||
body = json.loads(body)
|
||||
self.validate_response(schema.list_security_groups, resp, body)
|
||||
return service_client.ResponseBodyList(resp, body['security_groups'])
|
||||
return service_client.ResponseBody(resp, body)
|
||||
|
||||
def show_security_group(self, security_group_id):
|
||||
"""Get the details of a Security Group."""
|
||||
@@ -41,7 +41,7 @@ class SecurityGroupsClient(service_client.ServiceClient):
|
||||
resp, body = self.get(url)
|
||||
body = json.loads(body)
|
||||
self.validate_response(schema.get_security_group, resp, body)
|
||||
return service_client.ResponseBody(resp, body['security_group'])
|
||||
return service_client.ResponseBody(resp, body)
|
||||
|
||||
def create_security_group(self, **kwargs):
|
||||
"""
|
||||
@@ -53,7 +53,7 @@ class SecurityGroupsClient(service_client.ServiceClient):
|
||||
resp, body = self.post('os-security-groups', post_body)
|
||||
body = json.loads(body)
|
||||
self.validate_response(schema.get_security_group, resp, body)
|
||||
return service_client.ResponseBody(resp, body['security_group'])
|
||||
return service_client.ResponseBody(resp, body)
|
||||
|
||||
def update_security_group(self, security_group_id, **kwargs):
|
||||
"""
|
||||
@@ -67,7 +67,7 @@ class SecurityGroupsClient(service_client.ServiceClient):
|
||||
post_body)
|
||||
body = json.loads(body)
|
||||
self.validate_response(schema.update_security_group, resp, body)
|
||||
return service_client.ResponseBody(resp, body['security_group'])
|
||||
return service_client.ResponseBody(resp, body)
|
||||
|
||||
def delete_security_group(self, security_group_id):
|
||||
"""Deletes the provided Security Group."""
|
||||
|
||||
@@ -95,7 +95,7 @@ class FloatingStress(stressaction.StressAction):
|
||||
s_name = data_utils.rand_name('sec_grp')
|
||||
s_description = data_utils.rand_name('desc')
|
||||
self.sec_grp = sec_grp_cli.create_security_group(
|
||||
name=s_name, description=s_description)
|
||||
name=s_name, description=s_description)['security_group']
|
||||
create_rule = sec_grp_cli.create_security_group_rule
|
||||
create_rule(parent_group_id=self.sec_grp['id'], ip_protocol='tcp',
|
||||
from_port=22, to_port=22)
|
||||
|
||||
@@ -58,7 +58,7 @@ class VolumeVerifyStress(stressaction.StressAction):
|
||||
s_name = data_utils.rand_name('sec_grp')
|
||||
s_description = data_utils.rand_name('desc')
|
||||
self.sec_grp = sec_grp_cli.create_security_group(
|
||||
name=s_name, description=s_description)
|
||||
name=s_name, description=s_description)['security_group']
|
||||
create_rule = sec_grp_cli.create_security_group_rule
|
||||
create_rule(parent_group_id=self.sec_grp['id'], ip_protocol='tcp',
|
||||
from_port=22, to_port=22)
|
||||
|
||||
@@ -49,7 +49,8 @@ def cleanup():
|
||||
pass
|
||||
|
||||
secgrp_client = admin_manager.security_groups_client
|
||||
secgrp = secgrp_client.list_security_groups(all_tenants=True)
|
||||
secgrp = (secgrp_client.list_security_groups(all_tenants=True)
|
||||
['security_groups'])
|
||||
secgrp_del = [grp for grp in secgrp if grp['name'] != 'default']
|
||||
LOG.info("Cleanup::remove %s Security Group" % len(secgrp_del))
|
||||
for g in secgrp_del:
|
||||
|
||||
@@ -270,9 +270,10 @@ class TestCreateResources(JavelinUnitTest):
|
||||
def test_create_secgroup(self):
|
||||
self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
|
||||
return_value=self.fake_client))
|
||||
self.fake_client.secgroups.list_security_groups.return_value = []
|
||||
self.fake_client.secgroups.list_security_groups.return_value = (
|
||||
{'security_groups': []})
|
||||
self.fake_client.secgroups.create_security_group.return_value = \
|
||||
{'id': self.fake_object['secgroup_id']}
|
||||
{'security_group': {'id': self.fake_object['secgroup_id']}}
|
||||
|
||||
javelin.create_secgroups([self.fake_object])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user