Ejemplo n.º 1
0
 def test_stacker_build_parse_args_region_from_env(self):
     stacker = Stacker()
     args = stacker.parse_args([
         "build", "-e", "namespace=test.override",
         "stacker/tests/fixtures/basic.env",
         "stacker/tests/fixtures/vpc-bastion-db-web.yaml"
     ])
     self.assertEqual(args.region, None)
Ejemplo n.º 2
0
 def test_stacker_build_fail_when_parameters_in_stack_def(self):
     stacker = Stacker()
     args = stacker.parse_args([
         "build", "-r", "us-west-2", "stacker/tests/fixtures/basic.env",
         "stacker/tests/fixtures/vpc-bastion-db-web-pre-1.0.yaml"
     ])
     with self.assertRaises(InvalidConfig):
         stacker.configure(args)
Ejemplo n.º 3
0
 def test_stacker_build_fail_when_parameters_in_stack_def(self):
     stacker = Stacker()
     args = stacker.parse_args([
         "build", "-r", "us-west-2", "stacker/tests/fixtures/basic.env",
         "stacker/tests/fixtures/vpc-bastion-db-web-pre-1.0.yaml"
     ])
     stacker.configure(args)
     with self.assertRaises(AttributeError):
         args.context.get_stacks_dict()
Ejemplo n.º 4
0
 def test_stacker_build_parse_args_region_from_env(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ["build",
          "-e", "namespace=test.override",
          "stacker/tests/fixtures/basic.env",
          "stacker/tests/fixtures/vpc-bastion-db-web.yaml"]
     )
     self.assertEqual(args.region, None)
Ejemplo n.º 5
0
 def test_stacker_build_context_stack_names_specified(self):
     stacker = Stacker()
     args = stacker.parse_args([
         "build", "-r", "us-west-2", "stacker/tests/fixtures/basic.env",
         "stacker/tests/fixtures/vpc-bastion-db-web.yaml", "--stacks",
         "vpc", "--stacks", "bastion"
     ])
     stacker.configure(args)
     stacks = args.context.get_stacks()
     self.assertEqual(len(stacks), 2)
Ejemplo n.º 6
0
 def test_stacker_build_fail_when_parameters_in_stack_def(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ["build",
          "-r", "us-west-2",
          "stacker/tests/fixtures/basic.env",
          "stacker/tests/fixtures/vpc-bastion-db-web-pre-1.0.yaml"]
     )
     with self.assertRaises(InvalidConfig):
         stacker.configure(args)
Ejemplo n.º 7
0
 def test_stacker_blueprint_property_access_does_not_reset_blueprint(self):
     stacker = Stacker()
     args = stacker.parse_args([
         "build", "-r", "us-west-2", "stacker/tests/fixtures/basic.env",
         "stacker/tests/fixtures/vpc-bastion-db-web.yaml"
     ])
     stacker.configure(args)
     stacks_dict = args.context.get_stacks_dict()
     bastion_stack = stacks_dict[args.context.get_fqn("bastion")]
     bastion_stack.blueprint.render_template()
     self.assertIn("DefaultSG", bastion_stack.blueprint.template.parameters)
Ejemplo n.º 8
0
 def test_stacker_build_custom_info_log_format(self):
     stacker = Stacker()
     args = stacker.parse_args([
         "build", "-r", "us-west-2", "stacker/tests/fixtures/not-basic.env",
         "stacker/tests/fixtures/vpc-custom-log-format-info.yaml"
     ])
     stacker.configure(args)
     self.assertEqual(stacker.config.log_formats["info"],
                      '[%(asctime)s] test custom log format - %(message)s')
     self.assertIsNone(stacker.config.log_formats.get("color"))
     self.assertIsNone(stacker.config.log_formats.get("debug"))
Ejemplo n.º 9
0
 def test_stacker_build_parse_args(self):
     stacker = Stacker()
     args = stacker.parse_args([
         "build", "-r", "us-west-2", "-e", "namespace=test.override",
         "stacker/tests/fixtures/basic.env",
         "stacker/tests/fixtures/vpc-bastion-db-web.yaml"
     ])
     self.assertEqual(args.region, "us-west-2")
     self.assertFalse(args.outline)
     # verify namespace was modified
     self.assertEqual(args.environment["namespace"], "test.override")
