From c23411acc04b13d2576702530828f131cb3a22e1 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Mon, 22 Jan 2024 07:15:19 -0700 Subject: [PATCH] Ignore @tmp directories in test (#37677) --- dev-tools/mage/gotest.go | 12 ++++----- .../fields/module_fields_collector.go | 9 ++++--- pytest.ini | 1 + x-pack/metricbeat/Jenkinsfile.yml | 25 +++++++++---------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/dev-tools/mage/gotest.go b/dev-tools/mage/gotest.go index 5065882fdb8..bc49c3e643c 100644 --- a/dev-tools/mage/gotest.go +++ b/dev-tools/mage/gotest.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -169,15 +168,16 @@ func DefaultTestBinaryArgs() TestBinaryArgs { // Use MODULE=module to run only tests for `module`. func GoTestIntegrationForModule(ctx context.Context) error { module := EnvOr("MODULE", "") - modulesFileInfo, err := ioutil.ReadDir("./module") + modulesFileInfo, err := os.ReadDir("./module") if err != nil { return err } foundModule := false - failedModules := []string{} + failedModules := make([]string, 0, len(modulesFileInfo)) for _, fi := range modulesFileInfo { - if !fi.IsDir() { + // skip the ones that are not directories or with suffix @tmp, which are created by Jenkins build job + if !fi.IsDir() || strings.HasSuffix(fi.Name(), "@tmp") { continue } if module != "" && module != fi.Name() { @@ -289,7 +289,7 @@ func GoTest(ctx context.Context, params GoTestArgs) error { } if params.OutputFile != "" { - fileOutput, err := os.Create(createDir(params.OutputFile)) + fileOutput, err := os.Create(CreateDir(params.OutputFile)) if err != nil { return fmt.Errorf("failed to create go test output file: %w", err) } @@ -356,7 +356,7 @@ func makeCommand(ctx context.Context, env map[string]string, cmd string, args .. for k, v := range env { c.Env = append(c.Env, k+"="+v) } - c.Stdout = ioutil.Discard + c.Stdout = io.Discard if mg.Verbose() { c.Stdout = os.Stdout } diff --git a/libbeat/generator/fields/module_fields_collector.go b/libbeat/generator/fields/module_fields_collector.go index 85f917cacf6..2bf7c7190d4 100644 --- a/libbeat/generator/fields/module_fields_collector.go +++ b/libbeat/generator/fields/module_fields_collector.go @@ -18,9 +18,9 @@ package fields import ( - "io/ioutil" "os" "path/filepath" + "strings" ) var indentByModule = map[string]int{ @@ -38,9 +38,10 @@ func GetModules(modulesDir string) ([]string, error) { return nil, err } - var names []string + names := make([]string, 0, len(moduleInfos)) for _, info := range moduleInfos { - if !info.IsDir() { + // skip the ones that are not directories or with suffix @tmp, which are created by Jenkins build job + if !info.IsDir() || strings.HasSuffix(info.Name(), "@tmp") { continue } names = append(names, info.Name()) @@ -80,7 +81,7 @@ func CollectFiles(module string, modulesPath string) ([]*YmlFile, error) { files = append(files, ymls...) modulesRoot := filepath.Base(modulesPath) - sets, err := ioutil.ReadDir(filepath.Join(modulesPath, module)) + sets, err := os.ReadDir(filepath.Join(modulesPath, module)) if err != nil { return nil, err } diff --git a/pytest.ini b/pytest.ini index 5112e773668..c8a34025f6f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -17,3 +17,4 @@ filterwarnings = ignore:distutils Version classes are deprecated. Use packaging.version instead.:DeprecationWarning:.*compose.* ignore:distutils Version classes are deprecated. Use packaging.version instead.:DeprecationWarning:.*docker.* ignore:HTTPResponse.getheaders\(\) is deprecated and will be removed in urllib3 v2.1.0. Instead access HTTPResponse.headers directly.:DeprecationWarning + ignore:The 'warn' method is deprecated, use 'warning' instead:DeprecationWarning diff --git a/x-pack/metricbeat/Jenkinsfile.yml b/x-pack/metricbeat/Jenkinsfile.yml index f9fbd76a6ce..27574b62ada 100644 --- a/x-pack/metricbeat/Jenkinsfile.yml +++ b/x-pack/metricbeat/Jenkinsfile.yml @@ -24,19 +24,18 @@ stages: mage: "mage pythonIntegTest" withModule: true stage: mandatory - # Skip test until fixed https://github.com/elastic/beats/issues/37498 - #cloud: - # cloud: "mage build test" - # withModule: true ## run the ITs only if the changeset affects a specific module. - # dirs: ## run the cloud tests for the given modules. - # - "x-pack/metricbeat/module/aws" - # when: ## Override the top-level when. - # parameters: - # - "awsCloudTests" - # comments: - # - "/test x-pack/metricbeat for aws cloud" - # labels: - # - "aws" + cloud: + cloud: "mage build test" + withModule: true ## run the ITs only if the changeset affects a specific module. + dirs: ## run the cloud tests for the given modules. + - "x-pack/metricbeat/module/aws" + when: ## Override the top-level when. + parameters: + - "awsCloudTests" + comments: + - "/test x-pack/metricbeat for aws cloud" + labels: + - "aws" # stage: extended # Skip test until fixed https://github.com/elastic/beats/issues/36425 #cloudAWS: