Skip to content

feat(cli): add --parameter flag to exp scaletest command #10132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions cli/exp_scaletest.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {

useHostUser bool

parameterFlags workspaceParameterFlags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI This may also pull --build-options, not sure if you want to support them too. Probably not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a need at present. We don't rebuild workspaces in this command, only create.


tracingFlags = &scaletestTracingFlags{}
strategy = &scaletestStrategyFlags{}
cleanupStrategy = &scaletestStrategyFlags{cleanup: true}
Expand Down Expand Up @@ -597,11 +599,29 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
return xerrors.Errorf("get template version %q: %w", tpl.ActiveVersionID, err)
}

cliRichParameters, err := asWorkspaceBuildParameters(parameterFlags.richParameters)
if err != nil {
return xerrors.Errorf("can't parse given parameter values: %w", err)
}

richParameters, err := prepWorkspaceBuild(inv, client, prepWorkspaceBuildArgs{
Action: WorkspaceCreate,
Template: tpl,
NewWorkspaceName: "scaletest-%", // TODO: the scaletest runner will pass in a different name here. Does this matter?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mtojek Does the value here only matter for showing the plan output?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only for dry-run purposes. Not sure what happens if there is a workspace with such name exists. In the worst case, you can append a random number.


RichParameterFile: parameterFlags.richParameterFile,
RichParameters: cliRichParameters,
})
if err != nil {
return xerrors.Errorf("prepare build: %w", err)
}

// Do a dry-run to ensure the template and parameters are valid
// before we start creating users and workspaces.
if !noPlan {
dryRun, err := client.CreateTemplateVersionDryRun(ctx, templateVersion.ID, codersdk.CreateTemplateVersionDryRunRequest{
WorkspaceName: "scaletest",
WorkspaceName: "scaletest",
RichParameterValues: richParameters,
})
if err != nil {
return xerrors.Errorf("start dry run workspace creation: %w", err)
Expand Down Expand Up @@ -653,7 +673,8 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
OrganizationID: me.OrganizationIDs[0],
// UserID is set by the test automatically.
Request: codersdk.CreateWorkspaceRequest{
TemplateID: tpl.ID,
TemplateID: tpl.ID,
RichParameterValues: richParameters,
},
NoWaitForAgents: noWaitForAgents,
},
Expand Down Expand Up @@ -865,6 +886,7 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
},
}

cmd.Options = append(cmd.Options, parameterFlags.cliParameters()...)
tracingFlags.attach(&cmd.Options)
strategy.attach(&cmd.Options)
cleanupStrategy.attach(&cmd.Options)
Expand Down
2 changes: 2 additions & 0 deletions cli/exp_scaletest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func TestScaleTestCreateWorkspaces(t *testing.T) {
"--cleanup-job-timeout", "15s",
"--output", "text",
"--output", "json:"+outputFile,
"--parameter", "foo=baz",
"--rich-parameter-file", "/path/to/some/parameter/file.ext",
)
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t)
Expand Down
87 changes: 75 additions & 12 deletions scaletest/createworkspaces/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ func Test_Runner(t *testing.T) {
t.Skip("Race detector enabled, skipping time-sensitive test.")
}

testParameters := []*proto.RichParameter{
{
Name: "foo",
DefaultValue: "baz",
},
}
testParameterValues := []codersdk.WorkspaceBuildParameter{
{
Name: "foo",
Value: "baz",
},
}

