def test_generate_template_with_arguments(): cloudformation_simple_stack, _ = load_cloudformation_template( here('resources/simple_cloudformation_stack/cloudformation_with_arguments.py') ) context = {'foo': 'bar'} config_simple_stack = fix_old_kumo_config(read_json_config( here('resources/simple_cloudformation_stack/gcdt_dev.json') ))['kumo'] expected_template_body = read_json_config( here('resources/simple_cloudformation_stack/expected_template_body.json') ) template_body = json.loads( generate_template(context, config_simple_stack, cloudformation_simple_stack) ) assert template_body == expected_template_body
def test_generate_template_invalid_arguments(): cloudformation_simple_stack, _ = load_cloudformation_template( here('resources/simple_cloudformation_stack/cloudformation_invalid_arguments.py') ) context = {'foo': 'bar'} config_simple_stack = fix_old_kumo_config(read_json_config( here('resources/simple_cloudformation_stack/gcdt_dev.json') ))['kumo'] with pytest.raises(Exception) as einfo: generate_template(context, config_simple_stack, cloudformation_simple_stack) assert einfo.match(r"Arguments of 'generate_template' not as expected: \['invalid_context', 'invalid_config'\]")
def get_tooldata(awsclient, tool, command, config=None, config_base_name=None, location=None): """Helper for main tests to assemble tool data. used in testing to read from 'gcdt_<env>.json' files :param awsclient: :param tool: :param command: :param config: provide custom config or empty to read from file :param config_base_name: :param location: :return: """ from gcdt_lookups.lookups import _resolve_lookups if config is None: if config_base_name is None: config_base_name = 'gcdt' if location is None: location = '.' env = get_env() gcdt_config_file = os.path.join(location, '%s_%s.json' % (config_base_name, env)) context = {'_awsclient': awsclient, 'tool': tool, 'command': command} config = fix_old_kumo_config(read_json_config(gcdt_config_file))[tool] _resolve_lookups( context, config, config.get('lookups', ['secret', 'ssl', 'stack', 'baseami'])) tooldata = { 'context': { 'tool': tool, 'command': command, 'version': __version__, 'user': '******', '_awsclient': awsclient }, 'config': config } return tooldata
def sample_cloudformation_stack_with_hooks(awsclient): # create a stack we use for the test lifecycle are_credentials_still_valid(awsclient) cloudformation_stack, _ = load_cloudformation_template( here( 'resources/sample_cloudformation_stack_with_hooks/cloudformation.py' )) config_stack = read_json_config( here('resources/sample_cloudformation_stack_with_hooks/gcdt_dev.json') )['kumo'] exit_code = deploy_stack(awsclient, config_stack, cloudformation_stack, override_stack_policy=False) assert not exit_code yield 'infra-dev-kumo-sample-stack-with-hooks' # cleanup exit_code = delete_stack(awsclient, config_stack) # check whether delete was completed! assert not exit_code, 'delete_stack was not completed please make sure to clean up the stack manually'
delete_stack, _get_stack_name from gcdt.utils import are_credentials_still_valid, fix_old_kumo_config from gcdt.servicediscovery import get_outputs_for_stack from gcdt.tenkai_core import deploy as tenkai_deploy, output_deployment_status, \ output_deployment_diagnostics, output_deployment_summary from gcdt.gcdt_config_reader import read_json_config from gcdt_testtools.helpers_aws import check_preconditions from gcdt_testtools.helpers_aws import cleanup_buckets, awsclient # fixtures! from gcdt_testtools.helpers import logcapture # fixtures! from . import here log = logging.getLogger(__name__) # read config config_sample_codeploy_stack = fix_old_kumo_config( read_json_config( here('resources/sample_codedeploy_app/gcdt_dev.json')))['kumo'] @pytest.fixture(scope='function') # 'function' or 'module' def cleanup_stack_tenkai(awsclient): """Remove the ec2 stack to cleanup after test run. This is intended to be called during test teardown""" yield # cleanup exit_code = delete_stack(awsclient, config_sample_codeploy_stack) # check whether delete was completed! assert_false( exit_code, 'delete_stack was not completed\n' + 'please make sure to clean up the stack manually')
print_parameter_diff, deploy_stack, \ delete_stack, create_change_set, _get_stack_name, describe_change_set, \ _get_artifact_bucket, _s3_upload, _get_stack_state from gcdt.kumo_util import ensure_ebs_volume_tags_ec2_instance, \ ensure_ebs_volume_tags_autoscaling_group from gcdt.utils import are_credentials_still_valid from gcdt.servicediscovery import get_outputs_for_stack from gcdt.s3 import prepare_artifacts_bucket from gcdt.gcdt_config_reader import read_json_config from gcdt_testtools.helpers_aws import check_preconditions from gcdt_testtools.helpers_aws import cleanup_buckets, awsclient # fixtures! from . import here # read template and config config_simple_stack = read_json_config( here('resources/simple_cloudformation_stack/gcdt_dev.json'))['kumo'] config_ec2 = read_json_config( here('resources/sample_ec2_cloudformation_stack/gcdt_dev.json'))['kumo'] config_autoscaling = read_json_config( here('resources/sample_autoscaling_cloudformation_stack/gcdt_dev.json') )['kumo'] @pytest.fixture(scope='function') # 'function' or 'module' def simple_cloudformation_stack(awsclient): # create a stack we use for the test lifecycle #print_parameter_diff(awsclient, config_simple_stack) are_credentials_still_valid(awsclient) cloudformation_simple_stack, _ = load_cloudformation_template(
ensure_ebs_volume_tags_autoscaling_group from gcdt.utils import are_credentials_still_valid, fix_old_kumo_config, all_pages from gcdt.servicediscovery import get_outputs_for_stack from gcdt.s3 import prepare_artifacts_bucket, remove_file_from_s3 from gcdt.gcdt_config_reader import read_json_config from gcdt_testtools.helpers_aws import check_preconditions, create_role_helper from gcdt_testtools.helpers_aws import cleanup_buckets, awsclient, \ cleanup_roles, temp_cloudformation_policy # fixtures! from gcdt_testtools import helpers from . import here # read template and config config_simple_stack = fix_old_kumo_config( read_json_config( here('resources/simple_cloudformation_stack/gcdt_dev.json')))['kumo'] # all things are hardcoded here :( config_ec2 = fix_old_kumo_config( read_json_config( here('resources/sample_ec2_cloudformation_stack/gcdt_dev.json')) )['kumo'] config_autoscaling = fix_old_kumo_config( read_json_config( here('resources/sample_autoscaling_cloudformation_stack/gcdt_dev.json') ))['kumo'] config_rds_stack = read_json_config( here('resources/simple_cloudformation_stack_with_rds/gcdt_dev_lookups.json' ))['kumo']