garm/test/integration/e2e/pools.go
Ionut Balutoiu 318bc52b57 Refactor integration E2E tests
* General cleanup of the integration tests Golang code. Move the
  `e2e.go` codebase into its own package and separate files.
* Reduce the overall log spam from the integration tests output.
* Add final GitHub workflow step that stops GARM server, and does the
  GitHub cleanup of any orphaned resources.
* Add `TODO` to implement cleanup of the orphaned GitHub webhooks.
  This is useful, if the uninstall of the webhooks failed.
* Add `TODO` for extra missing checks on the GitHub webhooks
  install / uninstall logic.

Signed-off-by: Ionut Balutoiu <ibalutoiu@cloudbasesolutions.com>
2023-08-24 15:22:46 +03:00

54 lines
1.2 KiB
Go

package e2e
import (
"fmt"
"log"
"time"
"github.com/cloudbase/garm/params"
)
func waitPoolNoInstances(id string, timeout time.Duration) error {
var timeWaited time.Duration = 0
var pool *params.Pool
var err error
log.Printf("Wait until pool %s has no instances", id)
for timeWaited < timeout {
pool, err = getPool(cli, authToken, id)
if err != nil {
return err
}
log.Printf("Current pool instances: %d", len(pool.Instances))
if len(pool.Instances) == 0 {
return nil
}
time.Sleep(5 * time.Second)
timeWaited += 5 * time.Second
}
_ = dumpPoolInstancesDetails(pool.ID)
return fmt.Errorf("failed to wait for pool %s to have no instances", pool.ID)
}
func dumpPoolInstancesDetails(poolID string) error {
pool, err := getPool(cli, authToken, poolID)
if err != nil {
return err
}
if err := printJsonResponse(pool); err != nil {
return err
}
for _, instance := range pool.Instances {
instanceDetails, err := getInstance(cli, authToken, instance.Name)
if err != nil {
return err
}
log.Printf("Instance %s details:", instance.Name)
if err := printJsonResponse(instanceDetails); err != nil {
return err
}
}
return nil
}