feat(scaletest): allow scaletests to run using the host credentials (#7075)

This commit is contained in:
Colin Adler
2023-04-11 14:49:28 -05:00
committed by GitHub
parent 2585249014
commit a44070e2ec
6 changed files with 93 additions and 54 deletions

View File

@ -471,7 +471,7 @@ func (r *RootCmd) scaletestCleanup() *clibase.Cmd {
}
cliui.Errorf(inv.Stderr, "Found %d scaletest users\n", len(users))
if len(workspaces) != 0 {
if len(users) != 0 {
cliui.Infof(inv.Stdout, "Deleting scaletest users..."+"\n")
harness := harness.NewTestHarness(cleanupStrategy.toStrategy(), harness.ConcurrentExecutionStrategy{})
@ -535,6 +535,8 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
connectInterval time.Duration
connectTimeout time.Duration
useHostUser bool
tracingFlags = &scaletestTracingFlags{}
strategy = &scaletestStrategyFlags{}
cleanupStrategy = &scaletestStrategyFlags{cleanup: true}
@ -693,28 +695,16 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
const name = "workspacebuild"
id := strconv.Itoa(i)
username, email, err := newScaleTestUser(id)
if err != nil {
return xerrors.Errorf("create scaletest username and email: %w", err)
}
workspaceName, err := newScaleTestWorkspace(id)
if err != nil {
return xerrors.Errorf("create scaletest workspace name: %w", err)
}
config := createworkspaces.Config{
User: createworkspaces.UserConfig{
// TODO: configurable org
OrganizationID: me.OrganizationIDs[0],
Username: username,
Email: email,
},
Workspace: workspacebuild.Config{
OrganizationID: me.OrganizationIDs[0],
// UserID is set by the test automatically.
Request: codersdk.CreateWorkspaceRequest{
TemplateID: tpl.ID,
Name: workspaceName,
ParameterValues: params,
},
NoWaitForAgents: noWaitForAgents,
@ -722,6 +712,20 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
NoCleanup: noCleanup,
}
if useHostUser {
config.User.SessionToken = client.SessionToken()
} else {
config.User.Username, config.User.Email, err = newScaleTestUser(id)
if err != nil {
return xerrors.Errorf("create scaletest username and email: %w", err)
}
}
config.Workspace.Request.Name, err = newScaleTestWorkspace(id)
if err != nil {
return xerrors.Errorf("create scaletest workspace name: %w", err)
}
if runCommand != "" {
config.ReconnectingPTY = &reconnectingpty.Config{
// AgentID is set by the test automatically.
@ -927,6 +931,13 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
Description: "Timeout for each request to the --connect-url.",
Value: clibase.DurationOf(&connectTimeout),
},
{
Flag: "use-host-login",
Env: "CODER_SCALETEST_USE_HOST_LOGIN",
Default: "false",
Description: "Use the use logged in on the host machine, instead of creating users.",
Value: clibase.BoolOf(&useHostUser),
},
}
tracingFlags.attach(&cmd.Options)
@ -1009,9 +1020,6 @@ func isScaleTestUser(user codersdk.User) bool {
}
func isScaleTestWorkspace(workspace codersdk.Workspace) bool {
if !strings.HasPrefix(workspace.OwnerName, "scaletest-") {
return false
}
return strings.HasPrefix(workspace.Name, "scaletest-")
return strings.HasPrefix(workspace.OwnerName, "scaletest-") ||
strings.HasPrefix(workspace.Name, "scaletest-")
}