예제 #1
0
    def test_context_bucket_name_is_overriden_but_is_none(self):
        config = Config({"namespace": "test", "stacker_bucket": ""})
        context = Context(config=config)
        self.assertEqual(context.bucket_name, None)

        config = Config({"namespace": "test", "stacker_bucket": None})
        context = Context(config=config)
        self.assertEqual(context.bucket_name, "stacker-test")
예제 #2
0
    def test_context_default_bucket_no_namespace(self):
        context = Context(config=Config({"namespace": ""}))
        self.assertEqual(context.bucket_name, None)

        context = Context(config=Config({"namespace": None}))
        self.assertEqual(context.bucket_name, None)

        context = Context(
            config=Config({"namespace": None, "stacker_bucket": ""}))
        self.assertEqual(context.bucket_name, None)
예제 #3
0
def mock_context(namespace="default", extra_config_args=None, **kwargs):
    config_args = {"namespace": namespace}
    if extra_config_args:
        config_args.update(extra_config_args)
    config = Config(config_args)
    if kwargs.get("environment"):
        return Context(
            config=config,
            **kwargs)
    return Context(
        config=config,
        environment={},
        **kwargs)
예제 #4
0
def generate_sample_k8s_cfn_repo(env_root):
    """Generate sample k8s infrastructure repo."""
    repo_dir = os.path.join(env_root, 'k8s-cfn-infrastructure')
    if os.path.isdir(repo_dir):
        LOGGER.error("Error generating sample repo -- directory %s "
                     "already exists!",
                     repo_dir)
        sys.exit(1)

    from runway.blueprints.k8s.k8s_master import Cluster
    from runway.blueprints.k8s.k8s_iam import Iam
    from runway.blueprints.k8s.k8s_workers import NodeGroup as WorkerNodeGroup

    shutil.copytree(
        os.path.join(ROOT,
                     'templates',
                     'k8s-cfn-repo'),
        repo_dir
    )
    os.rename(os.path.join(repo_dir, '_gitignore'),
              os.path.join(repo_dir, '.gitignore'))

    # Generate masters CFN templates from blueprints
    master_template_dir = os.path.join(repo_dir, 'k8s-master.cfn', 'templates')
    os.mkdir(master_template_dir)
    with open(os.path.join(master_template_dir, 'k8s_iam.yaml'), 'w') as stream:
        stream.write(to_yaml(Iam('test',
                                 Context({"namespace": "test"}),
                                 None).to_json()))
    with open(os.path.join(master_template_dir, 'k8s_master.yaml'), 'w') as stream:
        stream.write(to_yaml(Cluster('test',
                                     Context({"namespace": "test"}),
                                     None).to_json()))

    # Generate workers CFN template from blueprint
    worker_template_dir = os.path.join(repo_dir,
                                       'k8s-workers.cfn',
                                       'templates')
    os.mkdir(worker_template_dir)
    with open(os.path.join(worker_template_dir,
                           'k8s_workers.yaml'), 'w') as stream:
        stream.write(to_yaml(WorkerNodeGroup('test',
                                             Context({"namespace": "test"}),
                                             None).to_json()))

    LOGGER.info("Sample k8s infrastructure repo created at %s",
                repo_dir)
    LOGGER.info('(see its README for setup and deployment instructions)')
예제 #5
0
 def setUp(self):
     self.context = Context({'namespace': 'namespace'})
     self.context.config = {
         'stacks': [
             {
                 'name': 'vpc'
             },
             {
                 'name': 'bastion',
                 'requires': ['vpc']
             },
             {
                 'name': 'instance',
                 'requires': ['vpc', 'bastion']
             },
             {
                 'name': 'db',
                 'requires': ['instance', 'vpc', 'bastion']
             },
             {
                 'name': 'other',
                 'requires': ['db']
             },
         ],
     }
     self.action = destroy.Action(self.context, provider=mock.MagicMock())
예제 #6
0
 def test_context_optional_keys_set(self):
     context = Context(
         config=Config({}),
         stack_names=["stack"],
     )
     self.assertEqual(context.mappings, {})
     self.assertEqual(context.stack_names, ["stack"])
예제 #7
0
파일: e2e.py 프로젝트: aarongorka/ebs-pin
def construct_context(subnet_id):
    config_dict = {
        "namespace": "",
        "namespace_delimiter": "",
        "stacker_bucket": "",
        "bucket_region": "ap-southeast-2",
        "region": "ap-southeast-2",
        "stacks": [
            {
                "name": "ebs-pin-test",
                "template_path": "./e2e/cloudformation.yml",
                "variables": {
                    "AvailabilityZone": "ap-southeast-2a",
                    "AMI": ami,
                    "VpcId": vpc_id,
                    "Subnets": subnet_id,
                    "KeyName": "id_rsa"
                },
                "tags": {
                    "Name": "ebs-pin-test"
                }
            }
        ]
    }
    config = Config(config_dict)
    context = Context(config=config)
    return context
