Merge pull request #30867 from rallytime/boto-utils-fix

Pass in 'pack' variable to utils.boto.assign_funcs function from ALL boto modules
This commit is contained in:
Colton Myers 2016-02-04 11:37:05 -07:00
commit 89bac9076a
18 changed files with 87 additions and 43 deletions

View File

@ -78,7 +78,7 @@ def __virtual__():
if not HAS_BOTO:
return False
__utils__['boto.assign_funcs'](__name__, 'asg', module='ec2.autoscale')
__utils__['boto.assign_funcs'](__name__, 'asg', module='ec2.autoscale', pack=__salt__)
setattr(sys.modules[__name__], '_get_ec2_conn',
__utils__['boto.get_connection_func']('ec2'))
return True

View File

@ -64,7 +64,7 @@ def __virtual__():
def __init__(opts):
if HAS_BOTO:
__utils__['boto.assign_funcs'](__name__, 'cfn', module='cloudformation')
__utils__['boto.assign_funcs'](__name__, 'cfn', module='cloudformation', pack=__salt__)
def exists(name, region=None, key=None, keyid=None, profile=None):

View File

@ -76,7 +76,8 @@ def __virtual__():
if not HAS_BOTO:
return (False, 'The boto_cloudwatch module cannot be loaded: boto libraries are unavailable.')
__utils__['boto.assign_funcs'](__name__, 'cloudwatch',
module='ec2.cloudwatch')
module='ec2.cloudwatch',
pack=__salt__)
return True

View File

@ -75,7 +75,7 @@ def __virtual__():
'''
if not HAS_BOTO:
return False
__utils__['boto.assign_funcs'](__name__, 'dynamodb2')
__utils__['boto.assign_funcs'](__name__, 'dynamodb2', pack=__salt__)
return True

View File

@ -83,7 +83,7 @@ def __virtual__():
elif _LooseVersion(boto.__version__) < _LooseVersion(required_boto_version):
return False
else:
__utils__['boto.assign_funcs'](__name__, 'ec2')
__utils__['boto.assign_funcs'](__name__, 'ec2', pack=__salt__)
return True

View File

@ -74,7 +74,7 @@ def __virtual__():
'''
if not HAS_BOTO:
return False
__utils__['boto.assign_funcs'](__name__, 'elasticache')
__utils__['boto.assign_funcs'](__name__, 'elasticache', pack=__salt__)
return True

View File

@ -86,7 +86,7 @@ def __virtual__():
'''
if not HAS_BOTO:
return False
__utils__['boto.assign_funcs'](__name__, 'elb', module='ec2.elb')
__utils__['boto.assign_funcs'](__name__, 'elb', module='ec2.elb', pack=__salt__)
return True

View File

@ -67,7 +67,7 @@ def __virtual__():
'''
if not HAS_BOTO:
return False
__utils__['boto.assign_funcs'](__name__, 'iam')
__utils__['boto.assign_funcs'](__name__, 'iam', pack=__salt__)
return True

View File

