def test_batch_get_builds__end_point_connection_error_raised(
            self, make_api_call_mock):
        make_api_call_mock.side_effect = codebuild.EndpointConnectionError(
            endpoint_url='www.codebuild.non-existent-region.com')

        with self.assertRaises(codebuild.ServiceError) as context_manager:
            codebuild.batch_get_builds(['some-build-id'])

        self.assertEqual(
            'Elastic Beanstalk does not support AWS CodeBuild in this region.',
            str(context_manager.exception))
    def test_batch_get_builds__service_error_raised(self, echo_mock,
                                                    make_api_call_mock):
        make_api_call_mock.side_effect = codebuild.aws.ServiceError(
            code='AccessDeniedException')

        with self.assertRaises(codebuild.ServiceError):
            codebuild.batch_get_builds(['some-build-id'])

        echo_mock.assert_called_once_with(
            'EB CLI does not have the right permissions to access CodeBuild.\n'
            'To learn more, see Docs: '
            'https://docs-aws.amazon.com/codebuild/latest/userguide/auth-and-access-control-permissions-reference.html'
        )
def stream_build_configuration_app_version_creation(app_name,
                                                    app_version_label):
    # Get the CloudWatch logs link
    successfully_generated = wait_for_app_version_attribute(
        app_name, [app_version_label], 'BuildArn', timeout=1)
    app_version_response = elasticbeanstalk.get_application_versions(
        app_name, version_labels=[app_version_label])['ApplicationVersions']

    build_response = codebuild.batch_get_builds([app_version_response[0]['BuildArn']]) \
        if successfully_generated else None

    if build_response is not None and 'logs' in build_response['builds'][0]:
        log_link_text = strings['codebuild.buildlogs'].replace(
            '{logs_link}', build_response['builds'][0]['logs']['deepLink'])
        io.echo(log_link_text)
    else:
        io.log_warning("Could not retrieve CloudWatch link for CodeBuild logs")

    # Wait for the success events
    try:
        from ebcli.operations.commonops import wait_for_success_events
        wait_for_success_events(None,
                                timeout_in_minutes=5,
                                can_abort=False,
                                version_label=app_version_label)
    except ServiceError as ex:
        LOG.debug(
            "Caught service error while creating application version '{0}' "
            "deleting the created applicaiton version as it is useless now.")
        elasticbeanstalk.delete_application_version(app_name,
                                                    app_version_label)
        raise ex
    def test_batch_get_builds(self, make_api_call_mock):
        make_api_call_mock.return_value = mock_responses.BATCH_GET_BUILDS

        build_ids = [
            'Elastic-Beanstalk-my-web-app-app-170706_000919-uUTqM:3362ef1d-584d-48c1-800a-c1c695b71562',
            'Elastic-Beanstalk-my-web-app-app-170706_001032-OYjRZ:a4db9491-91ba-4614-b5e4-3f8d9e994a19',
            'bad-batch-id-170706_001032-OYjRZ:a4db9491-91ba-4614-b5e4-3f8d9e994a19'
        ]

        self.assertEqual(mock_responses.BATCH_GET_BUILDS,
                         codebuild.batch_get_builds(build_ids))
Example #5
0
def stream_build_configuration_app_version_creation(app_name, app_version_label, build_spec):
    # Get the CloudWatch logs link
    successfully_generated = wait_for_app_version_attribute(
        app_name,
        [app_version_label],
        timeout=1
    )
    app_version_response = elasticbeanstalk.get_application_versions(
        app_name,
        version_labels=[app_version_label]
    )['ApplicationVersions']

    build_response = codebuild.batch_get_builds([app_version_response[0]['BuildArn']]) \
        if successfully_generated else None

    codebuild_timeout = build_spec.timeout or 60
    if build_response is not None and 'logs' in build_response['builds'][0]:
        log_link_text = strings['codebuild.buildlogs'].replace(
            '{logs_link}',
            build_response['builds'][0]['logs']['deepLink']
        )
        io.echo(log_link_text)
        io.echo(
            "NOTE: The CodeBuild timeout is set to {0} minutes, so this "
            "operation may take upto '{0}' minutes to complete.".format(codebuild_timeout)
        )
    else:
        io.log_warning("Could not retrieve CloudWatch link for CodeBuild logs")

    try:
        # Need to lazy-import `ebcli.lib.commonops` because `pytest` is unable to load it
        # at module load-time using Python 2.7 and Python 3.4
        from ebcli.operations import commonops
        timeout_error_message = ' '.join([
            'The CodeBuild build timed out after {} minute(s).'.format(codebuild_timeout),
            "To increase the time limit, use the 'Timeout' option in the 'buildspec.yml' file."
        ])
        commonops.wait_for_success_events(
            app_name=app_name,
            can_abort=False,
            request_id=None,
            timeout_error_message=timeout_error_message,
            timeout_in_minutes=codebuild_timeout,
            version_label=app_version_label
        )

    except ServiceError as exception:
        LOG.debug("Caught service error while creating application version '{0}' "
                  "deleting the created application version as it is useless now.".format(app_version_label))
        elasticbeanstalk.delete_application_version(app_name, app_version_label)
        raise exception
Example #6
0
def stream_build_configuration_app_version_creation(app_name, app_version_label, build_spec):
    # Get the CloudWatch logs link
    successfully_generated = wait_for_app_version_attribute(app_name, [app_version_label], 'BuildArn', timeout=1)
    app_version_response = elasticbeanstalk.get_application_versions(app_name, version_labels=[app_version_label])['ApplicationVersions']

    build_response = codebuild.batch_get_builds([app_version_response[0]['BuildArn']]) \
        if successfully_generated else None

    codebuild_timeout = build_spec.timeout or 60
    if build_response is not None and 'logs' in build_response['builds'][0]:
        log_link_text = strings['codebuild.buildlogs'].replace('{logs_link}',
                                                               build_response['builds'][0]['logs']['deepLink'])
        io.echo(log_link_text)
        io.echo("NOTE: The CodeBuild timeout is set to {0} minutes, so this operation may take upto '{0}' minutes to complete.".format(codebuild_timeout))
    else:
        io.log_warning("Could not retrieve CloudWatch link for CodeBuild logs")

    # Wait for the success events
    try:
        # Need to lazy-import `ebcli.lib.commonops` because `pytest` is unable to load it
        # at module load-time using Python 2.7 and Python 3.4
        from ebcli.operations import commonops
        timeout_error_message = ' '.join([
            'The CodeBuild build timed out after {} minute(s).'.format(codebuild_timeout),
            "To increase the time limit, use the 'Timeout' option in the 'buildspec.yml' file."
        ])
        commonops.wait_for_success_events(
            app_name=app_name,
            can_abort=False,
            request_id=None,
            timeout_error_message=timeout_error_message,
            timeout_in_minutes=codebuild_timeout,
            version_label=app_version_label
        )

    except ServiceError as exception:
        LOG.debug("Caught service error while creating application version '{0}' "
                  "deleting the created application version as it is useless now.".format(app_version_label))
        elasticbeanstalk.delete_application_version(app_name, app_version_label)
        raise exception