예제 #8
0
 def setUp(self):
     config = Config({
         "namespace":
         "namespace",
         "stacks": [
             {
                 "name": "vpc"
             },
             {
                 "name": "bastion",
                 "requires": ["vpc"]
             },
             {
                 "name": "instance",
                 "requires": ["vpc", "bastion"]
             },
             {
                 "name": "db",
                 "requires": ["instance", "vpc", "bastion"]
             },
             {
                 "name": "other",
                 "requires": ["db"]
             },
         ],
     })
     self.context = Context(config=config)
     self.action = destroy.Action(self.context, provider=mock.MagicMock())
예제 #9
0
    def test_s3_static_website(self):
        """Test a static website blog bucket."""
        ctx = Context(config=Config({'namespace': 'test'}))
        blueprint = Buckets('s3_static_website', ctx)

        v = self.variables = [
            Variable(
                'Buckets', {
                    'Blog': {
                        'AccessControl': 'PublicRead',
                        'WebsiteConfiguration': {
                            'IndexDocument': 'index.html'
                        }
                    },
                }),
            Variable('ReadRoles', [
                'Role1',
                'Role2',
            ]),
            Variable('ReadWriteRoles', [
                'Role3',
                'Role4',
            ]),
        ]

        blueprint.resolve_variables(v)
        blueprint.create_template()
        self.assertRenderedBlueprint(blueprint)
예제 #10
0
 def setUp(self):
     self.provider = MagicMock()
     self.context = Context(
         environment={
             'namespace': 'test',
             'env_var': 'val_in_env'}
     )
예제 #11
0
 def setUp(self):
     self.sd = {"name": "test"}
     self.context = Context({"namespace": "namespace"})
     self.stack = Stack(
         definition=generate_definition("vpc", 1),
         context=self.context,
     )
예제 #12
0
 def test_dynamodb_autoscaling(self):
     ctx = Context({'namespace': 'test', 'environment': 'test'})
     blueprint = stacker_blueprints.dynamodb.AutoScaling(
         'dynamodb_autoscaling', ctx)
     blueprint.resolve_variables(self.dynamodb_autoscaling_variables)
     blueprint.create_template()
     self.assertRenderedBlueprint(blueprint)
예제 #13
0
 def setUp(self):
     config = Config({
         "namespace":
         "namespace",
         "stacks": [
             {
                 "name": "vpc"
             },
             {
                 "name": "bastion",
                 "requires": ["vpc"]
             },
             {
                 "name": "instance",
                 "requires": ["vpc", "bastion"]
             },
             {
                 "name": "db",
                 "requires": ["instance", "vpc", "bastion"]
             },
             {
                 "name": "other",
                 "requires": ["db"]
             },
         ],
     })
     self.context = Context(config=config)
     self.action = destroy.Action(self.context, cancel=MockThreadingEvent())
예제 #14
0
 def setUp(self):
     self.sd = {"name": "test"}
     self.context = Context({'namespace': 'namespace'})
     self.stack = Stack(
         definition=generate_definition('vpc', 1),
         context=self.context,
     )
예제 #15
0
def generate_tfstate_cfn_template():
    """Return rendered CFN template yaml."""
    from runway.blueprints.tf_state import TfState

    return to_yaml(TfState('test',
                           Context({"namespace": "test"}),
                           None).to_json())
예제 #16
0
파일: factories.py 프로젝트: nynhex/stacker
def mock_context(namespace=None, **kwargs):
    config = Config({"namespace": namespace})
    environment = kwargs.get("environment", {})
    return Context(
        config=config,
        environment=environment,
        **kwargs)
예제 #17
0
 def setUp(self):
     self.ctx = Context(config=Config({'namespace': 'test'}))
     self.common_variables = {
         "VpcId": "vpc-abc1234",
         "VpcDefaultSecurityGroup": "sg-01234abc",
         "AvailabilityZone": "us-east-1a",
         "CidrBlock": "10.0.0.0/24",
     }
예제 #18
0
 def setUp(self):
     self.sd = {"name": "test"}
     self.config = Config({"namespace": "namespace"})
     self.context = Context(config=self.config)
     self.stack = Stack(
         definition=generate_definition("vpc", 1),
         context=self.context,
     )
     register_lookup_handler("noop", lambda **kwargs: "test")
예제 #19
0
    def setUp(self):
        self.common_variables = [
            Variable("Instances",
                     {"MyInstance": {
                         "ImageId": "ami-abc12345",
                     }})
        ]

        self.ctx = Context({'namespace': 'test', 'environment': 'test'})
예제 #20
0
 def _get_context(self, **kwargs):
     config = {"stacks": [
         {"name": "vpc"},
         {"name": "bastion", "parameters": {"test": "vpc::something"}},
         {"name": "db", "parameters": {"test": "vpc::something",
                                       "else": "bastion::something"}},
         {"name": "other", "parameters": {}}
     ]}
     return Context({"namespace": "namespace"}, config=config, **kwargs)
