boto_vpc: lint

This commit is contained in:
Matthew Williams 2015-04-27 16:05:55 +00:00
parent 682b4940c8
commit 76f739d7c7
4 changed files with 18 additions and 18 deletions

View File

@ -127,11 +127,10 @@ def _check_vpc(vpc_id, vpc_name, region, key, keyid, profile):
if vpc_name:
vpc_id = _get_id(vpc_name=vpc_name, region=region, key=key, keyid=keyid,
profile=profile)
else:
if not _find_vpcs(vpc_id=vpc_id, region=region, key=key, keyid=keyid,
profile=profile):
log.info('VPC {0} does not exist.'.format(vpc_id))
return None
elif not _find_vpcs(vpc_id=vpc_id, region=region, key=key, keyid=keyid,
profile=profile):
log.info('VPC {0} does not exist.'.format(vpc_id))
return None
return vpc_id
@ -197,13 +196,12 @@ def _delete_resource(resource, name=None, resource_id=None, region=None,
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
try:
delete_resource = getattr(conn, 'delete_' + resource)
except AttributeError:
raise AttributeError('{0} function does not exist for boto VPC '
'connection.'.format('delete_' + resource))
if name:
resource_id = _get_resource_id(resource, name,
region=region, key=key,
@ -211,7 +209,7 @@ def _delete_resource(resource, name=None, resource_id=None, region=None,
if not resource_id:
return {'deleted': False, 'error': {'message':
'{0} {1} does not exist.'.format(resource, name)}}
if delete_resource(resource_id, **kwargs):
_cache_id(name, sub_resource=resource,
resource_id=resource_id,
@ -522,7 +520,6 @@ def create(cidr_block, instance_tenancy=None, vpc_name=None,
'''
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
vpc = conn.create_vpc(cidr_block, instance_tenancy=instance_tenancy)
@ -1080,7 +1077,7 @@ def delete_internet_gateway(internet_gateway_id=None,
region=region, key=key, keyid=keyid,
profile=profile)
except BotoServerError as e:
return {'deleted': False, 'error': salt.utils.boto.get_error(e)}
return {'deleted': False, 'error': salt.utils.boto.get_error(e)}
def create_customer_gateway(vpn_connection_type, ip_address, bgp_asn,
@ -1361,7 +1358,7 @@ def create_network_acl(vpc_id=None, vpc_name=None, network_acl_name=None,
profile=profile)
if r.get('created') and subnet_id:
try:
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
association_id = conn.associate_network_acl(r['id'], subnet_id)
except BotoServerError as e:

View File

@ -536,11 +536,11 @@ def route_table_present(name, vpc_name=None, vpc_id=None, routes=None, subnets=N
Either vpc_name or vpc_id must be provided.
routes
A list of routes.
A list of routes.
subnets
A list of subnets.
tags
A list of tags.

View File

@ -728,7 +728,7 @@ class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
with self.assertRaisesRegexp(SaltInvocationError,
'At least one of the following must be specified: subnet id, cidr, subnet_name, tags, or zones.'):
boto_vpc.subnet_exists(**conn_parameters)
@mock_ec2
def test_that_describe_subnet_by_id_for_existing_subnet_returns_correct_data(self):
'''
@ -817,7 +817,7 @@ class BotoVpcInternetGatewayTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
igw_creation_result = boto_vpc.create_internet_gateway()
self.assertTrue(igw_creation_result.get('created'))
@mock_ec2
def test_that_when_creating_an_internet_gateway_with_non_existent_vpc_the_create_internet_gateway_method_returns_an_error(self):
'''
@ -875,7 +875,7 @@ class BotoVpcCustomerGatewayTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
'''
Tests checking if a subnet exists when it does exist
'''
gw_creation_result = boto_vpc.create_customer_gateway('ipsec.1', '10.1.1.1', None)
gw_exists_result = boto_vpc.customer_gateway_exists(customer_gateway_id=gw_creation_result['id'])
self.assertTrue(gw_exists_result['exists'])

View File

@ -15,10 +15,11 @@ ensure_in_syspath('../../')
# Import Salt libs
import salt.config
import salt.loader
# pylint: disable=import-error
from unit.modules.boto_vpc_test import BotoVpcTestCaseMixin
# Import 3rd-party libs
# pylint: disable=import-error
try:
import boto
from boto.exception import BotoServerError
@ -81,10 +82,12 @@ def _has_required_boto():
else:
return True
class BotoVpcStateTestCaseBase(TestCase):
def setUp(self):
ctx.clear()
@skipIf(NO_MOCK, NO_MOCK_REASON)
@skipIf(HAS_BOTO is False, 'The boto module must be installed.')
@skipIf(HAS_MOTO is False, 'The moto module must be installed.')
@ -312,7 +315,7 @@ class BotoVpcRouteTableTestCase(BotoVpcStateTestCaseBase, BotoVpcResourceTestCas
vpc = self._create_vpc(name='test')
subnet1 = self._create_subnet(vpc_id=vpc.id, name='test1')
subnet2 = self._create_subnet(vpc_id=vpc.id, name='test2')
route_table_present_result = salt_states['boto_vpc.route_table_present'](
name='test', vpc_name='test', subnets=[{'name': 'test1'}, {'subnet_id': subnet2.id}])