Skip to content

Commit 27a19c8

Browse files
Jakub Sliacanopenshift-merge-robot
authored andcommitted
e2e: Move cleanup and timesync to Before/After hooks
To make sure that timesync is re-enabled even if some Steps fail, move this action to After hook of the given Scenario. Do the same thing with `crc cleanup` to make sure cluster is destroyed after selected Scenarios.
1 parent a8efd07 commit 27a19c8

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

test/e2e/features/basic.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Feature: Basic test
2828
When executing crc status command fails
2929
Then stderr should contain "crc does not seem to be setup correctly, have you run 'crc setup'?"
3030

31-
@darwin @linux @windows
31+
@darwin @linux @windows @cleanup
3232
Scenario: CRC start usecase
3333
Given executing "crc setup --check-only" fails
3434
# Request start with monitoring stack
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
@cert_rotation @linux
22
Feature: Certificate rotation test
33

4-
User starts CRC more than one month after the release. They expect
4+
User starts CRC more than 13 months after the release. They expect
55
certificate rotation to happen successfully and to be able to deploy
66
an app and check its accessibility.
77

8-
Background: Setup CRC and rewind the clock forward
9-
When executing single crc setup command succeeds
10-
And executing "sudo timedatectl set-ntp off" succeeds
11-
Then executing "sudo date -s '13 month'" succeeds
12-
And with up to "10" retries with wait period of "1s" command "virsh --readonly -c qemu:///system capabilities" output matches "^<capabilities>"
13-
8+
@timesync @cleanup
149
Scenario: Start CRC "in the future" and clean up
10+
Given executing single crc setup command succeeds
1511
When starting CRC with default bundle along with stopped network time synchronization succeeds
1612
Then stdout should contain "Started the OpenShift cluster"
1713
And executing "eval $(crc oc-env)" succeeds
1814
When checking that CRC is running
1915
Then login to the oc cluster succeeds
2016
Then executing "oc whoami" succeeds
2117
And stdout should contain "kubeadmin"
22-
# Set clock back to the original time
23-
When executing "sudo date -s '-13 month'" succeeds
24-
And executing "sudo timedatectl set-ntp on" succeeds
25-
# CRC delete and cleanup
26-
When executing "crc delete -f" succeeds
27-
Then stdout should contain "Deleted the instance"
28-
When executing crc cleanup command succeeds
18+

test/e2e/features/proxy.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Feature: Behind proxy test
77
Background: Setup the proxy container using podman
88
* executing "podman run --name squid -d -p 3128:3128 quay.io/crcont/squid" succeeds
99

10+
@cleanup
1011
Scenario: Start CRC behind proxy
1112
Given executing single crc setup command succeeds
1213
And executing "crc config set http-proxy http://192.168.130.1:3128" succeeds

test/e2e/features/story_openshift.feature

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Feature: 4 Openshift stories
7575

7676
# Operator from marketplace
7777

78-
@darwin @linux @windows @testdata @story_marketplace
78+
@darwin @linux @windows @testdata @story_marketplace @cleanup
7979
Scenario: Install new operator
8080
When executing "oc apply -f redis-sub.yaml" succeeds
8181
Then with up to "20" retries with wait period of "30s" command "oc get csv" output matches ".*redis-operator\.(.*)Succeeded$"
@@ -86,8 +86,5 @@ Feature: 4 Openshift stories
8686
Then stdout should match "^pod(.*)deleted$"
8787
# after a while 1 pods should be up & running again
8888
And with up to "10" retries with wait period of "30s" command "oc get pods" output matches "redis-standalone-[a-z0-9]* .*Running.*"
89-
# cleanup
90-
When executing "crc delete -f" succeeds
91-
And executing crc cleanup command succeeds
9289

9390

test/e2e/testsuite/testsuite.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,64 @@ func InitializeScenario(s *godog.ScenarioContext) {
179179
fmt.Println("error logging:", err)
180180
}
181181

182-
// copy data/config files to test dir
183182
for _, tag := range sc.Tags {
183+
// copy data/config files to test dir
184184
if tag.Name == "@testdata" {
185185
err := util.CopyFilesToTestDir()
186186
if err != nil {
187187
os.Exit(1)
188188
}
189+
}
190+
191+
// move host's date 13 months forward and turn timesync off
192+
if tag.Name == "@timesync" {
193+
err := util.ExecuteCommand("sudo timedatectl set-ntp off")
194+
if err != nil {
195+
fmt.Println(err)
196+
os.Exit(1)
197+
}
198+
err = util.ExecuteCommand("sudo date -s '13 month'")
199+
if err != nil {
200+
fmt.Println(err)
201+
os.Exit(1)
202+
}
203+
err = util.ExecuteCommandWithRetry(10, "1s", "virsh --readonly -c qemu:///system capabilities", "contains", "<capabilities>")
204+
if err != nil {
205+
fmt.Println(err)
206+
os.Exit(1)
207+
}
208+
}
209+
}
210+
211+
return ctx, nil
212+
})
189213

214+
s.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
215+
216+
for _, tag := range sc.Tags {
217+
218+
// move host's date 13 months back and turn timesync on
219+
if tag.Name == "@timesync" {
220+
err := util.ExecuteCommand("sudo date -s '-13 month'")
221+
if err != nil {
222+
fmt.Println(err)
223+
os.Exit(1)
224+
}
225+
err = util.ExecuteCommand("sudo timedatectl set-ntp on")
226+
if err != nil {
227+
fmt.Println(err)
228+
os.Exit(1)
229+
}
230+
}
231+
232+
if tag.Name == "@cleanup" {
233+
err := util.ExecuteCommand("crc cleanup")
234+
if err != nil {
235+
fmt.Println(err)
236+
os.Exit(1)
237+
}
190238
}
239+
191240
}
192241

193242
return ctx, nil

0 commit comments

Comments
 (0)