Skip to content

Commit

Permalink
Merge pull request #213 from galasa-dev/iss1479
Browse files Browse the repository at this point in the history
Iss1479 and 1685 - Reset and Cancel an active test run.
  • Loading branch information
jadecarino authored Feb 20, 2024
2 parents b34f68a + ec3742e commit 053903f
Show file tree
Hide file tree
Showing 18 changed files with 1,796 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,35 @@ galasactl runs download --name C1234 --destination /Users/me/my/folder
A complete list of supported parameters for the `runs download` command is available [here](./docs/generated/galasactl_runs_download.md).


## runs reset

This command will reset a running test in the Ecosystem that is either stuck in a timeout condition or looping, by requeing the test. Note: The reset command does not wait for the server to complete the act of resetting the test, but if the command succeeds, then the server has accepted the request to reset the test.


## Example

The run "C1234" can be reset using the following command:

```
galasactl runs reset --name C1234
```


## runs cancel

If after running `runs reset` the test is still not able to run through successfully, it can be abandoned with `runs cancel`.

This command will cancel a running test in the Ecosystem. It will not delete any information that is already stored in the RAS about the test, it will only cancel the execution of the test. Note: The cancel command does not wait for the server to complete the act of cancelling the test, but if the command succeeds, then the server has accepted the request to cancel the test.

## Example

The run "C1234" can be cancelled using the following command:

```
galasactl runs cancel --name C1234
```


## properties get
This command retrieves details of properties in a namespace.

Expand Down
7 changes: 7 additions & 0 deletions docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ The `galasactl` tool can generate the following errors:
- GAL1123E: Failed to read 3270 terminal JSON because the content is in the wrong format. Reason: {}
- GAL1124E: Internal Failure. Terminal image could not be encoded into PNG format. Reason: {}
- GAL1125E: Authentication property {} is invalid. Please ensure that it the value is made up of two parts that are separated by a '{}'.
- GAL1132E: No active run found matching run name '{}'.
- GAL1133E: Error resetting run '{}'. Reason: '{}'
- GAL1134E: The runs reset operation failed. Unable to process the error information returned from the server.
- GAL1135E: Error cancelling run '{}'. Reason: '{}'
- GAL1136E: The runs cancel operation failed. Unable to process the error information returned from the server.
- GAL1225E: Failed to open file '{}' cause: {}. Check that this file exists, and that you have read permissions.
- GAL1226E: Internal failure. Contents of gzip could be read, but not decoded. New gzip reader failed: file: {} error: {}
- GAL1227E: Internal failure. Contents of gzip could not be decoded. {} error: {}
Expand All @@ -136,3 +141,5 @@ The `galasactl` tool can generate the following errors:

- GAL2502I: Rendered {} image files.

- GAL2503I: Run '{}' has been reset successfully.
- GAL2504I: Run '{}' has been cancelled successfully.
2 changes: 2 additions & 0 deletions docs/generated/galasactl_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ Assembles, submits and monitors test runs in Galasa Ecosystem
### SEE ALSO

* [galasactl](galasactl.md) - CLI for Galasa
* [galasactl runs cancel](galasactl_runs_cancel.md) - cancel an active run in the ecosystem
* [galasactl runs download](galasactl_runs_download.md) - Download the artifacts of a test run which ran.
* [galasactl runs get](galasactl_runs_get.md) - Get the details of a test runname which ran or is running.
* [galasactl runs prepare](galasactl_runs_prepare.md) - prepares a list of tests
* [galasactl runs reset](galasactl_runs_reset.md) - reset an active run in the ecosystem
* [galasactl runs submit](galasactl_runs_submit.md) - submit a list of tests to the ecosystem

31 changes: 31 additions & 0 deletions docs/generated/galasactl_runs_cancel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## galasactl runs cancel

cancel an active run in the ecosystem

### Synopsis

Cancel an active test run in the ecosystem if it is stuck or looping.

```
galasactl runs cancel [flags]
```

### Options

```
-h, --help Displays the options for the 'runs cancel' command.
--name string the name of the test run to cancel
```

