예제 #1
0
class TestContainerDefinition_terraform_statefile_interpolation(unittest.TestCase):

    def setUp(self):
        current_dir = os.path.dirname(os.path.abspath(__file__))
        config_yml = os.path.join(current_dir, 'terraform_interpolate.yml')
        with Replacer() as r:
            self.get_mock = r('deployfish.terraform.Terraform._get_state_file_from_s3', Mock())
            self.get_mock.side_effect = statefile_loader
            self.config = Config(filename=config_yml)

    def test_environment_gets_replaced_for_each_environment(self):
        calls = [
            call('s3://my-qa-statefile', profile=None, region=None),
            call('s3://my-prod-statefile', profile=None, region=None),
        ]
        self.get_mock.assert_has_calls(calls)

    def test_file_interpolation_gets_values_from_correct_statefile(self):
        prod = self.config.get_section_item('services', 'foobar-prod')
        self.assertEqual(prod['cluster'], 'foobar-cluster-prod')
        self.assertEqual(prod['load_balancer']['load_balancer_name'], 'foobar-prod-elb')
        self.assertEqual(prod['task_role_arn'], 'arn:aws:iam::324958023459:role/foobar-prod-task')
        qa = self.config.get_section_item('services', 'foobar-qa')
        self.assertEqual(qa['cluster'], 'foobar-cluster-qa')
        self.assertEqual(qa['load_balancer']['load_balancer_name'], 'foobar-qa-elb')
        self.assertEqual(qa['task_role_arn'], 'arn:aws:iam::324958023459:role/foobar-qa-task')
예제 #2
0
def _entrypoint(ctx, section, section_name, cluster_name, parameter_prefix,
                command, dry_run):
    if section_name and cluster_name:
        # The only thing we need out of Config is the names of any config:
        # section variables we might have.  We don't need to do interpolation
        # in the config: section, because we retrieve the values from Parameter
        # Store, and we don't want to use any aws: section that might be in the
        # deployfish.yml to configure our boto3 session because we want to defer
        # to the IAM ECS Task Role.
        config = Config(filename=ctx.obj['CONFIG_FILE'],
                        interpolate=False,
                        use_aws_section=False)
        try:
            section_yml = config.get_section_item(section, section_name)
        except KeyError:
            click.echo(
                "Our container's deployfish config file '{}' does not have section '{}' in '{}'"
                .format(ctx.obj['CONFIG_FILE'] or 'deployfish.yml',
                        section_name, section))
            sys.exit(1)
        parameter_store = []
        if 'config' in section_yml:
            parameter_name = parameter_prefix + section_name
            parameter_store = ParameterStore(parameter_name,
                                             cluster_name,
                                             yml=section_yml['config'])
            parameter_store.populate()
        if not dry_run:
            for param in parameter_store:
                if param.exists:
                    if param.should_exist:
                        os.environ[param.key] = param.aws_value
                    else:
                        print(
                            "event='deploy.entrypoint.parameter.ignored.not_in_deployfish_yml' "
                            "section='{}' parameter='{}'".format(
                                section_name, param.name))
                else:
                    print(
                        "event='deploy.entrypoint.parameter.ignored.not_in_aws' section='{}' parameter='{}'"
                        .format(section_name, param.name))
        else:
            exists = []
            not_exists = []
            for param in parameter_store:
                if param.exists:
                    exists.append(param)
                else:
                    not_exists.append(param)
            click.secho("Would have set these environment variables:",
                        fg="cyan")
            for param in exists:
                click.echo('  {}={}'.format(param.key, param.aws_value))
            click.secho("\nThese parameters are not in AWS:", fg="red")
            for param in not_exists:
                click.echo('  {}'.format(param.key))
    if dry_run:
        click.secho('\n\nCOMMAND: {}'.format(command))
    else:
        subprocess.call(command)
예제 #3
0
class TestTunnelParameters_load_yaml(unittest.TestCase):

    def setUp(self):
        current_dir = os.path.dirname(os.path.abspath(__file__))
        config_yml = os.path.join(current_dir, 'interpolate.yml')
        env_file = os.path.join(current_dir, 'env_file.env')
        self.config = Config(filename=config_yml, env_file=env_file, interpolate=False)

    def test_tunnel_find_instance(self):
        yml = self.config.get_section_item('tunnels', 'test')
        self.assertEqual(yml['service'], 'foobar-prod')
        self.assertEqual(yml['host'], 'config.DB_HOST')
        self.assertEqual(yml['port'], 3306)
        self.assertEqual(yml['local_port'], 8888)