@ -80,7 +80,7 @@ def __virtual__():
def __init__(opts):
salt.utils.compat.pack_dunder(__name__)
if HAS_BOTO:
__utils__['boto.assign_funcs'](__name__, 'kms')
__utils__['boto.assign_funcs'](__name__, 'kms', pack=__salt__)
def create_alias(alias_name, target_key_id, region=None, key=None, keyid=None,

View File

@ -70,7 +70,7 @@ def __virtual__():
'''
if not HAS_BOTO:
return False
__utils__['boto.assign_funcs'](__name__, 'rds', module='rds2')
__utils__['boto.assign_funcs'](__name__, 'rds', module='rds2', pack=__salt__)
return True

View File

@ -88,7 +88,7 @@ def __virtual__():
def __init__(opts):
salt.utils.compat.pack_dunder(__name__)
if HAS_BOTO:
__utils__['boto.assign_funcs'](__name__, 'route53')
__utils__['boto.assign_funcs'](__name__, 'route53', pack=__salt__)
def _get_split_zone(zone, _conn, private_zone):

View File

@ -85,7 +85,7 @@ def __virtual__():
elif _LooseVersion(boto.__version__) < _LooseVersion(required_boto_version):
return False
else:
__utils__['boto.assign_funcs'](__name__, 'ec2')
__utils__['boto.assign_funcs'](__name__, 'ec2', pack=__salt__)
return True

View File

@ -66,7 +66,7 @@ def __virtual__():
'''
if not HAS_BOTO:
return False
__utils__['boto.assign_funcs'](__name__, 'sns')
__utils__['boto.assign_funcs'](__name__, 'sns', pack=__salt__)
return True

View File

@ -73,7 +73,7 @@ def __virtual__():
'''
if not HAS_BOTO:
return False
__utils__['boto.assign_funcs'](__name__, 'sqs')
__utils__['boto.assign_funcs'](__name__, 'sqs', pack=__salt__)
return True

View File

@ -125,10 +125,10 @@ def __virtual__():
return True
def __init__(opts, pack=None):
def __init__(opts):
salt.utils.compat.pack_dunder(__name__)
if HAS_BOTO:
__utils__['boto.assign_funcs'](__name__, 'vpc', pack=pack)
__utils__['boto.assign_funcs'](__name__, 'vpc', pack=__salt__)
def _check_vpc(vpc_id, vpc_name, region, key, keyid, profile):

View File

@ -63,6 +63,8 @@ except ImportError:
log = logging.getLogger(__name__)
__salt__ = {}
def __virtual__():
'''

View File

@ -73,7 +73,8 @@ utils = salt.loader.utils(opts, whitelist=['boto'])
mods = salt.loader.minion_mods(opts)
boto_vpc.__utils__ = utils
boto_vpc.__init__(opts, pack=mods)
boto_vpc.__salt__ = {}
boto_vpc.__init__(opts)
def _has_required_boto():
@ -726,7 +727,8 @@ class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
Tests checking subnet existence without any filters
'''
with self.assertRaisesRegexp(SaltInvocationError,
'At least one of the following must be specified: subnet id, cidr, subnet_name, tags, or zones.'):
'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
@ -737,7 +739,10 @@ class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
vpc = self._create_vpc()
subnet = self._create_subnet(vpc.id)
describe_subnet_results = boto_vpc.describe_subnet(subnet_id=subnet.id)
describe_subnet_results = boto_vpc.describe_subnet(region=region,
key=secret_key,
keyid=access_key,
subnet_id=subnet.id)
self.assertEqual(set(describe_subnet_results['subnet'].keys()),
set(['id', 'cidr_block', 'availability_zone', 'tags']))
@ -746,9 +751,12 @@ class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
'''
Tests describing a non-existent subnet by id.
'''
vpc = self._create_vpc()
self._create_vpc()
describe_subnet_results = boto_vpc.describe_subnet(subnet_id='subnet-a1b2c3')
describe_subnet_results = boto_vpc.describe_subnet(region=region,
key=secret_key,
keyid=access_key,
subnet_id='subnet-a1b2c3')
self.assertEqual(describe_subnet_results['subnet'], None)
@mock_ec2
@ -757,9 +765,12 @@ class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
Tests describing a subnet by name.
'''
vpc = self._create_vpc()
subnet = self._create_subnet(vpc.id, name='test')
self._create_subnet(vpc.id, name='test')
describe_subnet_results = boto_vpc.describe_subnet(subnet_name='test')
describe_subnet_results = boto_vpc.describe_subnet(region=region,
key=secret_key,
keyid=access_key,
subnet_name='test')
self.assertEqual(set(describe_subnet_results['subnet'].keys()),
set(['id', 'cidr_block', 'availability_zone', 'tags']))
@ -768,9 +779,12 @@ class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
'''
Tests describing a non-existent subnet by id.
'''
vpc = self._create_vpc()
self._create_vpc()
describe_subnet_results = boto_vpc.describe_subnet(subnet_name='test')
describe_subnet_results = boto_vpc.describe_subnet(region=region,
key=secret_key,
keyid=access_key,
subnet_name='test')
self.assertEqual(describe_subnet_results['subnet'], None)
@mock_ec2
@ -782,7 +796,10 @@ class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
subnet1 = self._create_subnet(vpc.id)
subnet2 = self._create_subnet(vpc.id)
describe_subnet_results = boto_vpc.describe_subnets(subnet_ids=[subnet1.id, subnet2.id])
describe_subnet_results = boto_vpc.describe_subnets(region=region,
key=secret_key,
keyid=access_key,
subnet_ids=[subnet1.id, subnet2.id])
self.assertEqual(len(describe_subnet_results['subnets']), 2)
self.assertEqual(set(describe_subnet_results['subnets'][0].keys()),
set(['id', 'cidr_block', 'availability_zone', 'tags']))
@ -793,10 +810,13 @@ class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
Tests describing multiple subnets by id.
'''
vpc = self._create_vpc()
subnet1 = self._create_subnet(vpc.id, name='subnet1')
subnet2 = self._create_subnet(vpc.id, name='subnet2')
self._create_subnet(vpc.id, name='subnet1')
self._create_subnet(vpc.id, name='subnet2')
describe_subnet_results = boto_vpc.describe_subnets(subnet_names=['subnet1', 'subnet2'])
describe_subnet_results = boto_vpc.describe_subnets(region=region,
key=secret_key,
keyid=access_key,
subnet_names=['subnet1', 'subnet2'])
self.assertEqual(len(describe_subnet_results['subnets']), 2)
self.assertEqual(set(describe_subnet_results['subnets'][0].keys()),
set(['id', 'cidr_block', 'availability_zone', 'tags']))
@ -808,7 +828,10 @@ class BotoVpcSubnetsTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
'''
vpc = self._create_vpc()
self._create_subnet(vpc.id, name='subnet1', availability_zone='us-east-1a')
describe_subnet_results = boto_vpc.describe_subnets(subnet_names=['subnet1'])
describe_subnet_results = boto_vpc.describe_subnets(region=region,
key=secret_key,
keyid=access_key,
subnet_names=['subnet1'])
self.assertEqual(describe_subnet_results['subnets'][0]['availability_zone'], 'us-east-1a')
@ -825,7 +848,9 @@ class BotoVpcInternetGatewayTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
Tests creating an internet gateway successfully (with no vpc id or name)
'''
igw_creation_result = boto_vpc.create_internet_gateway()
igw_creation_result = boto_vpc.create_internet_gateway(region=region,
key=secret_key,
keyid=access_key)
self.assertTrue(igw_creation_result.get('created'))
@mock_ec2
@ -834,7 +859,10 @@ class BotoVpcInternetGatewayTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
Tests that creating an internet gateway for a non-existent VPC fails.
'''
igw_creation_result = boto_vpc.create_internet_gateway(vpc_name='non-existent-vpc')
igw_creation_result = boto_vpc.create_internet_gateway(region=region,
key=secret_key,
keyid=access_key,
vpc_name='non-existent-vpc')
self.assertTrue('error' in igw_creation_result)
@mock_ec2
@ -845,7 +873,10 @@ class BotoVpcInternetGatewayTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
self._create_vpc(name='test-vpc')
igw_creation_result = boto_vpc.create_internet_gateway(vpc_name='test-vpc')
igw_creation_result = boto_vpc.create_internet_gateway(region=region,
key=secret_key,
keyid=access_key,
vpc_name='test-vpc')
self.assertTrue(igw_creation_result.get('created'))
@ -857,7 +888,10 @@ class BotoVpcInternetGatewayTestCase(BotoVpcTestCaseBase, BotoVpcTestCaseMixin):
vpc = self._create_vpc()
igw_creation_result = boto_vpc.create_internet_gateway(vpc_id=vpc.id)
igw_creation_result = boto_vpc.create_internet_gateway(region=region,
key=secret_key,
keyid=access_key,
vpc_id=vpc.id)
self.assertTrue(igw_creation_result.get('created'))

View File

@ -104,6 +104,7 @@ class BotoVpcTestCase(BotoVpcStateTestCaseBase, BotoVpcTestCaseMixin):
'''
Tests present on a VPC that does not exist.
'''
with patch.dict('salt.utils.boto.__salt__', funcs):
vpc_present_result = salt_states['boto_vpc.present']('test', cidr_block)
self.assertTrue(vpc_present_result['result'])
@ -129,6 +130,7 @@ class BotoVpcTestCase(BotoVpcStateTestCaseBase, BotoVpcTestCaseMixin):
'''
Tests absent on a VPC that does not exist.
'''
with patch.dict('salt.utils.boto.__salt__', funcs):
vpc_absent_result = salt_states['boto_vpc.absent']('test')
self.assertTrue(vpc_absent_result['result'])
self.assertEqual(vpc_absent_result['changes'], {})
@ -136,6 +138,7 @@ class BotoVpcTestCase(BotoVpcStateTestCaseBase, BotoVpcTestCaseMixin):
@mock_ec2
def test_absent_when_vpc_exists(self):
vpc = self._create_vpc(name='test')
with patch.dict('salt.utils.boto.__salt__', funcs):
vpc_absent_result = salt_states['boto_vpc.absent']('test')
self.assertTrue(vpc_absent_result['result'])
self.assertEqual(vpc_absent_result['changes']['new']['vpc'], None)
@ -166,6 +169,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
Tests present on a resource that does not exist.
'''
vpc = self._create_vpc(name='test')
with patch.dict('salt.utils.boto.__salt__', funcs):
resource_present_result = salt_states['boto_vpc.{0}_present'.format(self.resource_type)](
name='test', vpc_name='test', **self.extra_kwargs)
@ -178,6 +182,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
def test_present_when_resource_exists(self):
vpc = self._create_vpc(name='test')
resource = self._create_resource(vpc_id=vpc.id, name='test')
with patch.dict('salt.utils.boto.__salt__', funcs):
resource_present_result = salt_states['boto_vpc.{0}_present'.format(self.resource_type)](
name='test', vpc_name='test', **self.extra_kwargs)
self.assertTrue(resource_present_result['result'])
@ -199,6 +204,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
'''
Tests absent on a resource that does not exist.
'''
with patch.dict('salt.utils.boto.__salt__', funcs):
resource_absent_result = salt_states['boto_vpc.{0}_absent'.format(self.resource_type)]('test')
self.assertTrue(resource_absent_result['result'])
self.assertEqual(resource_absent_result['changes'], {})
@ -208,6 +214,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
vpc = self._create_vpc(name='test')
self._create_resource(vpc_id=vpc.id, name='test')
with patch.dict('salt.utils.boto.__salt__', funcs):
resource_absent_result = salt_states['boto_vpc.{0}_absent'.format(self.resource_type)]('test')
self.assertTrue(resource_absent_result['result'])
self.assertEqual(resource_absent_result['changes']['new'][self.resource_type], None)