Ejemplo n.º 10
0
 def test_stacker_build_context_stack_names_specified(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ['build', '-p', 'BaseDomain=mike.com', '-r', 'us-west-2', '-p',
          'AZCount=2', '-p', 'CidrBlock=10.128.0.0/16',
          'stacker/tests/fixtures/basic.env',
          'stacker/tests/fixtures/vpc-bastion-db-web.yaml', '--stacks',
          'vpc', '--stacks', 'bastion']
     )
     stacker.configure(args)
     stacks = args.context.get_stacks()
     self.assertEqual(len(stacks), 2)
Ejemplo n.º 11
0
 def test_stacker_build_context_stack_names_specified(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ["build", "-p", "BaseDomain=mike.com", "-r", "us-west-2", "-p",
          "AZCount=2", "-p", "CidrBlock=10.128.0.0/16",
          "stacker/tests/fixtures/basic.env",
          "stacker/tests/fixtures/vpc-bastion-db-web.yaml", "--stacks",
          "vpc", "--stacks", "bastion"]
     )
     stacker.configure(args)
     stacks = args.context.get_stacks()
     self.assertEqual(len(stacks), 2)
Ejemplo n.º 12
0
 def test_stacker_build_parse_args(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ["build",
          "-r", "us-west-2",
          "-e", "namespace=test.override",
          "stacker/tests/fixtures/basic.env",
          "stacker/tests/fixtures/vpc-bastion-db-web.yaml"]
     )
     self.assertEqual(args.region, "us-west-2")
     self.assertFalse(args.outline)
     # verify namespace was modified
     self.assertEqual(args.environment["namespace"], "test.override")
Ejemplo n.º 13
0
 def test_stacker_blueprint_property_access_does_not_reset_blueprint(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ["build",
          "-r", "us-west-2",
          "stacker/tests/fixtures/basic.env",
          "stacker/tests/fixtures/vpc-bastion-db-web.yaml"]
     )
     stacker.configure(args)
     stacks_dict = args.context.get_stacks_dict()
     bastion_stack = stacks_dict[args.context.get_fqn("bastion")]
     bastion_stack.blueprint.render_template()
     self.assertIn("DefaultSG", bastion_stack.blueprint.template.parameters)
Ejemplo n.º 14
0
 def test_stacker_build_context_stack_names_specified(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ["build",
          "-r", "us-west-2",
          "stacker/tests/fixtures/basic.env",
          "stacker/tests/fixtures/vpc-bastion-db-web.yaml",
          "--stacks", "vpc",
          "--stacks", "bastion"]
     )
     stacker.configure(args)
     stacks = args.context.get_stacks()
     self.assertEqual(len(stacks), 2)
Ejemplo n.º 15
0
 def test_stacker_build_context_stack_names_specified(self):
     stacker = Stacker()
     parser = argparse.ArgumentParser(description=stacker.description)
     stacker.add_subcommands(parser)
     args = parser.parse_args(
         ['build', '-p', 'BaseDomain=mike.com', '-r', 'us-west-2', '-p',
          'AZCount=2', '-p', 'CidrBlock=10.128.0.0/16', 'stacker-test',
          'stacker/tests/fixtures/vpc-bastion-db-web.yaml', '--stacks',
          'vpc', '--stacks', 'bastion']
     )
     stacker.configure(args)
     stacks = args.context.get_stacks()
     self.assertEqual(len(stacks), 2)
Ejemplo n.º 16
0
 def test_stacker_build_context_single_stack_specified(self):
     # Added the below test that is similar to the
     # test_stacker_build_context_stack_names_specified test because
     # someone could break stacks lookup flags but still get back 2 stacks
     # with the assertEquil to 2. Now we also check for assertEquil to 1
     stacker = Stacker()
     args = stacker.parse_args([
         "build", "-r", "us-west-2", "stacker/tests/fixtures/basic.env",
         "stacker/tests/fixtures/vpc-bastion-db-web.yaml", "--stacks", "vpc"
     ])
     stacker.configure(args)
     stacks = args.context.get_stacks()
     self.assertEqual(len(stacks), 1)
