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)
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)
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()
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)
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)
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)
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)
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"))
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")
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)
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)
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")
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)
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)
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)
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)
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)
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)
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)
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)
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)
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')
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")
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)
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)
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") )