Пример #1
0
    def test_compilation_error_dotnet(self):
        stack_name = stack_namer()
        project_dir = test_path("errors", compilation_error_project, "dotnet")
        stack = create_stack(stack_name, work_dir=project_dir)

        try:
            self.assertRaises(CompilationError, stack.up)
            self.assertRaisesRegex(CompilationError, "Build FAILED.", stack.up)
        finally:
            stack.workspace.remove_stack(stack_name)
Пример #2
0
    def test_compilation_error_go(self):
        stack_name = stack_namer()
        project_dir = test_path("errors", compilation_error_project, "go")
        stack = create_stack(stack_name, work_dir=project_dir)

        try:
            self.assertRaises(CompilationError, stack.up)
            self.assertRaisesRegex(CompilationError,
                                   ": syntax error:|: undefined:", stack.up)
        finally:
            stack.workspace.remove_stack(stack_name)
Пример #3
0
 def test_project_settings_respected(self):
     stack_name = stack_namer()
     project_name = "project_was_overwritten"
     stack = create_stack(
         stack_name,
         program=pulumi_program,
         project_name=project_name,
         opts=LocalWorkspaceOptions(
             work_dir=test_path("data", "correct_project")))
     project_settings = stack.workspace.project_settings()
     self.assertEqual(project_settings.name, "correct_project")
     self.assertEqual(project_settings.description, "This is a description")
     stack.workspace.remove_stack(stack_name)
Пример #4
0
    def test_compilation_error_typescript(self):
        stack_name = stack_namer()
        project_dir = test_path("errors", compilation_error_project,
                                "typescript")
        subprocess.run(["npm", "install"],
                       check=True,
                       cwd=project_dir,
                       capture_output=True)
        stack = create_stack(stack_name, work_dir=project_dir)

        try:
            self.assertRaises(CompilationError, stack.up)
            self.assertRaisesRegex(CompilationError,
                                   "Unable to compile TypeScript", stack.up)
        finally:
            stack.workspace.remove_stack(stack_name)
Пример #5
0
    def test_inline_runtime_error_python(self):
        stack_name = stack_namer()
        project_name = "inline_runtime_error_python"
        stack = create_stack(stack_name,
                             program=failing_program,
                             project_name=project_name)
        inline_error_text = "python inline source runtime error"

        try:
            self.assertRaises(InlineSourceRuntimeError, stack.up)
            self.assertRaisesRegex(InlineSourceRuntimeError, inline_error_text,
                                   stack.up)
            self.assertRaises(InlineSourceRuntimeError, stack.preview)
            self.assertRaisesRegex(InlineSourceRuntimeError, inline_error_text,
                                   stack.preview)
        finally:
            stack.workspace.remove_stack(stack_name)
Пример #6
0
    def test_supports_stack_outputs(self):
        stack_name = stack_namer()
        project_name = "inline_python"
        stack = create_stack(stack_name,
                             program=pulumi_program,
                             project_name=project_name)

        stack_config: ConfigMap = {
            "bar": ConfigValue(value="abc"),
            "buzz": ConfigValue(value="secret", secret=True)
        }

        def assertOutputs(outputs):
            self.assertEqual(len(outputs), 3)
            self.assertEqual(outputs["exp_static"].value, "foo")
            self.assertFalse(outputs["exp_static"].secret)
            self.assertEqual(outputs["exp_cfg"].value, "abc")
            self.assertFalse(outputs["exp_cfg"].secret)
            self.assertEqual(outputs["exp_secret"].value, "secret")
            self.assertTrue(outputs["exp_secret"].secret)

        try:
            stack.set_all_config(stack_config)

            initial_outputs = stack.outputs()
            self.assertEqual(len(initial_outputs), 0)

            # pulumi up
            up_res = stack.up()
            self.assertEqual(up_res.summary.kind, "update")
            self.assertEqual(up_res.summary.result, "succeeded")
            assertOutputs(up_res.outputs)

            outputs_after_up = stack.outputs()
            assertOutputs(outputs_after_up)

            # pulumi destroy
            destroy_res = stack.destroy()
            self.assertEqual(destroy_res.summary.kind, "destroy")
            self.assertEqual(destroy_res.summary.result, "succeeded")

            outputs_after_destroy = stack.outputs()
            self.assertEqual(len(outputs_after_destroy), 0)
        finally:
            stack.workspace.remove_stack(stack_name)
