Exemplo n.º 1
0
    def parse_commandline(self):
        params = {}
        run_params = {}
        result = False
        if self.args.command_name == "deploy":
            if self.args.lambdafunctions and self.args.lambdafunctions is not "_ALL_":
                params["lambdas_to_deploy"] = self.args.lambdafunctions
            if getattr(self.args, "environment", False):
                params["environment"] = self.args.environment
            if getattr(self.args, "zipfile", False):
                run_params["path_to_zip_file"] = self.args.zipfile

            deploy = Deploy(config=self.config, **params)
            result = deploy.run(**run_params)

        elif self.args.command_name == "invoke":
            pass
        elif self.args.command_name == "build":
            if getattr(self.args, "requirements", False):
                run_params["requirements"] = self.args.requirements
            build = Build(config=self.config)
            result = build.run(**params)
        else:
            self.parser.print_help()
        return result
Exemplo n.º 2
0
    def test_run_with_version(self, create_artefact_mock, copytree_mock, pip_install_mock, is_client_result_ok):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file
        is_client_result_ok.return_value = True

        self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)), filename="config_with_version.json")

        # Create lambdas
        self.deploy.run("myexamplelambdaproject")

        self.assertTrue(pip_install_mock.called)
        self.assertTrue(copytree_mock.called)
        self.assertTrue(create_artefact_mock.called)

        # Update lambdas
        self.deploy.run("myexamplelambdaproject")

        os.remove(zip_file)
Exemplo n.º 3
0
    def test_run_with_version(self, create_artefact_mock, copytree_mock, pip_install_mock, is_client_result_ok):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file
        is_client_result_ok.return_value = True

        self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)),
                             filename="config_with_alias_and_version.json")

        # TODO: Search why moto rise errors
        try:
            # Create lambdas
            self.deploy.run("myexamplelambdaproject")

            self.assertTrue(pip_install_mock.called)
            self.assertTrue(copytree_mock.called)
            self.assertTrue(create_artefact_mock.called)

            # Update lambdas
            self.deploy.run("myexamplelambdaproject")

        except ConnectionError as e:
            print(e)

        os.remove(zip_file)
Exemplo n.º 4
0
    def test_run_with_trigger_sns(self, create_artefact_mock, copytree_mock, pip_install_mock, is_client_result_ok):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file
        is_client_result_ok.return_value = True

        client = boto3.client('sns', region_name="eu-west-1")
        _ = client.create_topic(
            Name='TestLambdas'
        )

        self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)), filename="config_with_triggers.json",
                             lambdas_to_deploy=["LambdaExample_SNS_8", ])

        # Create lambdas
        self.deploy.run("myexamplelambdaproject")

        self.assertTrue(pip_install_mock.called)
        self.assertTrue(copytree_mock.called)
        self.assertTrue(create_artefact_mock.called)

        # Update lambdas
        self.deploy.run("myexamplelambdaproject")

        os.remove(zip_file)
Exemplo n.º 5
0
# coding=utf-8
# python imports
from __future__ import unicode_literals, print_function, absolute_import

import os

from ardy.core.deploy import Deploy

# App imports

if __name__ == '__main__':
    deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)), lambdas_to_deploy=["LambdaExample1", ],
                    environment="dev")
    deploy.run("myexamplelambdaproject")
Exemplo n.º 6
0
# coding=utf-8
# python imports
from __future__ import unicode_literals, print_function, absolute_import

import os

# App imports
from ardy.core.deploy import Deploy

if __name__ == '__main__':
    deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)))

    deploy.run("myexamplelambdaproject")