Ejemplo n.º 17
0
 def test_stacker_blueprint_property_access_does_not_reset_blueprint(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ["build", "-p", "BaseDomain=mike.com", "-r", "us-west-2", "-p",
          "AZCount=2", "-p", "CidrBlock=10.128.0.0/16",
          "stacker/tests/fixtures/basic.env",
          "stacker/tests/fixtures/vpc-bastion-db-web.yaml"]
     )
     stacker.configure(args)
     stacks_dict = args.context.get_stacks_dict()
     bastion_stack = stacks_dict[args.context.get_fqn("bastion")]
     bastion_stack.blueprint.create_template()
     bastion_stack.blueprint.setup_parameters()
     self.assertIn("DefaultSG", bastion_stack.blueprint.parameters)
Ejemplo n.º 18
0
 def test_stacker_blueprint_property_access_does_not_reset_blueprint(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ['build', '-p', 'BaseDomain=mike.com', '-r', 'us-west-2', '-p',
          'AZCount=2', '-p', 'CidrBlock=10.128.0.0/16',
          'stacker/tests/fixtures/basic.env',
          'stacker/tests/fixtures/vpc-bastion-db-web.yaml']
     )
     stacker.configure(args)
     stacks_dict = args.context.get_stacks_dict()
     bastion_stack = stacks_dict[args.context.get_fqn('bastion')]
     bastion_stack.blueprint.create_template()
     bastion_stack.blueprint.setup_parameters()
     self.assertIn('DefaultSG', bastion_stack.blueprint.parameters)
Ejemplo n.º 19
0
 def execute(self):
     """Execute stacker."""
     cmd_line_args = strip_leading_option_delim(
         self._cli_arguments.get('<stacker-args>', [])
     )
     lib_path = get_embedded_lib_path()
     sys.argv = ['stacker'] + cmd_line_args
     sys.path.insert(1, lib_path)
     from stacker.logger import setup_logging
     from stacker.commands import Stacker
     stacker = Stacker(setup_logging=setup_logging)
     args = stacker.parse_args(cmd_line_args)
     stacker.configure(args)
     args.run(args)
Ejemplo n.º 20
0
 def test_stacker_build_parse_args(self):
     stacker = Stacker()
     parser = argparse.ArgumentParser(description=stacker.description)
     stacker.add_subcommands(parser)
     args = parser.parse_args(
         ['build', '-p', 'BaseDomain=mike.com', '-r', 'us-west-2', '-p',
          'AZCount=2', '-p', 'CidrBlock=10.128.0.0/16', 'stacker-test',
          'stacker/tests/fixtures/vpc-bastion-db-web.yaml']
     )
     # verify parameters
     parameters = args.parameters
     self.assertEqual(parameters['BaseDomain'], 'mike.com')
     self.assertEqual(parameters['CidrBlock'], '10.128.0.0/16')
     self.assertEqual(parameters['AZCount'], '2')
     self.assertEqual(args.region, 'us-west-2')
     self.assertEqual(args.namespace, 'stacker-test')
     self.assertFalse(args.outline)
Ejemplo n.º 21
0
 def test_stacker_build_context_passed_to_blueprint(self):
     stacker = Stacker()
     args = stacker.parse_args([
         "build", "-r", "us-west-2", "stacker/tests/fixtures/basic.env",
         "stacker/tests/fixtures/vpc-bastion-db-web.yaml"
     ])
     stacker.configure(args)
     stacks_dict = args.context.get_stacks_dict()
     blueprint = stacks_dict[args.context.get_fqn("bastion")].blueprint
     self.assertTrue(hasattr(blueprint, "context"))
     blueprint.render_template()
     # verify that the bastion blueprint only contains blueprint variables,
     # not BaseDomain, AZCount or CidrBlock. Any variables that get passed
     # in from the command line shouldn't be resovled at the blueprint level
     self.assertNotIn("BaseDomain", blueprint.template.parameters)
     self.assertNotIn("AZCount", blueprint.template.parameters)
     self.assertNotIn("CidrBlock", blueprint.template.parameters)
Ejemplo n.º 22
0
 def test_stacker_build_parse_args(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ['build', '-p', 'BaseDomain=mike.com', '-r', 'us-west-2', '-p',
          'AZCount=2', '-p', 'CidrBlock=10.128.0.0/16',
          '-e', 'namespace=test.override',
          'stacker/tests/fixtures/basic.env',
          'stacker/tests/fixtures/vpc-bastion-db-web.yaml']
     )
     # verify parameters
     parameters = args.parameters
     self.assertEqual(parameters['BaseDomain'], 'mike.com')
     self.assertEqual(parameters['CidrBlock'], '10.128.0.0/16')
     self.assertEqual(parameters['AZCount'], '2')
     self.assertEqual(args.region, 'us-west-2')
     self.assertFalse(args.outline)
     # verify namespace was modified
     self.assertEqual(args.environment['namespace'], 'test.override')
Ejemplo n.º 23
0
 def test_stacker_build_parse_args(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ["build", "-p", "BaseDomain=mike.com", "-r", "us-west-2", "-p",
          "AZCount=2", "-p", "CidrBlock=10.128.0.0/16",
          "-e", "namespace=test.override",
          "stacker/tests/fixtures/basic.env",
          "stacker/tests/fixtures/vpc-bastion-db-web.yaml"]
     )
     # verify parameters
     parameters = args.parameters
     self.assertEqual(parameters["BaseDomain"], "mike.com")
     self.assertEqual(parameters["CidrBlock"], "10.128.0.0/16")
     self.assertEqual(parameters["AZCount"], "2")
     self.assertEqual(args.region, "us-west-2")
     self.assertFalse(args.outline)
     # verify namespace was modified
     self.assertEqual(args.environment["namespace"], "test.override")
Ejemplo n.º 24
0
 def test_stacker_build_context_passed_to_blueprint(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ["build",
          "-r", "us-west-2",
          "stacker/tests/fixtures/basic.env",
          "stacker/tests/fixtures/vpc-bastion-db-web.yaml"]
     )
     stacker.configure(args)
     stacks_dict = args.context.get_stacks_dict()
     blueprint = stacks_dict[args.context.get_fqn("bastion")].blueprint
     self.assertTrue(hasattr(blueprint, "context"))
     blueprint.render_template()
     # verify that the bastion blueprint only contains blueprint variables,
     # not BaseDomain, AZCount or CidrBlock. Any variables that get passed
     # in from the command line shouldn't be resovled at the blueprint level
     self.assertNotIn("BaseDomain", blueprint.template.parameters)
     self.assertNotIn("AZCount", blueprint.template.parameters)
     self.assertNotIn("CidrBlock", blueprint.template.parameters)
Ejemplo n.º 25
0
 def test_stacker_build_context_passed_to_blueprint(self):
     stacker = Stacker()
     args = stacker.parse_args(
         ['build', '-p', 'BaseDomain=mike.com', '-r', 'us-west-2', '-p',
          'AZCount=2', '-p', 'CidrBlock=10.128.0.0/16',
          'stacker/tests/fixtures/basic.env',
          'stacker/tests/fixtures/vpc-bastion-db-web.yaml']
     )
     stacker.configure(args)
     stacks_dict = args.context.get_stacks_dict()
     blueprint = stacks_dict[args.context.get_fqn('bastion')].blueprint
     self.assertTrue(hasattr(blueprint, 'context'))
     blueprint.create_template()
     blueprint.setup_parameters()
     # verify that the bastion blueprint only contains blueprint parameters,
     # not BaseDomain, AZCount or CidrBlock. Any parameters that get passed
     # in from the command line shouldn't be resovled at the blueprint level
     self.assertNotIn('BaseDomain', blueprint.parameters)
     self.assertNotIn('AZCount', blueprint.parameters)
     self.assertNotIn('CidrBlock', blueprint.parameters)
Ejemplo n.º 26
0
 def test_stacker_build_custom_info_log_format(self):
     stacker = Stacker()
     args = stacker.parse_args(
         [
             "build", "-r", "us-west-2",
             "stacker/tests/fixtures/not-basic.env",
             "stacker/tests/fixtures/vpc-custom-log-format-info.yaml"
         ]
     )
     stacker.configure(args)
     self.assertEqual(
         stacker.config.log_formats["info"],
         '[%(asctime)s] test custom log format - %(message)s'
     )
     self.assertIsNone(
         stacker.config.log_formats.get("color")
     )
     self.assertIsNone(
         stacker.config.log_formats.get("debug")
     )