mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix failing unit.states.boto_vpc_test.BotoVpcRouteTableTestCase.test_present_with_routes
This commit is contained in:
parent
7a7e36728f
commit
3424a108ac
2 changed files with 34 additions and 7 deletions
|
@ -8,10 +8,12 @@ from __future__ import absolute_import
|
|||
from distutils.version import LooseVersion # pylint: disable=import-error,no-name-in-module
|
||||
import pkg_resources
|
||||
from pkg_resources import DistributionNotFound
|
||||
import random
|
||||
import string
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting.unit import skipIf, TestCase
|
||||
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, patch
|
||||
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
@ -22,6 +24,7 @@ import salt.loader
|
|||
from salt.modules import boto_vpc
|
||||
from salt.exceptions import SaltInvocationError, CommandExecutionError
|
||||
from salt.modules.boto_vpc import _maybe_set_name_tag, _maybe_set_tags
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
|
||||
# Import 3rd-party libs
|
||||
import salt.ext.six as six
|
||||
|
@ -118,6 +121,9 @@ def _has_required_moto():
|
|||
return True
|
||||
|
||||
|
||||
context = {}
|
||||
|
||||
|
||||
@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.')
|
||||
|
@ -128,6 +134,19 @@ def _has_required_moto():
|
|||
class BotoVpcTestCaseBase(TestCase):
|
||||
def setUp(self):
|
||||
boto_vpc.__context__ = {}
|
||||
context.clear()
|
||||
# connections keep getting cached from prior tests, can't find the
|
||||
# correct context object to clear it. So randomize the cache key, to prevent any
|
||||
# cache hits
|
||||
conn_parameters['key'] = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(50))
|
||||
|
||||
self.patcher = patch('boto3.session.Session')
|
||||
self.addCleanup(self.patcher.stop)
|
||||
mock_session = self.patcher.start()
|
||||
|
||||
session_instance = mock_session.return_value
|
||||
self.conn3 = MagicMock()
|
||||
session_instance.client.return_value = self.conn3
|
||||
|
||||
|
||||
class BotoVpcTestCaseMixin(object):
|
||||
|
@ -165,7 +184,7 @@ class BotoVpcTestCaseMixin(object):
|
|||
if not self.conn:
|
||||
self.conn = boto.vpc.connect_to_region(region)
|
||||
|
||||
igw = self.conn.create_internet_gateway(vpc_id)
|
||||
igw = self.conn.create_internet_gateway()
|
||||
_maybe_set_name_tag(name, igw)
|
||||
_maybe_set_tags(tags, igw)
|
||||
return igw
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from distutils.version import LooseVersion # pylint: disable=import-error,no-name-in-module
|
||||
import random
|
||||
import string
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting.unit import skipIf, TestCase
|
||||
|
@ -15,6 +17,7 @@ ensure_in_syspath('../../')
|
|||
# Import Salt libs
|
||||
import salt.config
|
||||
import salt.loader
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
|
||||
# pylint: disable=import-error
|
||||
from unit.modules.boto_vpc_test import BotoVpcTestCaseMixin
|
||||
|
@ -86,6 +89,10 @@ def _has_required_boto():
|
|||
class BotoVpcStateTestCaseBase(TestCase):
|
||||
def setUp(self):
|
||||
ctx.clear()
|
||||
# connections keep getting cached from prior tests, can't find the
|
||||
# correct context object to clear it. So randomize the cache key, to prevent any
|
||||
# cache hits
|
||||
conn_parameters['key'] = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(50))
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
|
@ -299,11 +306,12 @@ class BotoVpcRouteTableTestCase(BotoVpcStateTestCaseBase, BotoVpcResourceTestCas
|
|||
vpc = self._create_vpc(name='test')
|
||||
igw = self._create_internet_gateway(name='test', vpc_id=vpc.id)
|
||||
|
||||
route_table_present_result = salt_states['boto_vpc.route_table_present'](
|
||||
name='test', vpc_name='test', routes=[{'destination_cidr_block': '0.0.0.0/0',
|
||||
'gateway_id': igw.id},
|
||||
{'destination_cidr_block': '10.0.0.0/24',
|
||||
'gateway_id': 'local'}])
|
||||
with patch.dict('salt.utils.boto.__salt__', funcs):
|
||||
route_table_present_result = salt_states['boto_vpc.route_table_present'](
|
||||
name='test', vpc_name='test', routes=[{'destination_cidr_block': '0.0.0.0/0',
|
||||
'gateway_id': igw.id},
|
||||
{'destination_cidr_block': '10.0.0.0/24',
|
||||
'gateway_id': 'local'}])
|
||||
routes = [x['gateway_id'] for x in route_table_present_result['changes']['new']['routes']]
|
||||
|
||||
self.assertEqual(set(routes), set(['local', igw.id]))
|
||||
|
|
Loading…
Add table
Reference in a new issue