Create default VPC during describe route tables
fix unit tests add unit tests Change-Id: Ia7f4c485ca8083e8c99ded26ea96b1d48319218f
This commit is contained in:
parent
9fd28fbed3
commit
f245fbcf6a
|
@ -296,6 +296,7 @@ class RouteTableDescriber(common.TaggableItemsDescriber,
|
|||
|
||||
|
||||
def describe_route_tables(context, route_table_id=None, filter=None):
|
||||
ec2utils.check_and_create_default_vpc(context)
|
||||
formatted_route_tables = RouteTableDescriber().describe(
|
||||
context, ids=route_table_id, filter=filter)
|
||||
return {'routeTableSet': formatted_route_tables}
|
||||
|
|
|
@ -169,6 +169,8 @@ ID_EC2_ROUTE_TABLE_DEFAULT = random_ec2_id('rtb')
|
|||
ID_EC2_ROUTE_TABLE_1 = random_ec2_id('rtb')
|
||||
ID_EC2_ROUTE_TABLE_2 = random_ec2_id('rtb')
|
||||
ID_EC2_ROUTE_TABLE_3 = random_ec2_id('rtb')
|
||||
ID_EC2_ROUTE_TABLE_ASSOCIATION_DEFAULT = ID_EC2_VPC_DEFAULT.replace('vpc',
|
||||
'rtbassoc')
|
||||
ID_EC2_ROUTE_TABLE_ASSOCIATION_1 = ID_EC2_VPC_1.replace('vpc', 'rtbassoc')
|
||||
ID_EC2_ROUTE_TABLE_ASSOCIATION_2 = ID_EC2_SUBNET_2.replace('subnet',
|
||||
'rtbassoc')
|
||||
|
@ -1242,6 +1244,21 @@ DB_ROUTE_TABLE_3 = {
|
|||
{'destination_cidr_block': CIDR_VPN_1_STATIC,
|
||||
'gateway_id': ID_EC2_VPN_GATEWAY_1}],
|
||||
}
|
||||
EC2_ROUTE_TABLE_DEFAULT = {
|
||||
'routeTableId': ID_EC2_ROUTE_TABLE_DEFAULT,
|
||||
'vpcId': ID_EC2_VPC_DEFAULT,
|
||||
'routeSet': [
|
||||
{'destinationCidrBlock': CIDR_VPC_DEFAULT,
|
||||
'gatewayId': 'local',
|
||||
'state': 'active',
|
||||
'origin': 'CreateRouteTable'}],
|
||||
'associationSet': [
|
||||
{'routeTableAssociationId': ID_EC2_ROUTE_TABLE_ASSOCIATION_DEFAULT,
|
||||
'routeTableId': ID_EC2_ROUTE_TABLE_DEFAULT,
|
||||
'main': True}],
|
||||
'propagatingVgwSet': [],
|
||||
'tagSet': [],
|
||||
}
|
||||
EC2_ROUTE_TABLE_1 = {
|
||||
'routeTableId': ID_EC2_ROUTE_TABLE_1,
|
||||
'vpcId': ID_EC2_VPC_1,
|
||||
|
|
|
@ -726,7 +726,8 @@ class RouteTableTestCase(base.ApiTestCase):
|
|||
'DependencyViolation', 'DeleteRouteTable',
|
||||
{'RouteTableId': fakes.ID_EC2_ROUTE_TABLE_2})
|
||||
|
||||
def test_describe_route_tables(self):
|
||||
@mock.patch('ec2api.api.ec2utils.check_and_create_default_vpc')
|
||||
def test_describe_route_tables(self, check_and_create):
|
||||
self.set_mock_db_items(
|
||||
fakes.DB_ROUTE_TABLE_1, fakes.DB_ROUTE_TABLE_2,
|
||||
fakes.DB_ROUTE_TABLE_3, fakes.DB_SUBNET_1, fakes.DB_SUBNET_2,
|
||||
|
@ -769,7 +770,8 @@ class RouteTableTestCase(base.ApiTestCase):
|
|||
'DescribeRouteTables', 'routeTableSet',
|
||||
fakes.ID_EC2_ROUTE_TABLE_1, 'routeTableId')
|
||||
|
||||
def test_describe_route_tables_variations(self):
|
||||
@mock.patch('ec2api.api.ec2utils.check_and_create_default_vpc')
|
||||
def test_describe_route_tables_variations(self, check_and_create):
|
||||
igw_1 = tools.purge_dict(fakes.DB_IGW_1, ('vpc_id',))
|
||||
igw_2 = tools.update_dict(fakes.DB_IGW_2,
|
||||
{'vpc_id': fakes.ID_EC2_VPC_2})
|
||||
|
@ -1129,6 +1131,19 @@ class RouteTableTestCase(base.ApiTestCase):
|
|||
mock.ANY, self.neutron, 'fake_cleaner', fakes.DB_ROUTE_TABLE_1,
|
||||
[fakes.DB_SUBNET_1])
|
||||
|
||||
@mock.patch('ec2api.api.ec2utils.check_and_create_default_vpc')
|
||||
def test_describe_route_tables_no_default_vpc(self, check_and_create):
|
||||
def mock_check_and_create(context):
|
||||
self.set_mock_db_items(fakes.DB_VPC_DEFAULT,
|
||||
fakes.DB_ROUTE_TABLE_DEFAULT)
|
||||
check_and_create.side_effect = mock_check_and_create
|
||||
|
||||
resp = self.execute('DescribeRouteTables', {})
|
||||
self.assertEqual(resp['routeTableSet'],
|
||||
[fakes.EC2_ROUTE_TABLE_DEFAULT])
|
||||
|
||||
check_and_create.assert_called_once_with(mock.ANY)
|
||||
|
||||
|
||||
class RouteTableValidatorTestCase(test_base.BaseTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue