def test_deploy_cmd(awsclient, sample_codedeploy_app, sample_codedeploy_app_working_folder): tooldata = get_tooldata(awsclient, 'tenkai', 'deploy') # gcdt-plugins are installed anyway so this is ok # TODO alternatively prepare a stock bundle.zip! tooldata['context']['_bundle_file'] = bundle_revision() deploy_cmd(**tooldata)
def test_ping_cmd(awsclient, vendored_folder, temp_lambda, capsys): log.info('running test_ping_cmd') tooldata = get_tooldata(awsclient, 'ramuda', 'ping', config={}) lambda_name = temp_lambda[0] ping_cmd(lambda_name, **tooldata) out, err = capsys.readouterr() assert '"alive"' in out
def test_deploy_delete_cmds(awsclient, simple_cloudformation_stack_folder): tooldata = get_tooldata(awsclient, 'kumo', 'deploy') assert deploy_cmd(False, **tooldata) == 0 assert _get_stack_state(awsclient.get_client('cloudformation'), 'infra-dev-kumo-sample-stack') in ['CREATE_COMPLETE'] tooldata['context']['command'] = 'delete' assert delete_cmd(True, **tooldata) == 0 assert _get_stack_state(awsclient.get_client('cloudformation'), 'infra-dev-kumo-sample-stack') is None
def test_list_cmd(awsclient, capsys): tooldata = get_tooldata( awsclient, 'kumo', 'list', config_base_name='gcdt_large', location=here('./resources/simple_cloudformation_stack/')) list_cmd(**tooldata) out, err = capsys.readouterr() # using regular expression search in captured output assert regex.search('listed \d+ stacks', out) is not None
def test_preview_cmd(awsclient, simple_cloudformation_stack, simple_cloudformation_stack_folder, capsys): tooldata = get_tooldata( awsclient, 'kumo', 'preview', config_base_name='gcdt_large', location=here('./resources/simple_cloudformation_stack/')) preview_cmd(**tooldata) out, err = capsys.readouterr() # verify diff results assert 'InstanceType │ t2.micro │ t2.medium ' in out
def test_metrics_cmd(awsclient, vendored_folder, temp_lambda, capsys): log.info('running test_metrics_cmd') tooldata = get_tooldata(awsclient, 'ramuda', 'metrics', config={}) lambda_name = temp_lambda[0] metrics_cmd(lambda_name, **tooldata) out, err = capsys.readouterr() assert_regexp_matches( out.strip(), 'Duration 0\\n\\tErrors 0\\n\\tInvocations [0,1]{1}\\n\\tThrottles 0')
def test_ping_cmd(awsclient, vendored_folder, temp_lambda, logcapture): logcapture.level = logging.INFO log.info('running test_ping_cmd') tooldata = get_tooldata(awsclient, 'ramuda', 'ping', config={}) lambda_name = temp_lambda[0] ping_cmd(lambda_name, **tooldata) logcapture.check( ('tests.test_ramuda_main', 'INFO', u'running test_ping_cmd'), ('gcdt.ramuda_main', 'INFO', u'Cool, your lambda function did respond to ping with "alive".'))
def test_invoke_cmd(awsclient, vendored_folder, temp_lambda): log.info('running test_invoke_cmd') tooldata = get_tooldata(awsclient, 'ramuda', 'invoke', config={}) lambda_name = temp_lambda[0] outfile = NamedTemporaryFile(delete=False, dir=None, suffix='').name invoke_cmd(lambda_name, None, None, '{"ramuda_action": "ping"}', outfile, **tooldata) with open(outfile, 'r') as ofile: assert ofile.read() == '"alive"' # cleanup os.unlink(outfile)
def test_metrics_cmd(awsclient, vendored_folder, temp_lambda, logcapture): logcapture.level = logging.INFO log.info('running test_metrics_cmd') tooldata = get_tooldata(awsclient, 'ramuda', 'metrics', config={}) lambda_name = temp_lambda[0] metrics_cmd(lambda_name, **tooldata) logcapture.check( ('tests.test_ramuda_main', 'INFO', u'running test_metrics_cmd'), ('gcdt.ramuda_core', 'INFO', u'\tDuration 0'), ('gcdt.ramuda_core', 'INFO', u'\tErrors 0'), ('gcdt.ramuda_core', 'INFO', u'\tInvocations 0'), ('gcdt.ramuda_core', 'INFO', u'\tThrottles 0'))
def test_list_cmd(awsclient, vendored_folder, temp_lambda, capsys): log.info('running test_list_cmd') tooldata = get_tooldata(awsclient, 'ramuda', 'list', config={}) lambda_name = temp_lambda[0] role_name = temp_lambda[1] list_cmd(**tooldata) out, err = capsys.readouterr() expected_regex = ".*%s\\n\\tMemory: 128\\n\\tTimeout: 300\\n\\tRole: arn:aws:iam::\d{12}:role\/%s\\n\\tCurrent Version: \$LATEST.*" \ % (lambda_name, role_name) assert_regexp_matches(out.strip(), expected_regex)
def test_list_cmd(awsclient, vendored_folder, temp_lambda, logcapture): logcapture.level = logging.INFO log.info('running test_list_cmd') tooldata = get_tooldata(awsclient, 'ramuda', 'list', config={}) list_cmd(**tooldata) records = list(logcapture.actual()) assert records[0][1] == 'INFO' assert records[0][2] == 'running test_list_cmd' assert records[2][1] == 'INFO' assert records[2][2].startswith('\tMemory') assert records[3][1] == 'INFO' assert records[3][2].startswith('\tTimeout')
def test_logs_cmd(awsclient, vendored_folder, temp_lambda, logcapture): logcapture.level = logging.INFO log.info('running test_logs_cmd') tooldata = get_tooldata(awsclient, 'ramuda', 'logs', config={}) lambda_name = temp_lambda[0] # this testcase is potentially flaky since we depend on the log events # to eventually arrive in AWS cloudwatch time.sleep(10) # automatically removed in playback mode! logs_cmd(lambda_name, '2m', None, False, **tooldata) records = list(logcapture.actual()) assert records[3][1] == 'INFO' assert "{u'ramuda_action': u'ping'}" in records[3][2]
def test_basic_lifecycle_cmds(awsclient, simple_cloudformation_stack_folder): # note this only covers parts of the lifecycle # a more sorrow lifecycle test using `gcdt-sample-stack` is contained # in the gcdt PR builder lifecycle tooldata = get_tooldata(awsclient, 'kumo', 'deploy') assert deploy_cmd(False, **tooldata) == 0 assert _get_stack_state( awsclient.get_client('cloudformation'), 'infra-dev-kumo-sample-stack') in ['CREATE_COMPLETE'] tooldata['context']['command'] = 'stop' assert stop_cmd(**tooldata) == 0 tooldata['context']['command'] = 'start' assert start_cmd(**tooldata) == 0 tooldata['context']['command'] = 'delete' assert delete_cmd(True, **tooldata) == 0 assert _get_stack_state(awsclient.get_client('cloudformation'), 'infra-dev-kumo-sample-stack') is None
def test_generate_cmd(awsclient, simple_cloudformation_stack_folder): tooldata = get_tooldata(awsclient, 'kumo', 'generate') assert generate_cmd(**tooldata) == 0 filename = 'infra-dev-kumo-sample-stack-generated-cf-template.json' assert os.path.exists(filename) os.unlink(filename)
def test_dot_cmd(awsclient, sample_ec2_cloudformation_stack_folder): tooldata = get_tooldata(awsclient, 'kumo', 'dot') assert dot_cmd(**tooldata) == 0 assert os.path.exists('cloudformation.svg') os.unlink('cloudformation.svg')
def test_deploy_delete_cmds(awsclient, vendored_folder, cleanup_roles, temp_bucket): log.info('running test_create_lambda') temp_string = utils.random_string() lambda_name = 'jenkins_test_' + temp_string log.info(lambda_name) role = create_role_helper( awsclient, 'unittest_%s_lambda' % temp_string, policies=[ 'arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole', 'arn:aws:iam::aws:policy/AWSLambdaExecute' ]) cleanup_roles.append(role['RoleName']) config = { "lambda": { "name": lambda_name, "description": "unittest for ramuda", "role": role['Arn'], "handlerFunction": "handler.handle", "handlerFile": "./resources/sample_lambda/handler.py", "timeout": 300, "memorySize": 256, "events": { "s3Sources": [{ "bucket": temp_bucket, "type": "s3:ObjectCreated:*", "suffix": ".gz" }], "timeSchedules": [{ "ruleName": "infra-dev-sample-lambda-jobr-T1", "ruleDescription": "run every 5 min from 0-5", "scheduleExpression": "cron(0/5 0-5 ? * * *)" }, { "ruleName": "infra-dev-sample-lambda-jobr-T2", "ruleDescription": "run every 5 min from 8-23:59", "scheduleExpression": "cron(0/5 8-23:59 ? * * *)" }] }, "vpc": { "subnetIds": [ "subnet-d5ffb0b1", "subnet-d5ffb0b1", "subnet-d5ffb0b1", "subnet-e9db9f9f" ], "securityGroups": ["sg-660dd700"] } }, "bundling": { "zip": "bundle.zip", "folders": [{ "source": "./vendored", "target": "." }, { "source": "./impl", "target": "impl" }] }, "deployment": { "region": "eu-west-1" } } tooldata = get_tooldata(awsclient, 'ramuda', 'deploy', config=config) tooldata['context']['_arguments'] = {'--keep': False} bundle((tooldata['context'], {'ramuda': tooldata['config']})) deploy_cmd(False, **tooldata) # now we use the delete cmd to remove the lambda function tooldata['context']['command'] = 'delete' delete_cmd(True, lambda_name, True, **tooldata)