Exemplo n.º 7
0
class DeployTest(DeployBaseTest):
    @mock_s3
    @mock_lambda
    @patch.object(Build, "pip_install_to_target")
    @patch.object(Build, "copytree")
    @patch.object(Build, "create_artefact")
    def test_run(self, create_artefact_mock, copytree_mock, pip_install_mock):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file

        # Create lambdas
        self.deploy.run("myexamplelambdaproject")

        self.assertTrue(pip_install_mock.called)
        self.assertTrue(copytree_mock.called)
        self.assertTrue(create_artefact_mock.called)

        # Update lambdas
        # self.deploy.run("myexamplelambdaproject")

        os.remove(zip_file)

    @mock_s3
    @mock_lambda
    @patch('botocore.client.BaseClient._make_api_call', new=mock_make_api_call)
    @patch.object(Deploy, "is_client_result_ok")
    @patch.object(Build, "pip_install_to_target")
    @patch.object(Build, "copytree")
    @patch.object(Build, "create_artefact")
    def test_run_with_version(self, create_artefact_mock, copytree_mock, pip_install_mock, is_client_result_ok):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file
        is_client_result_ok.return_value = True

        self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)),
                             filename="config_with_alias_and_version.json")

        # TODO: Search why moto rise errors
        try:
            # Create lambdas
            self.deploy.run("myexamplelambdaproject")

            self.assertTrue(pip_install_mock.called)
            self.assertTrue(copytree_mock.called)
            self.assertTrue(create_artefact_mock.called)

            # Update lambdas
            self.deploy.run("myexamplelambdaproject")

        except ConnectionError as e:
            print(e)

        os.remove(zip_file)

    @mock_s3
    @mock_lambda
    @patch('botocore.client.BaseClient._make_api_call', new=mock_make_api_call)
    @patch.object(Deploy, "is_client_result_ok")
    @patch.object(Build, "pip_install_to_target")
    @patch.object(Build, "copytree")
    @patch.object(Build, "create_artefact")
    def test_run_with_version(self, create_artefact_mock, copytree_mock, pip_install_mock, is_client_result_ok):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file
        is_client_result_ok.return_value = True

        self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)), filename="config_with_version.json")

        # Create lambdas
        self.deploy.run("myexamplelambdaproject")

        self.assertTrue(pip_install_mock.called)
        self.assertTrue(copytree_mock.called)
        self.assertTrue(create_artefact_mock.called)

        # Update lambdas
        self.deploy.run("myexamplelambdaproject")

        os.remove(zip_file)

    @mock_s3
    @mock_lambda
    @patch('botocore.client.BaseClient._make_api_call', new=mock_make_api_call)
    @patch.object(Deploy, "is_client_result_ok")
    @patch.object(Build, "pip_install_to_target")
    @patch.object(Build, "copytree")
    @patch.object(Build, "create_artefact")
    def test_run_with_alias(self, create_artefact_mock, copytree_mock, pip_install_mock, is_client_result_ok):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file
        is_client_result_ok.return_value = True

        self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)), filename="config_with_alias.json")

        # Create lambdas
        self.deploy.run("myexamplelambdaproject")

        self.assertTrue(pip_install_mock.called)
        self.assertTrue(copytree_mock.called)
        self.assertTrue(create_artefact_mock.called)

        # Update lambdas
        self.deploy.run("myexamplelambdaproject")

        os.remove(zip_file)

    @mock_s3
    @mock_lambda
    @patch('botocore.client.BaseClient._make_api_call', new=mock_make_api_call)
    @patch.object(Deploy, "is_client_result_ok")
    @patch.object(Build, "pip_install_to_target")
    @patch.object(Build, "copytree")
    @patch.object(Build, "create_artefact")
    def test_run_with_trigger_s3(self, create_artefact_mock, copytree_mock, pip_install_mock, is_client_result_ok):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file
        is_client_result_ok.return_value = True

        self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)), filename="config_with_triggers.json",
                             lambdas_to_deploy=["LambdaExample_S3_7", ])

        # Create lambdas
        self.deploy.run("myexamplelambdaproject")

        self.assertTrue(pip_install_mock.called)
        self.assertTrue(copytree_mock.called)
        self.assertTrue(create_artefact_mock.called)

        # Update lambdas
        self.deploy.run("myexamplelambdaproject")

        os.remove(zip_file)

    @mock_s3
    @mock_sns
    @mock_lambda
    @patch('botocore.client.BaseClient._make_api_call', new=mock_make_api_call)
    @patch.object(Deploy, "is_client_result_ok")
    @patch.object(Build, "pip_install_to_target")
    @patch.object(Build, "copytree")
    @patch.object(Build, "create_artefact")
    def test_run_with_trigger_sns(self, create_artefact_mock, copytree_mock, pip_install_mock, is_client_result_ok):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file
        is_client_result_ok.return_value = True

        client = boto3.client('sns', region_name="eu-west-1")
        _ = client.create_topic(
            Name='TestLambdas'
        )

        self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)), filename="config_with_triggers.json",
                             lambdas_to_deploy=["LambdaExample_SNS_8", ])

        # Create lambdas
        self.deploy.run("myexamplelambdaproject")

        self.assertTrue(pip_install_mock.called)
        self.assertTrue(copytree_mock.called)
        self.assertTrue(create_artefact_mock.called)

        # Update lambdas
        self.deploy.run("myexamplelambdaproject")

        os.remove(zip_file)

    @mock_s3
    @mock_cloudwatch
    @mock_lambda
    @patch('botocore.client.BaseClient._make_api_call', new=mock_make_api_call)
    @patch.object(Deploy, "is_client_result_ok")
    @patch.object(Build, "pip_install_to_target")
    @patch.object(Build, "copytree")
    @patch.object(Build, "create_artefact")
    def test_run_with_trigger_cloudwatch(self, create_artefact_mock, copytree_mock, pip_install_mock,
                                         is_client_result_ok):
        zip_file = MockZipFile.create_zip("test")
        create_artefact_mock.return_value = zip_file
        is_client_result_ok.return_value = True

        self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)), filename="config_with_triggers.json",
                             lambdas_to_deploy=["LambdaExample_CWE_9", ])

        # Create lambdas
        self.deploy.run("myexamplelambdaproject")

        self.assertTrue(pip_install_mock.called)
        self.assertTrue(copytree_mock.called)
        self.assertTrue(create_artefact_mock.called)

        # Update lambdas
        self.deploy.run("myexamplelambdaproject")

        os.remove(zip_file)