예제 #21
0
 def setUp(self):
     self.ctx = Context(config=Config({'namespace': 'test'}))
     self.common_variables = {
         "VPC": {
             VPC_NAME: {
                 "CidrBlock": "10.0.0.0/16"
             }
         }
     }
예제 #22
0
 def setUp(self):
     self.context = Context({"namespace": "namespace"})
     stack = Stack(
         definition=generate_definition("vpc", 1),
         context=self.context,
     )
     self.step = Step(
         stack=stack,
         run_func=lambda x, y: (x, y),
     )
예제 #23
0
    def setUp(self):
        self.common_variables = [
            Variable(
                "SecurityGroups",
                {"MySG1": {
                    "GroupDescription": "My first SecurityGroup",
                }})
        ]

        self.ctx = Context({'namespace': 'test', 'environment': 'test'})
예제 #24
0
 def _get_context(self, **kwargs):
     config = Config({
         "namespace": "namespace",
         "stacks": [
             {"name": "vpc"},
             {"name": "bastion",
              "variables": {"test": "${output vpc::something}"}},
             {"name": "db",
              "variables": {"test": "${output vpc::something}",
                            "else": "${output bastion::something}"}},
             {"name": "other", "variables": {}}
         ]
     })
     return Context(config=config, **kwargs)
예제 #25
0
 def setUp(self):
     self.code = Code(S3Bucket="test_bucket", S3Key="code_key")
     self.common_variables = {
         "Code": self.code,
         "DeadLetterArn": "arn:aws:sqs:us-east-1:12345:dlq",
         "Description": "Test function.",
         "Environment": {
             "Env1": "Value1"
         },
         "Handler": "handler",
         "KmsKeyArn": "arn:aws:kms:us-east-1:12345:key",
         "MemorySize": 128,
         "Runtime": "python2.7",
         "Timeout": 3,
     }
     self.ctx = Context(config=Config({'namespace': 'test'}))
예제 #26
0
    def setUp(self):
        self.context = Context(config=Config({
            'namespace': 'test',
            'stacker_bucket': 'test'
        }))
        self.provider = mock_provider(region="us-east-1")

        self.mock_process = MockProcess()
        self.popen_mock = \
            mock.patch('stacker.hooks.command.Popen',
                       return_value=self.mock_process).start()

        self.devnull = mock.Mock()
        self.devnull_mock = \
            mock.patch('stacker.hooks.command._devnull',
                       return_value=self.devnull).start()
예제 #27
0
 def test_hook_with_sys_path(self):
     config = Config({
         "namespace": "test",
         "sys_path": "stacker/tests",
         "pre_build": [
             {
                 "data_key": "myHook",
                 "path": "fixtures.mock_hooks.mock_hook",
                 "required": True,
                 "args": {
                     "value": "mockResult"}}]})
     load(config)
     context = Context(config=config)
     stage = "pre_build"
     handle_hooks(stage, context.config[stage], "mock-region-1", context)
     self.assertEqual("mockResult", context.hook_data["myHook"]["result"])
예제 #28
0
 def test_Raises_StackDoesNotExist_from_lookup_non_included_stack(self):
     # This test is testing the specific scenario listed in PR 466
     # Because the issue only threw a KeyError when a stack was missing
     # in the `--stacks` flag at runtime of a `stacker build` run
     # but needed for an output lookup in the stack specified
     mock_provider = mock.MagicMock()
     context = Context(config=Config({
         "namespace": "namespace",
         "stacks": [
             {"name": "bastion",
              "variables": {"test": "${output vpc::something}"}
              }]
     }))
     build_action = build.Action(context, provider=mock_provider)
     with self.assertRaises(StackDoesNotExist):
         build_action._generate_plan()
예제 #29
0
    def setUp(self):
        self.common_variables = {
            "ServiceName": "WorkerService",
            "Image": "fake_repo/image:12345",
            "Command": ["/bin/run", "--args 1"],
            "Cluster": "fake-fargate-cluster",
            "CPU": 1024,
            "Memory": 2048,
            "Count": 3,
            "Environment": {
                "DATABASE_URL": "sql://fake_db/fake_db",
                "DEBUG": "false",
            },
        }

        self.ctx = Context({'namespace': 'test', 'environment': 'test'})
예제 #30
0
            def __call__(self):
                # Use the context property of the baseclass, if present.
                # If not, default to a basic context.
                try:
                    ctx = self.context
                except AttributeError:
                    ctx = Context(config=self.config,
                                  environment={'environment': 'test'})

                configvars = self.stack.variables or {}
                variables = [Variable(k, v) for k, v in configvars.iteritems()]

                blueprint_class = load_object_from_string(
                    self.stack.class_path)
                blueprint = blueprint_class(self.stack.name, ctx)
                blueprint.resolve_variables(variables or [])
                blueprint.setup_parameters()
                blueprint.create_template()
                self.assertRenderedBlueprint(blueprint)