2018-05-22 21:43:36 +02:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2017-08-05 20:37:14 +02:00
|
|
|
|
|
|
|
package integration
|
2017-07-13 21:19:17 +02:00
|
|
|
|
|
|
|
import (
|
2018-02-04 01:17:51 +01:00
|
|
|
"context"
|
2018-06-05 01:34:38 +02:00
|
|
|
cryptorand "crypto/rand"
|
2018-04-12 22:50:07 +02:00
|
|
|
"encoding/hex"
|
2018-04-03 06:34:54 +02:00
|
|
|
"encoding/json"
|
2018-09-20 22:08:29 +02:00
|
|
|
"flag"
|
2017-07-13 21:19:17 +02:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2017-08-06 02:49:48 +02:00
|
|
|
"io/ioutil"
|
2017-07-13 21:19:17 +02:00
|
|
|
"os"
|
2018-02-04 01:17:51 +01:00
|
|
|
"os/exec"
|
2017-08-06 02:49:48 +02:00
|
|
|
"path/filepath"
|
2018-09-20 22:08:29 +02:00
|
|
|
"regexp"
|
2020-02-06 20:34:05 +01:00
|
|
|
"runtime"
|
2017-12-01 02:23:58 +01:00
|
|
|
"strconv"
|
2017-07-13 21:19:17 +02:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2018-02-04 01:17:51 +01:00
|
|
|
"time"
|
2017-07-13 21:19:17 +02:00
|
|
|
|
2019-09-07 02:07:54 +02:00
|
|
|
multierror "github.com/hashicorp/go-multierror"
|
2017-10-28 05:03:38 +02:00
|
|
|
"github.com/pkg/errors"
|
2020-04-14 10:30:25 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/v2/backend/filestate"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v2/engine"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v2/operations"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v2/resource/stack"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/apitype"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/resource"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/resource/config"
|
|
|
|
pulumi_testing "github.com/pulumi/pulumi/sdk/v2/go/common/testing"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/tokens"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/tools"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/util/ciutil"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/util/contract"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/util/fsutil"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/util/retry"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/workspace"
|
2021-01-11 19:07:59 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
user "github.com/tweekmonster/luser"
|
2017-07-13 21:19:17 +02:00
|
|
|
)
|
|
|
|
|
2019-08-20 10:08:09 +02:00
|
|
|
const PythonRuntime = "python"
|
|
|
|
const NodeJSRuntime = "nodejs"
|
|
|
|
const GoRuntime = "go"
|
2019-10-26 01:59:50 +02:00
|
|
|
const DotNetRuntime = "dotnet"
|
2019-08-20 10:08:09 +02:00
|
|
|
|
2020-06-10 01:42:53 +02:00
|
|
|
const windowsOS = "windows"
|
|
|
|
|
2017-12-14 01:09:14 +01:00
|
|
|
// RuntimeValidationStackInfo contains details related to the stack that runtime validation logic may want to use.
|
|
|
|
type RuntimeValidationStackInfo struct {
|
2018-04-12 22:50:07 +02:00
|
|
|
StackName tokens.QName
|
Implement more precise delete-before-replace semantics. (#2369)
This implements the new algorithm for deciding which resources must be
deleted due to a delete-before-replace operation.
We need to compute the set of resources that may be replaced by a
change to the resource under consideration. We do this by taking the
complete set of transitive dependents on the resource under
consideration and removing any resources that would not be replaced by
changes to their dependencies. We determine whether or not a resource
may be replaced by substituting unknowns for input properties that may
change due to deletion of the resources their value depends on and
calling the resource provider's Diff method.
This is perhaps clearer when described by example. Consider the
following dependency graph:
A
__|__
B C
| _|_
D E F
In this graph, all of B, C, D, E, and F transitively depend on A. It may
be the case, however, that changes to the specific properties of any of
those resources R that would occur if a resource on the path to A were
deleted and recreated may not cause R to be replaced. For example, the
edge from B to A may be a simple dependsOn edge such that a change to
B does not actually influence any of B's input properties. In that case,
neither B nor D would need to be deleted before A could be deleted.
In order to make the above algorithm a reality, the resource monitor
interface has been updated to include a map that associates an input
property key with the list of resources that input property depends on.
Older clients of the resource monitor will leave this map empty, in
which case all input properties will be treated as depending on all
dependencies of the resource. This is probably overly conservative, but
it is less conservative than what we currently implement, and is
certainly correct.
2019-01-28 18:46:30 +01:00
|
|
|
Deployment *apitype.DeploymentV3
|
|
|
|
RootResource apitype.ResourceV3
|
2017-12-14 01:09:14 +01:00
|
|
|
Outputs map[string]interface{}
|
2019-09-07 02:07:54 +02:00
|
|
|
Events []apitype.EngineEvent
|
2017-12-14 01:09:14 +01:00
|
|
|
}
|
|
|
|
|
2017-10-27 01:01:28 +02:00
|
|
|
// EditDir is an optional edit to apply to the example, as subsequent deployments.
|
|
|
|
type EditDir struct {
|
|
|
|
Dir string
|
2017-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation func(t *testing.T, stack RuntimeValidationStackInfo)
|
2017-12-15 02:10:05 +01:00
|
|
|
|
2018-01-10 01:47:17 +01:00
|
|
|
// Additive is true if Dir should be copied *on top* of the test directory.
|
2018-03-07 00:57:57 +01:00
|
|
|
// Otherwise Dir *replaces* the test directory, except we keep .pulumi/ and Pulumi.yaml and Pulumi.<stack>.yaml.
|
2018-01-10 01:47:17 +01:00
|
|
|
Additive bool
|
|
|
|
|
2017-12-20 21:10:46 +01:00
|
|
|
// ExpectFailure is true if we expect this test to fail. This is very coarse grained, and will essentially
|
|
|
|
// tolerate *any* failure in the program (IDEA: in the future, offer a way to narrow this down more).
|
|
|
|
ExpectFailure bool
|
|
|
|
|
2019-06-01 08:01:01 +02:00
|
|
|
// ExpectNoChanges is true if the edit is expected to not propose any changes.
|
|
|
|
ExpectNoChanges bool
|
|
|
|
|
2017-12-15 02:10:05 +01:00
|
|
|
// Stdout is the writer to use for all stdout messages.
|
|
|
|
Stdout io.Writer
|
|
|
|
// Stderr is the writer to use for all stderr messages.
|
|
|
|
Stderr io.Writer
|
|
|
|
// Verbose may be set to true to print messages as they occur, rather than buffering and showing upon failure.
|
|
|
|
Verbose bool
|
2019-04-19 00:25:15 +02:00
|
|
|
|
|
|
|
// Run program directory in query mode.
|
|
|
|
QueryMode bool
|
2017-10-27 01:01:28 +02:00
|
|
|
}
|
|
|
|
|
2017-11-14 18:33:22 +01:00
|
|
|
// TestCommandStats is a collection of data related to running a single command during a test.
|
|
|
|
type TestCommandStats struct {
|
|
|
|
// StartTime is the time at which the command was started
|
|
|
|
StartTime string `json:"startTime"`
|
|
|
|
// EndTime is the time at which the command exited
|
|
|
|
EndTime string `json:"endTime"`
|
|
|
|
// ElapsedSeconds is the time at which the command exited
|
|
|
|
ElapsedSeconds float64 `json:"elapsedSeconds"`
|
|
|
|
// StackName is the name of the stack
|
|
|
|
StackName string `json:"stackName"`
|
|
|
|
// TestId is the unique ID of the test run
|
|
|
|
TestID string `json:"testId"`
|
2019-01-03 23:18:19 +01:00
|
|
|
// StepName is the command line which was invoked
|
2017-11-14 18:33:22 +01:00
|
|
|
StepName string `json:"stepName"`
|
2019-01-03 23:18:19 +01:00
|
|
|
// CommandLine is the command line which was invoked
|
2017-11-14 18:33:22 +01:00
|
|
|
CommandLine string `json:"commandLine"`
|
|
|
|
// TestName is the name of the directory in which the test was executed
|
|
|
|
TestName string `json:"testName"`
|
|
|
|
// IsError is true if the command failed
|
|
|
|
IsError bool `json:"isError"`
|
2018-01-30 22:10:32 +01:00
|
|
|
// The Cloud that the test was run against, or empty for local deployments
|
|
|
|
CloudURL string `json:"cloudURL"`
|
2017-11-14 18:33:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestStatsReporter reports results and metadata from a test run.
|
|
|
|
type TestStatsReporter interface {
|
|
|
|
ReportCommand(stats TestCommandStats)
|
|
|
|
}
|
|
|
|
|
Support lists and maps in config (#3342)
This change adds support for lists and maps in config. We now allow
lists/maps (and nested structures) in `Pulumi.<stack>.yaml` (or
`Pulumi.<stack>.json`; yes, we currently support that).
For example:
```yaml
config:
proj:blah:
- a
- b
- c
proj:hello: world
proj:outer:
inner: value
proj:servers:
- port: 80
```
While such structures could be specified in the `.yaml` file manually,
we support setting values in maps/lists from the command line.
As always, you can specify single values with:
```shell
$ pulumi config set hello world
```
Which results in the following YAML:
```yaml
proj:hello world
```
And single value secrets via:
```shell
$ pulumi config set --secret token shhh
```
Which results in the following YAML:
```yaml
proj:token:
secure: v1:VZAhuroR69FkEPTk:isKafsoZVMWA9pQayGzbWNynww==
```
Values in a list can be set from the command line using the new
`--path` flag, which indicates the config key contains a path to a
property in a map or list:
```shell
$ pulumi config set --path names[0] a
$ pulumi config set --path names[1] b
$ pulumi config set --path names[2] c
```
Which results in:
```yaml
proj:names
- a
- b
- c
```
Values can be obtained similarly:
```shell
$ pulumi config get --path names[1]
b
```
Or setting values in a map:
```shell
$ pulumi config set --path outer.inner value
```
Which results in:
```yaml
proj:outer:
inner: value
```
Of course, setting values in nested structures is supported:
```shell
$ pulumi config set --path servers[0].port 80
```
Which results in:
```yaml
proj:servers:
- port: 80
```
If you want to include a period in the name of a property, it can be
specified as:
```
$ pulumi config set --path 'nested["foo.bar"]' baz
```
Which results in:
```yaml
proj:nested:
foo.bar: baz
```
Examples of valid paths:
- root
- root.nested
- 'root["nested"]'
- root.double.nest
- 'root["double"].nest'
- 'root["double"]["nest"]'
- root.array[0]
- root.array[100]
- root.array[0].nested
- root.array[0][1].nested
- root.nested.array[0].double[1]
- 'root["key with \"escaped\" quotes"]'
- 'root["key with a ."]'
- '["root key with \"escaped\" quotes"].nested'
- '["root key with a ."][100]'
Note: paths that contain quotes can be surrounded by single quotes.
When setting values with `--path`, if the value is `"false"` or
`"true"`, it will be saved as the boolean value, and if it is
convertible to an integer, it will be saved as an integer.
Secure values are supported in lists/maps as well:
```shell
$ pulumi config set --path --secret tokens[0] shh
```
Will result in:
```yaml
proj:tokens:
- secure: v1:wpZRCe36sFg1RxwG:WzPeQrCn4n+m4Ks8ps15MxvFXg==
```
Note: maps of length 1 with a key of “secure” and string value are
reserved for storing secret values. Attempting to create such a value
manually will result in an error:
```shell
$ pulumi config set --path parent.secure foo
error: "secure" key in maps of length 1 are reserved
```
**Accessing config values from the command line with JSON**
```shell
$ pulumi config --json
```
Will output:
```json
{
"proj:hello": {
"value": "world",
"secret": false,
"object": false
},
"proj:names": {
"value": "[\"a\",\"b\",\"c\"]",
"secret": false,
"object": true,
"objectValue": [
"a",
"b",
"c"
]
},
"proj:nested": {
"value": "{\"foo.bar\":\"baz\"}",
"secret": false,
"object": true,
"objectValue": {
"foo.bar": "baz"
}
},
"proj:outer": {
"value": "{\"inner\":\"value\"}",
"secret": false,
"object": true,
"objectValue": {
"inner": "value"
}
},
"proj:servers": {
"value": "[{\"port\":80}]",
"secret": false,
"object": true,
"objectValue": [
{
"port": 80
}
]
},
"proj:token": {
"secret": true,
"object": false
},
"proj:tokens": {
"secret": true,
"object": true
}
}
```
If the value is a map or list, `"object"` will be `true`. `"value"` will
contain the object as serialized JSON and a new `"objectValue"` property
will be available containing the value of the object.
If the object contains any secret values, `"secret"` will be `true`, and
just like with scalar values, the value will not be outputted unless
`--show-secrets` is specified.
**Accessing config values from Pulumi programs**
Map/list values are available to Pulumi programs as serialized JSON, so
the existing
`getObject`/`requireObject`/`getSecretObject`/`requireSecretObject`
functions can be used to retrieve such values, e.g.:
```typescript
import * as pulumi from "@pulumi/pulumi";
interface Server {
port: number;
}
const config = new pulumi.Config();
const names = config.requireObject<string[]>("names");
for (const n of names) {
console.log(n);
}
const servers = config.requireObject<Server[]>("servers");
for (const s of servers) {
console.log(s.port);
}
```
2019-11-01 21:41:27 +01:00
|
|
|
// ConfigValue is used to provide config values to a test program.
|
|
|
|
type ConfigValue struct {
|
|
|
|
// The config key to pass to `pulumi config`.
|
|
|
|
Key string
|
|
|
|
// The config value to pass to `pulumi config`.
|
|
|
|
Value string
|
|
|
|
// Secret indicates that the `--secret` flag should be specified when calling `pulumi config`.
|
|
|
|
Secret bool
|
|
|
|
// Path indicates that the `--path` flag should be specified when calling `pulumi config`.
|
|
|
|
Path bool
|
|
|
|
}
|
|
|
|
|
2017-12-08 21:59:39 +01:00
|
|
|
// ProgramTestOptions provides options for ProgramTest
|
2017-10-23 03:54:29 +02:00
|
|
|
type ProgramTestOptions struct {
|
2017-08-06 02:49:48 +02:00
|
|
|
// Dir is the program directory to test.
|
|
|
|
Dir string
|
2017-09-22 04:18:21 +02:00
|
|
|
// Array of NPM packages which must be `yarn linked` (e.g. {"pulumi", "@pulumi/aws"})
|
2017-07-13 21:19:17 +02:00
|
|
|
Dependencies []string
|
2018-11-14 22:27:32 +01:00
|
|
|
// Map of package names to versions. The test will use the specified versions of these packages instead of what
|
|
|
|
// is declared in `package.json`.
|
|
|
|
Overrides map[string]string
|
Support lists and maps in config (#3342)
This change adds support for lists and maps in config. We now allow
lists/maps (and nested structures) in `Pulumi.<stack>.yaml` (or
`Pulumi.<stack>.json`; yes, we currently support that).
For example:
```yaml
config:
proj:blah:
- a
- b
- c
proj:hello: world
proj:outer:
inner: value
proj:servers:
- port: 80
```
While such structures could be specified in the `.yaml` file manually,
we support setting values in maps/lists from the command line.
As always, you can specify single values with:
```shell
$ pulumi config set hello world
```
Which results in the following YAML:
```yaml
proj:hello world
```
And single value secrets via:
```shell
$ pulumi config set --secret token shhh
```
Which results in the following YAML:
```yaml
proj:token:
secure: v1:VZAhuroR69FkEPTk:isKafsoZVMWA9pQayGzbWNynww==
```
Values in a list can be set from the command line using the new
`--path` flag, which indicates the config key contains a path to a
property in a map or list:
```shell
$ pulumi config set --path names[0] a
$ pulumi config set --path names[1] b
$ pulumi config set --path names[2] c
```
Which results in:
```yaml
proj:names
- a
- b
- c
```
Values can be obtained similarly:
```shell
$ pulumi config get --path names[1]
b
```
Or setting values in a map:
```shell
$ pulumi config set --path outer.inner value
```
Which results in:
```yaml
proj:outer:
inner: value
```
Of course, setting values in nested structures is supported:
```shell
$ pulumi config set --path servers[0].port 80
```
Which results in:
```yaml
proj:servers:
- port: 80
```
If you want to include a period in the name of a property, it can be
specified as:
```
$ pulumi config set --path 'nested["foo.bar"]' baz
```
Which results in:
```yaml
proj:nested:
foo.bar: baz
```
Examples of valid paths:
- root
- root.nested
- 'root["nested"]'
- root.double.nest
- 'root["double"].nest'
- 'root["double"]["nest"]'
- root.array[0]
- root.array[100]
- root.array[0].nested
- root.array[0][1].nested
- root.nested.array[0].double[1]
- 'root["key with \"escaped\" quotes"]'
- 'root["key with a ."]'
- '["root key with \"escaped\" quotes"].nested'
- '["root key with a ."][100]'
Note: paths that contain quotes can be surrounded by single quotes.
When setting values with `--path`, if the value is `"false"` or
`"true"`, it will be saved as the boolean value, and if it is
convertible to an integer, it will be saved as an integer.
Secure values are supported in lists/maps as well:
```shell
$ pulumi config set --path --secret tokens[0] shh
```
Will result in:
```yaml
proj:tokens:
- secure: v1:wpZRCe36sFg1RxwG:WzPeQrCn4n+m4Ks8ps15MxvFXg==
```
Note: maps of length 1 with a key of “secure” and string value are
reserved for storing secret values. Attempting to create such a value
manually will result in an error:
```shell
$ pulumi config set --path parent.secure foo
error: "secure" key in maps of length 1 are reserved
```
**Accessing config values from the command line with JSON**
```shell
$ pulumi config --json
```
Will output:
```json
{
"proj:hello": {
"value": "world",
"secret": false,
"object": false
},
"proj:names": {
"value": "[\"a\",\"b\",\"c\"]",
"secret": false,
"object": true,
"objectValue": [
"a",
"b",
"c"
]
},
"proj:nested": {
"value": "{\"foo.bar\":\"baz\"}",
"secret": false,
"object": true,
"objectValue": {
"foo.bar": "baz"
}
},
"proj:outer": {
"value": "{\"inner\":\"value\"}",
"secret": false,
"object": true,
"objectValue": {
"inner": "value"
}
},
"proj:servers": {
"value": "[{\"port\":80}]",
"secret": false,
"object": true,
"objectValue": [
{
"port": 80
}
]
},
"proj:token": {
"secret": true,
"object": false
},
"proj:tokens": {
"secret": true,
"object": true
}
}
```
If the value is a map or list, `"object"` will be `true`. `"value"` will
contain the object as serialized JSON and a new `"objectValue"` property
will be available containing the value of the object.
If the object contains any secret values, `"secret"` will be `true`, and
just like with scalar values, the value will not be outputted unless
`--show-secrets` is specified.
**Accessing config values from Pulumi programs**
Map/list values are available to Pulumi programs as serialized JSON, so
the existing
`getObject`/`requireObject`/`getSecretObject`/`requireSecretObject`
functions can be used to retrieve such values, e.g.:
```typescript
import * as pulumi from "@pulumi/pulumi";
interface Server {
port: number;
}
const config = new pulumi.Config();
const names = config.requireObject<string[]>("names");
for (const n of names) {
console.log(n);
}
const servers = config.requireObject<Server[]>("servers");
for (const s of servers) {
console.log(s.port);
}
```
2019-11-01 21:41:27 +01:00
|
|
|
// Map of config keys and values to set (e.g. {"aws:region": "us-east-2"}).
|
2017-07-13 21:19:17 +02:00
|
|
|
Config map[string]string
|
Support lists and maps in config (#3342)
This change adds support for lists and maps in config. We now allow
lists/maps (and nested structures) in `Pulumi.<stack>.yaml` (or
`Pulumi.<stack>.json`; yes, we currently support that).
For example:
```yaml
config:
proj:blah:
- a
- b
- c
proj:hello: world
proj:outer:
inner: value
proj:servers:
- port: 80
```
While such structures could be specified in the `.yaml` file manually,
we support setting values in maps/lists from the command line.
As always, you can specify single values with:
```shell
$ pulumi config set hello world
```
Which results in the following YAML:
```yaml
proj:hello world
```
And single value secrets via:
```shell
$ pulumi config set --secret token shhh
```
Which results in the following YAML:
```yaml
proj:token:
secure: v1:VZAhuroR69FkEPTk:isKafsoZVMWA9pQayGzbWNynww==
```
Values in a list can be set from the command line using the new
`--path` flag, which indicates the config key contains a path to a
property in a map or list:
```shell
$ pulumi config set --path names[0] a
$ pulumi config set --path names[1] b
$ pulumi config set --path names[2] c
```
Which results in:
```yaml
proj:names
- a
- b
- c
```
Values can be obtained similarly:
```shell
$ pulumi config get --path names[1]
b
```
Or setting values in a map:
```shell
$ pulumi config set --path outer.inner value
```
Which results in:
```yaml
proj:outer:
inner: value
```
Of course, setting values in nested structures is supported:
```shell
$ pulumi config set --path servers[0].port 80
```
Which results in:
```yaml
proj:servers:
- port: 80
```
If you want to include a period in the name of a property, it can be
specified as:
```
$ pulumi config set --path 'nested["foo.bar"]' baz
```
Which results in:
```yaml
proj:nested:
foo.bar: baz
```
Examples of valid paths:
- root
- root.nested
- 'root["nested"]'
- root.double.nest
- 'root["double"].nest'
- 'root["double"]["nest"]'
- root.array[0]
- root.array[100]
- root.array[0].nested
- root.array[0][1].nested
- root.nested.array[0].double[1]
- 'root["key with \"escaped\" quotes"]'
- 'root["key with a ."]'
- '["root key with \"escaped\" quotes"].nested'
- '["root key with a ."][100]'
Note: paths that contain quotes can be surrounded by single quotes.
When setting values with `--path`, if the value is `"false"` or
`"true"`, it will be saved as the boolean value, and if it is
convertible to an integer, it will be saved as an integer.
Secure values are supported in lists/maps as well:
```shell
$ pulumi config set --path --secret tokens[0] shh
```
Will result in:
```yaml
proj:tokens:
- secure: v1:wpZRCe36sFg1RxwG:WzPeQrCn4n+m4Ks8ps15MxvFXg==
```
Note: maps of length 1 with a key of “secure” and string value are
reserved for storing secret values. Attempting to create such a value
manually will result in an error:
```shell
$ pulumi config set --path parent.secure foo
error: "secure" key in maps of length 1 are reserved
```
**Accessing config values from the command line with JSON**
```shell
$ pulumi config --json
```
Will output:
```json
{
"proj:hello": {
"value": "world",
"secret": false,
"object": false
},
"proj:names": {
"value": "[\"a\",\"b\",\"c\"]",
"secret": false,
"object": true,
"objectValue": [
"a",
"b",
"c"
]
},
"proj:nested": {
"value": "{\"foo.bar\":\"baz\"}",
"secret": false,
"object": true,
"objectValue": {
"foo.bar": "baz"
}
},
"proj:outer": {
"value": "{\"inner\":\"value\"}",
"secret": false,
"object": true,
"objectValue": {
"inner": "value"
}
},
"proj:servers": {
"value": "[{\"port\":80}]",
"secret": false,
"object": true,
"objectValue": [
{
"port": 80
}
]
},
"proj:token": {
"secret": true,
"object": false
},
"proj:tokens": {
"secret": true,
"object": true
}
}
```
If the value is a map or list, `"object"` will be `true`. `"value"` will
contain the object as serialized JSON and a new `"objectValue"` property
will be available containing the value of the object.
If the object contains any secret values, `"secret"` will be `true`, and
just like with scalar values, the value will not be outputted unless
`--show-secrets` is specified.
**Accessing config values from Pulumi programs**
Map/list values are available to Pulumi programs as serialized JSON, so
the existing
`getObject`/`requireObject`/`getSecretObject`/`requireSecretObject`
functions can be used to retrieve such values, e.g.:
```typescript
import * as pulumi from "@pulumi/pulumi";
interface Server {
port: number;
}
const config = new pulumi.Config();
const names = config.requireObject<string[]>("names");
for (const n of names) {
console.log(n);
}
const servers = config.requireObject<Server[]>("servers");
for (const s of servers) {
console.log(s.port);
}
```
2019-11-01 21:41:27 +01:00
|
|
|
// Map of secure config keys and values to set (e.g. {"aws:region": "us-east-2"}).
|
2017-10-19 00:37:18 +02:00
|
|
|
Secrets map[string]string
|
Support lists and maps in config (#3342)
This change adds support for lists and maps in config. We now allow
lists/maps (and nested structures) in `Pulumi.<stack>.yaml` (or
`Pulumi.<stack>.json`; yes, we currently support that).
For example:
```yaml
config:
proj:blah:
- a
- b
- c
proj:hello: world
proj:outer:
inner: value
proj:servers:
- port: 80
```
While such structures could be specified in the `.yaml` file manually,
we support setting values in maps/lists from the command line.
As always, you can specify single values with:
```shell
$ pulumi config set hello world
```
Which results in the following YAML:
```yaml
proj:hello world
```
And single value secrets via:
```shell
$ pulumi config set --secret token shhh
```
Which results in the following YAML:
```yaml
proj:token:
secure: v1:VZAhuroR69FkEPTk:isKafsoZVMWA9pQayGzbWNynww==
```
Values in a list can be set from the command line using the new
`--path` flag, which indicates the config key contains a path to a
property in a map or list:
```shell
$ pulumi config set --path names[0] a
$ pulumi config set --path names[1] b
$ pulumi config set --path names[2] c
```
Which results in:
```yaml
proj:names
- a
- b
- c
```
Values can be obtained similarly:
```shell
$ pulumi config get --path names[1]
b
```
Or setting values in a map:
```shell
$ pulumi config set --path outer.inner value
```
Which results in:
```yaml
proj:outer:
inner: value
```
Of course, setting values in nested structures is supported:
```shell
$ pulumi config set --path servers[0].port 80
```
Which results in:
```yaml
proj:servers:
- port: 80
```
If you want to include a period in the name of a property, it can be
specified as:
```
$ pulumi config set --path 'nested["foo.bar"]' baz
```
Which results in:
```yaml
proj:nested:
foo.bar: baz
```
Examples of valid paths:
- root
- root.nested
- 'root["nested"]'
- root.double.nest
- 'root["double"].nest'
- 'root["double"]["nest"]'
- root.array[0]
- root.array[100]
- root.array[0].nested
- root.array[0][1].nested
- root.nested.array[0].double[1]
- 'root["key with \"escaped\" quotes"]'
- 'root["key with a ."]'
- '["root key with \"escaped\" quotes"].nested'
- '["root key with a ."][100]'
Note: paths that contain quotes can be surrounded by single quotes.
When setting values with `--path`, if the value is `"false"` or
`"true"`, it will be saved as the boolean value, and if it is
convertible to an integer, it will be saved as an integer.
Secure values are supported in lists/maps as well:
```shell
$ pulumi config set --path --secret tokens[0] shh
```
Will result in:
```yaml
proj:tokens:
- secure: v1:wpZRCe36sFg1RxwG:WzPeQrCn4n+m4Ks8ps15MxvFXg==
```
Note: maps of length 1 with a key of “secure” and string value are
reserved for storing secret values. Attempting to create such a value
manually will result in an error:
```shell
$ pulumi config set --path parent.secure foo
error: "secure" key in maps of length 1 are reserved
```
**Accessing config values from the command line with JSON**
```shell
$ pulumi config --json
```
Will output:
```json
{
"proj:hello": {
"value": "world",
"secret": false,
"object": false
},
"proj:names": {
"value": "[\"a\",\"b\",\"c\"]",
"secret": false,
"object": true,
"objectValue": [
"a",
"b",
"c"
]
},
"proj:nested": {
"value": "{\"foo.bar\":\"baz\"}",
"secret": false,
"object": true,
"objectValue": {
"foo.bar": "baz"
}
},
"proj:outer": {
"value": "{\"inner\":\"value\"}",
"secret": false,
"object": true,
"objectValue": {
"inner": "value"
}
},
"proj:servers": {
"value": "[{\"port\":80}]",
"secret": false,
"object": true,
"objectValue": [
{
"port": 80
}
]
},
"proj:token": {
"secret": true,
"object": false
},
"proj:tokens": {
"secret": true,
"object": true
}
}
```
If the value is a map or list, `"object"` will be `true`. `"value"` will
contain the object as serialized JSON and a new `"objectValue"` property
will be available containing the value of the object.
If the object contains any secret values, `"secret"` will be `true`, and
just like with scalar values, the value will not be outputted unless
`--show-secrets` is specified.
**Accessing config values from Pulumi programs**
Map/list values are available to Pulumi programs as serialized JSON, so
the existing
`getObject`/`requireObject`/`getSecretObject`/`requireSecretObject`
functions can be used to retrieve such values, e.g.:
```typescript
import * as pulumi from "@pulumi/pulumi";
interface Server {
port: number;
}
const config = new pulumi.Config();
const names = config.requireObject<string[]>("names");
for (const n of names) {
console.log(n);
}
const servers = config.requireObject<Server[]>("servers");
for (const s of servers) {
console.log(s.port);
}
```
2019-11-01 21:41:27 +01:00
|
|
|
// List of config keys and values to set in order, including Secret and Path options.
|
|
|
|
OrderedConfig []ConfigValue
|
2019-08-03 01:12:16 +02:00
|
|
|
// SecretsProvider is the optional custom secrets provider to use instead of the default.
|
|
|
|
SecretsProvider string
|
2017-08-06 02:49:48 +02:00
|
|
|
// EditDirs is an optional list of edits to apply to the example, as subsequent deployments.
|
2017-10-27 01:01:28 +02:00
|
|
|
EditDirs []EditDir
|
2017-08-18 07:12:58 +02:00
|
|
|
// ExtraRuntimeValidation is an optional callback for additional validation, called before applying edits.
|
2017-12-14 01:09:14 +01:00
|
|
|
ExtraRuntimeValidation func(t *testing.T, stack RuntimeValidationStackInfo)
|
2017-11-15 06:02:47 +01:00
|
|
|
// RelativeWorkDir is an optional path relative to `Dir` which should be used as working directory during tests.
|
|
|
|
RelativeWorkDir string
|
2018-05-23 18:17:10 +02:00
|
|
|
// AllowEmptyPreviewChanges is true if we expect that this test's no-op preview may propose changes (e.g.
|
|
|
|
// because the test is sensitive to the exact contents of its working directory and those contents change
|
|
|
|
// incidentally between the initial update and the empty update).
|
|
|
|
AllowEmptyPreviewChanges bool
|
|
|
|
// AllowEmptyUpdateChanges is true if we expect that this test's no-op update may perform changes (e.g.
|
|
|
|
// because the test is sensitive to the exact contents of its working directory and those contents change
|
|
|
|
// incidentally between the initial update and the empty update).
|
|
|
|
AllowEmptyUpdateChanges bool
|
2017-12-20 21:10:46 +01:00
|
|
|
// ExpectFailure is true if we expect this test to fail. This is very coarse grained, and will essentially
|
|
|
|
// tolerate *any* failure in the program (IDEA: in the future, offer a way to narrow this down more).
|
|
|
|
ExpectFailure bool
|
2018-08-23 02:52:46 +02:00
|
|
|
// ExpectRefreshChanges may be set to true if a test is expected to have changes yielded by an immediate refresh.
|
|
|
|
// This could occur, for example, is a resource's state is constantly changing outside of Pulumi (e.g., timestamps).
|
|
|
|
ExpectRefreshChanges bool
|
2019-11-20 21:52:57 +01:00
|
|
|
// RetryFailedSteps indicates that failed updates, refreshes, and destroys should be retried after a brief
|
|
|
|
// intermission. A maximum of 3 retries will be attempted.
|
|
|
|
RetryFailedSteps bool
|
2018-08-31 18:34:26 +02:00
|
|
|
// SkipRefresh indicates that the refresh step should be skipped entirely.
|
|
|
|
SkipRefresh bool
|
2020-02-07 21:36:23 +01:00
|
|
|
// SkipPreview indicates that the preview step should be skipped entirely.
|
|
|
|
SkipPreview bool
|
|
|
|
// SkipUpdate indicates that the update step should be skipped entirely.
|
|
|
|
SkipUpdate bool
|
|
|
|
// SkipExportImport skips testing that exporting and importing the stack works properly.
|
|
|
|
SkipExportImport bool
|
|
|
|
// SkipEmptyPreviewUpdate skips the no-change preview/update that is performed that validates
|
|
|
|
// that no changes happen.
|
|
|
|
SkipEmptyPreviewUpdate bool
|
2019-06-28 18:40:21 +02:00
|
|
|
// SkipStackRemoval indicates that the stack should not be removed. (And so the test's results could be inspected
|
|
|
|
// in the Pulumi Service after the test has completed.)
|
|
|
|
SkipStackRemoval bool
|
2020-02-07 21:36:23 +01:00
|
|
|
// Quick implies SkipPreview, SkipExportImport and SkipEmptyPreviewUpdate
|
2017-11-16 17:15:56 +01:00
|
|
|
Quick bool
|
2018-11-20 11:05:24 +01:00
|
|
|
// PreviewCommandlineFlags specifies flags to add to the `pulumi preview` command line (e.g. "--color=raw")
|
|
|
|
PreviewCommandlineFlags []string
|
2019-05-06 23:00:18 +02:00
|
|
|
// UpdateCommandlineFlags specifies flags to add to the `pulumi up` command line (e.g. "--color=raw")
|
2017-12-20 20:17:25 +01:00
|
|
|
UpdateCommandlineFlags []string
|
2019-04-19 00:25:15 +02:00
|
|
|
// QueryCommandlineFlags specifies flags to add to the `pulumi query` command line (e.g. "--color=raw")
|
|
|
|
QueryCommandlineFlags []string
|
2018-06-25 07:47:54 +02:00
|
|
|
// RunBuild indicates that the build step should be run (e.g. run `yarn build` for `nodejs` programs)
|
|
|
|
RunBuild bool
|
2019-08-20 10:08:09 +02:00
|
|
|
// RunUpdateTest will ensure that updates to the package version can test for spurious diffs
|
|
|
|
RunUpdateTest bool
|
2021-01-19 20:18:45 +01:00
|
|
|
// DecryptSecretsInOutput will ensure that stack output is passed `--show-secrets` parameter
|
|
|
|
// Used in conjunction with ExtraRuntimeValidation
|
|
|
|
DecryptSecretsInOutput bool
|
2017-08-06 02:49:48 +02:00
|
|
|
|
2018-04-03 06:34:54 +02:00
|
|
|
// CloudURL is an optional URL to override the default Pulumi Service API (https://api.pulumi-staging.io). The
|
|
|
|
// PULUMI_ACCESS_TOKEN environment variable must also be set to a valid access token for the target cloud.
|
2018-01-04 06:26:50 +01:00
|
|
|
CloudURL string
|
|
|
|
|
2017-12-15 02:10:05 +01:00
|
|
|
// StackName allows the stack name to be explicitly provided instead of computed from the
|
|
|
|
// environment during tests.
|
|
|
|
StackName string
|
|
|
|
|
2019-06-28 18:40:21 +02:00
|
|
|
// Tracing specifies the Zipkin endpoint if any to use for tracing Pulumi invocations.
|
2018-05-03 22:44:21 +02:00
|
|
|
Tracing string
|
2019-01-03 23:18:19 +01:00
|
|
|
// NoParallel will opt the test out of being ran in parallel.
|
|
|
|
NoParallel bool
|
2018-05-03 22:44:21 +02:00
|
|
|
|
2018-05-15 18:48:56 +02:00
|
|
|
// PrePulumiCommand specifies a callback that will be executed before each `pulumi` invocation. This callback may
|
|
|
|
// optionally return another callback to be invoked after the `pulumi` invocation completes.
|
|
|
|
PrePulumiCommand func(verb string) (func(err error) error, error)
|
|
|
|
|
2017-11-14 18:33:22 +01:00
|
|
|
// ReportStats optionally specifies how to report results from the test for external collection.
|
|
|
|
ReportStats TestStatsReporter
|
|
|
|
|
2017-08-06 02:49:48 +02:00
|
|
|
// Stdout is the writer to use for all stdout messages.
|
|
|
|
Stdout io.Writer
|
|
|
|
// Stderr is the writer to use for all stderr messages.
|
|
|
|
Stderr io.Writer
|
2017-11-06 02:28:12 +01:00
|
|
|
// Verbose may be set to true to print messages as they occur, rather than buffering and showing upon failure.
|
|
|
|
Verbose bool
|
2017-08-06 02:49:48 +02:00
|
|
|
|
2017-12-01 02:23:58 +01:00
|
|
|
// DebugLogging may be set to anything >0 to enable excessively verbose debug logging from `pulumi`. This is
|
|
|
|
// equivalent to `--logtostderr -v=N`, where N is the value of DebugLogLevel. This may also be enabled by setting
|
|
|
|
// the environment variable PULUMI_TEST_DEBUG_LOG_LEVEL.
|
|
|
|
DebugLogLevel int
|
2019-05-06 23:00:18 +02:00
|
|
|
// DebugUpdates may be set to true to enable debug logging from `pulumi preview`, `pulumi up`, and
|
2017-12-01 02:23:58 +01:00
|
|
|
// `pulumi destroy`. This may also be enabled by setting the environment variable PULUMI_TEST_DEBUG_UPDATES.
|
2017-11-25 00:21:43 +01:00
|
|
|
DebugUpdates bool
|
|
|
|
|
2017-10-23 03:54:29 +02:00
|
|
|
// Bin is a location of a `pulumi` executable to be run. Taken from the $PATH if missing.
|
|
|
|
Bin string
|
2017-08-06 02:49:48 +02:00
|
|
|
// YarnBin is a location of a `yarn` executable to be run. Taken from the $PATH if missing.
|
|
|
|
YarnBin string
|
2018-06-10 18:17:19 +02:00
|
|
|
// GoBin is a location of a `go` executable to be run. Taken from the $PATH if missing.
|
|
|
|
GoBin string
|
2020-06-10 01:42:53 +02:00
|
|
|
// PythonBin is a location of a `python` executable to be run. Taken from the $PATH if missing.
|
|
|
|
PythonBin string
|
2018-11-05 22:52:37 +01:00
|
|
|
// PipenvBin is a location of a `pipenv` executable to run. Taken from the $PATH if missing.
|
|
|
|
PipenvBin string
|
2019-10-26 01:59:50 +02:00
|
|
|
// DotNetBin is a location of a `dotnet` executable to be run. Taken from the $PATH if missing.
|
|
|
|
DotNetBin string
|
2018-04-05 00:31:01 +02:00
|
|
|
|
2019-06-28 18:40:21 +02:00
|
|
|
// Additional environment variables to pass for each command we run.
|
2018-04-05 00:31:01 +02:00
|
|
|
Env []string
|
2020-06-10 01:42:53 +02:00
|
|
|
|
2021-02-12 03:16:07 +01:00
|
|
|
// Automatically create and use a virtual environment, rather than using the Pipenv tool. This is now the default
|
|
|
|
// behavior, so this option no longer has any affect. To go back to the old behavior use the `UsePipenv` option.
|
2020-06-10 01:42:53 +02:00
|
|
|
UseAutomaticVirtualEnv bool
|
2021-02-12 03:16:07 +01:00
|
|
|
// Use the Pipenv tool to manage the virtual environment.
|
|
|
|
UsePipenv bool
|
2017-08-06 02:49:48 +02:00
|
|
|
}
|
|
|
|
|
2017-12-09 01:59:28 +01:00
|
|
|
func (opts *ProgramTestOptions) GetDebugLogLevel() int {
|
2017-12-01 02:23:58 +01:00
|
|
|
if opts.DebugLogLevel > 0 {
|
|
|
|
return opts.DebugLogLevel
|
|
|
|
}
|
|
|
|
if du := os.Getenv("PULUMI_TEST_DEBUG_LOG_LEVEL"); du != "" {
|
2018-03-30 00:15:52 +02:00
|
|
|
if n, e := strconv.Atoi(du); e != nil {
|
|
|
|
panic(e)
|
|
|
|
} else if n > 0 {
|
2017-12-01 02:23:58 +01:00
|
|
|
return n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2017-12-09 01:59:28 +01:00
|
|
|
func (opts *ProgramTestOptions) GetDebugUpdates() bool {
|
2017-12-01 02:23:58 +01:00
|
|
|
return opts.DebugUpdates || os.Getenv("PULUMI_TEST_DEBUG_UPDATES") != ""
|
|
|
|
}
|
|
|
|
|
2017-12-15 02:10:05 +01:00
|
|
|
// GetStackName returns a stack name to use for this test.
|
|
|
|
func (opts *ProgramTestOptions) GetStackName() tokens.QName {
|
|
|
|
if opts.StackName == "" {
|
|
|
|
// Fetch the host and test dir names, cleaned so to contain just [a-zA-Z0-9-_] chars.
|
|
|
|
hostname, err := os.Hostname()
|
|
|
|
contract.AssertNoErrorf(err, "failure to fetch hostname for stack prefix")
|
|
|
|
var host string
|
|
|
|
for _, c := range hostname {
|
|
|
|
if len(host) >= 10 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
|
|
|
(c >= '0' && c <= '9') || c == '-' || c == '_' {
|
|
|
|
host += string(c)
|
|
|
|
}
|
2017-11-06 16:23:07 +01:00
|
|
|
}
|
2017-11-16 16:49:07 +01:00
|
|
|
|
2017-12-15 02:10:05 +01:00
|
|
|
var test string
|
|
|
|
for _, c := range filepath.Base(opts.Dir) {
|
|
|
|
if len(test) >= 10 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
|
|
|
(c >= '0' && c <= '9') || c == '-' || c == '_' {
|
|
|
|
test += string(c)
|
|
|
|
}
|
2017-11-06 16:23:07 +01:00
|
|
|
}
|
2017-12-15 02:10:05 +01:00
|
|
|
|
2018-04-12 22:50:07 +02:00
|
|
|
b := make([]byte, 4)
|
2018-06-05 01:34:38 +02:00
|
|
|
_, err = cryptorand.Read(b)
|
2018-04-12 22:50:07 +02:00
|
|
|
contract.AssertNoError(err)
|
|
|
|
|
|
|
|
opts.StackName = strings.ToLower("p-it-" + host + "-" + test + "-" + hex.EncodeToString(b))
|
2017-11-06 16:23:07 +01:00
|
|
|
}
|
2017-11-16 16:49:07 +01:00
|
|
|
|
2017-12-15 02:10:05 +01:00
|
|
|
return tokens.QName(opts.StackName)
|
2017-11-06 16:23:07 +01:00
|
|
|
}
|
|
|
|
|
2018-08-16 03:14:17 +02:00
|
|
|
// GetStackNameWithOwner gets the name of the stack prepended with an owner, if PULUMI_TEST_OWNER is set.
|
|
|
|
// We use this in CI to create test stacks in an organization that all developers have access to, for debugging.
|
|
|
|
func (opts *ProgramTestOptions) GetStackNameWithOwner() tokens.QName {
|
|
|
|
if owner := os.Getenv("PULUMI_TEST_OWNER"); owner != "" {
|
|
|
|
return tokens.QName(fmt.Sprintf("%s/%s", owner, opts.GetStackName()))
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts.GetStackName()
|
|
|
|
}
|
|
|
|
|
2017-08-06 02:49:48 +02:00
|
|
|
// With combines a source set of options with a set of overrides.
|
2017-10-23 03:54:29 +02:00
|
|
|
func (opts ProgramTestOptions) With(overrides ProgramTestOptions) ProgramTestOptions {
|
2017-08-06 02:49:48 +02:00
|
|
|
if overrides.Dir != "" {
|
|
|
|
opts.Dir = overrides.Dir
|
|
|
|
}
|
|
|
|
if overrides.Dependencies != nil {
|
|
|
|
opts.Dependencies = overrides.Dependencies
|
|
|
|
}
|
2018-11-14 22:27:32 +01:00
|
|
|
if overrides.Overrides != nil {
|
|
|
|
opts.Overrides = overrides.Overrides
|
|
|
|
}
|
2017-08-06 02:49:48 +02:00
|
|
|
for k, v := range overrides.Config {
|
|
|
|
if opts.Config == nil {
|
|
|
|
opts.Config = make(map[string]string)
|
|
|
|
}
|
|
|
|
opts.Config[k] = v
|
|
|
|
}
|
2017-11-14 18:33:22 +01:00
|
|
|
for k, v := range overrides.Secrets {
|
|
|
|
if opts.Secrets == nil {
|
|
|
|
opts.Secrets = make(map[string]string)
|
|
|
|
}
|
|
|
|
opts.Secrets[k] = v
|
|
|
|
}
|
2019-10-07 13:11:36 +02:00
|
|
|
if overrides.SecretsProvider != "" {
|
|
|
|
opts.SecretsProvider = overrides.SecretsProvider
|
2018-05-03 22:44:21 +02:00
|
|
|
}
|
2017-08-06 02:49:48 +02:00
|
|
|
if overrides.EditDirs != nil {
|
|
|
|
opts.EditDirs = overrides.EditDirs
|
|
|
|
}
|
2017-11-14 18:33:22 +01:00
|
|
|
if overrides.ExtraRuntimeValidation != nil {
|
|
|
|
opts.ExtraRuntimeValidation = overrides.ExtraRuntimeValidation
|
|
|
|
}
|
2017-11-15 06:02:47 +01:00
|
|
|
if overrides.RelativeWorkDir != "" {
|
|
|
|
opts.RelativeWorkDir = overrides.RelativeWorkDir
|
|
|
|
}
|
2019-10-07 13:11:36 +02:00
|
|
|
if overrides.AllowEmptyPreviewChanges {
|
|
|
|
opts.AllowEmptyPreviewChanges = overrides.AllowEmptyPreviewChanges
|
2017-11-14 18:33:22 +01:00
|
|
|
}
|
2019-10-07 13:11:36 +02:00
|
|
|
if overrides.AllowEmptyUpdateChanges {
|
|
|
|
opts.AllowEmptyUpdateChanges = overrides.AllowEmptyUpdateChanges
|
2018-07-07 07:06:28 +02:00
|
|
|
}
|
2018-08-30 18:08:19 +02:00
|
|
|
if overrides.ExpectFailure {
|
|
|
|
opts.ExpectFailure = overrides.ExpectFailure
|
|
|
|
}
|
|
|
|
if overrides.ExpectRefreshChanges {
|
|
|
|
opts.ExpectRefreshChanges = overrides.ExpectRefreshChanges
|
|
|
|
}
|
2020-01-29 20:57:45 +01:00
|
|
|
if overrides.RetryFailedSteps {
|
|
|
|
opts.RetryFailedSteps = overrides.RetryFailedSteps
|
|
|
|
}
|
2018-08-31 18:34:26 +02:00
|
|
|
if overrides.SkipRefresh {
|
|
|
|
opts.SkipRefresh = overrides.SkipRefresh
|
|
|
|
}
|
2020-02-07 21:36:23 +01:00
|
|
|
if overrides.SkipPreview {
|
|
|
|
opts.SkipPreview = overrides.SkipPreview
|
|
|
|
}
|
|
|
|
if overrides.SkipUpdate {
|
|
|
|
opts.SkipUpdate = overrides.SkipUpdate
|
|
|
|
}
|
|
|
|
if overrides.SkipExportImport {
|
|
|
|
opts.SkipExportImport = overrides.SkipExportImport
|
|
|
|
}
|
|
|
|
if overrides.SkipEmptyPreviewUpdate {
|
|
|
|
opts.SkipEmptyPreviewUpdate = overrides.SkipEmptyPreviewUpdate
|
|
|
|
}
|
2019-06-28 18:40:21 +02:00
|
|
|
if overrides.SkipStackRemoval {
|
|
|
|
opts.SkipStackRemoval = overrides.SkipStackRemoval
|
|
|
|
}
|
2019-10-07 13:11:36 +02:00
|
|
|
if overrides.Quick {
|
|
|
|
opts.Quick = overrides.Quick
|
2018-08-30 18:08:19 +02:00
|
|
|
}
|
2019-10-07 13:11:36 +02:00
|
|
|
if overrides.PreviewCommandlineFlags != nil {
|
|
|
|
opts.PreviewCommandlineFlags = append(opts.PreviewCommandlineFlags, overrides.PreviewCommandlineFlags...)
|
2018-08-30 18:08:19 +02:00
|
|
|
}
|
2019-10-07 13:11:36 +02:00
|
|
|
if overrides.UpdateCommandlineFlags != nil {
|
|
|
|
opts.UpdateCommandlineFlags = append(opts.UpdateCommandlineFlags, overrides.UpdateCommandlineFlags...)
|
|
|
|
}
|
|
|
|
if overrides.QueryCommandlineFlags != nil {
|
|
|
|
opts.QueryCommandlineFlags = append(opts.QueryCommandlineFlags, overrides.QueryCommandlineFlags...)
|
|
|
|
}
|
|
|
|
if overrides.RunBuild {
|
|
|
|
opts.RunBuild = overrides.RunBuild
|
|
|
|
}
|
|
|
|
if overrides.RunUpdateTest {
|
|
|
|
opts.RunUpdateTest = overrides.RunUpdateTest
|
|
|
|
}
|
2021-01-19 20:18:45 +01:00
|
|
|
if overrides.DecryptSecretsInOutput {
|
|
|
|
opts.DecryptSecretsInOutput = overrides.DecryptSecretsInOutput
|
|
|
|
}
|
2019-10-07 13:11:36 +02:00
|
|
|
if overrides.CloudURL != "" {
|
|
|
|
opts.CloudURL = overrides.CloudURL
|
|
|
|
}
|
|
|
|
if overrides.StackName != "" {
|
|
|
|
opts.StackName = overrides.StackName
|
|
|
|
}
|
|
|
|
if overrides.Tracing != "" {
|
|
|
|
opts.Tracing = overrides.Tracing
|
|
|
|
}
|
|
|
|
if overrides.NoParallel {
|
|
|
|
opts.NoParallel = overrides.NoParallel
|
|
|
|
}
|
|
|
|
if overrides.PrePulumiCommand != nil {
|
|
|
|
opts.PrePulumiCommand = overrides.PrePulumiCommand
|
|
|
|
}
|
|
|
|
if overrides.ReportStats != nil {
|
|
|
|
opts.ReportStats = overrides.ReportStats
|
|
|
|
}
|
|
|
|
if overrides.Stdout != nil {
|
|
|
|
opts.Stdout = overrides.Stdout
|
|
|
|
}
|
|
|
|
if overrides.Stderr != nil {
|
|
|
|
opts.Stderr = overrides.Stderr
|
|
|
|
}
|
|
|
|
if overrides.Verbose {
|
|
|
|
opts.Verbose = overrides.Verbose
|
2018-08-30 18:08:19 +02:00
|
|
|
}
|
|
|
|
if overrides.DebugLogLevel != 0 {
|
|
|
|
opts.DebugLogLevel = overrides.DebugLogLevel
|
|
|
|
}
|
|
|
|
if overrides.DebugUpdates {
|
|
|
|
opts.DebugUpdates = overrides.DebugUpdates
|
|
|
|
}
|
2019-10-07 13:11:36 +02:00
|
|
|
if overrides.Bin != "" {
|
|
|
|
opts.Bin = overrides.Bin
|
|
|
|
}
|
|
|
|
if overrides.YarnBin != "" {
|
|
|
|
opts.YarnBin = overrides.YarnBin
|
|
|
|
}
|
|
|
|
if overrides.GoBin != "" {
|
|
|
|
opts.GoBin = overrides.GoBin
|
|
|
|
}
|
|
|
|
if overrides.PipenvBin != "" {
|
|
|
|
opts.PipenvBin = overrides.PipenvBin
|
|
|
|
}
|
2018-08-30 18:08:19 +02:00
|
|
|
if overrides.Env != nil {
|
|
|
|
opts.Env = append(opts.Env, overrides.Env...)
|
|
|
|
}
|
2021-02-12 03:16:07 +01:00
|
|
|
if overrides.UsePipenv {
|
|
|
|
opts.UsePipenv = overrides.UsePipenv
|
|
|
|
}
|
2017-08-06 02:49:48 +02:00
|
|
|
return opts
|
2017-07-13 21:19:17 +02:00
|
|
|
}
|
|
|
|
|
2018-09-20 22:08:29 +02:00
|
|
|
type regexFlag struct {
|
|
|
|
re *regexp.Regexp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rf *regexFlag) String() string {
|
|
|
|
if rf.re == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return rf.re.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rf *regexFlag) Set(v string) error {
|
|
|
|
r, err := regexp.Compile(v)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rf.re = r
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var directoryMatcher regexFlag
|
|
|
|
var listDirs bool
|
2020-06-10 01:42:53 +02:00
|
|
|
var pipMutex *fsutil.FileMutex
|
2018-09-20 22:08:29 +02:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.Var(&directoryMatcher, "dirs", "optional list of regexes to use to select integration tests to run")
|
|
|
|
flag.BoolVar(&listDirs, "list-dirs", false, "list available integration tests without running them")
|
2019-01-23 18:32:59 +01:00
|
|
|
|
2020-06-10 01:42:53 +02:00
|
|
|
mutexPath := filepath.Join(os.TempDir(), "pip-mutex.lock")
|
|
|
|
pipMutex = fsutil.NewFileMutex(mutexPath)
|
2018-09-20 22:08:29 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 20:46:10 +01:00
|
|
|
// GetLogs retrieves the logs for a given stack in a particular region making the query provided.
|
|
|
|
//
|
|
|
|
// [provider] should be one of "aws" or "azure"
|
|
|
|
func GetLogs(
|
|
|
|
t *testing.T,
|
|
|
|
provider, region string,
|
|
|
|
stackInfo RuntimeValidationStackInfo,
|
|
|
|
query operations.LogQuery) *[]operations.LogEntry {
|
|
|
|
|
2019-08-01 19:33:52 +02:00
|
|
|
snap, err := stack.DeserializeDeploymentV3(*stackInfo.Deployment, stack.DefaultSecretsProvider)
|
2019-04-17 22:48:38 +02:00
|
|
|
assert.NoError(t, err)
|
2018-11-28 20:46:10 +01:00
|
|
|
|
2019-04-17 22:48:38 +02:00
|
|
|
tree := operations.NewResourceTree(snap.Resources)
|
2018-11-28 20:46:10 +01:00
|
|
|
if !assert.NotNil(t, tree) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := map[config.Key]string{
|
|
|
|
config.MustMakeKey(provider, "region"): region,
|
|
|
|
}
|
|
|
|
ops := tree.OperationsProvider(cfg)
|
|
|
|
|
|
|
|
// Validate logs from example
|
|
|
|
logs, err := ops.GetLogs(query)
|
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return logs
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func prepareProgram(t *testing.T, opts *ProgramTestOptions) {
|
2018-09-20 22:08:29 +02:00
|
|
|
// If we're just listing tests, simply print this test's directory.
|
|
|
|
if listDirs {
|
|
|
|
fmt.Printf("%s\n", opts.Dir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a matcher, ensure that this test matches its pattern.
|
|
|
|
if directoryMatcher.re != nil && !directoryMatcher.re.Match([]byte(opts.Dir)) {
|
|
|
|
t.Skip(fmt.Sprintf("Skipping: '%v' does not match '%v'", opts.Dir, directoryMatcher.re))
|
|
|
|
}
|
|
|
|
|
2018-02-21 06:05:57 +01:00
|
|
|
// Disable stack backups for tests to avoid filling up ~/.pulumi/backups with unnecessary
|
|
|
|
// backups of test stacks.
|
2018-09-05 16:53:31 +02:00
|
|
|
if err := os.Setenv(filestate.DisableCheckpointBackupsEnvVar, "1"); err != nil {
|
|
|
|
t.Errorf("error setting env var '%s': %v", filestate.DisableCheckpointBackupsEnvVar, err)
|
2018-02-21 06:05:57 +01:00
|
|
|
}
|
|
|
|
|
2019-01-03 23:18:19 +01:00
|
|
|
// We want tests to default into being ran in parallel, hence the odd double negative.
|
|
|
|
if !opts.NoParallel {
|
|
|
|
t.Parallel()
|
|
|
|
}
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
|
2018-10-03 01:08:03 +02:00
|
|
|
if ciutil.IsCI() && os.Getenv("PULUMI_ACCESS_TOKEN") == "" {
|
2018-06-12 01:01:04 +02:00
|
|
|
t.Skip("Skipping: PULUMI_ACCESS_TOKEN is not set")
|
|
|
|
}
|
|
|
|
|
2018-01-20 08:07:38 +01:00
|
|
|
// If the test panics, recover and log instead of letting the panic escape the test. Even though *this* test will
|
|
|
|
// have run deferred functions and cleaned up, if the panic reaches toplevel it will kill the process and prevent
|
|
|
|
// other tests running in parallel from cleaning up.
|
|
|
|
defer func() {
|
|
|
|
if failure := recover(); failure != nil {
|
|
|
|
t.Errorf("panic testing %v: %v", opts.Dir, failure)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-05-29 20:24:51 +02:00
|
|
|
// Set up some default values for sending test reports and tracing data. We use environment varaiables to
|
|
|
|
// control these globally and set reasonable values for our own use in CI.
|
|
|
|
if opts.ReportStats == nil {
|
|
|
|
if v := os.Getenv("PULUMI_TEST_REPORT_CONFIG"); v != "" {
|
|
|
|
splits := strings.Split(v, ":")
|
|
|
|
if len(splits) != 3 {
|
|
|
|
t.Errorf("report config should be set to a value of the form: <aws-region>:<bucket-name>:<keyPrefix>")
|
|
|
|
}
|
|
|
|
|
|
|
|
opts.ReportStats = NewS3Reporter(splits[0], splits[1], splits[2])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.Tracing == "" {
|
|
|
|
opts.Tracing = os.Getenv("PULUMI_TEST_TRACE_ENDPOINT")
|
|
|
|
}
|
2020-02-17 19:40:46 +01:00
|
|
|
}
|
2018-05-29 20:24:51 +02:00
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// ProgramTest runs a lifecycle of Pulumi commands in a program working directory, using the `pulumi` and `yarn`
|
|
|
|
// binaries available on PATH. It essentially executes the following workflow:
|
|
|
|
//
|
|
|
|
// yarn install
|
|
|
|
// yarn link <each opts.Depencies>
|
|
|
|
// (+) yarn run build
|
|
|
|
// pulumi init
|
|
|
|
// (*) pulumi login
|
|
|
|
// pulumi stack init integrationtesting
|
|
|
|
// pulumi config set <each opts.Config>
|
|
|
|
// pulumi config set --secret <each opts.Secrets>
|
|
|
|
// pulumi preview
|
|
|
|
// pulumi up
|
|
|
|
// pulumi stack export --file stack.json
|
|
|
|
// pulumi stack import --file stack.json
|
|
|
|
// pulumi preview (expected to be empty)
|
|
|
|
// pulumi up (expected to be empty)
|
|
|
|
// pulumi destroy --yes
|
|
|
|
// pulumi stack rm --yes integrationtesting
|
|
|
|
//
|
|
|
|
// (*) Only if PULUMI_ACCESS_TOKEN is set.
|
|
|
|
// (+) Only if `opts.RunBuild` is true.
|
|
|
|
//
|
|
|
|
// All commands must return success return codes for the test to succeed, unless ExpectFailure is true.
|
|
|
|
func ProgramTest(t *testing.T, opts *ProgramTestOptions) {
|
|
|
|
prepareProgram(t, opts)
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
pt := newProgramTester(t, opts)
|
2020-02-17 19:40:46 +01:00
|
|
|
err := pt.TestLifeCycleInitAndDestroy()
|
2017-12-20 21:10:46 +01:00
|
|
|
assert.NoError(t, err)
|
2017-12-11 23:42:42 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// ProgramTestManualLifeCycle returns a ProgramTester than must be manually controlled in terms of its lifecycle
|
|
|
|
func ProgramTestManualLifeCycle(t *testing.T, opts *ProgramTestOptions) *ProgramTester {
|
|
|
|
prepareProgram(t, opts)
|
|
|
|
pt := newProgramTester(t, opts)
|
|
|
|
return pt
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProgramTester contains state associated with running a single test pass.
|
|
|
|
type ProgramTester struct {
|
2019-11-20 21:52:57 +01:00
|
|
|
t *testing.T // the Go tester for this run.
|
|
|
|
opts *ProgramTestOptions // options that control this test run.
|
|
|
|
bin string // the `pulumi` binary we are using.
|
|
|
|
yarnBin string // the `yarn` binary we are using.
|
|
|
|
goBin string // the `go` binary we are using.
|
2020-06-10 01:42:53 +02:00
|
|
|
pythonBin string // the `python` binary we are using.
|
2019-11-20 21:52:57 +01:00
|
|
|
pipenvBin string // The `pipenv` binary we are using.
|
|
|
|
dotNetBin string // the `dotnet` binary we are using.
|
|
|
|
eventLog string // The path to the event log for this test.
|
|
|
|
maxStepTries int // The maximum number of times to retry a failed pulumi step.
|
2020-02-17 19:40:46 +01:00
|
|
|
tmpdir string // the temporary directory we use for our test environment
|
|
|
|
projdir string // the project directory we use for this run
|
|
|
|
TestFinished bool // whether or not the test if finished
|
2018-01-06 02:40:41 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func newProgramTester(t *testing.T, opts *ProgramTestOptions) *ProgramTester {
|
2019-09-07 02:07:54 +02:00
|
|
|
stackName := opts.GetStackName()
|
2019-11-20 21:52:57 +01:00
|
|
|
maxStepTries := 1
|
|
|
|
if opts.RetryFailedSteps {
|
|
|
|
maxStepTries = 3
|
|
|
|
}
|
2020-02-07 21:36:23 +01:00
|
|
|
if opts.Quick {
|
|
|
|
opts.SkipPreview = true
|
|
|
|
opts.SkipExportImport = true
|
|
|
|
opts.SkipEmptyPreviewUpdate = true
|
|
|
|
}
|
2020-02-17 19:40:46 +01:00
|
|
|
return &ProgramTester{
|
2019-11-20 21:52:57 +01:00
|
|
|
t: t,
|
|
|
|
opts: opts,
|
2019-12-13 13:58:52 +01:00
|
|
|
eventLog: filepath.Join(os.TempDir(), string(stackName)+"-events.json"),
|
2019-11-20 21:52:57 +01:00
|
|
|
maxStepTries: maxStepTries,
|
2019-01-19 02:00:12 +01:00
|
|
|
}
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
2017-12-11 23:42:42 +01:00
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) getBin() (string, error) {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
return getCmdBin(&pt.bin, "pulumi", pt.opts.Bin)
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) getYarnBin() (string, error) {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
return getCmdBin(&pt.yarnBin, "yarn", pt.opts.YarnBin)
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) getGoBin() (string, error) {
|
2018-06-10 18:17:19 +02:00
|
|
|
return getCmdBin(&pt.goBin, "go", pt.opts.GoBin)
|
|
|
|
}
|
|
|
|
|
2020-06-10 01:42:53 +02:00
|
|
|
// getPythonBin returns a path to the currently-installed `python` binary, or an error if it could not be found.
|
|
|
|
func (pt *ProgramTester) getPythonBin() (string, error) {
|
|
|
|
if pt.pythonBin == "" {
|
|
|
|
pt.pythonBin = pt.opts.PythonBin
|
|
|
|
if pt.opts.PythonBin == "" {
|
|
|
|
var err error
|
2021-02-11 20:34:07 +01:00
|
|
|
// Look for `python3` by default, but fallback to `python` if not found, except on Windows
|
|
|
|
// where we look for these in the reverse order because the default python.org Windows
|
|
|
|
// installation does not include a `python3` binary, and the existence of a `python3.exe`
|
|
|
|
// symlink to `python.exe` on some systems does not work correctly with the Python `venv`
|
|
|
|
// module.
|
2020-06-10 01:42:53 +02:00
|
|
|
pythonCmds := []string{"python3", "python"}
|
2021-02-11 20:34:07 +01:00
|
|
|
if runtime.GOOS == windowsOS {
|
|
|
|
pythonCmds = []string{"python", "python3"}
|
|
|
|
}
|
2020-06-10 01:42:53 +02:00
|
|
|
for _, bin := range pythonCmds {
|
|
|
|
pt.pythonBin, err = exec.LookPath(bin)
|
|
|
|
// Break on the first cmd we find on the path (if any).
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.Wrapf(err, "Expected to find one of %q on $PATH", pythonCmds)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pt.pythonBin, nil
|
|
|
|
}
|
|
|
|
|
2018-11-05 22:52:37 +01:00
|
|
|
// getPipenvBin returns a path to the currently-installed Pipenv tool, or an error if the tool could not be found.
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) getPipenvBin() (string, error) {
|
2018-11-05 22:52:37 +01:00
|
|
|
return getCmdBin(&pt.pipenvBin, "pipenv", pt.opts.PipenvBin)
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) getDotNetBin() (string, error) {
|
2019-10-26 01:59:50 +02:00
|
|
|
return getCmdBin(&pt.dotNetBin, "dotnet", pt.opts.DotNetBin)
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) pulumiCmd(args []string) ([]string, error) {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
bin, err := pt.getBin()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cmd := []string{bin}
|
|
|
|
if du := pt.opts.GetDebugLogLevel(); du > 0 {
|
2018-05-03 22:44:21 +02:00
|
|
|
cmd = append(cmd, "--logtostderr", "-v="+strconv.Itoa(du))
|
|
|
|
}
|
|
|
|
cmd = append(cmd, args...)
|
|
|
|
if tracing := pt.opts.Tracing; tracing != "" {
|
|
|
|
cmd = append(cmd, "--tracing", tracing)
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
2018-05-03 22:44:21 +02:00
|
|
|
return cmd, nil
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) yarnCmd(args []string) ([]string, error) {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
bin, err := pt.getYarnBin()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
result := []string{bin}
|
|
|
|
result = append(result, args...)
|
|
|
|
return withOptionalYarnFlags(result), nil
|
|
|
|
}
|
|
|
|
|
2020-06-10 01:42:53 +02:00
|
|
|
func (pt *ProgramTester) pythonCmd(args []string) ([]string, error) {
|
|
|
|
bin, err := pt.getPythonBin()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := []string{bin}
|
|
|
|
return append(cmd, args...), nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) pipenvCmd(args []string) ([]string, error) {
|
2018-11-05 22:52:37 +01:00
|
|
|
bin, err := pt.getPipenvBin()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := []string{bin}
|
|
|
|
return append(cmd, args...), nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) runCommand(name string, args []string, wd string) error {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
return RunCommand(pt.t, name, args, wd, pt.opts)
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) runPulumiCommand(name string, args []string, wd string, expectFailure bool) error {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
cmd, err := pt.pulumiCmd(args)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-05-15 18:48:56 +02:00
|
|
|
|
|
|
|
var postFn func(error) error
|
|
|
|
if pt.opts.PrePulumiCommand != nil {
|
|
|
|
postFn, err = pt.opts.PrePulumiCommand(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-20 21:52:57 +01:00
|
|
|
isUpdate := args[0] == "preview" || args[0] == "up" || args[0] == "destroy" || args[0] == "refresh"
|
|
|
|
|
Python Dynamic Providers (#2900)
Dynamic providers in Python.
This PR uses [dill](https://pypi.org/project/dill/) for code serialization, along with a customization to help ensure deterministic serialization results.
One notable limitation - which I believe is a general requirement of Python - is that any serialization of Python functions must serialize byte code, and byte code is not safely versioned across Python versions. So any resource created with Python `3.x.y` can only be updated by exactly the same version of Python. This is very constraining, but it's not clear there is any other option within the realm of what "dynamic providers" are as a feature. It is plausible that we could ensure that updates which only update the serialized provider can avoid calling the dynamic provider operations, so that version updates could still be accomplished. We can explore this separately.
```py
from pulumi import ComponentResource, export, Input, Output
from pulumi.dynamic import Resource, ResourceProvider, CreateResult, UpdateResult
from typing import Optional
from github import Github, GithubObject
auth = "<auth token>"
g = Github(auth)
class GithubLabelArgs(object):
owner: Input[str]
repo: Input[str]
name: Input[str]
color: Input[str]
description: Optional[Input[str]]
def __init__(self, owner, repo, name, color, description=None):
self.owner = owner
self.repo = repo
self.name = name
self.color = color
self.description = description
class GithubLabelProvider(ResourceProvider):
def create(self, props):
l = g.get_user(props["owner"]).get_repo(props["repo"]).create_label(
name=props["name"],
color=props["color"],
description=props.get("description", GithubObject.NotSet))
return CreateResult(l.name, {**props, **l.raw_data})
def update(self, id, _olds, props):
l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id)
l.edit(name=props["name"],
color=props["color"],
description=props.get("description", GithubObject.NotSet))
return UpdateResult({**props, **l.raw_data})
def delete(self, id, props):
l = g.get_user(props["owner"]).get_repo(props["repo"]).get_label(id)
l.delete()
class GithubLabel(Resource):
name: Output[str]
color: Output[str]
url: Output[str]
description: Output[str]
def __init__(self, name, args: GithubLabelArgs, opts = None):
full_args = {'url':None, 'description':None, 'name':None, 'color':None, **vars(args)}
super().__init__(GithubLabelProvider(), name, full_args, opts)
label = GithubLabel("foo", GithubLabelArgs("lukehoban", "todo", "mylabel", "d94f0b"))
export("label_color", label.color)
export("label_url", label.url)
```
Fixes https://github.com/pulumi/pulumi/issues/2902.
2019-07-19 19:18:25 +02:00
|
|
|
// If we're doing a preview or an update and this project is a Python project, we need to run
|
|
|
|
// the command in the context of the virtual environment that Pipenv created in order to pick up
|
|
|
|
// the correct version of Python. We also need to do this for destroy and refresh so that
|
|
|
|
// dynamic providers are run in the right virtual environment.
|
2020-06-10 01:42:53 +02:00
|
|
|
// This is only necessary when not using automatic virtual environment support.
|
2021-02-12 03:16:07 +01:00
|
|
|
if pt.opts.UsePipenv && isUpdate {
|
2018-11-05 22:52:37 +01:00
|
|
|
projinfo, err := pt.getProjinfo(wd)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if projinfo.Proj.Runtime.Name() == "python" {
|
|
|
|
pipenvBin, err := pt.getPipenvBin()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// "pipenv run" activates the current virtual environment and runs the remainder of the arguments as if it
|
|
|
|
// were a command.
|
|
|
|
cmd = append([]string{pipenvBin, "run"}, cmd...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-20 21:52:57 +01:00
|
|
|
_, _, err = retry.Until(context.Background(), retry.Acceptor{
|
|
|
|
Accept: func(try int, nextRetryTime time.Duration) (bool, interface{}, error) {
|
|
|
|
runerr := pt.runCommand(name, cmd, wd)
|
|
|
|
if runerr == nil {
|
|
|
|
return true, nil, nil
|
|
|
|
} else if _, ok := runerr.(*exec.ExitError); ok && isUpdate && !expectFailure {
|
|
|
|
// the update command failed, let's try again, assuming we haven't failed a few times.
|
|
|
|
if try+1 >= pt.maxStepTries {
|
|
|
|
return false, nil, errors.Errorf("%v did not succeed after %v tries", cmd, try+1)
|
|
|
|
}
|
|
|
|
|
|
|
|
pt.t.Logf("%v failed: %v; retrying...", cmd, runerr)
|
|
|
|
return false, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// someother error, fail
|
|
|
|
return false, nil, runerr
|
|
|
|
},
|
|
|
|
})
|
2018-05-15 18:48:56 +02:00
|
|
|
if postFn != nil {
|
2019-11-20 21:52:57 +01:00
|
|
|
if postErr := postFn(err); postErr != nil {
|
|
|
|
return multierror.Append(err, postErr)
|
2018-05-15 18:48:56 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-20 21:52:57 +01:00
|
|
|
return err
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
2017-08-06 02:49:48 +02:00
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) runYarnCommand(name string, args []string, wd string) error {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
cmd, err := pt.yarnCmd(args)
|
2018-01-06 01:39:13 +01:00
|
|
|
if err != nil {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
return err
|
|
|
|
}
|
2018-02-04 01:17:51 +01:00
|
|
|
|
|
|
|
_, _, err = retry.Until(context.Background(), retry.Acceptor{
|
|
|
|
Accept: func(try int, nextRetryTime time.Duration) (bool, interface{}, error) {
|
|
|
|
runerr := pt.runCommand(name, cmd, wd)
|
|
|
|
if runerr == nil {
|
|
|
|
return true, nil, nil
|
|
|
|
} else if _, ok := runerr.(*exec.ExitError); ok {
|
|
|
|
// yarn failed, let's try again, assuming we haven't failed a few times.
|
2019-11-20 21:52:57 +01:00
|
|
|
if try+1 >= 3 {
|
|
|
|
return false, nil, errors.Errorf("%v did not complete after %v tries", cmd, try+1)
|
2018-02-04 01:17:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// someother error, fail
|
|
|
|
return false, nil, runerr
|
|
|
|
},
|
|
|
|
})
|
|
|
|
return err
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
|
|
|
|
2020-06-10 01:42:53 +02:00
|
|
|
func (pt *ProgramTester) runPythonCommand(name string, args []string, wd string) error {
|
|
|
|
cmd, err := pt.pythonCmd(args)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return pt.runCommand(name, cmd, wd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ProgramTester) runVirtualEnvCommand(name string, args []string, wd string) error {
|
|
|
|
// When installing with `pip install -e`, a PKG-INFO file is created. If two packages are being installed
|
|
|
|
// this way simultaneously (which happens often, when running tests), both installations will be writing the
|
|
|
|
// same file simultaneously. If one process catches "PKG-INFO" in a half-written state, the one process that
|
|
|
|
// observed the torn write will fail to install the package.
|
|
|
|
//
|
|
|
|
// To avoid this problem, we use pipMutex to explicitly serialize installation operations. Doing so avoids
|
|
|
|
// the problem of multiple processes stomping on the same files in the source tree. Note that pipMutex is a
|
|
|
|
// file mutex, so this strategy works even if the go test runner chooses to split up text execution across
|
|
|
|
// multiple processes. (Furthermore, each test gets an instance of ProgramTester and thus the mutex, so we'd
|
|
|
|
// need to be sharing the mutex globally in each test process if we weren't using the file system to lock.)
|
|
|
|
if name == "virtualenv-pip-install-package" {
|
|
|
|
if err := pipMutex.Lock(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if pt.opts.Verbose {
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("acquired pip install lock")
|
|
|
|
defer pt.t.Log("released pip install lock")
|
2020-06-10 01:42:53 +02:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := pipMutex.Unlock(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
virtualenvBinPath, err := getVirtualenvBinPath(wd, args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := append([]string{virtualenvBinPath}, args[1:]...)
|
|
|
|
return pt.runCommand(name, cmd, wd)
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) runPipenvCommand(name string, args []string, wd string) error {
|
2019-01-17 21:41:53 +01:00
|
|
|
// Pipenv uses setuptools to install and uninstall packages. Setuptools has an installation mode called "develop"
|
|
|
|
// that we use to install the package being tested, since it is 1) lightweight and 2) not doing so has its own set
|
|
|
|
// of annoying problems.
|
|
|
|
//
|
|
|
|
// Setuptools develop does three things:
|
|
|
|
// 1. It invokes the "egg_info" command in the target package,
|
|
|
|
// 2. It creates a special `.egg-link` sentinel file in the current site-packages folder, pointing to the package
|
|
|
|
// being installed's path on disk
|
|
|
|
// 3. It updates easy-install.pth in site-packages so that pip understand that this package has been installed.
|
|
|
|
//
|
|
|
|
// Steps 2 and 3 operate entirely within the context of a virtualenv. The state that they mutate is fully contained
|
|
|
|
// within the current virtualenv. However, step 1 operates in the context of the package's source tree. Egg info
|
|
|
|
// is responsible for producing a minimal "egg" for a particular package, and its largest responsibility is creating
|
|
|
|
// a PKG-INFO file for a package. PKG-INFO contains, among other things, the version of the package being installed.
|
|
|
|
//
|
|
|
|
// If two packages are being installed in "develop" mode simultaneously (which happens often, when running tests),
|
|
|
|
// both installations will run "egg_info" on the source tree and both processes will be writing the same files
|
|
|
|
// simultaneously. If one process catches "PKG-INFO" in a half-written state, the one process that observed the
|
|
|
|
// torn write will fail to install the package (setuptools crashes).
|
|
|
|
//
|
2020-06-10 01:42:53 +02:00
|
|
|
// To avoid this problem, we use pipMutex to explicitly serialize installation operations. Doing so avoids the
|
|
|
|
// problem of multiple processes stomping on the same files in the source tree. Note that pipMutex is a file
|
2019-01-19 02:00:12 +01:00
|
|
|
// mutex, so this strategy works even if the go test runner chooses to split up text execution across multiple
|
2020-02-17 19:40:46 +01:00
|
|
|
// processes. (Furthermore, each test gets an instance of ProgramTester and thus the mutex, so we'd need to be
|
2019-01-19 02:00:12 +01:00
|
|
|
// sharing the mutex globally in each test process if we weren't using the file system to lock.)
|
2019-01-17 21:41:53 +01:00
|
|
|
if name == "pipenv-install-package" {
|
2020-06-10 01:42:53 +02:00
|
|
|
if err := pipMutex.Lock(); err != nil {
|
2019-01-23 18:32:59 +01:00
|
|
|
panic(err)
|
2019-01-17 21:41:53 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 18:32:59 +01:00
|
|
|
if pt.opts.Verbose {
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("acquired pip install lock")
|
|
|
|
defer pt.t.Log("released pip install lock")
|
2019-01-23 18:32:59 +01:00
|
|
|
}
|
|
|
|
defer func() {
|
2020-06-10 01:42:53 +02:00
|
|
|
if err := pipMutex.Unlock(); err != nil {
|
2019-01-23 18:32:59 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}()
|
2019-01-17 21:41:53 +01:00
|
|
|
}
|
|
|
|
|
2018-11-05 22:52:37 +01:00
|
|
|
cmd, err := pt.pipenvCmd(args)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return pt.runCommand(name, cmd, wd)
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// TestLifeCyclePrepare prepares a test by creating a temporary directory
|
|
|
|
func (pt *ProgramTester) TestLifeCyclePrepare() error {
|
2018-06-11 22:22:24 +02:00
|
|
|
tmpdir, projdir, err := pt.copyTestToTemporaryDirectory()
|
2020-02-17 19:40:46 +01:00
|
|
|
pt.tmpdir = tmpdir
|
|
|
|
pt.projdir = projdir
|
|
|
|
return err
|
|
|
|
}
|
2018-01-06 01:39:13 +01:00
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// TestCleanUp cleans up the temporary directory that a test used
|
|
|
|
func (pt *ProgramTester) TestCleanUp() {
|
|
|
|
testFinished := pt.TestFinished
|
|
|
|
if pt.tmpdir != "" {
|
|
|
|
if !testFinished || pt.t.Failed() {
|
|
|
|
// Test aborted or failed. Maybe copy to "failed tests" directory.
|
|
|
|
failedTestsDir := os.Getenv("PULUMI_FAILED_TESTS_DIR")
|
|
|
|
if failedTestsDir != "" {
|
|
|
|
dest := filepath.Join(failedTestsDir, pt.t.Name()+uniqueSuffix())
|
|
|
|
contract.IgnoreError(fsutil.CopyFile(dest, pt.tmpdir, nil))
|
2018-01-07 06:05:42 +01:00
|
|
|
}
|
2018-06-15 00:58:37 +02:00
|
|
|
} else {
|
2020-02-17 19:40:46 +01:00
|
|
|
contract.IgnoreError(os.RemoveAll(pt.tmpdir))
|
2018-06-15 00:58:37 +02:00
|
|
|
}
|
2020-02-17 19:40:46 +01:00
|
|
|
} else {
|
|
|
|
// When tmpdir is empty, we ran "in tree", which means we wrote output
|
|
|
|
// to the "command-output" folder in the projdir, and we should clean
|
|
|
|
// it up if the test passed
|
|
|
|
if testFinished && !pt.t.Failed() {
|
|
|
|
contract.IgnoreError(os.RemoveAll(filepath.Join(pt.projdir, commandOutputFolderName)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestLifeCycleInitAndDestroy executes the test and cleans up
|
|
|
|
func (pt *ProgramTester) TestLifeCycleInitAndDestroy() error {
|
|
|
|
err := pt.TestLifeCyclePrepare()
|
|
|
|
if err != nil {
|
2020-02-28 15:14:46 +01:00
|
|
|
return errors.Wrapf(err, "copying test to temp dir %s", pt.tmpdir)
|
2020-02-17 19:40:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pt.TestFinished = false
|
|
|
|
defer pt.TestCleanUp()
|
2018-01-06 01:39:13 +01:00
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
err = pt.TestLifeCycleInitialize()
|
2017-12-09 01:59:28 +01:00
|
|
|
if err != nil {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
return errors.Wrap(err, "initializing test project")
|
2017-12-09 01:59:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that before we exit, we attempt to destroy and remove the stack.
|
|
|
|
defer func() {
|
2020-02-17 19:40:46 +01:00
|
|
|
destroyErr := pt.TestLifeCycleDestroy()
|
|
|
|
assert.NoError(pt.t, destroyErr)
|
2017-12-09 01:59:28 +01:00
|
|
|
}()
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
if err = pt.TestPreviewUpdateAndEdits(); err != nil {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
return errors.Wrap(err, "running test preview, update, and edits")
|
2018-01-10 08:25:49 +01:00
|
|
|
}
|
|
|
|
|
2019-08-20 10:08:09 +02:00
|
|
|
if pt.opts.RunUpdateTest {
|
2020-02-17 19:40:46 +01:00
|
|
|
err = upgradeProjectDeps(pt.projdir, pt)
|
2019-08-20 10:08:09 +02:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "upgrading project dependencies")
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
if err = pt.TestPreviewUpdateAndEdits(); err != nil {
|
2019-08-20 10:08:09 +02:00
|
|
|
return errors.Wrap(err, "running test preview, update, and edits")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
pt.TestFinished = true
|
2018-01-10 08:25:49 +01:00
|
|
|
return nil
|
2017-12-09 01:59:28 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func upgradeProjectDeps(projectDir string, pt *ProgramTester) error {
|
2019-08-20 10:08:09 +02:00
|
|
|
projInfo, err := pt.getProjinfo(projectDir)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "getting project info")
|
|
|
|
}
|
|
|
|
|
|
|
|
switch rt := projInfo.Proj.Runtime.Name(); rt {
|
|
|
|
case NodeJSRuntime:
|
|
|
|
if err = pt.yarnLinkPackageDeps(projectDir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
case PythonRuntime:
|
|
|
|
if err = pt.installPipPackageDeps(projectDir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return errors.Errorf("unrecognized project runtime: %s", rt)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// TestLifeCycleInitialize initializes the project directory and stack along with any configuration
|
|
|
|
func (pt *ProgramTester) TestLifeCycleInitialize() error {
|
|
|
|
dir := pt.projdir
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
stackName := pt.opts.GetStackName()
|
2017-12-09 01:59:28 +01:00
|
|
|
|
2017-11-15 06:02:47 +01:00
|
|
|
// If RelativeWorkDir is specified, apply that relative to the temp folder for use as working directory during tests.
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
if pt.opts.RelativeWorkDir != "" {
|
2019-12-13 13:58:52 +01:00
|
|
|
dir = filepath.Join(dir, pt.opts.RelativeWorkDir)
|
2017-11-15 06:02:47 +01:00
|
|
|
}
|
|
|
|
|
2018-04-03 06:34:54 +02:00
|
|
|
// Set the default target Pulumi API if not overridden in options.
|
|
|
|
if pt.opts.CloudURL == "" {
|
|
|
|
pulumiAPI := os.Getenv("PULUMI_API")
|
|
|
|
if pulumiAPI != "" {
|
|
|
|
pt.opts.CloudURL = pulumiAPI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-16 21:04:35 +02:00
|
|
|
// Ensure all links are present, the stack is created, and all configs are applied.
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Logf("Initializing project (dir %s; stack %s)", dir, stackName)
|
2018-01-04 06:26:50 +01:00
|
|
|
|
|
|
|
// Login as needed.
|
2019-05-03 01:52:00 +02:00
|
|
|
stackInitName := string(pt.opts.GetStackNameWithOwner())
|
|
|
|
|
2018-04-05 00:31:01 +02:00
|
|
|
if os.Getenv("PULUMI_ACCESS_TOKEN") == "" && pt.opts.CloudURL == "" {
|
|
|
|
fmt.Printf("Using existing logged in user for tests. Set PULUMI_ACCESS_TOKEN and/or PULUMI_API to override.\n")
|
|
|
|
} else {
|
|
|
|
// Set PulumiCredentialsPathEnvVar to our CWD, so we use credentials specific to just this
|
|
|
|
// test.
|
|
|
|
pt.opts.Env = append(pt.opts.Env, fmt.Sprintf("%s=%s", workspace.PulumiCredentialsPathEnvVar, dir))
|
2018-01-04 06:26:50 +01:00
|
|
|
|
2018-04-05 00:31:01 +02:00
|
|
|
loginArgs := []string{"login"}
|
|
|
|
loginArgs = addFlagIfNonNil(loginArgs, "--cloud-url", pt.opts.CloudURL)
|
|
|
|
|
2019-09-02 18:29:45 +02:00
|
|
|
// If this is a local OR cloud login, then don't attach the owner to the stack-name.
|
|
|
|
if pt.opts.CloudURL != "" {
|
2019-05-03 01:52:00 +02:00
|
|
|
stackInitName = string(pt.opts.GetStackName())
|
|
|
|
}
|
|
|
|
|
2019-11-20 21:52:57 +01:00
|
|
|
if err := pt.runPulumiCommand("pulumi-login", loginArgs, dir, false); err != nil {
|
2018-04-05 00:31:01 +02:00
|
|
|
return err
|
2018-01-04 06:26:50 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-05 00:31:01 +02:00
|
|
|
|
2018-01-04 06:26:50 +01:00
|
|
|
// Stack init
|
2019-05-03 01:52:00 +02:00
|
|
|
stackInitArgs := []string{"stack", "init", stackInitName}
|
2019-08-03 01:12:16 +02:00
|
|
|
if pt.opts.SecretsProvider != "" {
|
|
|
|
stackInitArgs = append(stackInitArgs, "--secrets-provider", pt.opts.SecretsProvider)
|
|
|
|
}
|
2019-11-20 21:52:57 +01:00
|
|
|
if err := pt.runPulumiCommand("pulumi-stack-init", stackInitArgs, dir, false); err != nil {
|
2018-01-06 01:39:13 +01:00
|
|
|
return err
|
2017-11-06 18:04:38 +01:00
|
|
|
}
|
2017-12-09 01:59:28 +01:00
|
|
|
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
for key, value := range pt.opts.Config {
|
|
|
|
if err := pt.runPulumiCommand("pulumi-config",
|
2019-11-20 21:52:57 +01:00
|
|
|
[]string{"config", "set", key, value}, dir, false); err != nil {
|
2018-01-06 01:39:13 +01:00
|
|
|
return err
|
2017-11-06 18:04:38 +01:00
|
|
|
}
|
2017-10-19 00:37:18 +02:00
|
|
|
}
|
|
|
|
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
for key, value := range pt.opts.Secrets {
|
|
|
|
if err := pt.runPulumiCommand("pulumi-config",
|
2019-11-20 21:52:57 +01:00
|
|
|
[]string{"config", "set", "--secret", key, value}, dir, false); err != nil {
|
2018-01-06 01:39:13 +01:00
|
|
|
return err
|
2017-11-06 18:04:38 +01:00
|
|
|
}
|
2017-08-06 02:49:48 +02:00
|
|
|
}
|
|
|
|
|
Support lists and maps in config (#3342)
This change adds support for lists and maps in config. We now allow
lists/maps (and nested structures) in `Pulumi.<stack>.yaml` (or
`Pulumi.<stack>.json`; yes, we currently support that).
For example:
```yaml
config:
proj:blah:
- a
- b
- c
proj:hello: world
proj:outer:
inner: value
proj:servers:
- port: 80
```
While such structures could be specified in the `.yaml` file manually,
we support setting values in maps/lists from the command line.
As always, you can specify single values with:
```shell
$ pulumi config set hello world
```
Which results in the following YAML:
```yaml
proj:hello world
```
And single value secrets via:
```shell
$ pulumi config set --secret token shhh
```
Which results in the following YAML:
```yaml
proj:token:
secure: v1:VZAhuroR69FkEPTk:isKafsoZVMWA9pQayGzbWNynww==
```
Values in a list can be set from the command line using the new
`--path` flag, which indicates the config key contains a path to a
property in a map or list:
```shell
$ pulumi config set --path names[0] a
$ pulumi config set --path names[1] b
$ pulumi config set --path names[2] c
```
Which results in:
```yaml
proj:names
- a
- b
- c
```
Values can be obtained similarly:
```shell
$ pulumi config get --path names[1]
b
```
Or setting values in a map:
```shell
$ pulumi config set --path outer.inner value
```
Which results in:
```yaml
proj:outer:
inner: value
```
Of course, setting values in nested structures is supported:
```shell
$ pulumi config set --path servers[0].port 80
```
Which results in:
```yaml
proj:servers:
- port: 80
```
If you want to include a period in the name of a property, it can be
specified as:
```
$ pulumi config set --path 'nested["foo.bar"]' baz
```
Which results in:
```yaml
proj:nested:
foo.bar: baz
```
Examples of valid paths:
- root
- root.nested
- 'root["nested"]'
- root.double.nest
- 'root["double"].nest'
- 'root["double"]["nest"]'
- root.array[0]
- root.array[100]
- root.array[0].nested
- root.array[0][1].nested
- root.nested.array[0].double[1]
- 'root["key with \"escaped\" quotes"]'
- 'root["key with a ."]'
- '["root key with \"escaped\" quotes"].nested'
- '["root key with a ."][100]'
Note: paths that contain quotes can be surrounded by single quotes.
When setting values with `--path`, if the value is `"false"` or
`"true"`, it will be saved as the boolean value, and if it is
convertible to an integer, it will be saved as an integer.
Secure values are supported in lists/maps as well:
```shell
$ pulumi config set --path --secret tokens[0] shh
```
Will result in:
```yaml
proj:tokens:
- secure: v1:wpZRCe36sFg1RxwG:WzPeQrCn4n+m4Ks8ps15MxvFXg==
```
Note: maps of length 1 with a key of “secure” and string value are
reserved for storing secret values. Attempting to create such a value
manually will result in an error:
```shell
$ pulumi config set --path parent.secure foo
error: "secure" key in maps of length 1 are reserved
```
**Accessing config values from the command line with JSON**
```shell
$ pulumi config --json
```
Will output:
```json
{
"proj:hello": {
"value": "world",
"secret": false,
"object": false
},
"proj:names": {
"value": "[\"a\",\"b\",\"c\"]",
"secret": false,
"object": true,
"objectValue": [
"a",
"b",
"c"
]
},
"proj:nested": {
"value": "{\"foo.bar\":\"baz\"}",
"secret": false,
"object": true,
"objectValue": {
"foo.bar": "baz"
}
},
"proj:outer": {
"value": "{\"inner\":\"value\"}",
"secret": false,
"object": true,
"objectValue": {
"inner": "value"
}
},
"proj:servers": {
"value": "[{\"port\":80}]",
"secret": false,
"object": true,
"objectValue": [
{
"port": 80
}
]
},
"proj:token": {
"secret": true,
"object": false
},
"proj:tokens": {
"secret": true,
"object": true
}
}
```
If the value is a map or list, `"object"` will be `true`. `"value"` will
contain the object as serialized JSON and a new `"objectValue"` property
will be available containing the value of the object.
If the object contains any secret values, `"secret"` will be `true`, and
just like with scalar values, the value will not be outputted unless
`--show-secrets` is specified.
**Accessing config values from Pulumi programs**
Map/list values are available to Pulumi programs as serialized JSON, so
the existing
`getObject`/`requireObject`/`getSecretObject`/`requireSecretObject`
functions can be used to retrieve such values, e.g.:
```typescript
import * as pulumi from "@pulumi/pulumi";
interface Server {
port: number;
}
const config = new pulumi.Config();
const names = config.requireObject<string[]>("names");
for (const n of names) {
console.log(n);
}
const servers = config.requireObject<Server[]>("servers");
for (const s of servers) {
console.log(s.port);
}
```
2019-11-01 21:41:27 +01:00
|
|
|
for _, cv := range pt.opts.OrderedConfig {
|
|
|
|
configArgs := []string{"config", "set", cv.Key, cv.Value}
|
|
|
|
if cv.Secret {
|
|
|
|
configArgs = append(configArgs, "--secret")
|
|
|
|
}
|
|
|
|
if cv.Path {
|
|
|
|
configArgs = append(configArgs, "--path")
|
|
|
|
}
|
2019-11-20 21:52:57 +01:00
|
|
|
if err := pt.runPulumiCommand("pulumi-config", configArgs, dir, false); err != nil {
|
Support lists and maps in config (#3342)
This change adds support for lists and maps in config. We now allow
lists/maps (and nested structures) in `Pulumi.<stack>.yaml` (or
`Pulumi.<stack>.json`; yes, we currently support that).
For example:
```yaml
config:
proj:blah:
- a
- b
- c
proj:hello: world
proj:outer:
inner: value
proj:servers:
- port: 80
```
While such structures could be specified in the `.yaml` file manually,
we support setting values in maps/lists from the command line.
As always, you can specify single values with:
```shell
$ pulumi config set hello world
```
Which results in the following YAML:
```yaml
proj:hello world
```
And single value secrets via:
```shell
$ pulumi config set --secret token shhh
```
Which results in the following YAML:
```yaml
proj:token:
secure: v1:VZAhuroR69FkEPTk:isKafsoZVMWA9pQayGzbWNynww==
```
Values in a list can be set from the command line using the new
`--path` flag, which indicates the config key contains a path to a
property in a map or list:
```shell
$ pulumi config set --path names[0] a
$ pulumi config set --path names[1] b
$ pulumi config set --path names[2] c
```
Which results in:
```yaml
proj:names
- a
- b
- c
```
Values can be obtained similarly:
```shell
$ pulumi config get --path names[1]
b
```
Or setting values in a map:
```shell
$ pulumi config set --path outer.inner value
```
Which results in:
```yaml
proj:outer:
inner: value
```
Of course, setting values in nested structures is supported:
```shell
$ pulumi config set --path servers[0].port 80
```
Which results in:
```yaml
proj:servers:
- port: 80
```
If you want to include a period in the name of a property, it can be
specified as:
```
$ pulumi config set --path 'nested["foo.bar"]' baz
```
Which results in:
```yaml
proj:nested:
foo.bar: baz
```
Examples of valid paths:
- root
- root.nested
- 'root["nested"]'
- root.double.nest
- 'root["double"].nest'
- 'root["double"]["nest"]'
- root.array[0]
- root.array[100]
- root.array[0].nested
- root.array[0][1].nested
- root.nested.array[0].double[1]
- 'root["key with \"escaped\" quotes"]'
- 'root["key with a ."]'
- '["root key with \"escaped\" quotes"].nested'
- '["root key with a ."][100]'
Note: paths that contain quotes can be surrounded by single quotes.
When setting values with `--path`, if the value is `"false"` or
`"true"`, it will be saved as the boolean value, and if it is
convertible to an integer, it will be saved as an integer.
Secure values are supported in lists/maps as well:
```shell
$ pulumi config set --path --secret tokens[0] shh
```
Will result in:
```yaml
proj:tokens:
- secure: v1:wpZRCe36sFg1RxwG:WzPeQrCn4n+m4Ks8ps15MxvFXg==
```
Note: maps of length 1 with a key of “secure” and string value are
reserved for storing secret values. Attempting to create such a value
manually will result in an error:
```shell
$ pulumi config set --path parent.secure foo
error: "secure" key in maps of length 1 are reserved
```
**Accessing config values from the command line with JSON**
```shell
$ pulumi config --json
```
Will output:
```json
{
"proj:hello": {
"value": "world",
"secret": false,
"object": false
},
"proj:names": {
"value": "[\"a\",\"b\",\"c\"]",
"secret": false,
"object": true,
"objectValue": [
"a",
"b",
"c"
]
},
"proj:nested": {
"value": "{\"foo.bar\":\"baz\"}",
"secret": false,
"object": true,
"objectValue": {
"foo.bar": "baz"
}
},
"proj:outer": {
"value": "{\"inner\":\"value\"}",
"secret": false,
"object": true,
"objectValue": {
"inner": "value"
}
},
"proj:servers": {
"value": "[{\"port\":80}]",
"secret": false,
"object": true,
"objectValue": [
{
"port": 80
}
]
},
"proj:token": {
"secret": true,
"object": false
},
"proj:tokens": {
"secret": true,
"object": true
}
}
```
If the value is a map or list, `"object"` will be `true`. `"value"` will
contain the object as serialized JSON and a new `"objectValue"` property
will be available containing the value of the object.
If the object contains any secret values, `"secret"` will be `true`, and
just like with scalar values, the value will not be outputted unless
`--show-secrets` is specified.
**Accessing config values from Pulumi programs**
Map/list values are available to Pulumi programs as serialized JSON, so
the existing
`getObject`/`requireObject`/`getSecretObject`/`requireSecretObject`
functions can be used to retrieve such values, e.g.:
```typescript
import * as pulumi from "@pulumi/pulumi";
interface Server {
port: number;
}
const config = new pulumi.Config();
const names = config.requireObject<string[]>("names");
for (const n of names) {
console.log(n);
}
const servers = config.requireObject<Server[]>("servers");
for (const s of servers) {
console.log(s.port);
}
```
2019-11-01 21:41:27 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-06 01:39:13 +01:00
|
|
|
return nil
|
2017-12-09 01:59:28 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// TestLifeCycleDestroy destroys a stack and removes it
|
|
|
|
func (pt *ProgramTester) TestLifeCycleDestroy() error {
|
|
|
|
if pt.projdir != "" {
|
|
|
|
// Destroy and remove the stack.
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("Destroying stack")
|
2020-04-14 10:30:25 +02:00
|
|
|
destroy := []string{"destroy", "--non-interactive", "--yes", "--skip-preview"}
|
2020-02-17 19:40:46 +01:00
|
|
|
if pt.opts.GetDebugUpdates() {
|
|
|
|
destroy = append(destroy, "-d")
|
|
|
|
}
|
|
|
|
if err := pt.runPulumiCommand("pulumi-destroy", destroy, pt.projdir, false); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-04 06:26:50 +01:00
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
if pt.t.Failed() {
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Logf("Test failed, retaining stack '%s'", pt.opts.GetStackNameWithOwner())
|
2020-02-17 19:40:46 +01:00
|
|
|
return nil
|
|
|
|
}
|
2018-01-04 06:26:50 +01:00
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
if !pt.opts.SkipStackRemoval {
|
|
|
|
return pt.runPulumiCommand("pulumi-stack-rm", []string{"stack", "rm", "--yes"}, pt.projdir, false)
|
|
|
|
}
|
2019-06-28 18:40:21 +02:00
|
|
|
}
|
|
|
|
return nil
|
2017-12-09 01:59:28 +01:00
|
|
|
}
|
2017-12-08 21:59:39 +01:00
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// TestPreviewUpdateAndEdits runs the preview, update, and any relevant edits
|
|
|
|
func (pt *ProgramTester) TestPreviewUpdateAndEdits() error {
|
|
|
|
dir := pt.projdir
|
2017-12-11 23:42:42 +01:00
|
|
|
// Now preview and update the real changes.
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("Performing primary preview and update")
|
2020-02-17 19:40:46 +01:00
|
|
|
initErr := pt.PreviewAndUpdate(dir, "initial", pt.opts.ExpectFailure, false, false)
|
2017-12-11 23:42:42 +01:00
|
|
|
|
|
|
|
// If the initial preview/update failed, just exit without trying the rest (but make sure to destroy).
|
|
|
|
if initErr != nil {
|
2018-01-06 01:39:13 +01:00
|
|
|
return initErr
|
2017-12-11 23:42:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Perform an empty preview and update; nothing is expected to happen here.
|
2020-02-07 21:36:23 +01:00
|
|
|
if !pt.opts.SkipExportImport {
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("Roundtripping checkpoint via stack export and stack import")
|
2018-06-15 01:01:28 +02:00
|
|
|
|
|
|
|
if err := pt.exportImport(dir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-07 21:36:23 +01:00
|
|
|
}
|
2018-06-15 01:01:28 +02:00
|
|
|
|
2020-02-07 21:36:23 +01:00
|
|
|
if !pt.opts.SkipEmptyPreviewUpdate {
|
2018-05-23 18:17:10 +02:00
|
|
|
msg := ""
|
|
|
|
if !pt.opts.AllowEmptyUpdateChanges {
|
|
|
|
msg = "(no changes expected)"
|
|
|
|
}
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Logf("Performing empty preview and update%s", msg)
|
2020-02-17 19:40:46 +01:00
|
|
|
if err := pt.PreviewAndUpdate(
|
2018-05-23 18:17:10 +02:00
|
|
|
dir, "empty", false, !pt.opts.AllowEmptyPreviewChanges, !pt.opts.AllowEmptyUpdateChanges); err != nil {
|
|
|
|
|
2018-01-06 01:39:13 +01:00
|
|
|
return err
|
2017-12-11 23:42:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run additional validation provided by the test options, passing in the checkpoint info.
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
if err := pt.performExtraRuntimeValidation(pt.opts.ExtraRuntimeValidation, dir); err != nil {
|
2018-01-06 01:39:13 +01:00
|
|
|
return err
|
2017-12-11 23:42:42 +01:00
|
|
|
}
|
|
|
|
|
2018-08-31 18:34:26 +02:00
|
|
|
if !pt.opts.SkipRefresh {
|
|
|
|
// Perform a refresh and ensure it doesn't yield changes.
|
2020-04-14 10:30:25 +02:00
|
|
|
refresh := []string{"refresh", "--non-interactive", "--yes", "--skip-preview"}
|
2018-08-31 18:34:26 +02:00
|
|
|
if pt.opts.GetDebugUpdates() {
|
|
|
|
refresh = append(refresh, "-d")
|
|
|
|
}
|
|
|
|
if !pt.opts.ExpectRefreshChanges {
|
|
|
|
refresh = append(refresh, "--expect-no-changes")
|
|
|
|
}
|
2019-11-20 21:52:57 +01:00
|
|
|
if err := pt.runPulumiCommand("pulumi-refresh", refresh, dir, false); err != nil {
|
2018-08-31 18:34:26 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-08-23 02:52:46 +02:00
|
|
|
}
|
|
|
|
|
2017-12-11 23:42:42 +01:00
|
|
|
// If there are any edits, apply them and run a preview and update for each one.
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
return pt.testEdits(dir)
|
2017-12-11 23:42:42 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) exportImport(dir string) error {
|
2018-06-15 01:01:28 +02:00
|
|
|
exportCmd := []string{"stack", "export", "--file", "stack.json"}
|
|
|
|
importCmd := []string{"stack", "import", "--file", "stack.json"}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
contract.IgnoreError(os.Remove(filepath.Join(dir, "stack.json")))
|
|
|
|
}()
|
|
|
|
|
2019-11-20 21:52:57 +01:00
|
|
|
if err := pt.runPulumiCommand("pulumi-stack-export", exportCmd, dir, false); err != nil {
|
2018-06-15 01:01:28 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-20 21:52:57 +01:00
|
|
|
return pt.runPulumiCommand("pulumi-stack-import", importCmd, dir, false)
|
2018-06-15 01:01:28 +02:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// PreviewAndUpdate runs pulumi preview followed by pulumi up
|
|
|
|
func (pt *ProgramTester) PreviewAndUpdate(dir string, name string, shouldFail, expectNopPreview,
|
2018-05-23 18:17:10 +02:00
|
|
|
expectNopUpdate bool) error {
|
|
|
|
|
2018-05-05 20:57:09 +02:00
|
|
|
preview := []string{"preview", "--non-interactive"}
|
2020-04-14 10:30:25 +02:00
|
|
|
update := []string{"up", "--non-interactive", "--yes", "--skip-preview", "--event-log", pt.eventLog}
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
if pt.opts.GetDebugUpdates() {
|
2017-12-09 01:59:28 +01:00
|
|
|
preview = append(preview, "-d")
|
|
|
|
update = append(update, "-d")
|
2017-08-06 02:49:48 +02:00
|
|
|
}
|
2018-05-23 18:17:10 +02:00
|
|
|
if expectNopPreview {
|
2018-05-16 03:03:30 +02:00
|
|
|
preview = append(preview, "--expect-no-changes")
|
2018-05-23 18:17:10 +02:00
|
|
|
}
|
|
|
|
if expectNopUpdate {
|
2018-05-16 03:03:30 +02:00
|
|
|
update = append(update, "--expect-no-changes")
|
|
|
|
}
|
2018-11-20 11:05:24 +01:00
|
|
|
if pt.opts.PreviewCommandlineFlags != nil {
|
|
|
|
preview = append(preview, pt.opts.PreviewCommandlineFlags...)
|
|
|
|
}
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
if pt.opts.UpdateCommandlineFlags != nil {
|
|
|
|
update = append(update, pt.opts.UpdateCommandlineFlags...)
|
2017-12-20 20:17:25 +01:00
|
|
|
}
|
2017-08-06 02:49:48 +02:00
|
|
|
|
2018-08-23 02:52:46 +02:00
|
|
|
// If not in quick mode, run an explicit preview.
|
2020-02-07 21:36:23 +01:00
|
|
|
if !pt.opts.SkipPreview {
|
2019-11-20 21:52:57 +01:00
|
|
|
if err := pt.runPulumiCommand("pulumi-preview-"+name, preview, dir, shouldFail); err != nil {
|
2017-12-20 21:10:46 +01:00
|
|
|
if shouldFail {
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("Permitting failure (ExpectFailure=true for this preview)")
|
2017-12-20 21:10:46 +01:00
|
|
|
return nil
|
|
|
|
}
|
2017-12-09 01:59:28 +01:00
|
|
|
return err
|
2017-11-16 17:15:56 +01:00
|
|
|
}
|
2017-11-06 18:04:38 +01:00
|
|
|
}
|
2017-08-06 02:49:48 +02:00
|
|
|
|
2018-08-23 02:52:46 +02:00
|
|
|
// Now run an update.
|
2020-02-07 21:36:23 +01:00
|
|
|
if !pt.opts.SkipUpdate {
|
|
|
|
if err := pt.runPulumiCommand("pulumi-update-"+name, update, dir, shouldFail); err != nil {
|
|
|
|
if shouldFail {
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("Permitting failure (ExpectFailure=true for this update)")
|
2020-02-07 21:36:23 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
2017-12-20 21:10:46 +01:00
|
|
|
}
|
2017-12-08 01:29:48 +01:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:10:46 +01:00
|
|
|
// If we expected a failure, but none occurred, return an error.
|
|
|
|
if shouldFail {
|
|
|
|
return errors.New("expected this step to fail, but it succeeded")
|
|
|
|
}
|
|
|
|
|
2017-12-09 01:59:28 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) query(dir string, name string, shouldFail bool) error {
|
2019-04-19 00:25:15 +02:00
|
|
|
|
|
|
|
query := []string{"query", "--non-interactive"}
|
|
|
|
if pt.opts.GetDebugUpdates() {
|
|
|
|
query = append(query, "-d")
|
|
|
|
}
|
|
|
|
if pt.opts.QueryCommandlineFlags != nil {
|
|
|
|
query = append(query, pt.opts.QueryCommandlineFlags...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now run a query.
|
2019-11-20 21:52:57 +01:00
|
|
|
if err := pt.runPulumiCommand("pulumi-query-"+name, query, dir, shouldFail); err != nil {
|
2019-04-19 00:25:15 +02:00
|
|
|
if shouldFail {
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("Permitting failure (ExpectFailure=true for this update)")
|
2019-04-19 00:25:15 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we expected a failure, but none occurred, return an error.
|
|
|
|
if shouldFail {
|
|
|
|
return errors.New("expected this step to fail, but it succeeded")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) testEdits(dir string) error {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
for i, edit := range pt.opts.EditDirs {
|
2017-12-21 20:01:30 +01:00
|
|
|
var err error
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
if err = pt.testEdit(dir, i, edit); err != nil {
|
2018-01-06 01:39:13 +01:00
|
|
|
return err
|
2017-12-20 21:10:46 +01:00
|
|
|
}
|
2017-12-12 00:48:45 +01:00
|
|
|
}
|
2018-01-06 01:39:13 +01:00
|
|
|
return nil
|
2017-12-12 00:48:45 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) testEdit(dir string, i int, edit EditDir) error {
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Logf("Applying edit '%v' and rerunning preview and update", edit.Dir)
|
2017-12-12 00:48:45 +01:00
|
|
|
|
2018-01-10 01:47:17 +01:00
|
|
|
if edit.Additive {
|
|
|
|
// Just copy new files into dir
|
|
|
|
if err := fsutil.CopyFile(dir, edit.Dir, nil); err != nil {
|
|
|
|
return errors.Wrapf(err, "Couldn't copy %v into %v", edit.Dir, dir)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Create a new temporary directory
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
newDir, err := ioutil.TempDir("", pt.opts.StackName+"-")
|
2018-01-10 01:47:17 +01:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "Couldn't create new temporary directory")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete whichever copy of the test is unused when we return
|
|
|
|
dirToDelete := newDir
|
|
|
|
defer func() {
|
|
|
|
contract.IgnoreError(os.RemoveAll(dirToDelete))
|
|
|
|
}()
|
|
|
|
|
2018-03-07 00:57:57 +01:00
|
|
|
// Copy everything except Pulumi.yaml, Pulumi.<stack-name>.yaml, and .pulumi from source into new directory
|
2018-01-10 01:47:17 +01:00
|
|
|
exclusions := make(map[string]bool)
|
|
|
|
projectYaml := workspace.ProjectFile + ".yaml"
|
2018-03-07 00:57:57 +01:00
|
|
|
configYaml := workspace.ProjectFile + "." + pt.opts.StackName + ".yaml"
|
2018-01-10 01:47:17 +01:00
|
|
|
exclusions[workspace.BookkeepingDir] = true
|
|
|
|
exclusions[projectYaml] = true
|
2018-03-07 00:57:57 +01:00
|
|
|
exclusions[configYaml] = true
|
2018-01-10 01:47:17 +01:00
|
|
|
|
|
|
|
if err := fsutil.CopyFile(newDir, edit.Dir, exclusions); err != nil {
|
|
|
|
return errors.Wrapf(err, "Couldn't copy %v into %v", edit.Dir, newDir)
|
|
|
|
}
|
|
|
|
|
2018-03-07 00:57:57 +01:00
|
|
|
// Copy Pulumi.yaml, Pulumi.<stack-name>.yaml, and .pulumi from old directory to new directory
|
2018-01-10 01:47:17 +01:00
|
|
|
oldProjectYaml := filepath.Join(dir, projectYaml)
|
|
|
|
newProjectYaml := filepath.Join(newDir, projectYaml)
|
|
|
|
|
2018-03-07 00:57:57 +01:00
|
|
|
oldConfigYaml := filepath.Join(dir, configYaml)
|
|
|
|
newConfigYaml := filepath.Join(newDir, configYaml)
|
|
|
|
|
2018-01-10 01:47:17 +01:00
|
|
|
oldProjectDir := filepath.Join(dir, workspace.BookkeepingDir)
|
|
|
|
newProjectDir := filepath.Join(newDir, workspace.BookkeepingDir)
|
|
|
|
|
|
|
|
if err := fsutil.CopyFile(newProjectYaml, oldProjectYaml, nil); err != nil {
|
2018-03-07 00:57:57 +01:00
|
|
|
return errors.Wrap(err, "Couldn't copy Pulumi.yaml")
|
|
|
|
}
|
|
|
|
if err := fsutil.CopyFile(newConfigYaml, oldConfigYaml, nil); err != nil {
|
|
|
|
return errors.Wrapf(err, "Couldn't copy Pulumi.%s.yaml", pt.opts.StackName)
|
2018-01-10 01:47:17 +01:00
|
|
|
}
|
|
|
|
if err := fsutil.CopyFile(newProjectDir, oldProjectDir, nil); err != nil {
|
2018-03-07 00:57:57 +01:00
|
|
|
return errors.Wrap(err, "Couldn't copy .pulumi")
|
2018-01-10 01:47:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, replace our current temp directory with the new one.
|
|
|
|
dirOld := dir + ".old"
|
|
|
|
if err := os.Rename(dir, dirOld); err != nil {
|
|
|
|
return errors.Wrapf(err, "Couldn't rename %v to %v", dir, dirOld)
|
|
|
|
}
|
|
|
|
|
|
|
|
// There's a brief window here where the old temp dir name could be taken from us.
|
|
|
|
|
|
|
|
if err := os.Rename(newDir, dir); err != nil {
|
|
|
|
return errors.Wrapf(err, "Couldn't rename %v to %v", newDir, dir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep dir, delete oldDir
|
|
|
|
dirToDelete = dirOld
|
|
|
|
}
|
|
|
|
|
2018-06-11 22:22:24 +02:00
|
|
|
err := pt.prepareProjectDir(dir)
|
2017-12-20 21:10:46 +01:00
|
|
|
if err != nil {
|
2018-01-10 01:47:17 +01:00
|
|
|
return errors.Wrapf(err, "Couldn't prepare project in %v", dir)
|
2017-12-12 00:48:45 +01:00
|
|
|
}
|
2017-12-15 02:10:05 +01:00
|
|
|
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
oldStdOut := pt.opts.Stdout
|
|
|
|
oldStderr := pt.opts.Stderr
|
|
|
|
oldVerbose := pt.opts.Verbose
|
2017-12-15 02:10:05 +01:00
|
|
|
if edit.Stdout != nil {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
pt.opts.Stdout = edit.Stdout
|
2017-12-15 02:10:05 +01:00
|
|
|
}
|
|
|
|
if edit.Stderr != nil {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
pt.opts.Stderr = edit.Stderr
|
2017-12-15 02:10:05 +01:00
|
|
|
}
|
|
|
|
if edit.Verbose {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
pt.opts.Verbose = true
|
2017-12-15 02:10:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
pt.opts.Stdout = oldStdOut
|
|
|
|
pt.opts.Stderr = oldStderr
|
|
|
|
pt.opts.Verbose = oldVerbose
|
2017-12-15 02:10:05 +01:00
|
|
|
}()
|
|
|
|
|
2019-04-19 00:25:15 +02:00
|
|
|
if !edit.QueryMode {
|
2020-02-17 19:40:46 +01:00
|
|
|
if err = pt.PreviewAndUpdate(dir, fmt.Sprintf("edit-%d", i),
|
2019-04-19 00:25:15 +02:00
|
|
|
edit.ExpectFailure, edit.ExpectNoChanges, edit.ExpectNoChanges); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err = pt.query(dir, fmt.Sprintf("query-%d", i), edit.ExpectFailure); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-12 00:48:45 +01:00
|
|
|
}
|
2018-01-25 03:22:41 +01:00
|
|
|
return pt.performExtraRuntimeValidation(edit.ExtraRuntimeValidation, dir)
|
2017-09-25 23:03:16 +02:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) performExtraRuntimeValidation(
|
2017-12-14 01:09:14 +01:00
|
|
|
extraRuntimeValidation func(t *testing.T, stack RuntimeValidationStackInfo), dir string) error {
|
2017-12-09 01:59:28 +01:00
|
|
|
|
|
|
|
if extraRuntimeValidation == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
stackName := pt.opts.GetStackName()
|
2017-12-09 01:59:28 +01:00
|
|
|
|
2018-04-03 06:34:54 +02:00
|
|
|
// Create a temporary file name for the stack export
|
|
|
|
tempDir, err := ioutil.TempDir("", string(stackName))
|
2017-12-20 21:10:46 +01:00
|
|
|
if err != nil {
|
2018-04-03 06:34:54 +02:00
|
|
|
return err
|
2017-10-27 01:01:28 +02:00
|
|
|
}
|
2019-12-13 13:58:52 +01:00
|
|
|
fileName := filepath.Join(tempDir, "stack.json")
|
2018-04-03 06:34:54 +02:00
|
|
|
|
|
|
|
// Invoke `pulumi stack export`
|
2021-01-19 20:18:45 +01:00
|
|
|
// There are situations where we want to get access to the secrets in the validation
|
|
|
|
// this will allow us to get access to them as part of running ExtraRuntimeValidation
|
|
|
|
var pulumiCommand []string
|
|
|
|
if pt.opts.DecryptSecretsInOutput {
|
|
|
|
pulumiCommand = append(pulumiCommand, "stack", "export", "--show-secrets", "--file", fileName)
|
|
|
|
} else {
|
|
|
|
pulumiCommand = append(pulumiCommand, "stack", "export", "--file", fileName)
|
|
|
|
}
|
2019-11-20 21:52:57 +01:00
|
|
|
if err = pt.runPulumiCommand("pulumi-export",
|
2021-01-19 20:18:45 +01:00
|
|
|
pulumiCommand, dir, false); err != nil {
|
2018-04-03 06:34:54 +02:00
|
|
|
return errors.Wrapf(err, "expected to export stack to file: %s", fileName)
|
2017-10-27 01:01:28 +02:00
|
|
|
}
|
2017-12-14 01:09:14 +01:00
|
|
|
|
2018-04-03 06:34:54 +02:00
|
|
|
// Open the exported JSON file
|
|
|
|
f, err := os.Open(fileName)
|
2017-12-20 21:10:46 +01:00
|
|
|
if err != nil {
|
2018-04-03 06:34:54 +02:00
|
|
|
return errors.Wrapf(err, "expected to be able to open file with stack exports: %s", fileName)
|
2017-12-14 01:09:14 +01:00
|
|
|
}
|
2018-04-03 06:34:54 +02:00
|
|
|
defer func() {
|
|
|
|
contract.IgnoreClose(f)
|
|
|
|
contract.IgnoreError(os.RemoveAll(tempDir))
|
|
|
|
}()
|
2017-12-14 01:09:14 +01:00
|
|
|
|
2018-04-03 06:34:54 +02:00
|
|
|
// Unmarshal the Deployment
|
|
|
|
var untypedDeployment apitype.UntypedDeployment
|
|
|
|
if err = json.NewDecoder(f).Decode(&untypedDeployment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
Implement more precise delete-before-replace semantics. (#2369)
This implements the new algorithm for deciding which resources must be
deleted due to a delete-before-replace operation.
We need to compute the set of resources that may be replaced by a
change to the resource under consideration. We do this by taking the
complete set of transitive dependents on the resource under
consideration and removing any resources that would not be replaced by
changes to their dependencies. We determine whether or not a resource
may be replaced by substituting unknowns for input properties that may
change due to deletion of the resources their value depends on and
calling the resource provider's Diff method.
This is perhaps clearer when described by example. Consider the
following dependency graph:
A
__|__
B C
| _|_
D E F
In this graph, all of B, C, D, E, and F transitively depend on A. It may
be the case, however, that changes to the specific properties of any of
those resources R that would occur if a resource on the path to A were
deleted and recreated may not cause R to be replaced. For example, the
edge from B to A may be a simple dependsOn edge such that a change to
B does not actually influence any of B's input properties. In that case,
neither B nor D would need to be deleted before A could be deleted.
In order to make the above algorithm a reality, the resource monitor
interface has been updated to include a map that associates an input
property key with the list of resources that input property depends on.
Older clients of the resource monitor will leave this map empty, in
which case all input properties will be treated as depending on all
dependencies of the resource. This is probably overly conservative, but
it is less conservative than what we currently implement, and is
certainly correct.
2019-01-28 18:46:30 +01:00
|
|
|
var deployment apitype.DeploymentV3
|
2018-04-03 06:34:54 +02:00
|
|
|
if err = json.Unmarshal(untypedDeployment.Deployment, &deployment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the root resource and outputs from the deployment
|
Implement more precise delete-before-replace semantics. (#2369)
This implements the new algorithm for deciding which resources must be
deleted due to a delete-before-replace operation.
We need to compute the set of resources that may be replaced by a
change to the resource under consideration. We do this by taking the
complete set of transitive dependents on the resource under
consideration and removing any resources that would not be replaced by
changes to their dependencies. We determine whether or not a resource
may be replaced by substituting unknowns for input properties that may
change due to deletion of the resources their value depends on and
calling the resource provider's Diff method.
This is perhaps clearer when described by example. Consider the
following dependency graph:
A
__|__
B C
| _|_
D E F
In this graph, all of B, C, D, E, and F transitively depend on A. It may
be the case, however, that changes to the specific properties of any of
those resources R that would occur if a resource on the path to A were
deleted and recreated may not cause R to be replaced. For example, the
edge from B to A may be a simple dependsOn edge such that a change to
B does not actually influence any of B's input properties. In that case,
neither B nor D would need to be deleted before A could be deleted.
In order to make the above algorithm a reality, the resource monitor
interface has been updated to include a map that associates an input
property key with the list of resources that input property depends on.
Older clients of the resource monitor will leave this map empty, in
which case all input properties will be treated as depending on all
dependencies of the resource. This is probably overly conservative, but
it is less conservative than what we currently implement, and is
certainly correct.
2019-01-28 18:46:30 +01:00
|
|
|
var rootResource apitype.ResourceV3
|
2018-04-03 06:34:54 +02:00
|
|
|
var outputs map[string]interface{}
|
|
|
|
for _, res := range deployment.Resources {
|
|
|
|
if res.Type == resource.RootStackType {
|
|
|
|
rootResource = res
|
|
|
|
outputs = res.Outputs
|
|
|
|
}
|
2017-12-14 01:09:14 +01:00
|
|
|
}
|
|
|
|
|
2019-09-07 02:07:54 +02:00
|
|
|
// Read the event log.
|
|
|
|
eventsFile, err := os.Open(pt.eventLog)
|
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
return errors.Wrapf(err, "expected to be able to open event log file %s", pt.eventLog)
|
|
|
|
}
|
|
|
|
defer contract.IgnoreClose(eventsFile)
|
|
|
|
decoder, events := json.NewDecoder(eventsFile), []apitype.EngineEvent{}
|
|
|
|
for {
|
|
|
|
var event apitype.EngineEvent
|
|
|
|
if err = decoder.Decode(&event); err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return errors.Wrapf(err, "decoding engine event")
|
|
|
|
}
|
|
|
|
events = append(events, event)
|
|
|
|
}
|
|
|
|
|
2017-12-14 01:09:14 +01:00
|
|
|
// Populate stack info object with all of this data to pass to the validation function
|
|
|
|
stackInfo := RuntimeValidationStackInfo{
|
2018-04-12 22:50:07 +02:00
|
|
|
StackName: pt.opts.GetStackName(),
|
2018-04-03 06:34:54 +02:00
|
|
|
Deployment: &deployment,
|
|
|
|
RootResource: rootResource,
|
2017-12-14 01:09:14 +01:00
|
|
|
Outputs: outputs,
|
2019-09-07 02:07:54 +02:00
|
|
|
Events: events,
|
2017-12-14 01:09:14 +01:00
|
|
|
}
|
2019-01-29 22:14:06 +01:00
|
|
|
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("Performing extra runtime validation.")
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
extraRuntimeValidation(pt.t, stackInfo)
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Log("Extra runtime validation complete.")
|
2017-10-27 01:01:28 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
// copyTestToTemporaryDirectory creates a temporary directory to run the test in and copies the test to it.
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) copyTestToTemporaryDirectory() (string, string, error) {
|
2018-06-11 22:22:24 +02:00
|
|
|
// Get the source dir and project info.
|
|
|
|
sourceDir := pt.opts.Dir
|
|
|
|
projinfo, err := pt.getProjinfo(sourceDir)
|
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
|
2020-11-17 22:13:25 +01:00
|
|
|
if pt.opts.Stdout == nil {
|
|
|
|
pt.opts.Stdout = os.Stdout
|
2017-09-25 23:03:16 +02:00
|
|
|
}
|
2020-11-17 22:13:25 +01:00
|
|
|
if pt.opts.Stderr == nil {
|
|
|
|
pt.opts.Stderr = os.Stderr
|
2017-09-25 23:03:16 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Logf("sample: %v", sourceDir)
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
bin, err := pt.getBin()
|
|
|
|
if err != nil {
|
2018-06-11 22:22:24 +02:00
|
|
|
return "", "", err
|
Restructure test framework to ease multiple languages (#799)
This change restructures the test framework code a bit, to make it
easier to introduce additional languages. Our knowledge of Yarn and
Node.js project structure, for instance, was previously baked in to
the test logic, in a way that was hard to make, for instance, Yarn
optional. (In Python, of course, it will not be used.) To better
support this, I've moved some state onto a new programTester struct
that we can use to lazily find binaries required during the testing
(such as Yarn, Pip, and so on). I'm committing this separately so
that I can minimize merge conflicts in the Python work.
2018-01-13 02:10:53 +01:00
|
|
|
}
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Logf("pulumi: %v\n", bin)
|
2017-09-25 23:03:16 +02:00
|
|
|
|
2020-02-28 15:14:46 +01:00
|
|
|
stackName := string(pt.opts.GetStackName())
|
|
|
|
|
|
|
|
// For most projects, we will copy to a temporary directory. For Go projects, however, we must create
|
|
|
|
// a folder structure that adheres to GOPATH requirements
|
2018-06-11 22:22:24 +02:00
|
|
|
var tmpdir, projdir string
|
2018-11-01 16:28:11 +01:00
|
|
|
if projinfo.Proj.Runtime.Name() == "go" {
|
2020-02-28 15:14:46 +01:00
|
|
|
targetDir, err := tools.CreateTemporaryGoFolder("stackName")
|
|
|
|
if err != nil {
|
|
|
|
return "", "", errors.Wrap(err, "Couldn't create temporary directory")
|
|
|
|
}
|
|
|
|
tmpdir = targetDir
|
|
|
|
projdir = targetDir
|
2018-06-11 22:22:24 +02:00
|
|
|
} else {
|
|
|
|
targetDir, tempErr := ioutil.TempDir("", stackName+"-")
|
|
|
|
if tempErr != nil {
|
|
|
|
return "", "", errors.Wrap(tempErr, "Couldn't create temporary directory")
|
|
|
|
}
|
|
|
|
tmpdir = targetDir
|
|
|
|
projdir = targetDir
|
2018-01-10 01:47:17 +01:00
|
|
|
}
|
2020-02-28 15:14:46 +01:00
|
|
|
// Copy the source project.
|
|
|
|
if copyErr := fsutil.CopyFile(tmpdir, sourceDir, nil); copyErr != nil {
|
|
|
|
return "", "", copyErr
|
|
|
|
}
|
2018-06-11 22:22:24 +02:00
|
|
|
projinfo.Root = projdir
|
2018-01-10 01:47:17 +01:00
|
|
|
|
2018-06-11 22:22:24 +02:00
|
|
|
err = pt.prepareProject(projinfo)
|
2017-12-20 21:10:46 +01:00
|
|
|
if err != nil {
|
2018-06-11 22:22:24 +02:00
|
|
|
return "", "", errors.Wrapf(err, "Failed to prepare %v", projdir)
|
2017-09-25 23:03:16 +02:00
|
|
|
}
|
2017-12-11 23:42:42 +01:00
|
|
|
|
2020-09-30 23:09:20 +02:00
|
|
|
// TODO[pulumi/pulumi#5455]: Dynamic providers fail to load when used from multi-lang components.
|
|
|
|
// Until that's been fixed, this environment variable can be set by a test, which results in
|
|
|
|
// a package.json being emitted in the project directory and `yarn install && yarn link @pulumi/pulumi`
|
|
|
|
// being run.
|
|
|
|
// When the underlying issue has been fixed, the use of this environment variable should be removed.
|
|
|
|
var yarnLinkPulumi bool
|
|
|
|
for _, env := range pt.opts.Env {
|
|
|
|
if env == "PULUMI_TEST_YARN_LINK_PULUMI=true" {
|
|
|
|
yarnLinkPulumi = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if yarnLinkPulumi {
|
|
|
|
const packageJSON = `{
|
|
|
|
"name": "test",
|
|
|
|
"peerDependencies": {
|
|
|
|
"@pulumi/pulumi": "latest"
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
if err := ioutil.WriteFile(filepath.Join(projdir, "package.json"), []byte(packageJSON), 0600); err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
if err = pt.runYarnCommand("yarn-install", []string{"install"}, projdir); err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
if err := pt.runYarnCommand("yarn-link", []string{"link", "@pulumi/pulumi"}, projdir); err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Logf("projdir: %v", projdir)
|
2018-06-11 22:22:24 +02:00
|
|
|
return tmpdir, projdir, nil
|
2017-07-13 21:19:17 +02:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) getProjinfo(projectDir string) (*engine.Projinfo, error) {
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
// Load up the package so we know things like what language the project is.
|
|
|
|
projfile := filepath.Join(projectDir, workspace.ProjectFile+".yaml")
|
|
|
|
proj, err := workspace.LoadProject(projfile)
|
|
|
|
if err != nil {
|
2018-06-11 22:22:24 +02:00
|
|
|
return nil, err
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
}
|
2018-06-11 22:22:24 +02:00
|
|
|
return &engine.Projinfo{Proj: proj, Root: projectDir}, nil
|
|
|
|
}
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
|
2018-06-11 22:22:24 +02:00
|
|
|
// prepareProject runs setup necessary to get the project ready for `pulumi` commands.
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) prepareProject(projinfo *engine.Projinfo) error {
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
// Based on the language, invoke the right routine to prepare the target directory.
|
2018-11-01 16:28:11 +01:00
|
|
|
switch rt := projinfo.Proj.Runtime.Name(); rt {
|
2019-08-20 10:08:09 +02:00
|
|
|
case NodeJSRuntime:
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
return pt.prepareNodeJSProject(projinfo)
|
2019-08-20 10:08:09 +02:00
|
|
|
case PythonRuntime:
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
return pt.preparePythonProject(projinfo)
|
2019-08-20 10:08:09 +02:00
|
|
|
case GoRuntime:
|
2018-06-10 18:17:19 +02:00
|
|
|
return pt.prepareGoProject(projinfo)
|
2019-10-26 01:59:50 +02:00
|
|
|
case DotNetRuntime:
|
|
|
|
return pt.prepareDotNetProject(projinfo)
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
default:
|
2018-06-11 22:22:24 +02:00
|
|
|
return errors.Errorf("unrecognized project runtime: %s", rt)
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-11 22:22:24 +02:00
|
|
|
// prepareProjectDir runs setup necessary to get the project ready for `pulumi` commands.
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) prepareProjectDir(projectDir string) error {
|
2018-06-11 22:22:24 +02:00
|
|
|
projinfo, err := pt.getProjinfo(projectDir)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return pt.prepareProject(projinfo)
|
|
|
|
}
|
|
|
|
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
// prepareNodeJSProject runs setup necessary to get a Node.js project ready for `pulumi` commands.
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) prepareNodeJSProject(projinfo *engine.Projinfo) error {
|
2018-11-20 00:47:51 +01:00
|
|
|
if err := pulumi_testing.WriteYarnRCForTest(projinfo.Root); err != nil {
|
2018-01-06 01:39:13 +01:00
|
|
|
return err
|
2017-11-16 16:49:07 +01:00
|
|
|
}
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
|
|
|
|
// Get the correct pwd to run Yarn in.
|
2018-02-14 22:56:16 +01:00
|
|
|
cwd, _, err := projinfo.GetPwdMain()
|
2017-11-16 16:49:07 +01:00
|
|
|
if err != nil {
|
2018-01-06 01:39:13 +01:00
|
|
|
return err
|
2017-11-16 16:49:07 +01:00
|
|
|
}
|
|
|
|
|
2018-11-14 22:27:32 +01:00
|
|
|
// If the test requested some packages to be overridden, we do two things. First, if the package is listed as a
|
|
|
|
// direct dependency of the project, we change the version constraint in the package.json. For transitive
|
|
|
|
// dependeices, we use yarn's "resolutions" feature to force them to a specific version.
|
|
|
|
if len(pt.opts.Overrides) > 0 {
|
|
|
|
packageJSON, err := readPackageJSON(cwd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:16:22 +02:00
|
|
|
resolutions := make(map[string]interface{})
|
2018-11-14 22:27:32 +01:00
|
|
|
|
|
|
|
for packageName, packageVersion := range pt.opts.Overrides {
|
|
|
|
for _, section := range []string{"dependencies", "devDependencies"} {
|
|
|
|
if _, has := packageJSON[section]; has {
|
|
|
|
entry := packageJSON[section].(map[string]interface{})
|
|
|
|
|
|
|
|
if _, has := entry[packageName]; has {
|
|
|
|
entry[packageName] = packageVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 22:13:25 +01:00
|
|
|
pt.t.Logf("adding resolution for %s to version %s", packageName, packageVersion)
|
2019-07-12 01:16:22 +02:00
|
|
|
resolutions["**/"+packageName] = packageVersion
|
2018-11-14 22:27:32 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:16:22 +02:00
|
|
|
// Wack any existing resolutions section with our newly computed one.
|
|
|
|
packageJSON["resolutions"] = resolutions
|
2018-11-14 22:27:32 +01:00
|
|
|
|
|
|
|
if err := writePackageJSON(cwd, packageJSON); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-06 02:49:48 +02:00
|
|
|
// Now ensure dependencies are present.
|
2018-11-19 20:41:49 +01:00
|
|
|
if err = pt.runYarnCommand("yarn-install", []string{"install"}, cwd); err != nil {
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
return err
|
2017-11-06 18:04:38 +01:00
|
|
|
}
|
2018-11-14 22:27:32 +01:00
|
|
|
|
2019-08-20 10:08:09 +02:00
|
|
|
if !pt.opts.RunUpdateTest {
|
|
|
|
if err = pt.yarnLinkPackageDeps(cwd); err != nil {
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
return err
|
2017-11-06 18:04:38 +01:00
|
|
|
}
|
2017-08-06 02:49:48 +02:00
|
|
|
}
|
|
|
|
|
2018-06-25 07:47:54 +02:00
|
|
|
if pt.opts.RunBuild {
|
2018-07-07 07:06:28 +02:00
|
|
|
// And finally compile it using whatever build steps are in the package.json file.
|
|
|
|
if err = pt.runYarnCommand("yarn-build", []string{"run", "build"}, cwd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
2017-07-13 21:19:17 +02:00
|
|
|
}
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
|
2018-11-14 22:27:32 +01:00
|
|
|
// readPackageJSON unmarshals the package.json file located in pathToPackage.
|
|
|
|
func readPackageJSON(pathToPackage string) (map[string]interface{}, error) {
|
|
|
|
f, err := os.Open(filepath.Join(pathToPackage, "package.json"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "opening package.json")
|
|
|
|
}
|
|
|
|
defer contract.IgnoreClose(f)
|
|
|
|
|
|
|
|
var ret map[string]interface{}
|
|
|
|
if err := json.NewDecoder(f).Decode(&ret); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "decoding package.json")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func writePackageJSON(pathToPackage string, metadata map[string]interface{}) error {
|
|
|
|
// os.Create truncates the already existing file.
|
|
|
|
f, err := os.Create(filepath.Join(pathToPackage, "package.json"))
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "opening package.json")
|
|
|
|
}
|
|
|
|
defer contract.IgnoreClose(f)
|
|
|
|
|
|
|
|
encoder := json.NewEncoder(f)
|
|
|
|
encoder.SetIndent("", " ")
|
|
|
|
|
|
|
|
return errors.Wrap(encoder.Encode(metadata), "writing package.json")
|
|
|
|
}
|
|
|
|
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
// preparePythonProject runs setup necessary to get a Python project ready for `pulumi` commands.
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) preparePythonProject(projinfo *engine.Projinfo) error {
|
2018-11-05 22:52:37 +01:00
|
|
|
cwd, _, err := projinfo.GetPwdMain()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:16:07 +01:00
|
|
|
if pt.opts.UsePipenv {
|
|
|
|
if err = pt.preparePythonProjectWithPipenv(cwd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2020-06-10 01:42:53 +02:00
|
|
|
if err = pt.runPythonCommand("python-venv", []string{"-m", "venv", "venv"}, cwd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
projinfo.Proj.Runtime.SetOption("virtualenv", "venv")
|
|
|
|
projfile := filepath.Join(projinfo.Root, workspace.ProjectFile+".yaml")
|
|
|
|
if err = projinfo.Proj.Save(projfile); err != nil {
|
|
|
|
return errors.Wrap(err, "saving project")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := pt.runVirtualEnvCommand("virtualenv-pip-install",
|
2021-02-12 03:16:07 +01:00
|
|
|
[]string{"python", "-m", "pip", "install", "-r", "requirements.txt"}, cwd); err != nil {
|
2020-06-10 01:42:53 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !pt.opts.RunUpdateTest {
|
|
|
|
if err = pt.installPipPackageDeps(cwd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pt *ProgramTester) preparePythonProjectWithPipenv(cwd string) error {
|
2018-11-05 22:52:37 +01:00
|
|
|
// Create a new Pipenv environment. This bootstraps a new virtual environment containing the version of Python that
|
|
|
|
// we requested. Note that this version of Python is sourced from the machine, so you must first install the version
|
|
|
|
// of Python that you are requesting on the host machine before building a virtualenv for it.
|
2021-02-11 17:22:04 +01:00
|
|
|
if err := pt.runPipenvCommand("pipenv-new", []string{"--python", "3"}, cwd); err != nil {
|
2018-11-05 22:52:37 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-08-22 21:43:11 +02:00
|
|
|
// Install the package's dependencies. We do this by running `pip` inside the virtualenv that `pipenv` has created.
|
|
|
|
// We don't use `pipenv install` because we don't want a lock file and prefer the similar model of `pip install`
|
|
|
|
// which matches what our customers do
|
2020-06-10 01:42:53 +02:00
|
|
|
err := pt.runPipenvCommand("pipenv-install", []string{"run", "pip", "install", "-r", "requirements.txt"}, cwd)
|
2019-08-22 21:43:11 +02:00
|
|
|
if err != nil {
|
2018-11-05 22:52:37 +01:00
|
|
|
return err
|
|
|
|
}
|
2019-08-20 10:08:09 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// YarnLinkPackageDeps bring in package dependencies via yarn
|
|
|
|
func (pt *ProgramTester) yarnLinkPackageDeps(cwd string) error {
|
2019-08-20 10:08:09 +02:00
|
|
|
for _, dependency := range pt.opts.Dependencies {
|
|
|
|
if err := pt.runYarnCommand("yarn-link", []string{"link", dependency}, cwd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 19:40:46 +01:00
|
|
|
// InstallPipPackageDeps brings in package dependencies via pip install
|
|
|
|
func (pt *ProgramTester) installPipPackageDeps(cwd string) error {
|
2019-08-20 10:08:09 +02:00
|
|
|
var err error
|
2018-11-05 22:52:37 +01:00
|
|
|
for _, dep := range pt.opts.Dependencies {
|
|
|
|
// If the given filepath isn't absolute, make it absolute. We're about to pass it to pipenv and pipenv is
|
|
|
|
// operating inside of a random folder in /tmp.
|
2019-12-13 13:58:52 +01:00
|
|
|
if !filepath.IsAbs(dep) {
|
2018-11-05 22:52:37 +01:00
|
|
|
dep, err = filepath.Abs(dep)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 03:16:07 +01:00
|
|
|
if pt.opts.UsePipenv {
|
|
|
|
if err := pt.runPipenvCommand("pipenv-install-package",
|
|
|
|
[]string{"run", "pip", "install", "-e", dep}, cwd); err != nil {
|
2020-06-10 01:42:53 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2021-02-12 03:16:07 +01:00
|
|
|
if err := pt.runVirtualEnvCommand("virtualenv-pip-install-package",
|
|
|
|
[]string{"python", "-m", "pip", "install", "-e", dep}, cwd); err != nil {
|
2020-06-10 01:42:53 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-11-05 22:52:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Get the empty Python program working
This change gets enough of the Python SDK up and running that the
empty Python program will work. Mostly just scaffolding, but the
basic structure is now in place. The primary remaining work is to
wire up resource creation to the gRPC interfaces.
In summary:
* The basic structure is as follows:
- Everything goes into sdk/python/.
- sdk/python/cmd/pulumi-langhost-python is a Go language host
that simply knows how to spawn Python processes to run out
entrypoint in response to requests by the engine.
- sdk/python/cmd/pulumi-langhost-python-exec is a little Python
shim that is invoked by the language host to run Python programs,
and is responsible for setting up the minimal goo before we can
do so (RPC connections and the like).
- sdk/python/lib/ contains a Python Pip package suitable for PyPi.
- In there, we have two packages: the root pulumi package that
contains all of the basic Pulumi programming model abstractions,
and pulumi.runtime, which contains the implementation of
resource registration, RPC interfacing with the engine, and so on.
* Add logic in our test framework to conditionalize on the language
type and react accordingly. This will allow us to skip Yarn for
Python projects and eventually run Pip if there's a requirements.txt.
* Created the basic project structure, including all of the usual
Make targets for installing into the proper places.
* Building also runs Pylint and we are clean.
There are a few other minor things in here:
* Add an "empty" test for both Node.js and Python. These pass.
* Fix an existing bug in plugin shutdown logic. At some point, we
started waiting for stderr/stdout to flush before shutting down
the plugin; but if certain failures happen "early" during the
plugin launch process, these channels will never get initialized
and so waiting for them deadlocks.
* Recently we seem to have added logic to delete test temp
directories if a failure happened during initialization of said
temp directories. This is unfortunate, because you often need to
look at the temp directory to see what failed. We already clean
them up elsewhere after the full test completes successfully, so
I don't think we need to be doing this, and I've removed it.
Still many loose ends (config, resources, etc), but it's a start!
2018-01-13 19:29:34 +01:00
|
|
|
return nil
|
|
|
|
}
|
2018-06-10 18:17:19 +02:00
|
|
|
|
2020-06-10 01:42:53 +02:00
|
|
|
func getVirtualenvBinPath(cwd, bin string) (string, error) {
|
|
|
|
virtualenvBinPath := filepath.Join(cwd, "venv", "bin", bin)
|
|
|
|
if runtime.GOOS == windowsOS {
|
|
|
|
virtualenvBinPath = filepath.Join(cwd, "venv", "Scripts", fmt.Sprintf("%s.exe", bin))
|
|
|
|
}
|
|
|
|
if info, err := os.Stat(virtualenvBinPath); err != nil || info.IsDir() {
|
|
|
|
return "", errors.Errorf("Expected %s to exist in virtual environment at %q", bin, virtualenvBinPath)
|
|
|
|
}
|
|
|
|
return virtualenvBinPath, nil
|
|
|
|
}
|
|
|
|
|
2020-09-01 01:08:15 +02:00
|
|
|
// getSanitizedPkg strips the version string from a go dep
|
2020-09-01 03:57:05 +02:00
|
|
|
// Note: most of the pulumi modules don't use major version subdirectories for modules
|
|
|
|
func getSanitizedModulePath(pkg string) string {
|
2020-09-01 01:08:15 +02:00
|
|
|
re := regexp.MustCompile(`v\d`)
|
|
|
|
v := re.FindString(pkg)
|
|
|
|
if v != "" {
|
|
|
|
return strings.TrimSuffix(strings.Replace(pkg, v, "", -1), "/")
|
|
|
|
}
|
|
|
|
return pkg
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func getRewritePath(pkg string, gopath string, depRoot string) string {
|
|
|
|
|
|
|
|
var depParts []string
|
2020-09-01 03:57:05 +02:00
|
|
|
sanitizedPkg := getSanitizedModulePath(pkg)
|
2020-09-01 01:08:15 +02:00
|
|
|
|
|
|
|
splitPkg := strings.Split(sanitizedPkg, "/")
|
|
|
|
|
|
|
|
if depRoot != "" {
|
|
|
|
// Get the package name
|
|
|
|
// This is the value after "github.com/foo/bar"
|
2020-09-01 03:54:14 +02:00
|
|
|
repoName := splitPkg[2]
|
2020-09-01 04:01:23 +02:00
|
|
|
basePath := splitPkg[len(splitPkg)-1]
|
2020-09-01 03:54:14 +02:00
|
|
|
if basePath == repoName {
|
|
|
|
depParts = append([]string{depRoot, repoName})
|
|
|
|
} else {
|
|
|
|
depParts = append([]string{depRoot, repoName, basePath})
|
|
|
|
}
|
2020-09-01 01:08:15 +02:00
|
|
|
return filepath.Join(depParts...)
|
|
|
|
}
|
|
|
|
depParts = append([]string{gopath, "src"}, splitPkg...)
|
|
|
|
return filepath.Join(depParts...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-10 18:17:19 +02:00
|
|
|
// prepareGoProject runs setup necessary to get a Go project ready for `pulumi` commands.
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) prepareGoProject(projinfo *engine.Projinfo) error {
|
2018-06-10 18:17:19 +02:00
|
|
|
// Go programs are compiled, so we will compile the project first.
|
|
|
|
goBin, err := pt.getGoBin()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "locating `go` binary")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure GOPATH is known.
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
if gopath == "" {
|
2018-06-11 22:22:24 +02:00
|
|
|
usr, userErr := user.Current()
|
|
|
|
if userErr != nil {
|
|
|
|
return userErr
|
2018-06-11 22:08:46 +02:00
|
|
|
}
|
|
|
|
gopath = filepath.Join(usr.HomeDir, "go")
|
2018-06-10 18:17:19 +02:00
|
|
|
}
|
|
|
|
|
2020-08-28 21:40:07 +02:00
|
|
|
depRoot := os.Getenv("PULUMI_GO_DEP_ROOT")
|
|
|
|
|
2018-06-10 18:17:19 +02:00
|
|
|
cwd, _, err := projinfo.GetPwdMain()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-14 18:25:55 +01:00
|
|
|
|
2020-03-25 23:57:46 +01:00
|
|
|
// initialize a go.mod for dependency resolution if one doesn't exist
|
|
|
|
_, err = os.Stat(filepath.Join(cwd, "go.mod"))
|
|
|
|
if err != nil {
|
|
|
|
err = pt.runCommand("go-mod-init", []string{goBin, "mod", "init"}, cwd)
|
2020-02-28 15:14:46 +01:00
|
|
|
if err != nil {
|
2020-03-25 23:57:46 +01:00
|
|
|
return err
|
2020-02-28 15:14:46 +01:00
|
|
|
}
|
2020-03-25 23:57:46 +01:00
|
|
|
}
|
2020-03-12 16:49:52 +01:00
|
|
|
|
2020-03-25 23:57:46 +01:00
|
|
|
// initial tidy to resolve dependencies
|
|
|
|
err = pt.runCommand("go-mod-tidy", []string{goBin, "mod", "tidy"}, cwd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// link local dependencies
|
|
|
|
for _, pkg := range pt.opts.Dependencies {
|
2020-08-28 21:40:07 +02:00
|
|
|
|
2020-09-01 01:08:15 +02:00
|
|
|
dep := getRewritePath(pkg, gopath, depRoot)
|
2020-08-28 21:40:07 +02:00
|
|
|
|
2020-03-25 23:57:46 +01:00
|
|
|
editStr := fmt.Sprintf("%s=%s", pkg, dep)
|
|
|
|
err = pt.runCommand("go-mod-edit", []string{goBin, "mod", "edit", "-replace", editStr}, cwd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-03-12 16:49:52 +01:00
|
|
|
}
|
2019-11-14 18:25:55 +01:00
|
|
|
}
|
2020-03-25 23:57:46 +01:00
|
|
|
// resolve dependencies
|
|
|
|
err = pt.runCommand("go-mod-download", []string{goBin, "mod", "download"}, cwd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-07 10:23:05 +02:00
|
|
|
if pt.opts.RunBuild {
|
|
|
|
outBin := filepath.Join(gopath, "bin", string(projinfo.Proj.Name))
|
2020-06-10 01:42:53 +02:00
|
|
|
if runtime.GOOS == windowsOS {
|
2020-05-07 10:23:05 +02:00
|
|
|
outBin = fmt.Sprintf("%s.exe", outBin)
|
|
|
|
}
|
|
|
|
err = pt.runCommand("go-build", []string{goBin, "build", "-o", outBin, "."}, cwd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-28 15:14:46 +01:00
|
|
|
|
2020-05-07 10:23:05 +02:00
|
|
|
_, err = os.Stat(outBin)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error finding built application artifact: %w", err)
|
|
|
|
}
|
2020-02-28 15:14:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-06-10 18:17:19 +02:00
|
|
|
}
|
2019-10-26 01:59:50 +02:00
|
|
|
|
|
|
|
// prepareDotNetProject runs setup necessary to get a .NET project ready for `pulumi` commands.
|
2020-02-17 19:40:46 +01:00
|
|
|
func (pt *ProgramTester) prepareDotNetProject(projinfo *engine.Projinfo) error {
|
2019-10-26 01:59:50 +02:00
|
|
|
dotNetBin, err := pt.getDotNetBin()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "locating `dotnet` binary")
|
|
|
|
}
|
|
|
|
|
|
|
|
cwd, _, err := projinfo.GetPwdMain()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
localNuget := os.Getenv("PULUMI_LOCAL_NUGET")
|
|
|
|
if localNuget == "" {
|
2019-10-30 04:14:49 +01:00
|
|
|
localNuget = "/opt/pulumi/nuget"
|
2019-10-26 01:59:50 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 21:01:29 +01:00
|
|
|
for _, dep := range pt.opts.Dependencies {
|
|
|
|
|
|
|
|
// dotnet add package requires a specific version in case of a pre-release, so we have to look it up.
|
2019-12-03 08:22:32 +01:00
|
|
|
matches, err := filepath.Glob(filepath.Join(localNuget, dep+".?.*.nupkg"))
|
2019-11-19 21:01:29 +01:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to find a local Pulumi NuGet package")
|
|
|
|
}
|
|
|
|
if len(matches) != 1 {
|
|
|
|
return errors.New(fmt.Sprintf("attempting to find a local Pulumi NuGet package yielded %v results", matches))
|
|
|
|
}
|
|
|
|
file := filepath.Base(matches[0])
|
|
|
|
r := strings.NewReplacer(dep+".", "", ".nupkg", "")
|
|
|
|
version := r.Replace(file)
|
|
|
|
|
|
|
|
err = pt.runCommand("dotnet-add-package",
|
|
|
|
[]string{dotNetBin, "add", "package", dep, "-s", localNuget, "-v", version}, cwd)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "failed to add dependency on %s", dep)
|
|
|
|
}
|
2019-10-26 01:59:50 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 21:01:29 +01:00
|
|
|
return nil
|
2019-10-26 01:59:50 +02:00
|
|
|
}
|