mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge pull request #42959 from rallytime/bp-42883
Back-port #42883 to 2016.11
This commit is contained in:
commit
d6496eca72
@ -15,28 +15,28 @@ except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
try:
|
||||
from moto import mock_ec2, mock_elb
|
||||
from moto import mock_ec2_deprecated, mock_elb_deprecated
|
||||
HAS_MOTO = True
|
||||
except ImportError:
|
||||
HAS_MOTO = False
|
||||
|
||||
def mock_ec2(self):
|
||||
def mock_ec2_deprecated(self):
|
||||
'''
|
||||
if the mock_ec2 function is not available due to import failure
|
||||
if the mock_ec2_deprecated function is not available due to import failure
|
||||
this replaces the decorated function with stub_function.
|
||||
Allows boto_vpc unit tests to use the @mock_ec2 decorator
|
||||
without a "NameError: name 'mock_ec2' is not defined" error.
|
||||
Allows boto_elb unit tests to use the @mock_ec2_deprecated decorator
|
||||
without a "NameError: name 'mock_ec2_deprecated' is not defined" error.
|
||||
'''
|
||||
def stub_function(self):
|
||||
pass
|
||||
return stub_function
|
||||
|
||||
def mock_elb(self):
|
||||
def mock_elb_deprecated(self):
|
||||
'''
|
||||
if the mock_ec2 function is not available due to import failure
|
||||
if the mock_elb_deprecated function is not available due to import failure
|
||||
this replaces the decorated function with stub_function.
|
||||
Allows boto_vpc unit tests to use the @mock_ec2 decorator
|
||||
without a "NameError: name 'mock_ec2' is not defined" error.
|
||||
Allows boto_elb unit tests to use the @mock_elb_deprecated decorator
|
||||
without a "NameError: name 'mock_elb_deprecated' is not defined" error.
|
||||
'''
|
||||
def stub_function(self):
|
||||
pass
|
||||
@ -83,8 +83,8 @@ class BotoElbTestCase(TestCase):
|
||||
'''
|
||||
TestCase for salt.modules.boto_elb module
|
||||
'''
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
@mock_ec2_deprecated
|
||||
@mock_elb_deprecated
|
||||
def test_register_instances_valid_id_result_true(self):
|
||||
'''
|
||||
tests that given a valid instance id and valid ELB that
|
||||
@ -102,8 +102,8 @@ class BotoElbTestCase(TestCase):
|
||||
**conn_parameters)
|
||||
self.assertEqual(True, register_result)
|
||||
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
@mock_ec2_deprecated
|
||||
@mock_elb_deprecated
|
||||
def test_register_instances_valid_id_string(self):
|
||||
'''
|
||||
tests that given a string containing a instance id and valid ELB that
|
||||
@ -125,8 +125,8 @@ class BotoElbTestCase(TestCase):
|
||||
log.debug(load_balancer_refreshed.instances)
|
||||
self.assertEqual([reservations.instances[0].id], registered_instance_ids)
|
||||
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
@mock_ec2_deprecated
|
||||
@mock_elb_deprecated
|
||||
def test_deregister_instances_valid_id_result_true(self):
|
||||
'''
|
||||
tests that given an valid id the boto_elb deregister_instances method
|
||||
@ -146,8 +146,8 @@ class BotoElbTestCase(TestCase):
|
||||
**conn_parameters)
|
||||
self.assertEqual(True, deregister_result)
|
||||
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
@mock_ec2_deprecated
|
||||
@mock_elb_deprecated
|
||||
def test_deregister_instances_valid_id_string(self):
|
||||
'''
|
||||
tests that given an valid id the boto_elb deregister_instances method
|
||||
@ -172,8 +172,8 @@ class BotoElbTestCase(TestCase):
|
||||
load_balancer_refreshed.instances]
|
||||
self.assertEqual(actual_instances, expected_instances)
|
||||
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
@mock_ec2_deprecated
|
||||
@mock_elb_deprecated
|
||||
def test_deregister_instances_valid_id_list(self):
|
||||
'''
|
||||
tests that given an valid ids in the form of a list that the boto_elb
|
||||
|
@ -29,17 +29,17 @@ except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
try:
|
||||
from moto import mock_ec2
|
||||
from moto import mock_ec2_deprecated
|
||||
HAS_MOTO = True
|
||||
except ImportError:
|
||||
HAS_MOTO = False
|
||||
|
||||
def mock_ec2(self):
|
||||
def mock_ec2_deprecated(self):
|
||||
'''
|
||||
if the mock_ec2 function is not available due to import failure
|
||||
if the mock_ec2_deprecated function is not available due to import failure
|
||||
this replaces the decorated function with stub_function.
|
||||
Allows boto_secgroup unit tests to use the @mock_ec2 decorator
|
||||
without a "NameError: name 'mock_ec2' is not defined" error.
|
||||
Allows boto_secgroup unit tests to use the @mock_ec2_deprecated decorator
|
||||
without a "NameError: name 'mock_ec2_deprecated' is not defined" error.
|
||||
'''
|
||||
def stub_function(self):
|
||||
pass
|
||||
@ -111,7 +111,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
{'to_port': 80, 'from_port': 80, 'ip_protocol': u'tcp', 'cidr_ip': u'0.0.0.0/0'}]
|
||||
self.assertEqual(boto_secgroup._split_rules(rules), split_rules)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_create_ec2_classic(self):
|
||||
'''
|
||||
Test of creation of an EC2-Classic security group. The test ensures
|
||||
@ -131,7 +131,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
secgroup_created_group[0].vpc_id]
|
||||
self.assertEqual(expected_create_result, secgroup_create_result)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_create_ec2_vpc(self):
|
||||
'''
|
||||
test of creation of an EC2-VPC security group. The test ensures that a
|
||||
@ -151,7 +151,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
|
||||
@skipIf(True, 'test skipped due to error in moto return - fixed in'
|
||||
' https://github.com/spulec/moto/commit/cc0166964371f7b5247a49d45637a8f936ccbe6f')
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_get_group_id_ec2_classic(self):
|
||||
'''
|
||||
tests that given a name of a group in EC2-Classic that the correct
|
||||
@ -173,7 +173,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
|
||||
@skipIf(True, 'test skipped because moto does not yet support group'
|
||||
' filters https://github.com/spulec/moto/issues/154')
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_get_group_id_ec2_vpc(self):
|
||||
'''
|
||||
tests that given a name of a group in EC2-VPC that the correct
|
||||
@ -193,7 +193,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
**conn_parameters)
|
||||
self.assertEqual(group_vpc.id, retrieved_group_id)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_get_config_single_rule_group_name(self):
|
||||
'''
|
||||
tests return of 'config' when given group name. get_config returns an OrderedDict.
|
||||
@ -209,7 +209,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
group = conn.create_security_group(name=group_name, description=group_name)
|
||||
group.authorize(ip_protocol=ip_protocol, from_port=from_port, to_port=to_port, cidr_ip=cidr_ip)
|
||||
# setup the expected get_config result
|
||||
expected_get_config_result = OrderedDict([('name', group.name), ('group_id', group.id), ('owner_id', u'111122223333'),
|
||||
expected_get_config_result = OrderedDict([('name', group.name), ('group_id', group.id), ('owner_id', u'123456789012'),
|
||||
('description', group.description), ('tags', {}),
|
||||
('rules', [{'to_port': to_port, 'from_port': from_port,
|
||||
'ip_protocol': ip_protocol, 'cidr_ip': cidr_ip}]),
|
||||
@ -219,7 +219,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
|
||||
@skipIf(True, 'test skipped due to error in moto return - fixed in '
|
||||
'https://github.com/spulec/moto/commit/cc0166964371f7b5247a49d45637a8f936ccbe6f')
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_exists_true_name_classic(self):
|
||||
'''
|
||||
tests 'true' existence of a group in EC2-Classic when given name
|
||||
@ -234,11 +234,11 @@ class BotoSecgroupTestCase(TestCase):
|
||||
|
||||
@skipIf(True, 'test skipped because moto does not yet support group'
|
||||
' filters https://github.com/spulec/moto/issues/154')
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_exists_false_name_classic(self):
|
||||
pass
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_exists_true_name_vpc(self):
|
||||
'''
|
||||
tests 'true' existence of a group in EC2-VPC when given name and vpc_id
|
||||
@ -250,7 +250,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
salt_exists_result = boto_secgroup.exists(name=group_name, vpc_id=vpc_id, **conn_parameters)
|
||||
self.assertTrue(salt_exists_result)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_exists_false_name_vpc(self):
|
||||
'''
|
||||
tests 'false' existence of a group in vpc when given name and vpc_id
|
||||
@ -259,7 +259,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
salt_exists_result = boto_secgroup.exists(group_name, vpc_id=vpc_id, **conn_parameters)
|
||||
self.assertFalse(salt_exists_result)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_exists_true_group_id(self):
|
||||
'''
|
||||
tests 'true' existence of a group when given group_id
|
||||
@ -271,7 +271,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
salt_exists_result = boto_secgroup.exists(group_id=group.id, **conn_parameters)
|
||||
self.assertTrue(salt_exists_result)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_exists_false_group_id(self):
|
||||
'''
|
||||
tests 'false' existence of a group when given group_id
|
||||
@ -282,7 +282,7 @@ class BotoSecgroupTestCase(TestCase):
|
||||
|
||||
@skipIf(True, 'test skipped due to error in moto return - fixed in'
|
||||
' https://github.com/spulec/moto/commit/cc0166964371f7b5247a49d45637a8f936ccbe6f')
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_delete_group_ec2_classic(self):
|
||||
'''
|
||||
test deletion of a group in EC2-Classic. Test does the following:
|
||||
@ -310,11 +310,11 @@ class BotoSecgroupTestCase(TestCase):
|
||||
|
||||
@skipIf(True, 'test skipped because moto does not yet support group'
|
||||
' filters https://github.com/spulec/moto/issues/154')
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_delete_group_name_ec2_vpc(self):
|
||||
pass
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test__get_conn_true(self):
|
||||
'''
|
||||
tests ensures that _get_conn returns an boto.ec2.connection.EC2Connection object.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,10 +15,10 @@ from salttesting.helpers import ensure_in_syspath
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import Salt libs
|
||||
import salt.config
|
||||
import salt.loader
|
||||
import salt.utils.boto
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
from salt.ext import six
|
||||
from salt.utils.versions import LooseVersion
|
||||
|
||||
# pylint: disable=import-error,unused-import
|
||||
from unit.modules.boto_vpc_test import BotoVpcTestCaseMixin
|
||||
@ -34,18 +34,18 @@ except ImportError:
|
||||
HAS_BOTO = False
|
||||
|
||||
try:
|
||||
from moto import mock_ec2
|
||||
from moto import mock_ec2_deprecated
|
||||
|
||||
HAS_MOTO = True
|
||||
except ImportError:
|
||||
HAS_MOTO = False
|
||||
|
||||
def mock_ec2(self):
|
||||
def mock_ec2_deprecated(self):
|
||||
'''
|
||||
if the mock_ec2 function is not available due to import failure
|
||||
if the mock_ec2_deprecated function is not available due to import failure
|
||||
this replaces the decorated function with stub_function.
|
||||
Allows boto_vpc unit tests to use the @mock_ec2 decorator
|
||||
without a "NameError: name 'mock_ec2' is not defined" error.
|
||||
Allows boto_vpc unit tests to use the @mock_ec2_deprecated decorator
|
||||
without a "NameError: name 'mock_ec2_deprecated' is not defined" error.
|
||||
'''
|
||||
|
||||
def stub_function(self):
|
||||
@ -112,7 +112,7 @@ class BotoVpcTestCase(BotoVpcStateTestCaseBase, BotoVpcTestCaseMixin):
|
||||
TestCase for salt.states.boto_vpc state.module
|
||||
'''
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_present_when_vpc_does_not_exist(self):
|
||||
'''
|
||||
Tests present on a VPC that does not exist.
|
||||
@ -123,14 +123,14 @@ class BotoVpcTestCase(BotoVpcStateTestCaseBase, BotoVpcTestCaseMixin):
|
||||
self.assertTrue(vpc_present_result['result'])
|
||||
self.assertEqual(vpc_present_result['changes']['new']['vpc']['state'], 'available')
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_present_when_vpc_exists(self):
|
||||
vpc = self._create_vpc(name='test')
|
||||
vpc_present_result = salt_states['boto_vpc.present']('test', cidr_block)
|
||||
self.assertTrue(vpc_present_result['result'])
|
||||
self.assertEqual(vpc_present_result['changes'], {})
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
@skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493')
|
||||
def test_present_with_failure(self):
|
||||
with patch('moto.ec2.models.VPCBackend.create_vpc', side_effect=BotoServerError(400, 'Mocked error')):
|
||||
@ -138,7 +138,7 @@ class BotoVpcTestCase(BotoVpcStateTestCaseBase, BotoVpcTestCaseMixin):
|
||||
self.assertFalse(vpc_present_result['result'])
|
||||
self.assertTrue('Mocked error' in vpc_present_result['comment'])
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_absent_when_vpc_does_not_exist(self):
|
||||
'''
|
||||
Tests absent on a VPC that does not exist.
|
||||
@ -148,7 +148,7 @@ class BotoVpcTestCase(BotoVpcStateTestCaseBase, BotoVpcTestCaseMixin):
|
||||
self.assertTrue(vpc_absent_result['result'])
|
||||
self.assertEqual(vpc_absent_result['changes'], {})
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_absent_when_vpc_exists(self):
|
||||
vpc = self._create_vpc(name='test')
|
||||
with patch.dict('salt.utils.boto.__salt__', funcs):
|
||||
@ -156,7 +156,7 @@ class BotoVpcTestCase(BotoVpcStateTestCaseBase, BotoVpcTestCaseMixin):
|
||||
self.assertTrue(vpc_absent_result['result'])
|
||||
self.assertEqual(vpc_absent_result['changes']['new']['vpc'], None)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
@skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493')
|
||||
def test_absent_with_failure(self):
|
||||
vpc = self._create_vpc(name='test')
|
||||
@ -176,7 +176,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
|
||||
_create = getattr(self, '_create_' + self.resource_type)
|
||||
_create(vpc_id=vpc_id, name=name, **self.extra_kwargs)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_present_when_resource_does_not_exist(self):
|
||||
'''
|
||||
Tests present on a resource that does not exist.
|
||||
@ -191,7 +191,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
|
||||
exists = funcs['boto_vpc.resource_exists'](self.resource_type, 'test').get('exists')
|
||||
self.assertTrue(exists)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_present_when_resource_exists(self):
|
||||
vpc = self._create_vpc(name='test')
|
||||
resource = self._create_resource(vpc_id=vpc.id, name='test')
|
||||
@ -201,7 +201,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
|
||||
self.assertTrue(resource_present_result['result'])
|
||||
self.assertEqual(resource_present_result['changes'], {})
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
@skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493')
|
||||
def test_present_with_failure(self):
|
||||
vpc = self._create_vpc(name='test')
|
||||
@ -212,7 +212,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
|
||||
self.assertFalse(resource_present_result['result'])
|
||||
self.assertTrue('Mocked error' in resource_present_result['comment'])
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_absent_when_resource_does_not_exist(self):
|
||||
'''
|
||||
Tests absent on a resource that does not exist.
|
||||
@ -222,7 +222,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
|
||||
self.assertTrue(resource_absent_result['result'])
|
||||
self.assertEqual(resource_absent_result['changes'], {})
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_absent_when_resource_exists(self):
|
||||
vpc = self._create_vpc(name='test')
|
||||
self._create_resource(vpc_id=vpc.id, name='test')
|
||||
@ -234,7 +234,7 @@ class BotoVpcResourceTestCaseMixin(BotoVpcTestCaseMixin):
|
||||
exists = funcs['boto_vpc.resource_exists'](self.resource_type, 'test').get('exists')
|
||||
self.assertFalse(exists)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
@skipIf(True, 'Disabled pending https://github.com/spulec/moto/issues/493')
|
||||
def test_absent_with_failure(self):
|
||||
vpc = self._create_vpc(name='test')
|
||||
@ -272,6 +272,9 @@ class BotoVpcInternetGatewayTestCase(BotoVpcStateTestCaseBase, BotoVpcResourceTe
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
@skipIf(six.PY3, 'Disabled for Python 3 due to upstream bugs: '
|
||||
'https://github.com/spulec/moto/issues/548 and '
|
||||
'https://github.com/gabrielfalcao/HTTPretty/issues/325')
|
||||
@skipIf(HAS_BOTO is False, 'The boto module must be installed.')
|
||||
@skipIf(HAS_MOTO is False, 'The moto module must be installed.')
|
||||
@skipIf(_has_required_boto() is False, 'The boto module must be greater than'
|
||||
@ -282,7 +285,7 @@ class BotoVpcRouteTableTestCase(BotoVpcStateTestCaseBase, BotoVpcResourceTestCas
|
||||
backend_create = 'RouteTableBackend.create_route_table'
|
||||
backend_delete = 'RouteTableBackend.delete_route_table'
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_present_with_subnets(self):
|
||||
vpc = self._create_vpc(name='test')
|
||||
subnet1 = self._create_subnet(vpc_id=vpc.id, name='test1')
|
||||
@ -307,7 +310,7 @@ class BotoVpcRouteTableTestCase(BotoVpcStateTestCaseBase, BotoVpcResourceTestCas
|
||||
new_subnets = changes['new']['subnets_associations']
|
||||
self.assertEqual(new_subnets[0]['subnet_id'], subnet2.id)
|
||||
|
||||
@mock_ec2
|
||||
@mock_ec2_deprecated
|
||||
def test_present_with_routes(self):
|
||||
vpc = self._create_vpc(name='test')
|
||||
igw = self._create_internet_gateway(name='test', vpc_id=vpc.id)
|
||||
|
Loading…
Reference in New Issue
Block a user