mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat(cli): add --parameter flag to exp scaletest command (#10132)
This commit is contained in:
@ -525,6 +525,8 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
|
|||||||
|
|
||||||
useHostUser bool
|
useHostUser bool
|
||||||
|
|
||||||
|
parameterFlags workspaceParameterFlags
|
||||||
|
|
||||||
tracingFlags = &scaletestTracingFlags{}
|
tracingFlags = &scaletestTracingFlags{}
|
||||||
strategy = &scaletestStrategyFlags{}
|
strategy = &scaletestStrategyFlags{}
|
||||||
cleanupStrategy = &scaletestStrategyFlags{cleanup: true}
|
cleanupStrategy = &scaletestStrategyFlags{cleanup: true}
|
||||||
@ -597,11 +599,29 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
|
|||||||
return xerrors.Errorf("get template version %q: %w", tpl.ActiveVersionID, err)
|
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?
|
||||||
|
|
||||||
|
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
|
// Do a dry-run to ensure the template and parameters are valid
|
||||||
// before we start creating users and workspaces.
|
// before we start creating users and workspaces.
|
||||||
if !noPlan {
|
if !noPlan {
|
||||||
dryRun, err := client.CreateTemplateVersionDryRun(ctx, templateVersion.ID, codersdk.CreateTemplateVersionDryRunRequest{
|
dryRun, err := client.CreateTemplateVersionDryRun(ctx, templateVersion.ID, codersdk.CreateTemplateVersionDryRunRequest{
|
||||||
WorkspaceName: "scaletest",
|
WorkspaceName: "scaletest",
|
||||||
|
RichParameterValues: richParameters,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("start dry run workspace creation: %w", err)
|
return xerrors.Errorf("start dry run workspace creation: %w", err)
|
||||||
@ -653,7 +673,8 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
|
|||||||
OrganizationID: me.OrganizationIDs[0],
|
OrganizationID: me.OrganizationIDs[0],
|
||||||
// UserID is set by the test automatically.
|
// UserID is set by the test automatically.
|
||||||
Request: codersdk.CreateWorkspaceRequest{
|
Request: codersdk.CreateWorkspaceRequest{
|
||||||
TemplateID: tpl.ID,
|
TemplateID: tpl.ID,
|
||||||
|
RichParameterValues: richParameters,
|
||||||
},
|
},
|
||||||
NoWaitForAgents: noWaitForAgents,
|
NoWaitForAgents: noWaitForAgents,
|
||||||
},
|
},
|
||||||
@ -865,6 +886,7 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.Options = append(cmd.Options, parameterFlags.cliParameters()...)
|
||||||
tracingFlags.attach(&cmd.Options)
|
tracingFlags.attach(&cmd.Options)
|
||||||
strategy.attach(&cmd.Options)
|
strategy.attach(&cmd.Options)
|
||||||
cleanupStrategy.attach(&cmd.Options)
|
cleanupStrategy.attach(&cmd.Options)
|
||||||
|
@ -48,6 +48,8 @@ func TestScaleTestCreateWorkspaces(t *testing.T) {
|
|||||||
"--cleanup-job-timeout", "15s",
|
"--cleanup-job-timeout", "15s",
|
||||||
"--output", "text",
|
"--output", "text",
|
||||||
"--output", "json:"+outputFile,
|
"--output", "json:"+outputFile,
|
||||||
|
"--parameter", "foo=baz",
|
||||||
|
"--rich-parameter-file", "/path/to/some/parameter/file.ext",
|
||||||
)
|
)
|
||||||
clitest.SetupConfig(t, client, root)
|
clitest.SetupConfig(t, client, root)
|
||||||
pty := ptytest.New(t)
|
pty := ptytest.New(t)
|
||||||
|
@ -34,6 +34,19 @@ func Test_Runner(t *testing.T) {
|
|||||||
t.Skip("Race detector enabled, skipping time-sensitive test.")
|
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.Run("OK", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@ -47,8 +60,16 @@ func Test_Runner(t *testing.T) {
|
|||||||
|
|
||||||
authToken := uuid.NewString()
|
authToken := uuid.NewString()
|
||||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
||||||
Parse: echo.ParseComplete,
|
Parse: echo.ParseComplete,
|
||||||
ProvisionPlan: echo.PlanComplete,
|
ProvisionPlan: []*proto.Response{
|
||||||
|
{
|
||||||
|
Type: &proto.Response_Plan{
|
||||||
|
Plan: &proto.PlanComplete{
|
||||||
|
Parameters: testParameters,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
ProvisionApply: []*proto.Response{
|
ProvisionApply: []*proto.Response{
|
||||||
{
|
{
|
||||||
Type: &proto.Response_Log{
|
Type: &proto.Response_Log{
|
||||||
@ -102,7 +123,8 @@ func Test_Runner(t *testing.T) {
|
|||||||
Workspace: workspacebuild.Config{
|
Workspace: workspacebuild.Config{
|
||||||
OrganizationID: user.OrganizationID,
|
OrganizationID: user.OrganizationID,
|
||||||
Request: codersdk.CreateWorkspaceRequest{
|
Request: codersdk.CreateWorkspaceRequest{
|
||||||
TemplateID: template.ID,
|
TemplateID: template.ID,
|
||||||
|
RichParameterValues: testParameterValues,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ReconnectingPTY: &reconnectingpty.Config{
|
ReconnectingPTY: &reconnectingpty.Config{
|
||||||
@ -133,6 +155,13 @@ func Test_Runner(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, workspaces.Workspaces, 1)
|
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.
|
// Look for strings in the logs.
|
||||||
require.Contains(t, logsStr, "Generating user password...")
|
require.Contains(t, logsStr, "Generating user password...")
|
||||||
require.Contains(t, logsStr, "Creating user:")
|
require.Contains(t, logsStr, "Creating user:")
|
||||||
@ -173,8 +202,16 @@ func Test_Runner(t *testing.T) {
|
|||||||
user := coderdtest.CreateFirstUser(t, client)
|
user := coderdtest.CreateFirstUser(t, client)
|
||||||
|
|
||||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
||||||
Parse: echo.ParseComplete,
|
Parse: echo.ParseComplete,
|
||||||
ProvisionPlan: echo.PlanComplete,
|
ProvisionPlan: []*proto.Response{
|
||||||
|
{
|
||||||
|
Type: &proto.Response_Plan{
|
||||||
|
Plan: &proto.PlanComplete{
|
||||||
|
Parameters: testParameters,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
ProvisionApply: []*proto.Response{
|
ProvisionApply: []*proto.Response{
|
||||||
{
|
{
|
||||||
Type: &proto.Response_Log{Log: &proto.Log{}},
|
Type: &proto.Response_Log{Log: &proto.Log{}},
|
||||||
@ -200,7 +237,8 @@ func Test_Runner(t *testing.T) {
|
|||||||
Workspace: workspacebuild.Config{
|
Workspace: workspacebuild.Config{
|
||||||
OrganizationID: user.OrganizationID,
|
OrganizationID: user.OrganizationID,
|
||||||
Request: codersdk.CreateWorkspaceRequest{
|
Request: codersdk.CreateWorkspaceRequest{
|
||||||
TemplateID: template.ID,
|
TemplateID: template.ID,
|
||||||
|
RichParameterValues: testParameterValues,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -288,8 +326,16 @@ func Test_Runner(t *testing.T) {
|
|||||||
|
|
||||||
authToken := uuid.NewString()
|
authToken := uuid.NewString()
|
||||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
||||||
Parse: echo.ParseComplete,
|
Parse: echo.ParseComplete,
|
||||||
ProvisionPlan: echo.PlanComplete,
|
ProvisionPlan: []*proto.Response{
|
||||||
|
{
|
||||||
|
Type: &proto.Response_Plan{
|
||||||
|
Plan: &proto.PlanComplete{
|
||||||
|
Parameters: testParameters,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
ProvisionApply: []*proto.Response{
|
ProvisionApply: []*proto.Response{
|
||||||
{
|
{
|
||||||
Type: &proto.Response_Log{
|
Type: &proto.Response_Log{
|
||||||
@ -344,7 +390,8 @@ func Test_Runner(t *testing.T) {
|
|||||||
Workspace: workspacebuild.Config{
|
Workspace: workspacebuild.Config{
|
||||||
OrganizationID: user.OrganizationID,
|
OrganizationID: user.OrganizationID,
|
||||||
Request: codersdk.CreateWorkspaceRequest{
|
Request: codersdk.CreateWorkspaceRequest{
|
||||||
TemplateID: template.ID,
|
TemplateID: template.ID,
|
||||||
|
RichParameterValues: testParameterValues,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ReconnectingPTY: &reconnectingpty.Config{
|
ReconnectingPTY: &reconnectingpty.Config{
|
||||||
@ -375,6 +422,13 @@ func Test_Runner(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, workspaces.Workspaces, 1)
|
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.
|
// Look for strings in the logs.
|
||||||
require.Contains(t, logsStr, "Generating user password...")
|
require.Contains(t, logsStr, "Generating user password...")
|
||||||
require.Contains(t, logsStr, "Creating user:")
|
require.Contains(t, logsStr, "Creating user:")
|
||||||
@ -413,8 +467,16 @@ func Test_Runner(t *testing.T) {
|
|||||||
user := coderdtest.CreateFirstUser(t, client)
|
user := coderdtest.CreateFirstUser(t, client)
|
||||||
|
|
||||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
||||||
Parse: echo.ParseComplete,
|
Parse: echo.ParseComplete,
|
||||||
ProvisionPlan: echo.PlanComplete,
|
ProvisionPlan: []*proto.Response{
|
||||||
|
{
|
||||||
|
Type: &proto.Response_Plan{
|
||||||
|
Plan: &proto.PlanComplete{
|
||||||
|
Parameters: testParameters,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
ProvisionApply: []*proto.Response{
|
ProvisionApply: []*proto.Response{
|
||||||
{
|
{
|
||||||
Type: &proto.Response_Apply{
|
Type: &proto.Response_Apply{
|
||||||
@ -438,7 +500,8 @@ func Test_Runner(t *testing.T) {
|
|||||||
Workspace: workspacebuild.Config{
|
Workspace: workspacebuild.Config{
|
||||||
OrganizationID: user.OrganizationID,
|
OrganizationID: user.OrganizationID,
|
||||||
Request: codersdk.CreateWorkspaceRequest{
|
Request: codersdk.CreateWorkspaceRequest{
|
||||||
TemplateID: template.ID,
|
TemplateID: template.ID,
|
||||||
|
RichParameterValues: testParameterValues,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -17,6 +17,9 @@ fi
|
|||||||
if [[ ${1:-} == wsproxy ]] && [[ ${2:-} == server ]]; then
|
if [[ ${1:-} == wsproxy ]] && [[ ${2:-} == server ]]; then
|
||||||
BINARY_TYPE=coder
|
BINARY_TYPE=coder
|
||||||
fi
|
fi
|
||||||
|
if [[ ${1:-} == exp ]] && [[ ${2:-} == scaletest ]]; then
|
||||||
|
BINARY_TYPE=coder
|
||||||
|
fi
|
||||||
RELATIVE_BINARY_PATH="build/${BINARY_TYPE}_${GOOS}_${GOARCH}"
|
RELATIVE_BINARY_PATH="build/${BINARY_TYPE}_${GOOS}_${GOARCH}"
|
||||||
|
|
||||||
# To preserve the CWD when running the binary, we need to use pushd and popd to
|
# To preserve the CWD when running the binary, we need to use pushd and popd to
|
||||||
|
Reference in New Issue
Block a user