Skip to content

Commit 38ae8b9

Browse files
committed
[QE] add cpu consume track
1 parent 425c446 commit 38ae8b9

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
crcCmd "github.com/crc-org/crc/v2/test/extended/crc/cmd"
2929
"github.com/crc-org/crc/v2/test/extended/util"
3030
"github.com/cucumber/godog"
31+
"github.com/shirou/gopsutil/v4/cpu"
3132
"github.com/spf13/pflag"
3233
)
3334

@@ -261,6 +262,12 @@ func InitializeScenario(s *godog.ScenarioContext) {
261262
os.Exit(1)
262263
}
263264
}
265+
266+
if tag.Name == "@story_health" {
267+
if err := getCPUdata("Before start"); err != nil {
268+
fmt.Printf("Failed to collect CPU data: %v\n", err)
269+
}
270+
}
264271
}
265272

266273
return ctx, nil
@@ -568,6 +575,8 @@ func InitializeScenario(s *godog.ScenarioContext) {
568575
EnsureApplicationIsAccessibleViaNodePort)
569576
s.Step(`^persistent volume of size "([^"]*)"GB exists$`,
570577
EnsureVMPartitionSizeCorrect)
578+
s.Step(`^get cpu data "([^"]*)"`,
579+
getCPUdata)
571580

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

@@ -1304,3 +1313,17 @@ func deserializeListBlockDeviceCommandOutputToExtractPVSize(lsblkOutput string)
13041313
}
13051314
return diskSize - (lvmSize + 1), nil
13061315
}
1316+
1317+
func getCPUdata(content string) error {
1318+
cpuData, err := cpu.Percent(0, false)
1319+
if err != nil {
1320+
return fmt.Errorf("failed to get CPU data: %v", err)
1321+
}
1322+
if len(cpuData) == 0 {
1323+
return fmt.Errorf("no CPU data available")
1324+
}
1325+
data := fmt.Sprintf("%s: %.2f%%\n", content, cpuData)
1326+
wd, _ := os.Getwd()
1327+
file := filepath.Join(wd, "../test-results/cpu-consume.txt")
1328+
return util.WriteToFile(data, file)
1329+
}

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)