Пример #7
0
    def test_stack_lifecycle_inline_program(self):
        stack_name = stack_namer()
        project_name = "inline_python"
        stack = create_stack(stack_name,
                             program=pulumi_program,
                             project_name=project_name)

        stack_config: ConfigMap = {
            "bar": ConfigValue(value="abc"),
            "buzz": ConfigValue(value="secret", secret=True)
        }

        try:
            stack.set_all_config(stack_config)

            # pulumi up
            up_res = stack.up()
            self.assertEqual(len(up_res.outputs), 3)
            self.assertEqual(up_res.outputs["exp_static"].value, "foo")
            self.assertFalse(up_res.outputs["exp_static"].secret)
            self.assertEqual(up_res.outputs["exp_cfg"].value, "abc")
            self.assertFalse(up_res.outputs["exp_cfg"].secret)
            self.assertEqual(up_res.outputs["exp_secret"].value, "secret")
            self.assertTrue(up_res.outputs["exp_secret"].secret)
            self.assertEqual(up_res.summary.kind, "update")
            self.assertEqual(up_res.summary.result, "succeeded")

            # pulumi preview
            stack.preview()
            # TODO: update assertions when we have structured output

            # pulumi refresh
            refresh_res = stack.refresh()
            self.assertEqual(refresh_res.summary.kind, "refresh")
            self.assertEqual(refresh_res.summary.result, "succeeded")

            # pulumi destroy
            destroy_res = stack.destroy()
            self.assertEqual(destroy_res.summary.kind, "destroy")
            self.assertEqual(destroy_res.summary.result, "succeeded")
        finally:
            stack.workspace.remove_stack(stack_name)
Пример #8
0
def create_handler():
    """creates new sites"""
    stack_name = request.json.get('id')
    content = request.json.get('content')
    try:

        def pulumi_program():
            return create_pulumi_program(content)

        # create a new stack, generating our pulumi program on the fly from the POST body
        stack = auto.create_stack(stack_name=stack_name,
                                  project_name=project_name,
                                  program=pulumi_program)
        stack.set_config("aws:region", auto.ConfigValue("us-west-2"))
        # deploy the stack, tailing the logs to stdout
        up_res = stack.up(on_output=print)
        return jsonify(id=stack_name, url=up_res.outputs['website_url'].value)
    except auto.StackAlreadyExistsError:
        return make_response(f"stack '{stack_name}' already exists", 409)
    except Exception as exn:
        return make_response(str(exn), 500)
Пример #9
0
    def test_stack_lifecycle_local_program(self):
        stack_name = stack_namer()
        work_dir = test_path("data", "testproj")
        stack = create_stack(stack_name, work_dir=work_dir)

        config: ConfigMap = {
            "bar": ConfigValue(value="abc"),
            "buzz": ConfigValue(value="secret", secret=True)
        }
        stack.set_all_config(config)

        # pulumi up
        up_res = stack.up()
        self.assertEqual(len(up_res.outputs), 3)
        self.assertEqual(up_res.outputs["exp_static"].value, "foo")
        self.assertFalse(up_res.outputs["exp_static"].secret)
        self.assertEqual(up_res.outputs["exp_cfg"].value, "abc")
        self.assertFalse(up_res.outputs["exp_cfg"].secret)
        self.assertEqual(up_res.outputs["exp_secret"].value, "secret")
        self.assertTrue(up_res.outputs["exp_secret"].secret)
        self.assertEqual(up_res.summary.kind, "update")
        self.assertEqual(up_res.summary.result, "succeeded")

        # pulumi preview
        stack.preview()
        # TODO: update assertions when we have structured output

        # pulumi refresh
        refresh_res = stack.refresh()
        self.assertEqual(refresh_res.summary.kind, "refresh")
        self.assertEqual(refresh_res.summary.result, "succeeded")

        # pulumi destroy
        destroy_res = stack.destroy()
        self.assertEqual(destroy_res.summary.kind, "destroy")
        self.assertEqual(destroy_res.summary.result, "succeeded")

        stack.workspace.remove_stack(stack_name)
Пример #10
0
    def test_runtime_errors(self):
        for lang in ["python", "go", "dotnet", "javascript", "typescript"]:
            stack_name = stack_namer()
            project_dir = test_path("errors", runtime_error_project, lang)

            if lang in ["javascript", "typescript"]:
                subprocess.run(["npm", "install"],
                               check=True,
                               cwd=project_dir,
                               capture_output=True)
            if lang == "python":
                subprocess.run(["python3", "-m", "venv", "venv"],
                               check=True,
                               cwd=project_dir,
                               capture_output=True)
                subprocess.run([
                    os.path.join("venv", "bin", "pip"), "install", "-r",
                    "requirements.txt"
                ],
                               check=True,
                               cwd=project_dir,
                               capture_output=True)

            stack = create_stack(stack_name, work_dir=project_dir)

            try:
                self.assertRaises(RuntimeError, stack.up)
                if lang == "go":
                    self.assertRaisesRegex(RuntimeError,
                                           "panic: runtime error", stack.up)
                else:
                    self.assertRaisesRegex(
                        RuntimeError, "failed with an unhandled exception",
                        stack.up)
            finally:
                stack.workspace.remove_stack(stack_name)