Exemplo n.º 1
0
def stack_auto_complete(ctx, args, incomplete):
    """Autocomplete for --stack

    By default, returns qualified names start with qualified stack

    """
    import argparse
    # use argparse to extract config file name
    parser = argparse.ArgumentParser()
    parser.add_argument('--file', '-f', default=None)
    (namespace, remain) = parser.parse_known_args(args)
    config_filename = find_default_config(namespace.file)

    try:
        deployments = load_config(config_filename)
    except ConfigError as e:
        # ignore any config parsing errors
        return list()

    # get a sorted list of qualified names

    stack_names = sorted(d.stack_key.qualified_name
                         for d in deployments.query_stacks())

    # remove meta chars
    incomplete = incomplete.lower().translate({'*': '', '?': ''})
    return list((s.stack_key.qualified_name, s.parameters.StackName)
                for s in deployments.query_stacks()
                if s.stack_key.qualified_name.lower().startswith(incomplete))
Exemplo n.º 2
0
    def test_minium_config(self, data_dir):
        configfile = data_dir.join('data/test.config.minimum.yaml')
        c = config.load_config(configfile)
        assert c is not None

        stack = c.get_stack('Dev', 'Vpc')
        assert 'Vpc' == stack.parameters.StackName
        assert data_dir.join('data/test.template.yaml') == \
               stack.parameters.Template
Exemplo n.º 3
0
    def test_simple_stack_with_stack_name(self, data_dir):
        configfile = data_dir.join('data/test.config.general.yaml')
        c = config.load_config(configfile)

        stack = c.get_stack('Staging', 'Vpc1')

        assert stack.profile.Region == 'us-east-1'
        assert stack.profile.Profile == 'bob'
        assert stack.parameters.StackName == 'StackNameOfVpc1'
        assert stack.parameters.Template == data_dir.join(
            'data/test.template.yaml')
        assert stack.parameters.Tags['key1'] == 'value1'
        assert stack.parameters.Tags['key2'] == 'value2'
Exemplo n.º 4
0
    def test_config_with_stages(self, data_dir):
        configfile = data_dir.join('data/test.config.stages.yaml')
        c = config.load_config(configfile)
        assert c is not None

        stack1 = c.get_stack('Staging', 'Vpc')
        assert stack1 is not None

        stack1 = c.get_stack('Staging1', 'Vpc')
        assert stack1 is not None

        stack1 = c.get_stack('Production', 'Vpc1')
        assert stack1 is not None
        stack1 = c.get_stack('Production', 'Vpc2')
        assert stack1 is not None
Exemplo n.º 5
0
    def test_query_stacks_with_extends(self, data_dir):
        configfile = data_dir.join('data/test.config.extends.yaml')
        c = config.load_config(configfile)

        stacks = c.query_stacks('*', '*')
        assert len(stacks) == 3
        stack_keys = list(s.stack_key for s in stacks)
        assert StackKey(StageKey='Prod', StackKey='Vpc0') in stack_keys
        assert StackKey(StageKey='Staging', StackKey='Vpc0') in stack_keys
        assert StackKey(StageKey='Staging', StackKey='Vpc1') in stack_keys

        stacks = c.query_stacks('Prod', '*')
        assert len(stacks) == 1
        stack_keys = list(s.stack_key for s in stacks)
        assert StackKey(StageKey='Prod', StackKey='Vpc0') in stack_keys

        stacks = c.query_stacks('*', 'Vpc1')
        assert len(stacks) == 1
        stack_keys = list(s.stack_key for s in stacks)
        assert StackKey(StageKey='Staging', StackKey='Vpc1') in stack_keys
Exemplo n.º 6
0
    def test_config_with_extend(self, data_dir):
        configfile = data_dir.join('data/test.config.extends.yaml')
        c = config.load_config(configfile)

        stack = c.get_stack('Staging', 'Vpc0')

        assert stack.profile.Region == 'cn-east-1'
        assert stack.profile.Profile == 'ray'
        assert stack.parameters.StackName == 'Vpc0'
        assert stack.parameters.Template == data_dir.join(
            'data/test.template.yaml')
        assert stack.parameters.Capabilities == ['CAPABILITY_NAMED_IAM']
        assert stack.parameters.Tags['Environment'] == 'staging'
        assert stack.parameters.Tags['Project'] == 'demo'
        assert stack.parameters.Tags['Test'] == 'test'
        assert len(stack.parameters.Tags) == 3

        stack = c.get_stack('Staging', 'Vpc1')

        assert stack.profile.Region == 'us-east-1'
        assert stack.profile.Profile == 'ray'
        assert stack.parameters.StackName == 'Vpc1'
        assert stack.parameters.Template == data_dir.join(
            'data/test.template.yaml')
        assert stack.parameters.Capabilities == ['CAPABILITY_IAM']
        assert stack.parameters.Tags['Environment'] == 'dev'
        assert stack.parameters.Tags['Project'] == 'dummy'
        assert len(stack.parameters.Tags) == 2

        stack = c.get_stack('Prod', 'Vpc0')

        assert stack.profile.Region == 'cn-east-1'
        assert stack.profile.Profile == 'ray'
        assert stack.parameters.StackName == 'Vpc0'
        assert stack.parameters.Template == data_dir.join(
            'data/test.template.yaml')
        assert stack.parameters.Capabilities == ['CAPABILITY_IAM']
        assert stack.parameters.Tags['Environment'] == 'prod'
        assert stack.parameters.Tags['Project'] == 'test'
        assert len(stack.parameters.Tags) == 2
Exemplo n.º 7
0
    def test_output_reference(self, data_dir):
        configfile = data_dir.join('data/test.config.reference.yaml')
        c = config.load_config(configfile)

        stacks = c.query_stacks('*', '*')
        assert len(stacks) == 3
Exemplo n.º 8
0
    def test_query_stacks(self, data_dir):
        configfile = data_dir.join('data/test.config.stages.yaml')
        c = config.load_config(configfile)

        stacks = c.query_stacks('*', '*')
        assert len(stacks) == 4
Exemplo n.º 9
0
 def parse_config(config_filename):
     """Parse configuration file from options."""
     return load_config(config_filename)