t.Run("OK", func(t *testing.T) {
t.Parallel()

Expand All @@ -47,8 +60,16 @@ func Test_Runner(t *testing.T) {

authToken := uuid.NewString()
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionPlan: echo.PlanComplete,
Parse: echo.ParseComplete,
ProvisionPlan: []*proto.Response{
{
Type: &proto.Response_Plan{
Plan: &proto.PlanComplete{
Parameters: testParameters,
},
},
},
},
ProvisionApply: []*proto.Response{
{
Type: &proto.Response_Log{
Expand Down Expand Up @@ -102,7 +123,8 @@ func Test_Runner(t *testing.T) {
Workspace: workspacebuild.Config{
OrganizationID: user.OrganizationID,
Request: codersdk.CreateWorkspaceRequest{
TemplateID: template.ID,
TemplateID: template.ID,
RichParameterValues: testParameterValues,
},
},
ReconnectingPTY: &reconnectingpty.Config{
Expand Down Expand Up @@ -133,6 +155,13 @@ func Test_Runner(t *testing.T) {
require.NoError(t, err)
require.Len(t, workspaces.Workspaces, 1)

// Ensure the correct build parameters were used.
buildParams, err := client.WorkspaceBuildParameters(ctx, workspaces.Workspaces[0].LatestBuild.ID)
require.NoError(t, err)
require.Len(t, buildParams, 1)
require.Equal(t, testParameterValues[0].Name, buildParams[0].Name)
require.Equal(t, testParameterValues[0].Value, buildParams[0].Value)

// Look for strings in the logs.
require.Contains(t, logsStr, "Generating user password...")
require.Contains(t, logsStr, "Creating user:")
Expand Down Expand Up @@ -173,8 +202,16 @@ func Test_Runner(t *testing.T) {
user := coderdtest.CreateFirstUser(t, client)

version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionPlan: echo.PlanComplete,
Parse: echo.ParseComplete,
ProvisionPlan: []*proto.Response{
{
Type: &proto.Response_Plan{
Plan: &proto.PlanComplete{
Parameters: testParameters,
},
},
},
},
ProvisionApply: []*proto.Response{
{
Type: &proto.Response_Log{Log: &proto.Log{}},
Expand All @@ -200,7 +237,8 @@ func Test_Runner(t *testing.T) {
Workspace: workspacebuild.Config{
OrganizationID: user.OrganizationID,
Request: codersdk.CreateWorkspaceRequest{
TemplateID: template.ID,
TemplateID: template.ID,
RichParameterValues: testParameterValues,
},
},
})
Expand Down Expand Up @@ -288,8 +326,16 @@ func Test_Runner(t *testing.T) {

authToken := uuid.NewString()
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionPlan: echo.PlanComplete,
Parse: echo.ParseComplete,
ProvisionPlan: []*proto.Response{
{
Type: &proto.Response_Plan{
Plan: &proto.PlanComplete{
Parameters: testParameters,
},
},
},
},
ProvisionApply: []*proto.Response{
{
Type: &proto.Response_Log{
Expand Down Expand Up @@ -344,7 +390,8 @@ func Test_Runner(t *testing.T) {
Workspace: workspacebuild.Config{
OrganizationID: user.OrganizationID,
Request: codersdk.CreateWorkspaceRequest{
TemplateID: template.ID,
TemplateID: template.ID,
RichParameterValues: testParameterValues,
},
},
ReconnectingPTY: &reconnectingpty.Config{
Expand Down Expand Up @@ -375,6 +422,13 @@ func Test_Runner(t *testing.T) {
require.NoError(t, err)
require.Len(t, workspaces.Workspaces, 1)

// Ensure the correct build parameters were used.
buildParams, err := client.WorkspaceBuildParameters(ctx, workspaces.Workspaces[0].LatestBuild.ID)
require.NoError(t, err)
require.Len(t, buildParams, 1)
require.Equal(t, testParameterValues[0].Name, buildParams[0].Name)
require.Equal(t, testParameterValues[0].Value, buildParams[0].Value)

// Look for strings in the logs.
require.Contains(t, logsStr, "Generating user password...")
require.Contains(t, logsStr, "Creating user:")
Expand Down Expand Up @@ -413,8 +467,16 @@ func Test_Runner(t *testing.T) {
user := coderdtest.CreateFirstUser(t, client)

version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionPlan: echo.PlanComplete,
Parse: echo.ParseComplete,
ProvisionPlan: []*proto.Response{
{
Type: &proto.Response_Plan{
Plan: &proto.PlanComplete{
Parameters: testParameters,
},
},
},
},
ProvisionApply: []*proto.Response{
{
Type: &proto.Response_Apply{
Expand All @@ -438,7 +500,8 @@ func Test_Runner(t *testing.T) {
Workspace: workspacebuild.Config{
OrganizationID: user.OrganizationID,
Request: codersdk.CreateWorkspaceRequest{
TemplateID: template.ID,
TemplateID: template.ID,
RichParameterValues: testParameterValues,
},
},
})
Expand Down
3 changes: 3 additions & 0 deletions scripts/coder-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ fi
if [[ ${1:-} == wsproxy ]] && [[ ${2:-} == server ]]; then
BINARY_TYPE=coder
fi
if [[ ${1:-} == exp ]] && [[ ${2:-} == scaletest ]]; then
BINARY_TYPE=coder
fi
RELATIVE_BINARY_PATH="build/${BINARY_TYPE}_${GOOS}_${GOARCH}"

# To preserve the CWD when running the binary, we need to use pushd and popd to
Expand Down