How to use the runway.context.Context function in runway

To help you get started, we’ve selected a few runway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onicagroup / runway / tests / test_context.py View on Github external
def test_init(self, tmp_path):
        """Test init process."""
        env_name = 'test'
        env_region = 'us-east-1'
        env_root = str(tmp_path)
        config_file = tmp_path / 'config'
        config_file.write_text(u'[profile test]\n'
                               'aws_access_key_id = bar\n'
                               'aws_secret_access_key = foo')

        with environ(dict(AWS_PROFILE='test', **TEST_CREDENTIALS)):
            env_vars = os.environ.copy()
            env_vars['DEPLOY_ENVIRONMENT'] = env_name

            ctx = Context(env_name, env_region, env_root)
            assert not ctx.command
            assert not ctx.debug
            assert ctx.env_name == env_name
            assert ctx.env_region == env_region
            assert ctx.env_root == env_root
            assert sorted(ctx.env_vars) == sorted(env_vars)

        with environ({'AWS_PROFILE': 'test', 'AWS_CONFIG_FILE': str(config_file)}):
            os.environ.pop('AWS_ACCESS_KEY_ID', None)
            os.environ.pop('AWS_SECRET_ACCESS_KEY', None)
            os.environ.pop('AWS_SESSION_TOKEN', None)

            env_vars = os.environ.copy()
            env_vars['DEPLOY_ENVIRONMENT'] = env_name

            ctx = Context(env_name, env_region, env_root)
github onicagroup / runway / tests / test_context.py View on Github external
def test_account_id(self, monkeypatch):
        """Test account_id."""
        account_id = '123456789012'
        client = boto3.client('sts')
        stubber = Stubber(client)
        mock_session = MockBoto3Session(clients={'sts.us-east-1': client},
                                        region_name='us-east-1')
        monkeypatch.setattr(Context, 'get_session', lambda self_: mock_session)
        context = Context(env_name='test',
                          env_region='us-east-1',
                          env_root='./',
                          env_vars={})

        stubber.add_response(method='get_caller_identity',
                             service_response={'UserId': 'test-user',
                                               'Account': account_id,
                                               'Arn': 'arn:aws:iam::{}:'
                                                      'user/test-user'
                                                      .format(account_id)})

        with stubber as stub:
            assert context.account_id == account_id
        stub.assert_no_pending_responses()
github onicagroup / runway / tests / test_context.py View on Github external
def test_max_concurrent_modules(self):
        """Test max_concurrent_modules."""
        context = Context(env_name='test',
                          env_region='us-east-1',
                          env_root='./',
                          env_vars={'RUNWAY_MAX_CONCURRENT_MODULES': '1'})
        assert context.max_concurrent_modules == 1

        del context.env_vars['RUNWAY_MAX_CONCURRENT_MODULES']

        with patch('runway.context.multiprocessing.cpu_count') as cpu_count:
            cpu_count.return_value = 8
            assert context.max_concurrent_modules == 8
github onicagroup / runway / tests / test_context.py View on Github external
def test_use_concurrent(self):
        """Test use_concurrent."""
        from runway.context import sys
        context = Context(env_name='test',
                          env_region='us-east-1',
                          env_root='./',
                          env_vars={'NON_EMPTY': '1'})
        context_ci = Context(env_name='test',
                             env_region='us-east-1',
                             env_root='./',
                             env_vars={'CI': '1'})

        with patch.object(sys, 'version_info') as version_info:
            version_info.major = 2
            assert not context.use_concurrent
            assert not context_ci.use_concurrent

        with patch.object(sys, 'version_info') as version_info:
            version_info.major = 3
            assert not context.use_concurrent
github onicagroup / runway / tests / cfngin / test_cfngin.py View on Github external
def get_context(name='test', region='us-east-1'):
        """Create a basic Runway context object."""
        return Context(env_name=name,
                       env_region=region,
                       env_root=os.getcwd())
github onicagroup / runway / tests / test_context.py View on Github external
def test_use_concurrent(self):
        """Test use_concurrent."""
        from runway.context import sys
        context = Context(env_name='test',
                          env_region='us-east-1',
                          env_root='./',
                          env_vars={'NON_EMPTY': '1'})
        context_ci = Context(env_name='test',
                             env_region='us-east-1',
                             env_root='./',
                             env_vars={'CI': '1'})

        with patch.object(sys, 'version_info') as version_info:
            version_info.major = 2
            assert not context.use_concurrent
            assert not context_ci.use_concurrent

        with patch.object(sys, 'version_info') as version_info:
            version_info.major = 3
            assert not context.use_concurrent
            assert context_ci.use_concurrent
github onicagroup / runway / tests / test_context.py View on Github external
def test_echo_detected_environment_not_env(self, caplog):
        """Environment helper note when DEPLOY_ENVIRONMENT is not set."""
        context = Context(env_name='test', env_region='us-east-1',
                          env_root='./')
        expected = ['',
                    'Environment "test" was determined from the '
                    'current git branch or parent directory.',
                    'If this is not the environment name, update '
                    'the branch/folder name or set an override value via the '
                    'DEPLOY_ENVIRONMENT environment variable',
                    '']

        with caplog.at_level(logging.INFO):
            context.echo_detected_environment()

        assert [rec.message for rec in caplog.records] == expected
github onicagroup / runway / tests / test_context.py View on Github external
def test_is_noninteractive(self):
        """Test is_noninteractive."""
        context = Context(env_name='test',
                          env_region='us-east-1',
                          env_root='./',
                          env_vars={'NON_EMPTY': '1'})
        assert not context.is_noninteractive

        context.env_vars['CI'] = '1'
        assert context.is_noninteractive
github onicagroup / runway / runway / commands / env.py View on Github external
def run(self, deployments=None, command='plan'):  # noqa pylint: disable=too-many-branches,too-many-statements
        """Execute apps/code command."""
        if deployments is None:
            deployments = self.runway_config['deployments']
        context = Context(options=self.options,
                          env_name=get_env(
                              self.env_root,
                              self.runway_config.get('ignore_git_branch',
                                                     False)
                          ),
                          env_region=None,
                          env_root=self.env_root,
                          env_vars=os.environ.copy())
        if command == 'destroy':
            LOGGER.info('WARNING!')
            LOGGER.info('Runway is running in DESTROY mode.')
        if context.env_vars.get('CI', None):
            if command == 'destroy':
                deployments_to_run = self.reverse_deployments(deployments)
            else:
                deployments_to_run = deployments