Create default vpc during describe security groups
add unit test Change-Id: I96058de2bde3cff1e7b74d442f67803726cd1828
This commit is contained in:
parent
441c19f8d2
commit
ec3a7780b6
|
@ -197,6 +197,7 @@ class SecurityGroupDescriber(common.TaggableItemsDescriber):
|
|||
|
||||
def describe_security_groups(context, group_name=None, group_id=None,
|
||||
filter=None):
|
||||
ec2utils.check_and_create_default_vpc(context)
|
||||
formatted_security_groups = SecurityGroupDescriber().describe(
|
||||
context, group_id, group_name, filter)
|
||||
return {'securityGroupInfo': formatted_security_groups}
|
||||
|
|
|
@ -151,6 +151,7 @@ IP_ADDRESS_NOVA_1 = '192.168.2.100'
|
|||
|
||||
|
||||
# security group constants
|
||||
ID_EC2_SECURITY_GROUP_DEFAULT = random_ec2_id('sg')
|
||||
ID_EC2_SECURITY_GROUP_1 = random_ec2_id('sg')
|
||||
ID_EC2_SECURITY_GROUP_2 = random_ec2_id('sg')
|
||||
ID_EC2_SECURITY_GROUP_3 = random_ec2_id('sg')
|
||||
|
@ -1008,6 +1009,11 @@ class NovaSecurityGroup(object):
|
|||
self.tenant_id = ID_OS_PROJECT
|
||||
self.rules = nova_group_dict['security_group_rules']
|
||||
|
||||
DB_SECURITY_GROUP_DEFAULT = {
|
||||
'id': ID_EC2_SECURITY_GROUP_DEFAULT,
|
||||
'os_id': ID_OS_SECURITY_GROUP_DEFAULT,
|
||||
'vpc_id': ID_EC2_VPC_DEFAULT,
|
||||
}
|
||||
DB_SECURITY_GROUP_1 = {
|
||||
'id': ID_EC2_SECURITY_GROUP_1,
|
||||
'os_id': ID_OS_SECURITY_GROUP_1,
|
||||
|
@ -1048,10 +1054,16 @@ OS_SECURITY_GROUP_RULE_2 = {
|
|||
OS_SECURITY_GROUP_DEFAULT = {
|
||||
'id': ID_OS_SECURITY_GROUP_DEFAULT,
|
||||
'name': ID_EC2_VPC_DEFAULT,
|
||||
'security_group_rules': [
|
||||
OS_SECURITY_GROUP_RULE_1,
|
||||
OS_SECURITY_GROUP_RULE_2
|
||||
],
|
||||
'security_group_rules':
|
||||
[{'remote_group_id': None,
|
||||
'direction': 'egress',
|
||||
'remote_ip_prefix': None,
|
||||
'protocol': None,
|
||||
'port_range_max': None,
|
||||
'security_group_id': ID_OS_SECURITY_GROUP_DEFAULT,
|
||||
'port_range_min': None,
|
||||
'ethertype': 'IPv4',
|
||||
'id': random_os_id()}],
|
||||
'description': 'Group description',
|
||||
'tenant_id': ID_OS_PROJECT
|
||||
}
|
||||
|
@ -1096,6 +1108,18 @@ OS_SECURITY_GROUP_3 = {
|
|||
'description': 'Group description',
|
||||
'tenant_id': ID_OS_PROJECT
|
||||
}
|
||||
EC2_SECURITY_GROUP_DEFAULT = {
|
||||
'vpcId': ID_EC2_VPC_DEFAULT,
|
||||
'groupDescription': 'Group description',
|
||||
'ipPermissions': None,
|
||||
'groupName': NAME_DEFAULT_OS_SECURITY_GROUP,
|
||||
'ipPermissionsEgress':
|
||||
[{'toPort': -1,
|
||||
'ipProtocol': -1,
|
||||
'fromPort': -1}],
|
||||
'ownerId': ID_OS_PROJECT,
|
||||
'groupId': ID_EC2_SECURITY_GROUP_DEFAULT
|
||||
}
|
||||
EC2_SECURITY_GROUP_1 = {
|
||||
'vpcId': ID_EC2_VPC_1,
|
||||
'groupDescription': 'Group description',
|
||||
|
|
|
@ -313,6 +313,27 @@ class SecurityGroupTestCase(base.ApiTestCase):
|
|||
fakes.EC2_NOVA_SECURITY_GROUP_2],
|
||||
orderless_lists=True))
|
||||
|
||||
@mock.patch('ec2api.api.ec2utils.check_and_create_default_vpc')
|
||||
def test_describe_security_groups_no_default_vpc(self, check_and_create):
|
||||
self.configure(disable_ec2_classic=True)
|
||||
security_group.security_group_engine = (
|
||||
security_group.SecurityGroupEngineNeutron())
|
||||
|
||||
def mock_check_and_create(context):
|
||||
self.set_mock_db_items(fakes.DB_VPC_DEFAULT,
|
||||
fakes.DB_SECURITY_GROUP_DEFAULT)
|
||||
self.neutron.list_security_groups.return_value = (
|
||||
{'security_groups': [fakes.OS_SECURITY_GROUP_DEFAULT]})
|
||||
check_and_create.side_effect = mock_check_and_create
|
||||
|
||||
resp = self.execute('DescribeSecurityGroups', {})
|
||||
self.assertThat(resp['securityGroupInfo'],
|
||||
matchers.ListMatches([
|
||||
fakes.EC2_SECURITY_GROUP_DEFAULT],
|
||||
orderless_lists=True))
|
||||
|
||||
check_and_create.assert_called_once_with(mock.ANY)
|
||||
|
||||
def test_repair_default_security_group(self):
|
||||
security_group.security_group_engine = (
|
||||
security_group.SecurityGroupEngineNeutron())
|
||||
|
|
Loading…
Reference in New Issue