예제 #1
0
    def setUpClass(cls):
        cls.code_abs_path_for_throw_error = nodejs_lambda(THROW_ERROR_LAMBDA)

        # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder
        cls.cwd_for_throw_error = os.path.dirname(
            cls.code_abs_path_for_throw_error)
        cls.code_uri_for_throw_error = os.path.relpath(
            cls.code_abs_path_for_throw_error,
            cls.cwd_for_throw_error)  # Get relative path with respect to CWD

        cls.code_abs_path = nodejs_lambda(HELLO_FROM_LAMBDA)

        # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder
        cls.cwd = os.path.dirname(cls.code_abs_path)
        cls.code_uri = os.path.relpath(
            cls.code_abs_path,
            cls.cwd)  # Get relative path with respect to CWD

        cls.hello_world_function_name = "HelloWorld"

        cls.hello_world_function = provider.Function(
            name=cls.hello_world_function_name,
            runtime="nodejs4.3",
            memory=256,
            timeout=5,
            handler="index.handler",
            codeuri=cls.code_uri,
            environment=None,
            rolearn=None,
            layers=[])

        cls.throw_error_function_name = "ThrowError"

        cls.throw_error_function = provider.Function(
            name=cls.throw_error_function_name,
            runtime="nodejs4.3",
            memory=256,
            timeout=5,
            handler="index.handler",
            codeuri=cls.code_uri_for_throw_error,
            environment=None,
            rolearn=None,
            layers=[])

        cls.mock_function_provider = Mock()
        cls.mock_function_provider.get.side_effect = cls.mocked_function_provider

        cls.service, cls.port, cls.url, cls.scheme = make_service(
            cls.mock_function_provider, cls.cwd)
        cls.service.create()
        t = threading.Thread(name='thread', target=cls.service.run, args=())
        t.setDaemon(True)
        t.start()
        time.sleep(1)
예제 #2
0
    def setUpClass(cls):
        cls.code_abs_path = nodejs_lambda(ECHO_CODE)

        # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder
        cls.cwd = os.path.dirname(cls.code_abs_path)
        cls.code_uri = os.path.relpath(cls.code_abs_path, cls.cwd)  # Get relative path with respect to CWD

        cls.function_name = "HelloWorld"

        cls.function = provider.Function(
            name=cls.function_name,
            runtime="nodejs4.3",
            memory=256,
            timeout=5,
            handler="index.handler",
            codeuri=cls.code_uri,
            environment=None,
            rolearn=None,
            layers=[],
        )

        cls.mock_function_provider = Mock()
        cls.mock_function_provider.get.return_value = cls.function

        cls.service, cls.port, cls.url, cls.scheme = make_service(cls.mock_function_provider, cls.cwd)
        cls.service.create()
        # import pdb; pdb.set_trace()
        t = threading.Thread(name="thread", target=cls.service.run, args=())
        t.setDaemon(True)
        t.start()
        time.sleep(1)
예제 #3
0
    def setUp(self):
        self.code_abs_path = nodejs_lambda(GET_ENV_VAR)

        # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder
        self.cwd = os.path.dirname(self.code_abs_path)
        self.code_uri = os.path.relpath(
            self.code_abs_path,
            self.cwd)  # Get relative path with respect to CWD

        self.function_name = "name"
        self.variables = {"var1": "defaultvalue1", "var2": "defaultvalue2"}

        self.env_var_overrides = {
            self.function_name: {
                "var1": "override_value1"
            }
        }

        # Override "var2" through the Shell environment
        os.environ["var2"] = "shell_env_value2"

        self.function = provider.Function(
            name=self.function_name,
            runtime="nodejs4.3",
            memory=256,
            timeout=5,
            handler="index.handler",
            codeuri=self.code_uri,
            environment={"Variables": self.variables},
            rolearn=None)

        self.mock_function_provider = Mock()
        self.mock_function_provider.get.return_value = self.function
예제 #4
0
    def setUp(self):
        self.host = "127.0.0.1"
        self.port = random.randint(30000, 40000)  # get a random port
        self.url = "http://{}:{}".format(self.host, self.port)

        self.code_abs_path = nodejs_lambda(API_GATEWAY_ECHO_EVENT)

        # Let's convert this absolute path to relative path. Let the parent be the CWD, and codeuri be the folder
        self.cwd = os.path.dirname(self.code_abs_path)
        self.code_uri = os.path.relpath(self.code_abs_path, self.cwd)  # Get relative path with respect to CWD

        # Setup a static file in the directory
        self.static_dir = "mystaticdir"
        self.static_file_name = "myfile.txt"
        self.static_file_content = "This is a static file"
        self._setup_static_file(
            os.path.join(self.cwd, self.static_dir),  # Create static directory with in cwd
            self.static_file_name,
            self.static_file_content,
        )

        # Create one Lambda function
        self.function_name = "name"
        self.function = provider.Function(
            name=self.function_name,
            runtime="nodejs4.3",
            memory=256,
            timeout=5,
            handler="index.handler",
            codeuri=self.code_uri,
            environment={},
            rolearn=None,
            layers=[],
        )
        self.mock_function_provider = Mock()
        self.mock_function_provider.get.return_value = self.function

        # Setup two APIs pointing to the same function
        routes = [
            Route(path="/get", methods=["GET"], function_name=self.function_name),
            Route(path="/post", methods=["POST"], function_name=self.function_name),
        ]
        api = Api(routes=routes)

        self.api_provider_mock = Mock()
        self.api_provider_mock.get_all.return_value = api

        # Now wire up the Lambda invoker and pass it through the context
        self.lambda_invoke_context_mock = Mock()
        manager = ContainerManager()
        layer_downloader = LayerDownloader("./", "./")
        lambda_image = LambdaImage(layer_downloader, False, False)
        local_runtime = LambdaRuntime(manager, lambda_image)
        lambda_runner = LocalLambdaRunner(local_runtime, self.mock_function_provider, self.cwd, debug_context=None)
        self.lambda_invoke_context_mock.local_lambda_runner = lambda_runner
        self.lambda_invoke_context_mock.get_cwd.return_value = self.cwd