### Options inherited from parent commands

```
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
```

### SEE ALSO

* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem

31 changes: 31 additions & 0 deletions docs/generated/galasactl_runs_reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## galasactl runs reset

reset an active run in the ecosystem

### Synopsis

Reset an active test run in the ecosystem if it is stuck or looping.

```
galasactl runs reset [flags]
```

### Options

```
-h, --help Displays the options for the 'runs reset' command.
--name string the name of the test run to reset
```

### Options inherited from parent commands

```
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
```

### SEE ALSO

* [galasactl runs](galasactl_runs.md) - Manage test runs in the ecosystem

14 changes: 13 additions & 1 deletion pkg/cmd/commandCollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const (
COMMAND_NAME_RUNS_PREPARE = "runs prepare"
COMMAND_NAME_RUNS_SUBMIT = "runs submit"
COMMAND_NAME_RUNS_SUBMIT_LOCAL = "runs submit local"
COMMAND_NAME_RUNS_RESET = "runs reset"
COMMAND_NAME_RUNS_CANCEL = "runs cancel"
COMMAND_NAME_RESOURCES = "resources"
COMMAND_NAME_RESOURCES_APPLY = "resources apply"
COMMAND_NAME_RESOURCES_CREATE = "resources create"
Expand Down Expand Up @@ -78,7 +80,7 @@ func (commands *commandCollectionImpl) GetRootCommand() GalasaCommand {
func (commands *commandCollectionImpl) GetCommand(name string) (GalasaCommand, error) {
var err error
cmd, _ := commands.commandMap[name]
if cmd == nil{
if cmd == nil {
err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_COMMAND_NOT_FOUND_IN_CMD_COLLECTION)
log.Printf("Caller tried to lookup %s in the command collection and it was not found.\n", name)
}
Expand Down Expand Up @@ -266,6 +268,8 @@ func (commands *commandCollectionImpl) addRunsCommands(factory Factory, rootComm
var runsPrepareCommand GalasaCommand
var runsSubmitCommand GalasaCommand
var runsSubmitLocalCommand GalasaCommand
var runsResetCommand GalasaCommand
var runsCancelCommand GalasaCommand

if err == nil {
runsCommand, err = NewRunsCmd(rootCommand)
Expand All @@ -279,6 +283,12 @@ func (commands *commandCollectionImpl) addRunsCommands(factory Factory, rootComm
runsSubmitCommand, err = NewRunsSubmitCommand(factory, runsCommand, rootCommand)
if err == nil {
runsSubmitLocalCommand, err = NewRunsSubmitLocalCommand(factory, runsSubmitCommand, runsCommand, rootCommand)
if err == nil {
runsResetCommand, err = NewRunsResetCommand(factory, runsCommand, rootCommand)
if err == nil {
runsCancelCommand, err = NewRunsCancelCommand(factory, runsCommand, rootCommand)
}
}
}
}
}
Expand All @@ -293,6 +303,8 @@ func (commands *commandCollectionImpl) addRunsCommands(factory Factory, rootComm
commands.commandMap[runsPrepareCommand.Name()] = runsPrepareCommand
commands.commandMap[runsSubmitCommand.Name()] = runsSubmitCommand
commands.commandMap[runsSubmitLocalCommand.Name()] = runsSubmitLocalCommand
commands.commandMap[runsResetCommand.Name()] = runsResetCommand
commands.commandMap[runsCancelCommand.Name()] = runsCancelCommand
}

return err
Expand Down
149 changes: 149 additions & 0 deletions pkg/cmd/runsCancel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"log"

"github.com/galasa-dev/cli/pkg/api"
"github.com/galasa-dev/cli/pkg/auth"
"github.com/galasa-dev/cli/pkg/runs"
"github.com/galasa-dev/cli/pkg/utils"
"github.com/spf13/cobra"
)

// Objective: Allow the user to do this:
// runs cancel --name U123
// And then galasactl cancels the run by abandoning it.

type RunsCancelCommand struct {
values *RunsCancelCmdValues
cobraCommand *cobra.Command
}

type RunsCancelCmdValues struct {
runName string
}

// ------------------------------------------------------------------------------------------------
// Constructors methods
// ------------------------------------------------------------------------------------------------
func NewRunsCancelCommand(factory Factory, runsCommand GalasaCommand, rootCommand GalasaCommand) (GalasaCommand, error) {
cmd := new(RunsCancelCommand)
err := cmd.init(factory, runsCommand, rootCommand)
return cmd, err
}

// ------------------------------------------------------------------------------------------------
// Public methods
// ------------------------------------------------------------------------------------------------
func (cmd *RunsCancelCommand) Name() string {
return COMMAND_NAME_RUNS_CANCEL
}

func (cmd *RunsCancelCommand) CobraCommand() *cobra.Command {
return cmd.cobraCommand
}

func (cmd *RunsCancelCommand) Values() interface{} {
return cmd.values
}

// ------------------------------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------------------------------
func (cmd *RunsCancelCommand) init(factory Factory, runsCommand GalasaCommand, rootCommand GalasaCommand) error {
var err error
cmd.values = &RunsCancelCmdValues{}
cmd.cobraCommand, err = cmd.createRunsCancelCobraCmd(
factory,
runsCommand,
rootCommand.Values().(*RootCmdValues),
)
return err
}

func (cmd *RunsCancelCommand) createRunsCancelCobraCmd(factory Factory,
runsCommand GalasaCommand,
rootCmdValues *RootCmdValues,
) (*cobra.Command, error) {

var err error = nil
runsCmdValues := runsCommand.Values().(*RunsCmdValues)

runsCancelCmd := &cobra.Command{
Use: "cancel",
Short: "cancel an active run in the ecosystem",
Long: "Cancel an active test run in the ecosystem if it is stuck or looping.",
Args: cobra.NoArgs,
Aliases: []string{"runs cancel"},
RunE: func(cobraCmd *cobra.Command, args []string) error {
return cmd.executeCancel(factory, runsCmdValues, rootCmdValues)
},
}

runsCancelCmd.PersistentFlags().StringVar(&cmd.values.runName, "name", "", "the name of the test run to cancel")

runsCancelCmd.MarkPersistentFlagRequired("name")

runsCommand.CobraCommand().AddCommand(runsCancelCmd)

return runsCancelCmd, err
}

func (cmd *RunsCancelCommand) executeCancel(
factory Factory,
runsCmdValues *RunsCmdValues,
rootCmdValues *RootCmdValues,
) error {

var err error

// Operations on the file system will all be relative to the current folder.
fileSystem := factory.GetFileSystem()

err = utils.CaptureLog(fileSystem, rootCmdValues.logFileName)
if err == nil {
rootCmdValues.isCapturingLogs = true

log.Println("Galasa CLI - Cancel an active run by abandoning it.")

// Get the ability to query environment variables.
env := factory.GetEnvironment()

var galasaHome utils.GalasaHome
galasaHome, err = utils.NewGalasaHome(fileSystem, env, rootCmdValues.CmdParamGalasaHomePath)
if err == nil {

// Read the bootstrap properties
var urlService *api.RealUrlResolutionService = new(api.RealUrlResolutionService)
var bootstrapData *api.BootstrapData
bootstrapData, err = api.LoadBootstrap(galasaHome, fileSystem, env, runsCmdValues.bootstrap, urlService)
if err == nil {

var console = factory.GetStdOutConsole()
timeService := factory.GetTimeService()

apiServerUrl := bootstrapData.ApiServerURL
log.Printf("The API Server is at '%s'\n", apiServerUrl)

apiClient := auth.GetAuthenticatedAPIClient(apiServerUrl, fileSystem, galasaHome, timeService, env)

// Call to process command in unit-testable way.
err = runs.CancelRun(
cmd.values.runName,
timeService,
console,
apiServerUrl,
apiClient,
)
}
}
}

log.Printf("executeRunsCancel returning %v\n", err)
return err
}
Loading

0 comments on commit 053903f

Please sign in to comment.