Skip to content

Support galasactl runs delete --name U52 #1210

Description

@jasonrhughes

# Original Text from @jasonrhughes

Over time, local test runs build up and the local RAS directory content grows accordingly.
We could manually trim the directory contents (if this doesn't upset Galasa) but a more elegant solution might be to right click results (or group of results) in the Galasa Results view and delete them from there - which would also clear them from the RAS.

(I would personally not want this to be automatically time-based - i.e., delete test runs older than a certain age - but rather to be able to prune manually.)

I notice it's possible to do this from the Galasa Runs view but the very few runs contained there don't correspond to those in the Galasa Results view.

Story

As a user of galasa, I want to be able to delete test runs which have completed in the past, so that they don't take up space in my Galasa system.

Background

  • The user can query which test runs between dates already: galasactl runs get --age 6w:1w
  • Using the --format raw makes it easy to get the names of the runs out using a script.
  • We introduce the galasactl runs delete --name xxx command to allow individual runs to be removed.
  • Then the user has full control over what gets deleted. They can implement a regular check to delete old stuff, or be more selective.
  • The CLI must turn the run name into the run id ?
  • If the run is already deleted, the command passes.
  • If the run is deleted, no output is observed, only the 0 (OK) exit code.
  • Deleting the run also delete the re-runs
  • runs delete requires a bootstrap, and doesn't work locally.

The Rest API changes

DELETE /ras/runs/{id}

Does not take a body. Ignores it.

Status codes:

200 OK (same if the property was deleted, or it doesn't exist).
401 Unauthorised. Invalid JWT token, or you don't have permissions.
400 Bad request : The run is currently active. Cancel if first.

Assumptions: We have done the story which always makes sure that Finished state is reached when a test run is cancelled. Story #1775

Once complete, we can try as script like this:

#! /usr/bin/env bash

# Where is this script executing from ?
BASEDIR=$(dirname "$0");pushd $BASEDIR 2>&1 >> /dev/null ;BASEDIR=$(pwd);popd 2>&1 >> /dev/null
# echo "Running from directory ${BASEDIR}"
export ORIGINAL_DIR=$(pwd)
cd "${BASEDIR}"

#-----------------------------------------------------------------------------------------                   
#
# Set Colors
#
#-----------------------------------------------------------------------------------------                   
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 76)
white=$(tput setaf 7)
tan=$(tput setaf 202)
blue=$(tput setaf 25)

#-----------------------------------------------------------------------------------------                   
#
# Headers and Logging
#
#-----------------------------------------------------------------------------------------                   
underline() { printf "${underline}${bold}%s${reset}\n" "$@" ;}
h1() { printf "\n${underline}${bold}${blue}%s${reset}\n" "$@" ;}
h2() { printf "\n${underline}${bold}${white}%s${reset}\n" "$@" ;}
debug() { printf "${white}%s${reset}\n" "$@" ;}
info() { printf "${white}➜ %s${reset}\n" "$@" ;}
success() { printf "${green}✔ %s${reset}\n" "$@" ;}
error() { printf "${red}✖ %s${reset}\n" "$@" ;}
warn() { printf "${tan}➜ %s${reset}\n" "$@" ;}
bold() { printf "${bold}%s${reset}\n" "$@" ;}
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@" ;}

h2 "Querying the RAS for old records we don't want any longer."
mkdir $BASEDIR/temp
cd $BASEDIR/temp >> /dev/null

set -o pipefail

galasactl runs get --age 120d:90d --format raw | cut -f1 -d'|' | sort | uniq > files-to-delete.txt
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to query the test runs to delete." ; exit 1 ; fi
success "Queried the run records we want to delete."

h2 "Deleting the run records we don't care about."
while IFS="" read -r line || [ -n "$testRunName" ]
do
    info "Deleting test run $testRunName"
    galasactl runs delete --name $testRunName
    rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to delete the test runs $testRunName" ; exit 1 ; fi
    success "Deleted test run $testRunName"
done < files-to-delete.txt

cd - >> /dev/null 

Tasks

  • Code up the API servlet + unit test
    • handles deletion of re-runs also
    • add a delete method into the RAS extensions API discard already exists on the IRunResult interface
      • and the default implementation (can be a no-op)
      • and the couchdb implementation
    • openapi.yaml updates
  • Code up the CLI to call the new servlet
    • Converts the name to the id
    • insists on a bootstrap
    • insists on a run name (not a restart run name)
    • Calls the API endpoint
    • Handles the return code
    • Shows no output if things worked, or if the run wasn't found (already deleted).
  • Add test to the ecosystem scripts to delete a run and check it has gone.
  • Docs in the readme of the CLI
  • Docs in the galasa.dev site (administering the ecosystem section).

Metadata

Metadata

Labels

cliGalasa CLIenhancementNew feature or request

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions