pulumi/sdk/python/cmd/pulumi-language-python/language_test.go

283 lines
8.1 KiB
Go
Raw Normal View History

// Copyright 2016-2023, 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.
package main
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
"os"
"os/exec"
"sync"
"testing"
pbempty "google.golang.org/protobuf/types/known/emptypb"
Add SupportPack to schemas to write out in the new style (#15713) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> This adds a new flag to the schema metadata to tell codegen to use the new proposed style of SDKs where we fill in versions and write go.mods etc. I've reworked pack to operate on packages assuming they're in this new style. That is pack no longer has the responsibility to fill in any version information. This updates python and node codegen to write out SDKs in this new style, and fixes their core libraries to still be buildable via pack. There are two approaches to fixing those, I've chosen option 1 below but could pretty easily rework for option 2. 1) Write the version information directly to the SDKs at the same time as we edit the .version file. To simplify this I've added a new 'set-version.py' script that takes a version string an writes it to all the relevant places (.version, package.json, etc). 2) Write "pack" in the language host to search up the directory tree for the ".version" file and then fill in the version information as we we're doing before with envvar tricks and copying and editing package.json. I think 1 is simpler long term, but does force some amount of cleanup in unrelated bits of the system right now (release makefiles need a small edit). 2 is much more localised but keeps this complexity that sdk/nodejs sdk/python aren't actually valid source modules. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 09:25:46 +00:00
"github.com/pulumi/pulumi/sdk/v3"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
codegen "github.com/pulumi/pulumi/pkg/v3/codegen/python"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/rpcutil"
testingrpc "github.com/pulumi/pulumi/sdk/v3/proto/go/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
type hostEngine struct {
pulumirpc.UnimplementedEngineServer
t *testing.T
logLock sync.Mutex
logRepeat int
previousMessage string
}
func (e *hostEngine) Log(_ context.Context, req *pulumirpc.LogRequest) (*pbempty.Empty, error) {
e.logLock.Lock()
defer e.logLock.Unlock()
var sev diag.Severity
switch req.Severity {
case pulumirpc.LogSeverity_DEBUG:
sev = diag.Debug
case pulumirpc.LogSeverity_INFO:
sev = diag.Info
case pulumirpc.LogSeverity_WARNING:
sev = diag.Warning
case pulumirpc.LogSeverity_ERROR:
sev = diag.Error
default:
return nil, fmt.Errorf("Unrecognized logging severity: %v", req.Severity)
}
message := req.Message
if os.Getenv("PULUMI_LANGUAGE_TEST_SHOW_FULL_OUTPUT") != "true" {
// Cut down logs so they don't overwhelm the test output
if len(message) > 1024 {
message = message[:1024] + "... (truncated, run with PULUMI_LANGUAGE_TEST_SHOW_FULL_OUTPUT=true to see full logs))"
}
}
if e.previousMessage == message {
e.logRepeat++
return &pbempty.Empty{}, nil
}
if e.logRepeat > 1 {
e.t.Logf("Last message repeated %d times", e.logRepeat)
}
e.logRepeat = 1
e.previousMessage = message
if req.StreamId != 0 {
e.t.Logf("(%d) %s[%s]: %s", req.StreamId, sev, req.Urn, message)
} else {
e.t.Logf("%s[%s]: %s", sev, req.Urn, message)
}
return &pbempty.Empty{}, nil
}
func runEngine(t *testing.T) string {
// Run a gRPC server that implements the Pulumi engine RPC interface. But all we do is forward logs on to T.
engine := &hostEngine{t: t}
stop := make(chan bool)
t.Cleanup(func() {
close(stop)
})
handle, err := rpcutil.ServeWithOptions(rpcutil.ServeOptions{
Cancel: stop,
Init: func(srv *grpc.Server) error {
pulumirpc.RegisterEngineServer(srv, engine)
return nil
},
Options: rpcutil.OpenTracingServerInterceptorOptions(nil),
})
require.NoError(t, err)
return fmt.Sprintf("127.0.0.1:%v", handle.Port)
}
func runTestingHost(t *testing.T) (string, testingrpc.LanguageTestClient) {
// We can't just go run the pulumi-test-language package because of
// https://github.com/golang/go/issues/39172, so we build it to a temp file then run that.
binary := t.TempDir() + "/pulumi-test-language"
cmd := exec.Command("go", "build", "-C", "../../../../cmd/pulumi-test-language", "-o", binary)
output, err := cmd.CombinedOutput()
t.Logf("build output: %s", output)
require.NoError(t, err)
cmd = exec.Command(binary)
stdout, err := cmd.StdoutPipe()
require.NoError(t, err)
stderr, err := cmd.StderrPipe()
require.NoError(t, err)
stderrReader := bufio.NewReader(stderr)
var wg sync.WaitGroup
wg.Add(1)
go func() {
for {
text, err := stderrReader.ReadString('\n')
if err != nil {
wg.Done()
return
}
t.Logf("engine: %s", text)
}
}()
err = cmd.Start()
require.NoError(t, err)
stdoutBytes, err := io.ReadAll(stdout)
require.NoError(t, err)
address := string(stdoutBytes)
conn, err := grpc.Dial(
address,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithUnaryInterceptor(rpcutil.OpenTracingClientInterceptor()),
grpc.WithStreamInterceptor(rpcutil.OpenTracingStreamClientInterceptor()),
rpcutil.GrpcChannelOptions(),
)
require.NoError(t, err)
client := testingrpc.NewLanguageTestClient(conn)
t.Cleanup(func() {
assert.NoError(t, cmd.Process.Kill())
wg.Wait()
// We expect this to error because we just killed it.
contract.IgnoreError(cmd.Wait())
})
engineAddress := runEngine(t)
return engineAddress, client
}
func TestLanguage(t *testing.T) {
t.Parallel()
engineAddress, engine := runTestingHost(t)
tests, err := engine.GetLanguageTests(context.Background(), &testingrpc.GetLanguageTestsRequest{})
require.NoError(t, err)
runTests := func(t *testing.T, snapshotDir string, useToml bool, inputTypes, typechecker string) {
Test both setup.py and pyproject.toml in python conformance tests (#15758) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Run python conformance tests with setup.py and pyproject.toml. This is to ensure SDK generation and resolution works correctly for both project styles. Hopefully at some point we can deprecate and remove setup.py support, and halve the number of tests needed to run here. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 21:33:14 +00:00
cancel := make(chan bool)
// Run the language plugin
handle, err := rpcutil.ServeWithOptions(rpcutil.ServeOptions{
Init: func(srv *grpc.Server) error {
pythonExec := "../pulumi-language-python-exec"
host := newLanguageHost(pythonExec, engineAddress, "", typechecker)
Test both setup.py and pyproject.toml in python conformance tests (#15758) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Run python conformance tests with setup.py and pyproject.toml. This is to ensure SDK generation and resolution works correctly for both project styles. Hopefully at some point we can deprecate and remove setup.py support, and halve the number of tests needed to run here. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 21:33:14 +00:00
pulumirpc.RegisterLanguageRuntimeServer(srv, host)
return nil
Add SupportPack to schemas to write out in the new style (#15713) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> This adds a new flag to the schema metadata to tell codegen to use the new proposed style of SDKs where we fill in versions and write go.mods etc. I've reworked pack to operate on packages assuming they're in this new style. That is pack no longer has the responsibility to fill in any version information. This updates python and node codegen to write out SDKs in this new style, and fixes their core libraries to still be buildable via pack. There are two approaches to fixing those, I've chosen option 1 below but could pretty easily rework for option 2. 1) Write the version information directly to the SDKs at the same time as we edit the .version file. To simplify this I've added a new 'set-version.py' script that takes a version string an writes it to all the relevant places (.version, package.json, etc). 2) Write "pack" in the language host to search up the directory tree for the ".version" file and then fill in the version information as we we're doing before with envvar tricks and copying and editing package.json. I think 1 is simpler long term, but does force some amount of cleanup in unrelated bits of the system right now (release makefiles need a small edit). 2 is much more localised but keeps this complexity that sdk/nodejs sdk/python aren't actually valid source modules. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 09:25:46 +00:00
},
Test both setup.py and pyproject.toml in python conformance tests (#15758) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Run python conformance tests with setup.py and pyproject.toml. This is to ensure SDK generation and resolution works correctly for both project styles. Hopefully at some point we can deprecate and remove setup.py support, and halve the number of tests needed to run here. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 21:33:14 +00:00
Cancel: cancel,
})
require.NoError(t, err)
Test both setup.py and pyproject.toml in python conformance tests (#15758) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Run python conformance tests with setup.py and pyproject.toml. This is to ensure SDK generation and resolution works correctly for both project styles. Hopefully at some point we can deprecate and remove setup.py support, and halve the number of tests needed to run here. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 21:33:14 +00:00
// Create a temp project dir for the test to run in
rootDir := t.TempDir()
snapshotDir = "./testdata/" + snapshotDir
var languageInfo string
if useToml || inputTypes != "" {
var info codegen.PackageInfo
info.PyProject.Enabled = useToml
info.InputTypes = inputTypes
json, err := json.Marshal(info)
require.NoError(t, err)
languageInfo = string(json)
Test both setup.py and pyproject.toml in python conformance tests (#15758) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Run python conformance tests with setup.py and pyproject.toml. This is to ensure SDK generation and resolution works correctly for both project styles. Hopefully at some point we can deprecate and remove setup.py support, and halve the number of tests needed to run here. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 21:33:14 +00:00
}
// Prepare to run the tests
prepare, err := engine.PrepareLanguageTests(context.Background(), &testingrpc.PrepareLanguageTestsRequest{
LanguagePluginName: "python",
LanguagePluginTarget: fmt.Sprintf("127.0.0.1:%d", handle.Port),
TemporaryDirectory: rootDir,
SnapshotDirectory: snapshotDir,
CoreSdkDirectory: "../../lib",
CoreSdkVersion: sdk.Version.String(),
SnapshotEdits: []*testingrpc.PrepareLanguageTestsRequest_Replacement{
{
Make local dependencies absolute or relative paths (#15766) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need this for local dependencies in conformance tests for SDKs and programs. Things like NodeJS just record the path as is in the package.json put into the packed tgz, if a program then uses that tgz via a relative path NodeJS doesn't re-resolve the relative relative paths. Making these absolute for conformance testing fixes that as all the conformance tests do run in a stable folder location. We fix writing that folder path to the snapshots using the new regex replace facility added in https://github.com/pulumi/pulumi/pull/15747. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-25 10:27:56 +00:00
Path: "requirements\\.txt",
Test both setup.py and pyproject.toml in python conformance tests (#15758) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Run python conformance tests with setup.py and pyproject.toml. This is to ensure SDK generation and resolution works correctly for both project styles. Hopefully at some point we can deprecate and remove setup.py support, and halve the number of tests needed to run here. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 21:33:14 +00:00
Pattern: fmt.Sprintf("pulumi-%s-py3-none-any.whl", sdk.Version.String()),
Replacement: "pulumi-CORE.VERSION-py3-none-any.whl",
},
Make local dependencies absolute or relative paths (#15766) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need this for local dependencies in conformance tests for SDKs and programs. Things like NodeJS just record the path as is in the package.json put into the packed tgz, if a program then uses that tgz via a relative path NodeJS doesn't re-resolve the relative relative paths. Making these absolute for conformance testing fixes that as all the conformance tests do run in a stable folder location. We fix writing that folder path to the snapshots using the new regex replace facility added in https://github.com/pulumi/pulumi/pull/15747. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-25 10:27:56 +00:00
{
Path: "requirements\\.txt",
Pattern: rootDir + "/artifacts",
Make local dependencies absolute or relative paths (#15766) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> We need this for local dependencies in conformance tests for SDKs and programs. Things like NodeJS just record the path as is in the package.json put into the packed tgz, if a program then uses that tgz via a relative path NodeJS doesn't re-resolve the relative relative paths. Making these absolute for conformance testing fixes that as all the conformance tests do run in a stable folder location. We fix writing that folder path to the snapshots using the new regex replace facility added in https://github.com/pulumi/pulumi/pull/15747. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-25 10:27:56 +00:00
Replacement: "ROOT/artifacts",
},
Test both setup.py and pyproject.toml in python conformance tests (#15758) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Run python conformance tests with setup.py and pyproject.toml. This is to ensure SDK generation and resolution works correctly for both project styles. Hopefully at some point we can deprecate and remove setup.py support, and halve the number of tests needed to run here. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 21:33:14 +00:00
},
LanguageInfo: languageInfo,
})
Test both setup.py and pyproject.toml in python conformance tests (#15758) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Run python conformance tests with setup.py and pyproject.toml. This is to ensure SDK generation and resolution works correctly for both project styles. Hopefully at some point we can deprecate and remove setup.py support, and halve the number of tests needed to run here. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 21:33:14 +00:00
require.NoError(t, err)
// TODO(https://github.com/pulumi/pulumi/issues/13945): enable parallel tests
//nolint:paralleltest // These aren't yet safe to run in parallel
for _, tt := range tests.Tests {
tt := tt
[PCL] Implement package descriptor blocks to support parameterized packages (#17589) ### Description As part of fixing https://github.com/pulumi/pulumi-converter-terraform/issues/186 we need to be able to express resources and packages in PCL that are coming from parameterized providers. Today in PCL we will extract the package name from the token of a resource definition and load that package based on the name (using `LoadReference`) . For parameterized packages, this will not work because the schema of the parameterized resource is only available after we figure out which base provider is being parameterized and what the parameters are. In this PR we fix this problem by implementing top-level `package` blocks that are full package descriptors that contain sufficient information to load both classic resource plugins and parameterized packages. The block will looks like: ```tf package <name> { baseProviderName = <name> baseProviderVersion = <version> baseProviderDownloadUrl = <url> parameterization { name = <name> version = <version> value = <base64-encoded-value> } } ``` Example of a package descriptors for a `terraform-provider` provider parameterized with `hashicorp/random`: ```tf package "random" { baseProviderName = "terraform-provider" baseProviderVersion = "0.0.27" parameterization { name = "random" version = "3.6.2" value = "eyJyZW1vdGUiOnsidXJsIjoicmVnaXN0cnkub3BlbnRvZnUub3JnL2hhc2hpY29ycC9yYW5kb20iLCJ2ZXJzaW9uIjoiMy42LjIifX0=" } } resource "randomPet" "random:index/pet:Pet" { length = 10 } ``` Now when we extract the package name from `random:index/pet:Pet => random` we check if there is a package descriptor for it and use that descriptor to load the package, parameterizing the base provider when necessary. Otherwise if the package name doesn't have a descriptor, we fallback to old package loader that expects plugin `pulumi-resource-<packageName>` to be available in the plugin cache or PATH. These blocks are not mapped to specific `Program` nodes, they are read from the AST after the PCL files have been parsed. This information can be easily made available to `pcl.Program` if needed since it has access to the source binder. ### Conformance Tests With the ability to parameterize packages from a PCL program, we can support conformance testing parameterized providers! I've implemented a new test `l2-parameterized-resource` which implements a parameterized provider that has a schema and runtime behaviour dictated by the values it was parameterized with. ### Test this locally You can test this locally with different parameterized providers, you will need their parameter values which you can retrieve from the schema: ``` pulumi package get-schema terraform-provider hashicorp/random > random-schema.json ``` In `random-schema.json` you will find values you need in `$.parameterization` ### Converted Code The program above can be successfully converted to TypeScript for example and generates the following: ```ts import * as pulumi from "@pulumi/pulumi"; import * as random from "@pulumi/random"; const randomPet = new random.Pet("randomPet", {length: 10}); ``` This program loaded the parameterized schema and used it to generate the resource definition correctly. However the following still need to be addressed: - The `pulumi convert` doesn't generate the local SDKs are part of the conversion. Doing this might make https://github.com/pulumi/pulumi-converter-terraform/issues/186 a lot easier than expected. cc @brandonpollack23 - Program generators do not understand parameterized packages so they reference them like any of our provider sdk `"@pulumi/random": "3.6.2"` (this is wrong because there is not such sdk on npm). They should expect the SDK to be available locally and reference it via a relative path - ~We need a good way to (conformance) test these~ DONE ✅
2024-11-05 00:58:48 +00:00
t.Run(tt, func(t *testing.T) {
Test both setup.py and pyproject.toml in python conformance tests (#15758) <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Run python conformance tests with setup.py and pyproject.toml. This is to ensure SDK generation and resolution works correctly for both project styles. Hopefully at some point we can deprecate and remove setup.py support, and halve the number of tests needed to run here. ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-22 21:33:14 +00:00
result, err := engine.RunLanguageTest(context.Background(), &testingrpc.RunLanguageTestRequest{
Token: prepare.Token,
Test: tt,
})
require.NoError(t, err)
for _, msg := range result.Messages {
t.Log(msg)
}
t.Logf("stdout: %s", result.Stdout)
t.Logf("stderr: %s", result.Stderr)
assert.True(t, result.Success)
})
}
close(cancel)
assert.NoError(t, <-handle.Done)
}
// We need to run the python tests multiple times. Once with TOML projects and once with setup.py. We also want to
// test that explicitly setting the input types works as expected, as well as the default. This shouldn't interact
// with the project type so we vary both at once. We also want to test that the typechecker works, that doesn't vary
// by project type but it will vary over classes-vs-dicts. We could run all combinations but we take some time/risk
// tradeoff here only testing the old classes style with pyright.
//nolint:paralleltest
t.Run("default", func(t *testing.T) {
runTests(t, "setuppy", false, "", "mypy")
})
//nolint:paralleltest
t.Run("toml", func(t *testing.T) {
runTests(t, "toml", true, "classes-and-dicts", "pyright")
})
//nolint:paralleltest
t.Run("classes", func(t *testing.T) {
runTests(t, "classes", false, "classes", "pyright")
})
}