Skip to content

Commit 217db59

Browse files
committed
[QE] add cpu consume track
1 parent 425c446 commit 217db59

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

test/e2e/features/story_openshift.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Feature: 4 Openshift stories
1212
@darwin @linux @windows @testdata @story_health @needs_namespace
1313
Scenario: Overall cluster health
1414
Given executing "oc new-project testproj" succeeds
15+
And get cpu data "After start"
1516
When executing "oc apply -f httpd-example.yaml" succeeds
1617
And executing "oc rollout status deployment httpd-example" succeeds
1718
Then stdout should contain "successfully rolled out"
@@ -23,10 +24,12 @@ Feature: 4 Openshift stories
2324
Then stdout should contain "httpd-example exposed"
2425
When executing "oc expose svc httpd-example" succeeds
2526
Then stdout should contain "httpd-example exposed"
27+
And get cpu data "After deployment"
2628
When with up to "20" retries with wait period of "5s" http response from "http://httpd-example-testproj.apps-crc.testing" has status code "200"
2729
Then executing "curl -s http://httpd-example-testproj.apps-crc.testing" succeeds
2830
And stdout should contain "Hello CRC!"
2931
When executing "crc stop" succeeds
32+
And get cpu data "After stop"
3033
And starting CRC with default bundle succeeds
3134
And checking that CRC is running
3235
And with up to "4" retries with wait period of "1m" http response from "http://httpd-example-testproj.apps-crc.testing" has status code "200"

test/e2e/testsuite/testsuite.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/crc-org/crc/v2/test/extended/util"
3030
"github.com/cucumber/godog"
3131
"github.com/spf13/pflag"
32+
"github.com/shirou/gopsutil/v4/cpu"
3233
)
3334

3435
var (
@@ -261,6 +262,10 @@ func InitializeScenario(s *godog.ScenarioContext) {
261262
os.Exit(1)
262263
}
263264
}
265+
266+
if tag.Name == "@story_health" {
267+
getCPUdata("Before start")
268+
}
264269
}
265270

266271
return ctx, nil
@@ -568,6 +573,8 @@ func InitializeScenario(s *godog.ScenarioContext) {
568573
EnsureApplicationIsAccessibleViaNodePort)
569574
s.Step(`^persistent volume of size "([^"]*)"GB exists$`,
570575
EnsureVMPartitionSizeCorrect)
576+
s.Step(`^get cpu data "([^"]*)"`,
577+
getCPUdata)
571578

572579
s.After(func(ctx context.Context, _ *godog.Scenario, err error) (context.Context, error) {
573580

@@ -1304,3 +1311,11 @@ func deserializeListBlockDeviceCommandOutputToExtractPVSize(lsblkOutput string)
13041311
}
13051312
return diskSize - (lvmSize + 1), nil
13061313
}
1314+
1315+
func getCPUdata(content string){
1316+
cpu_data, _ := cpu.Percent(0, false)
1317+
data := fmt.Sprintf("%s: %.2f%%\n", content, cpu_data)
1318+
wd, _ := os.Getwd()
1319+
file := filepath.Join(wd, "../test-results/cpu-consume.txt")
1320+
util.WriteToFile(data,file)
1321+
}

test/extended/util/fileops.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func CreateFile(fileName string) error {
9191
}
9292

9393
func WriteToFile(text string, fileName string) error {
94-
file, err := os.OpenFile(fileName, os.O_RDWR, 0644)
94+
file, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
9595
if err != nil {
9696
return err
9797
}

0 commit comments

Comments
 (0)