Skip to content

Commit 4b23dd1

Browse files
authored
chore(test): fix postcleanup precheck (#2328)
- rename POST_CLEANUP to POST_CLEANUP_PRECHECK to control precheck execution - POST_CLEANUP now only controls cleanup behavior (validated by precheck) - remove duplicate validation from legacy package - add PostCleanupEnv constant in config package - update README with valid POST_CLEANUP values Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
1 parent db562e8 commit 4b23dd1

5 files changed

Lines changed: 19 additions & 32 deletions

File tree

test/e2e/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,18 @@ FOCUS="VirtualMachineConnectivity" POST_CLEANUP=no task run
101101

102102
### PostCleanUp option
103103

104-
POST_CLEANUP defines an environment variable used to explicitly request the deletion of created/used resources.
104+
`POST_CLEANUP` defines an environment variable used to explicitly request the deletion of created/used resources.
105+
106+
Valid values:
107+
- `yes` or "" (empty) - perform cleanup after tests (default)
108+
- `no` - skip cleanup after tests
105109

106110
You can also control cleanup behavior via the `isCleanupNeeded` field in `default_config.yaml`:
107111
```yaml
108112
isCleanupNeeded: true # default: cleanup enabled
109113
```
110114

111-
The POST_CLEANUP environment variable takes precedence over the YAML config.
115+
The `POST_CLEANUP` environment variable takes precedence over the YAML config.
112116

113117
For example, run a test in no-cleanup mode:
114118
```bash

test/e2e/internal/config/cleanup.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ package config
1818

1919
import (
2020
"fmt"
21-
"log"
2221
"os"
2322
)
2423

25-
// PostCleanUpEnv defines an environment variable used to explicitly request the deletion of created/used resources.
26-
const PostCleanUpEnv = "POST_CLEANUP"
27-
2824
// PrecreatedCVICleanupEnv defines an environment variable to explicitly enable deletion of precreated CVIs after the suite.
2925
//
3026
// By default, precreated CVIs are not deleted: they are shared across runs and may be reused.
3127
// Set PRECREATED_CVI_CLEANUP=yes to delete them after the suite; unset, empty, or "no" means no deletion.
3228
const PrecreatedCVICleanupEnv = "PRECREATED_CVI_CLEANUP"
3329

30+
// PostCleanupEnv defines an environment variable used to explicitly request the deletion of created/used resources.
31+
// Valid values: "yes", "no", or "" (default = yes).
32+
const PostCleanupEnv = "POST_CLEANUP"
33+
3434
func CheckPrecreatedCVICleanupOption() error {
3535
env := os.Getenv(PrecreatedCVICleanupEnv)
3636
switch env {
@@ -46,21 +46,3 @@ func CheckPrecreatedCVICleanupOption() error {
4646
func IsPrecreatedCVICleanupNeeded() bool {
4747
return os.Getenv(PrecreatedCVICleanupEnv) == "yes"
4848
}
49-
50-
func CheckWithPostCleanUpOption() error {
51-
env := os.Getenv(PostCleanUpEnv)
52-
switch env {
53-
case "yes", "no", "":
54-
return nil
55-
default:
56-
log.Printf(
57-
"Usual behaviour for tests is to make post cleanup (when %[1]s is not set or equal to 'yes'). Use %[1]s=no to skip post cleanup after tests.\n",
58-
PostCleanUpEnv,
59-
)
60-
return fmt.Errorf("invalid value for the %s env: %q", PostCleanUpEnv, env)
61-
}
62-
}
63-
64-
func IsCleanUpNeeded() bool {
65-
return os.Getenv(PostCleanUpEnv) != "no"
66-
}

test/e2e/internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ type HelperImages struct {
132132

133133
func (c *Config) setEnvs() error {
134134
// isCleanupNeeded: env var has priority over yaml config
135-
if e, ok := os.LookupEnv("POST_CLEANUP"); ok {
135+
if e, ok := os.LookupEnv(PostCleanupEnv); ok {
136136
c.IsCleanupNeeded = e != "no"
137137
}
138138
// ClusterTransport

test/e2e/internal/precheck/postcleanup.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ import (
2323

2424
. "github.com/onsi/ginkgo/v2"
2525

26+
"github.com/deckhouse/virtualization/test/e2e/internal/config"
2627
"github.com/deckhouse/virtualization/test/e2e/internal/framework"
2728
)
2829

2930
const (
30-
postCleanupPrecheckEnvName = "POST_CLEANUP"
31+
// POST_CLEANUP_PRECHECK controls whether the precheck runs.
32+
// Precheck validates that POST_CLEANUP has a valid value.
33+
// Set to "no" to disable precheck execution.
34+
postCleanupPrecheckEnvName = "POST_CLEANUP_PRECHECK"
3135
)
3236

3337
// postcleanupPrecheck implements Precheck interface for postcleanup option.
@@ -44,13 +48,13 @@ func (c *postcleanupPrecheck) Run(ctx context.Context, f *framework.Framework) e
4448
return nil
4549
}
4650

47-
// Validate POST_CLEANUP env var
48-
env := os.Getenv(postCleanupPrecheckEnvName)
51+
// Validate POST_CLEANUP env var (controls cleanup behavior)
52+
env := os.Getenv(config.PostCleanupEnv)
4953
switch env {
5054
case "yes", "no", "":
5155
// valid values
5256
default:
53-
return fmt.Errorf("invalid value for the %s env: %q (allowed: \"\", \"yes\", \"no\")", postCleanupPrecheckEnvName, env)
57+
return fmt.Errorf("invalid value for the %s env: %q (allowed: \"\", \"yes\", \"no\")", config.PostCleanupEnv, env)
5458
}
5559

5660
return nil

test/e2e/legacy/legacy.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ func Init() error {
6666
}
6767

6868
func configure() (err error) {
69-
if err = config.CheckWithPostCleanUpOption(); err != nil {
70-
return err
71-
}
7269
if err = config.CheckPrecreatedCVICleanupOption(); err != nil {
7370
return err
7471
}

0 commit comments

Comments
 (0)