pulumi/sdk/python
Fraser Waters c27d768bb1
Add matrix testing (#13705)
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

Adds the first pass of matrix testing.

Matrix testing allows us to define tests once in pulumi/pulumi via PCL
and then run those tests against each language plugin to verify code
generation and runtime correctness.

Rather than packing matrix tests and all the associated data and
machinery into the CLI itself we define a new Go package at
cmd/pulumi-test-lanaguage. This depends on pkg and runs the deployment
engine in a unique way for matrix tests but it is running the proper
deployment engine with a proper backend (always filestate, using $TEMP).

Currently only NodeJS is hooked up to run these tests, and all the code
for that currently lives in
sdk/nodejs/cmd/pulumi-language-nodejs/language_test.go. I expect we'll
move that helper code to sdk/go/common and use it in each language
plugin to run the tests in the same way.

This first pass includes 3 simple tests:
* l1-empty that runs an empty PCL file and checks just a stack is
created
* l1-output-bool that runs a PCL program that returns two stack outputs
of `true` and `false
* l2-resource-simple that runs a PCL program creating a simple resource
with a single bool property

These tests are themselves tested with a mock language runtime. This
verifies the behavior of the matrix test framework for both correct and
incorrect language hosts (that is some the mock language runtimes
purposefully cause errors or compute the wrong result).

There are a number of things missing from from the core framework still,
but I feel don't block getting this first pass merged and starting to be
used.

1. The tests can not currently run in parallel. That is calling
RunLanguageTest in parallel will break things. This is due to two
separate problems. Firstly is that the SDK snapshot's are not safe to
write in parallel (when PULUMI_ACCEPT is true), this should be fairly
easy to fix by doing a write to dst-{random} and them atomic move to
dst. Secondly is that the deployment engine itself has mutable global
state, short term we should probably just lock around that part
RunLanguageTest, long term it would be good to clean that up.
2. We need a way to verify "preview" behavior, I think this is probably
just a variation of the tests that would call `stack.Preview` and not
pass a snapshot to `assert`.
3. stdout, stderr and log messages are returned in bulk at the end of
the test. Plus there are a couple of calls to the language runtime that
don't correctly thread stdout/stderr to use and so default to the
process `os.Stdout/Stderr`. stdout/stderr streaming shows up in a load
of other places as well so I'm thinking of a clean way to handle all of
them together. Log message streaming we can probably do by just turning
RunLanguageTest to a streaming grpc call.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->

---------

Co-authored-by: Abhinav Gupta <abhinav@pulumi.com>
2023-09-13 15:17:46 +00:00
..
cmd Changelog and go.mod updates for v3.82.1 (#13937) 2023-09-13 00:46:50 +00:00
dist Fix windows build 2020-12-07 15:58:30 -08:00
lib Add matrix testing (#13705) 2023-09-13 15:17:46 +00:00
scripts ci: divide and conquer integration tests by sdk and package group 2022-03-04 18:08:23 -08:00
stubs Support WhoAmI in automation api for old CLI versions 2023-03-22 13:30:08 +00:00
.gitignore fix(sdk/python): Allow for duplicate output values in python programs 2022-12-07 11:59:09 -05:00
.pylintrc [sdk/*] Add support for resource source positions 2023-07-13 16:46:04 -07:00
Makefile make(sdk/py): Fix install, dist, test_go, brew (#13851) 2023-08-31 20:57:59 +00:00
README.md Add files via upload 2022-11-22 20:09:45 +05:30
mypy.ini Support deeply nested protobuf objects in python (#10284) 2022-07-29 16:17:09 +01:00
python.go all: Fix revive issues 2023-03-21 08:55:11 -07:00
python_test.go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00
requirements.txt fix: sdk/python/requirements.txt to reduce vulnerabilities 2023-08-10 18:51:34 +00:00
shim_unix.go Fix lint (#7915) 2021-09-07 16:41:17 -04:00
shim_windows.go Add copyright notice 2020-12-07 14:17:45 -08:00

README.md

Pulumi Python SDK

The Pulumi Python SDK (pulumi) is the core package used when writing Pulumi programs in Python. It contains everything that youll need in order to interact with Pulumi resource providers and express infrastructure using Python code. Pulumi resource providers all depend on this library and express their resources in terms of the types defined in this module.

The Pulumi Python SDK requires Python version 3.7 or greater through official python installer

note: pip is required to install dependencies. If you installed Python from source, with an installer from python.org, or via Homebrew you should already have pip. If Python is installed using your OS package manager, you may have to install pip separately, see Installing pip/setuptools/wheel with Linux Package Managers. For example, on Debian/Ubuntu you must run sudo apt install python3-venv python3-pip.

Getting Started

The fastest way to get up and running is to choose from one of the following Getting Started guides: -aws -microsoft azure -google cloud -kubernetes

Pulumi Programming Model

The Pulumi programming model defines the core concepts you will use when creating infrastructure as code programs using Pulumi. Architecture & Concepts describes these concepts with examples available in Python. These concepts are made available to you in the Pulumi SDK.

The Pulumi SDK is available to Python developers as a Pip package distributed on PyPI . To learn more, refer to the Pulumi SDK Reference Guide.

The Pulumi programming model includes a core concept of Input and Output values, which are used to track how outputs of one resource flow in as inputs to another resource. This concept is important to understand when getting started with Python and Pulumi, and the [Inputs and Outputs] (https://www.pulumi.com/docs/intro/concepts/inputs-outputs/)documentation is recommended to get a feel for how to work with this core part of Pulumi in common cases.

The Pulumi Python Resource Model

Like most languages usable with Pulumi, Pulumi represents cloud resources as classes and Python programs can instantiate those classes. All classes that can be instantiated to produce actual resources derive from the pulumi.Resource class.