def test_generate_stack_from_input(self, *args): prod = base.generate_environment_name() self.assertEqual(generate_stack_from_input('dummy1', prod, 'prod'), 'dummy1--%s' % prod) alt_config = base.generate_environment_name() self.assertEqual(generate_stack_from_input('dummy2', alt_config, alt_config='alt-config1'), 'dummy2--%s' % alt_config) end2end = base.generate_environment_name() self.assertEqual(generate_stack_from_input('dummy2', end2end, alt_config='alt-config1'), 'dummy2--%s' % end2end)
def test_generate_stack_from_input(self): prod = base.generate_environment_name() self.assertEqual(generate_stack_from_input('dummy1', prod, 'prod'), 'dummy1--%s' % prod) alt_config = base.generate_environment_name() self.assertEqual(generate_stack_from_input('dummy2', alt_config, 'alt-config1'), 'dummy2--%s' % alt_config) end2end = base.generate_environment_name() self.assertEqual(generate_stack_from_input('dummy2', end2end, alt_config='alt-config1'), 'dummy2--%s' % end2end)
def test_launch_project_with_unique_altconfig(test_projects): "calling the `launch` task with a unique alt-config should fail" pname = 'project-with-unique-alt-config' instance_id = base.generate_environment_name() alt_config = 'prod' with patch('buildercore.core.stack_is_active', return_value=True): with pytest.raises(utils.TaskExit) as exc: expected_msg = "stack 'project-with-unique-alt-config--prod' exists, cannot re-use unique configuration 'prod'." generate_stack_from_input(pname, instance_id, alt_config) assert str(exc.value) == expected_msg
def launch(pname, instance_id=None, alt_config='standalone', *repolist): stackname = cfn.generate_stack_from_input(pname, instance_id, alt_config) pdata = core.project_data_for_stackname(stackname) # ensure given alt config has masterless=True # todo: can the choices presented to the user remove non-masterless alt-configs? ensure(pdata['aws-alt'], "project has no alternate configurations") ensure(alt_config in pdata['aws-alt'], "unknown alt-config %r" % alt_config) ensure(pdata['aws-alt'][alt_config]['ec2']['masterless'], "alternative configuration %r has masterless=False" % alt_config) formula_revisions = parse_validate_repolist(pdata, *repolist) # todo: this is good UX but was simply debug output that got left in. # a better summary of what is to be created could be printed out, # preferably after the templates are printed out but before confirmation. LOG.info('attempting to create masterless stack:') LOG.info('stackname:\t' + stackname) LOG.info('region:\t' + pdata['aws']['region']) LOG.info('formula_revisions:\t%s' % pformat(formula_revisions)) if core.is_master_server_stack(stackname): checks.ensure_can_access_builder_private(pname) checks.ensure_stack_does_not_exist(stackname) bootstrap.create_stack(stackname) LOG.info('updating stack %s', stackname) bootstrap.update_stack(stackname, service_list=['ec2', 'sqs', 's3'], formula_revisions=formula_revisions)
def launch(pname, instance_id=None, alt_config='standalone', *repolist): stackname = cfn.generate_stack_from_input(pname, instance_id, alt_config) pdata = core.project_data_for_stackname(stackname) # ensure given alt config has masterless=True ensure(pdata['aws-alt'], "project has no alternate configurations") ensure(alt_config in pdata['aws-alt'], "unknown alt-config %r" % alt_config) ensure(pdata['aws-alt'][alt_config]['ec2']['masterless'], "alternative configuration %r has masterless=False" % alt_config) formula_revisions = parse_validate_repolist(pdata, *repolist) LOG.info('attempting to create masterless stack:') LOG.info('stackname:\t' + stackname) LOG.info('region:\t' + pdata['aws']['region']) LOG.info('formula_revisions:\t%s' % pformat(formula_revisions)) if core.is_master_server_stack(stackname): checks.ensure_can_access_builder_private(pname) checks.ensure_stack_does_not_exist(stackname) bootstrap.create_stack(stackname) LOG.info('updating stack %s', stackname) bootstrap.update_stack(stackname, service_list=['ec2', 'sqs', 's3'], formula_revisions=formula_revisions)
def test_altconfig_name_preserved(self, *args): # create a random instance id for the 'dummy2' project and use the 'alt-config1' alt-config # see: fixtures/dummy2-project.json instance_id = base.generate_environment_name() # "luke-20191001045227-270172" stackname = generate_stack_from_input('dummy2', instance_id, alt_config='alt-config1') # "dummy2--luke-20191001045222-883274" # ensure alt-config is in there and correct current_context = context_handler.load_context(stackname) self.assertEqual('alt-config1', current_context['alt-config']) # skip calling update_infrastructure, we just want to test the diff with any changes new_context = cfngen.regenerate_stack(stackname)[0] # ensure the alt-config value is correct (it was previously the instance-id) self.assertEqual(current_context['alt-config'], new_context['alt-config'])
def deploy(pname, instance_id=None, branch='master', part_filter=None): pdata = project.project_data(pname) if not branch: branch_list = utils.git_remote_branches(pdata['repo']) branch_list = impose_ordering(branch_list) branch = utils._pick('branch', branch_list, deffile('.branch')) stackname = cfn.generate_stack_from_input(pname, instance_id) region = pdata['aws']['region'] active_stacks = core.active_stack_names(region) if stackname in active_stacks: LOG.info("stack %r exists, skipping creation", stackname) else: LOG.info("stack %r doesn't exist, creating", stackname) more_context = cfngen.choose_config(stackname) more_context['branch'] = branch cfngen.generate_stack(pname, **more_context) bootstrap.create_update(stackname, part_filter) setdefault('.active-stack', stackname)
def launch(pname, instance_id=None, alt_config='standalone', *repolist): stackname = cfn.generate_stack_from_input(pname, instance_id, alt_config) pdata = core.project_data_for_stackname(stackname) # ensure given alt config has masterless=True ensure(pdata['aws-alt'], "project has no alternate configurations") ensure(alt_config in pdata['aws-alt'], "unknown alt-config %r" % alt_config) ensure(pdata['aws-alt'][alt_config]['ec2']['masterless'], "alternative configuration %r has masterless=False" % alt_config) formula_revisions = parse_validate_repolist(pdata, *repolist) LOG.info('attempting to create masterless stack:') LOG.info('stackname:\t' + stackname) LOG.info('region:\t' + pdata['aws']['region']) LOG.info('formula_revisions:\t%s' % pformat(formula_revisions)) if core.is_master_server_stack(stackname): checks.ensure_can_access_builder_private(pname) checks.ensure_stack_does_not_exist(stackname) bootstrap.create_stack(stackname) LOG.info('updating stack %s', stackname) bootstrap.update_stack(stackname, service_list=['ec2', 'sqs', 's3'], formula_revisions=formula_revisions)