From c5c05b515e8d2bf3c497335a4cad1ffdbf8a6b77 Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Fri, 2 Jun 2017 09:47:23 -0400 Subject: [PATCH] Cherry-pick various test fixes to 5.4 (#4404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Ignore permission errors in Metricbeat’s TestFileSystemList (#3562) The test can fail if some calls to statfs fail due to permission errors. For example: `stat("/var/lib/docker/aufs/mnt/50d0d5f599f0f19450e7649f73a0e23da1f172048e555df2b1cb78b3fefa355b", 0x7ffd2e5b8ed0) = -1 EACCES (Permission denied)` * Less strict error matching in Winlogbeat config_test Error string testing is brittle. The PR makes the test less stringent by not checking the full error message that includes the Golang stdlib error. * Miscellaneous test fixes - Fix and enable the python smoke test for heartbeat - Remove fmt.Printf from metricbeat ceph module - Fix Windows path issues in libbeat/paths tests - Fix ioutil.TempDir usage in Packetbeat tests (it broke windows) * Using single quotes around Windows paths The thrift test config used double quotes around Windows path separators and this was interpreted incorrectly in YAML parsing. * Rename TestBadCondition to TestConditions This test doesn’t actually test any bad conditions. Plus there is another test in the same directory with the name TestBadCondition. * Use logp.Beta or logp.Experimental in metricsets And in system tests, centralize the logic for asserting that there are no ERR or WARN in logs. Filter out errors about “The service process could not connect to the service controller” that occur when testing on Jenkins where Jenkins itself is running as a service. This confuses the Beat because it thinks that it is running as service, but it’s not. * Remove OS specific error message check from mockbeat The error message “no such file or directory” is an OS specific error message. There is a different error message on Windows. Simply checking for “error loading config file” should be sufficient. * Use shorter filename in Filebeat test for Windows The test was failing on Windows when `os.rename` failed with `[Error 3] The system cannot find the path specified`. The root cause of the failure was that the path was ~260 characters on Jenkins which is greater than the `MAX_PATH` value in Windows. This PR shortens the test log’s name to resolve the issue. The other changes to normalize the filepath are nice to have for Windows, but not strictly required. * Add filesystem name to test error message Errors that are logged by the system/filesystem test case don’t have enough context to debug them. This adds the filesystem that caused the error to the message. * Clean geoip.paths before using the path (#4306) Use filepath.Clean on the configured paths to fix any invalid OS path separators. Skip the geoip test with symlinks on Windows (`os.symlink` isn’t supported on Windows). * Improve winlogbeat checkpoint test (#4371) Check for errors and exit to stop panics from occurring when the test fails. Increase the sleep to 750ms to give the checkpoint more time to flush states to disk. * Fix Winlogbeat test by checking full hostname (#3942) The `computer_name` field in events is the full hostname, but the `win32api.GetComputerName` was returning the shortened netbios name. So the test fail on machines with longer hostnames. * Shorten test name to shorten path for windows (#4360) On our CI system we get the following error: ``` WindowsError: [Error 206] The filename or extension is too long: 'C:\\Users\\jenkins\\workspace\\elastic+beats+pull-request+multijob-windows\\beat\\filebeat\\label\\windows\\src\\github.com\\elastic\\beats\\filebeat\\build\\system-tests\\run\\test_prospector.Test.test_close_inactive_file_rotation_and_removal_while_new_file_created' ``` The problem is that this path is 267 characters long. According to https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx the MAX_PATH length is 260. In general it seems we could hit this limitation also in lots of other ways where we cannot just reduce the length of the test name. There seems to be some possibility to increase this limit: To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path". We should test if this could also solve the problem as it raises the limit to 32767. * Filter relative mounts in system filesystem metricset (#4370) Add filtering to system filesystem metricset to remove relative mountpoints like those from Linux network namespaces. --- CHANGELOG.asciidoc | 7 ++ filebeat/tests/system/test_prospector.py | 13 +-- heartbeat/Makefile | 2 +- .../tests/system/config/heartbeat.yml.j2 | 86 ++--------------- heartbeat/tests/system/heartbeat.py | 9 +- heartbeat/tests/system/test_base.py | 8 +- libbeat/common/geolite.go | 1 + libbeat/paths/paths_test.go | 94 +++++++++++-------- libbeat/processors/condition_test.go | 2 +- libbeat/tests/system/test_base.py | 1 - .../ceph/monitor_health/monitor_health.go | 7 -- .../monitor_health/monitor_health_test.go | 7 +- .../module/system/filesystem/filesystem.go | 2 +- metricbeat/module/system/filesystem/helper.go | 48 +++------- .../module/system/filesystem/helper_test.go | 6 +- metricbeat/tests/system/metricbeat.py | 12 +++ metricbeat/tests/system/test_apache.py | 5 +- metricbeat/tests/system/test_base.py | 5 +- metricbeat/tests/system/test_couchbase.py | 3 + metricbeat/tests/system/test_docker.py | 40 ++------ metricbeat/tests/system/test_haproxy.py | 10 +- metricbeat/tests/system/test_jolokia.py | 1 + metricbeat/tests/system/test_mongodb.py | 5 +- metricbeat/tests/system/test_mysql.py | 5 +- metricbeat/tests/system/test_phpfpm.py | 5 +- metricbeat/tests/system/test_prometheus.py | 5 +- metricbeat/tests/system/test_redis.py | 15 +-- metricbeat/tests/system/test_system.py | 55 +++-------- metricbeat/tests/system/test_zookeeper.py | 5 +- packetbeat/procs/procs_test.go | 6 +- .../tests/system/config/packetbeat.yml.j2 | 12 +-- packetbeat/tests/system/test_0011_geoip.py | 6 +- winlogbeat/checkpoint/checkpoint_test.go | 62 ++++++++---- winlogbeat/config/config_test.go | 6 +- winlogbeat/tests/system/winlogbeat.py | 4 +- 35 files changed, 221 insertions(+), 339 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 348adeb6b323..bd1cead2d03d 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -33,9 +33,16 @@ https://github.com/elastic/beats/compare/v5.4.1...master[Check the HEAD diff] *Heartbeat* *Metricbeat* +- Fix a debug statement that said a module wrapper had stopped when it hadn't. {pull}4264[4264] +- Use MemAvailable value from /proc/meminfo on Linux 3.14. {pull}4316[4316] +- Fix panic when events were dropped by filters. {issue}4327[4327] +- Add filtering to system filesystem metricset to remove relative mountpoints like those + from Linux network namespaces. {pull}4370[4370] *Packetbeat* +- Clean configured geoip.paths before attempting to open the database. {pull}4306[4306] + *Winlogbeat* diff --git a/filebeat/tests/system/test_prospector.py b/filebeat/tests/system/test_prospector.py index 1184673dad0c..0a7d59e6f9a5 100644 --- a/filebeat/tests/system/test_prospector.py +++ b/filebeat/tests/system/test_prospector.py @@ -485,22 +485,23 @@ def test_close_inactive_file_rotation_and_removal(self): filebeat.check_kill_and_wait() - def test_close_inactive_file_rotation_and_removal_while_new_file_created(self): + def test_close_inactive_file_rotation_and_removal2(self): """ Test that close_inactive still applies also if file was rotated, new file created, and rotated file removed. """ + log_path = os.path.abspath(os.path.join(self.working_dir, "log")) + os.mkdir(log_path) + testfile = os.path.join(log_path, "a.log") + renamed_file = os.path.join(log_path, "b.log") + self.render_config_template( - path=os.path.abspath(self.working_dir) + "/log/test.log", + path=testfile, ignore_older="1h", close_inactive="3s", scan_frequency="0.1s", ) - os.mkdir(self.working_dir + "/log/") - testfile = self.working_dir + "/log/test.log" - renamed_file = self.working_dir + "/log/test_renamed.log" - filebeat = self.start_beat() # wait for first "Start next scan" log message diff --git a/heartbeat/Makefile b/heartbeat/Makefile index c02f2a26e277..fef9ab776da3 100644 --- a/heartbeat/Makefile +++ b/heartbeat/Makefile @@ -1,6 +1,6 @@ BEAT_NAME=heartbeat BEAT_DESCRIPTION?=Ping remote services for availability and log results to Elasticsearch or send to Logstash. -SYSTEM_TESTS=false +SYSTEM_TESTS=true TEST_ENVIRONMENT=false # Path to the libbeat Makefile diff --git a/heartbeat/tests/system/config/heartbeat.yml.j2 b/heartbeat/tests/system/config/heartbeat.yml.j2 index 3af9f00364f6..1714337524d7 100644 --- a/heartbeat/tests/system/config/heartbeat.yml.j2 +++ b/heartbeat/tests/system/config/heartbeat.yml.j2 @@ -1,78 +1,8 @@ -################### Beat Configuration ######################### - - - -############################# Output ########################################## - -# Configure what outputs to use when sending the data collected by the beat. -# You can enable one or multiple outputs by setting enabled option to true. -output: - - ### File as output - file: - # Enabling file output - enabled: true - - # Path to the directory where to save the generated files. The option is mandatory. - path: {{ output_file_path|default(beat.working_dir + "/output") }} - - - # Name of the generated files. The default is `heartbeat` and it generates - # files: `heartbeat`, `heartbeat.1`, `heartbeat.2`, etc. - filename: "{{ output_file_filename|default("heartbeat") }}" - - # Maximum size in kilobytes of each file. When this size is reached, the files are - # rotated. The default value is 10 MB. - #rotate_every_kb: 10000 - - # Maximum number of files under path. When this number of files is reached, the - # oldest file is deleted and the rest are shifted from last to first. The default - # is 7 files. - #number_of_files: 7 - - - -############################# Beat ######################################### - -# The name of the shipper that publishes the network data. It can be used to group -# all the transactions sent by a single shipper in the web interface. -# If this options is not defined, the hostname is used. -#name: - -# The tags of the shipper are included in their own field with each -# transaction published. Tags make it easy to group servers by different -# logical properties. -#tags: ["service-X", "web-tier"] - - - -############################# Logging ######################################### - -#logging: - # Send all logging output to syslog. On Windows default is false, otherwise - # default is true. - #to_syslog: true - - # Write all logging output to files. Beats automatically rotate files if configurable - # limit is reached. - #to_files: false - - # Enable debug output for selected components. - #selectors: [] - - # Set log level - #level: error - - #files: - # The directory where the log files will written to. - #path: /var/log/heartbeat - - # The name of the files where the logs are written to. - #name: heartbeat - - # Configure log file size limit. If limit is reached, log file will be - # automatically rotated - #rotateeverybytes: 10485760 # = 10MB - - # Number of rotated log files to keep. Oldest files will be deleted first. - #keepfiles: 7 +heartbeat.monitors: +- type: icmp + hosts: ["localhost"] + schedule: '@every 10s' + +output.file: + path: {{ output_file_path|default(beat.working_dir + "/output") }} + filename: "{{ output_file_filename|default("heartbeat") }}" diff --git a/heartbeat/tests/system/heartbeat.py b/heartbeat/tests/system/heartbeat.py index 6d175f9f52f6..6467ac9164cf 100644 --- a/heartbeat/tests/system/heartbeat.py +++ b/heartbeat/tests/system/heartbeat.py @@ -1,12 +1,13 @@ +import os import sys -sys.path.append('../../vendor/github.com/elastic/beats/libbeat/tests/system') + +sys.path.append(os.path.join(os.path.dirname(__file__), '../../../libbeat/tests/system')) + from beat.beat import TestCase class BaseTest(TestCase): - @classmethod def setUpClass(self): self.beat_name = "heartbeat" - self.build_path = "../../build/system-tests/" - self.beat_path = "../../heartbeat.test" + super(BaseTest, self).setUpClass() diff --git a/heartbeat/tests/system/test_base.py b/heartbeat/tests/system/test_base.py index b71650b9b648..758fa108641c 100644 --- a/heartbeat/tests/system/test_base.py +++ b/heartbeat/tests/system/test_base.py @@ -1,10 +1,9 @@ -from heartbeat import BaseTest - import os +from heartbeat import BaseTest -class Test(BaseTest): +class Test(BaseTest): def test_base(self): """ Basic test with exiting Heartbeat normally @@ -15,5 +14,4 @@ def test_base(self): heartbeat_proc = self.start_beat() self.wait_until(lambda: self.log_contains("heartbeat is running")) - exit_code = heartbeat_proc.kill_and_wait() - assert exit_code == 0 + heartbeat_proc.check_kill_and_wait() diff --git a/libbeat/common/geolite.go b/libbeat/common/geolite.go index 38abad3c258e..914c2eb7fbad 100644 --- a/libbeat/common/geolite.go +++ b/libbeat/common/geolite.go @@ -30,6 +30,7 @@ func LoadGeoIPData(config Geoip) *libgeo.GeoIP { // look for the first existing path var geoipPath string for _, path := range geoipPaths { + path = filepath.Clean(path) fi, err := os.Lstat(path) if err != nil { logp.Err("GeoIP path could not be loaded: %s", path) diff --git a/libbeat/paths/paths_test.go b/libbeat/paths/paths_test.go index fbbc3b7a24ca..091a2fd11569 100644 --- a/libbeat/paths/paths_test.go +++ b/libbeat/paths/paths_test.go @@ -3,6 +3,7 @@ package paths import ( "os" "path/filepath" + "runtime" "testing" "github.com/stretchr/testify/assert" @@ -12,48 +13,51 @@ func TestHomePath(t *testing.T) { type io struct { Home string // cli flag home setting Path string // requested path - Result string // expected result + ResultHome string // expected home path ResultData string // expected data path } binDir, err := filepath.Abs(filepath.Dir(os.Args[0])) - assert.NoError(t, err) + if err != nil { + t.Fatal(err) + } tests := []io{ { Home: binDir, Path: "test", - Result: filepath.Join(binDir, "test"), + ResultHome: filepath.Join(binDir, "test"), ResultData: filepath.Join(binDir, "data", "test"), }, { - Home: "/tmp", + Home: rootDir("/tmp"), Path: "test", - Result: "/tmp/test", - ResultData: "/tmp/data/test", + ResultHome: rootDir("/tmp/test"), + ResultData: rootDir("/tmp/data/test"), }, { - Home: "/home/", - Path: "/abc/test", - Result: "/abc/test", - ResultData: "/abc/test", + Home: rootDir("/home"), + Path: rootDir("/abc/test"), + ResultHome: rootDir("/abc/test"), + ResultData: rootDir("/abc/test"), }, } for _, test := range tests { - t.Log("Executing test", test) cfg := Path{Home: test.Home} - assert.NoError(t, Paths.initPaths(&cfg)) + if err := Paths.initPaths(&cfg); err != nil { + t.Errorf("error on %+v: %v", test, err) + continue + } - assert.Equal(t, test.Result, Resolve(Home, test.Path)) + assert.Equal(t, test.ResultHome, Resolve(Home, test.Path), "failed on %+v", test) // config path same as home path - assert.Equal(t, test.Result, Resolve(Config, test.Path)) + assert.Equal(t, test.ResultHome, Resolve(Config, test.Path), "failed on %+v", test) // data path under home path - assert.Equal(t, test.ResultData, Resolve(Data, test.Path)) + assert.Equal(t, test.ResultData, Resolve(Data, test.Path), "failed on %+v", test) } - } func TestDataPath(t *testing.T) { @@ -65,7 +69,9 @@ func TestDataPath(t *testing.T) { } binDir, err := filepath.Abs(filepath.Dir(os.Args[0])) - assert.NoError(t, err) + if err != nil { + t.Fatal(err) + } tests := []io{ { @@ -75,25 +81,27 @@ func TestDataPath(t *testing.T) { ResultData: filepath.Join(binDir, "data", "test"), }, { - Home: "/tmp/", - Data: "/root/", + Home: rootDir("/tmp"), + Data: rootDir("/root"), Path: "test", - ResultData: "/root/test", + ResultData: rootDir("/root/test"), }, { - Home: "/tmp/", - Data: "/root/", - Path: "/var/data", - ResultData: "/var/data", + Home: rootDir("/tmp"), + Data: rootDir("root"), + Path: rootDir("/var/data"), + ResultData: rootDir("/var/data"), }, } for _, test := range tests { - t.Log("Executing test", test) cfg := Path{Home: test.Home, Data: test.Data} - assert.NoError(t, Paths.initPaths(&cfg)) + if err := Paths.initPaths(&cfg); err != nil { + t.Errorf("error on %+v: %v", test, err) + continue + } - assert.Equal(t, test.ResultData, Resolve(Data, test.Path)) + assert.Equal(t, test.ResultData, Resolve(Data, test.Path), "failed on %+v", test) } } @@ -107,7 +115,9 @@ func TestLogsPath(t *testing.T) { } binDir, err := filepath.Abs(filepath.Dir(os.Args[0])) - assert.NoError(t, err) + if err != nil { + t.Fatal(err) + } tests := []io{ { @@ -117,25 +127,35 @@ func TestLogsPath(t *testing.T) { ResultLogs: filepath.Join(binDir, "logs", "test"), }, { - Home: "/tmp/", - Logs: "/var/", + Home: rootDir("/tmp"), + Logs: rootDir("/var"), Path: "log", - ResultLogs: "/var/log", + ResultLogs: rootDir("/var/log"), }, { - Home: "/tmp/", - Logs: "/root/", - Path: "/var/log", - ResultLogs: "/var/log", + Home: rootDir("tmp"), + Logs: rootDir("root"), + Path: rootDir("/var/log"), + ResultLogs: rootDir("/var/log"), }, } for _, test := range tests { - t.Log("Executing test", test) cfg := Path{Home: test.Home, Logs: test.Logs} - assert.NoError(t, Paths.initPaths(&cfg)) + if err := Paths.initPaths(&cfg); err != nil { + t.Errorf("error on %+v: %v", test, err) + continue + } assert.Equal(t, test.ResultLogs, Resolve(Logs, test.Path)) } } + +// rootDir builds an OS specific absolute root directory. +func rootDir(path string) string { + if runtime.GOOS == "windows" { + return filepath.Join(`c:\`, path) + } + return filepath.Join("/", path) +} diff --git a/libbeat/processors/condition_test.go b/libbeat/processors/condition_test.go index a643c489a844..5e92d96d7c9b 100644 --- a/libbeat/processors/condition_test.go +++ b/libbeat/processors/condition_test.go @@ -20,7 +20,7 @@ func (c *countFilter) Run(e common.MapStr) (common.MapStr, error) { func (c *countFilter) String() string { return "count" } -func TestBadCondition(t *testing.T) { +func TestConditions(t *testing.T) { if testing.Verbose() { logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"*"}) diff --git a/libbeat/tests/system/test_base.py b/libbeat/tests/system/test_base.py index f6e908990163..cc52d6979395 100644 --- a/libbeat/tests/system/test_base.py +++ b/libbeat/tests/system/test_base.py @@ -26,7 +26,6 @@ def test_no_config(self): assert exit_code == 1 assert self.log_contains("error loading config file") is True - assert self.log_contains("no such file or directory") is True def test_invalid_config(self): """ diff --git a/metricbeat/module/ceph/monitor_health/monitor_health.go b/metricbeat/module/ceph/monitor_health/monitor_health.go index c00de44a3647..79956e6f5f82 100644 --- a/metricbeat/module/ceph/monitor_health/monitor_health.go +++ b/metricbeat/module/ceph/monitor_health/monitor_health.go @@ -1,8 +1,6 @@ package monitor_health import ( - "fmt" - "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/logp" "github.com/elastic/beats/metricbeat/helper" @@ -46,15 +44,10 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { } func (m *MetricSet) Fetch() ([]common.MapStr, error) { - content, err := m.HTTP.FetchContent() if err != nil { return nil, err } - fmt.Printf("%+v", string(content)) - fmt.Printf("%+v", eventsMapping(content)) - return eventsMapping(content), nil - } diff --git a/metricbeat/module/ceph/monitor_health/monitor_health_test.go b/metricbeat/module/ceph/monitor_health/monitor_health_test.go index bf78b3a60526..5260c8de4c7b 100644 --- a/metricbeat/module/ceph/monitor_health/monitor_health_test.go +++ b/metricbeat/module/ceph/monitor_health/monitor_health_test.go @@ -32,10 +32,10 @@ func TestFetchEventContents(t *testing.T) { f := mbtest.NewEventsFetcher(t, config) events, err := f.Fetch() - event := events[0] - if !assert.NoError(t, err) { - t.FailNow() + if err != nil { + t.Fatal(err) } + event := events[0] t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event.StringToPrint()) @@ -68,5 +68,4 @@ func TestFetchEventContents(t *testing.T) { total = store_stats["total"].(common.MapStr) assert.EqualValues(t, 8488943, total["bytes"]) - } diff --git a/metricbeat/module/system/filesystem/filesystem.go b/metricbeat/module/system/filesystem/filesystem.go index 4cf3cc5c1b16..24426db8bb12 100644 --- a/metricbeat/module/system/filesystem/filesystem.go +++ b/metricbeat/module/system/filesystem/filesystem.go @@ -11,7 +11,7 @@ import ( "github.com/pkg/errors" ) -var debugf = logp.MakeDebug("system-filesystem") +var debugf = logp.MakeDebug("system.filesystem") func init() { if err := mb.Registry.AddMetricSet("system", "filesystem", New, parse.EmptyHostParser); err != nil { diff --git a/metricbeat/module/system/filesystem/helper.go b/metricbeat/module/system/filesystem/helper.go index c1e93909954b..ca1ddaf4142b 100644 --- a/metricbeat/module/system/filesystem/helper.go +++ b/metricbeat/module/system/filesystem/helper.go @@ -3,10 +3,10 @@ package filesystem import ( + "path/filepath" "time" "github.com/elastic/beats/libbeat/common" - "github.com/elastic/beats/libbeat/logp" "github.com/elastic/beats/metricbeat/module/system" sigar "github.com/elastic/gosigar" ) @@ -20,13 +20,23 @@ type FileSystemStat struct { } func GetFileSystemList() ([]sigar.FileSystem, error) { - fss := sigar.FileSystemList{} - err := fss.Get() - if err != nil { + if err := fss.Get(); err != nil { return nil, err } + // Ignore relative mount points, which are present for example + // in /proc/mounts on Linux with network namespaces. + filtered := fss.List[:0] + for _, fs := range fss.List { + if filepath.IsAbs(fs.DirName) { + filtered = append(filtered, fs) + continue + } + debugf("Filtering filesystem with relative mountpoint %+v", fs) + } + fss.List = filtered + return fss.List, nil } @@ -54,26 +64,6 @@ func AddFileSystemUsedPercentage(f *FileSystemStat) { f.UsedPercent = system.Round(perc, .5, 4) } -func CollectFileSystemStats(fss []sigar.FileSystem) []common.MapStr { - events := make([]common.MapStr, 0, len(fss)) - for _, fs := range fss { - fsStat, err := GetFileSystemStat(fs) - if err != nil { - logp.Debug("system", "Skip filesystem %d: %v", fsStat, err) - continue - } - AddFileSystemUsedPercentage(fsStat) - - event := common.MapStr{ - "@timestamp": common.Time(time.Now()), - "type": "filesystem", - "fs": GetFilesystemEvent(fsStat), - } - events = append(events, event) - } - return events -} - func GetFilesystemEvent(fsStat *FileSystemStat) common.MapStr { return common.MapStr{ "device_name": fsStat.DevName, @@ -89,13 +79,3 @@ func GetFilesystemEvent(fsStat *FileSystemStat) common.MapStr { }, } } - -func GetFileSystemStats() ([]common.MapStr, error) { - fss, err := GetFileSystemList() - if err != nil { - logp.Warn("Getting filesystem list: %v", err) - return nil, err - } - - return CollectFileSystemStats(fss), nil -} diff --git a/metricbeat/module/system/filesystem/helper_test.go b/metricbeat/module/system/filesystem/helper_test.go index cffee33232f0..8c5e37228b26 100644 --- a/metricbeat/module/system/filesystem/helper_test.go +++ b/metricbeat/module/system/filesystem/helper_test.go @@ -28,7 +28,11 @@ func TestFileSystemList(t *testing.T) { } stat, err := GetFileSystemStat(fs) - if assert.NoError(t, err, "%v", err) { + if os.IsPermission(err) { + continue + } + + if assert.NoError(t, err, "filesystem=%v: %v", fs, err) { assert.True(t, (stat.Total >= 0)) assert.True(t, (stat.Free >= 0)) assert.True(t, (stat.Avail >= 0)) diff --git a/metricbeat/tests/system/metricbeat.py b/metricbeat/tests/system/metricbeat.py index b6c8d8af0382..0b4b3111eef6 100644 --- a/metricbeat/tests/system/metricbeat.py +++ b/metricbeat/tests/system/metricbeat.py @@ -51,3 +51,15 @@ def de_dot(self, existing_fields): fields[key] = self.de_dot(fields[key]) return fields + + def assert_no_logged_warnings(self): + """ + Assert that the log file contains no ERR or WARN lines. + """ + log = self.get_log() + log = log.replace("WARN EXPERIMENTAL", "") + log = log.replace("WARN BETA", "") + # Jenkins runs as a Windows service and when Jenkins executes theses + # tests the Beat is confused since it thinks it is running as a service. + log = log.replace("ERR Error: The service process could not connect to the service controller.", "") + self.assertNotRegexpMatches(log, "ERR|WARN") diff --git a/metricbeat/tests/system/test_apache.py b/metricbeat/tests/system/test_apache.py index 281182b9d119..77d2f47f7b86 100644 --- a/metricbeat/tests/system/test_apache.py +++ b/metricbeat/tests/system/test_apache.py @@ -44,10 +44,7 @@ def test_output(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) diff --git a/metricbeat/tests/system/test_base.py b/metricbeat/tests/system/test_base.py index 2f3d92ce909c..2c1db2f41efc 100644 --- a/metricbeat/tests/system/test_base.py +++ b/metricbeat/tests/system/test_base.py @@ -19,10 +19,7 @@ def test_start_stop(self): proc = self.start_beat() self.wait_until(lambda: self.log_contains("start running")) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() # Ensure all Beater stages are used. assert self.log_contains("Setup Beat: metricbeat") diff --git a/metricbeat/tests/system/test_couchbase.py b/metricbeat/tests/system/test_couchbase.py index d46bedb28231..8d3bb42ef585 100644 --- a/metricbeat/tests/system/test_couchbase.py +++ b/metricbeat/tests/system/test_couchbase.py @@ -18,6 +18,7 @@ def test_bucket(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=20) proc.check_kill_and_wait() + self.assert_no_logged_warnings() output = self.read_output_json() self.assertTrue(len(output) >= 1) @@ -40,6 +41,7 @@ def test_cluster(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=20) proc.check_kill_and_wait() + self.assert_no_logged_warnings() output = self.read_output_json() self.assertTrue(len(output) >= 1) @@ -62,6 +64,7 @@ def test_node(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=20) proc.check_kill_and_wait() + self.assert_no_logged_warnings() output = self.read_output_json() self.assertTrue(len(output) >= 1) diff --git a/metricbeat/tests/system/test_docker.py b/metricbeat/tests/system/test_docker.py index baab295dc28a..81f60402432b 100644 --- a/metricbeat/tests/system/test_docker.py +++ b/metricbeat/tests/system/test_docker.py @@ -21,10 +21,7 @@ def test_container_fields(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=20) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() evt = output[0] @@ -47,10 +44,7 @@ def test_cpu_fields(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=30) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() evt = output[0] @@ -77,10 +71,7 @@ def test_diskio_fields(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=30) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() evt = output[0] @@ -104,10 +95,7 @@ def test_info_fields(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=30) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() evt = output[0] @@ -129,10 +117,7 @@ def test_memory_fields(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=30) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() evt = output[0] @@ -155,10 +140,7 @@ def test_network_fields(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=30) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() evt = output[0] @@ -181,10 +163,7 @@ def test_health_fields(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=20) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() evt = output[0] @@ -207,10 +186,7 @@ def test_image_fields(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=20) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() evt = output[0] diff --git a/metricbeat/tests/system/test_haproxy.py b/metricbeat/tests/system/test_haproxy.py index 558a1f9a060f..7fa4b4207ec9 100644 --- a/metricbeat/tests/system/test_haproxy.py +++ b/metricbeat/tests/system/test_haproxy.py @@ -22,10 +22,7 @@ def test_info(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) @@ -49,10 +46,7 @@ def test_stat(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertGreater(len(output), 0) diff --git a/metricbeat/tests/system/test_jolokia.py b/metricbeat/tests/system/test_jolokia.py index 6c37b46f25ab..18a19d849014 100644 --- a/metricbeat/tests/system/test_jolokia.py +++ b/metricbeat/tests/system/test_jolokia.py @@ -31,6 +31,7 @@ def test_jmx(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0, max_timeout=20) proc.check_kill_and_wait() + self.assert_no_logged_warnings() output = self.read_output_json() self.assertTrue(len(output) >= 1) diff --git a/metricbeat/tests/system/test_mongodb.py b/metricbeat/tests/system/test_mongodb.py index 3cf1dd76c123..9497346cd6c8 100644 --- a/metricbeat/tests/system/test_mongodb.py +++ b/metricbeat/tests/system/test_mongodb.py @@ -23,10 +23,7 @@ def test_status(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) diff --git a/metricbeat/tests/system/test_mysql.py b/metricbeat/tests/system/test_mysql.py index b2631463cd67..e7271f43e143 100644 --- a/metricbeat/tests/system/test_mysql.py +++ b/metricbeat/tests/system/test_mysql.py @@ -26,10 +26,7 @@ def test_status(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) diff --git a/metricbeat/tests/system/test_phpfpm.py b/metricbeat/tests/system/test_phpfpm.py index 96c29ec5ebcc..475a8c3ec90e 100644 --- a/metricbeat/tests/system/test_phpfpm.py +++ b/metricbeat/tests/system/test_phpfpm.py @@ -21,10 +21,7 @@ def test_info(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) diff --git a/metricbeat/tests/system/test_prometheus.py b/metricbeat/tests/system/test_prometheus.py index f00407fba4c0..4e9eae4d263d 100644 --- a/metricbeat/tests/system/test_prometheus.py +++ b/metricbeat/tests/system/test_prometheus.py @@ -21,10 +21,7 @@ def test_stats(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log.replace("WARN BETA", ""), "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) diff --git a/metricbeat/tests/system/test_redis.py b/metricbeat/tests/system/test_redis.py index 21438252a01d..913c29f2b352 100644 --- a/metricbeat/tests/system/test_redis.py +++ b/metricbeat/tests/system/test_redis.py @@ -35,10 +35,7 @@ def test_info(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) @@ -71,10 +68,7 @@ def test_keysace(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) @@ -104,10 +98,7 @@ def test_filters(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) diff --git a/metricbeat/tests/system/test_system.py b/metricbeat/tests/system/test_system.py index 15248b550615..6b103f28a3da 100644 --- a/metricbeat/tests/system/test_system.py +++ b/metricbeat/tests/system/test_system.py @@ -57,10 +57,7 @@ def test_cpu(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) @@ -86,10 +83,7 @@ def test_cpu_ticks_option(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertGreater(len(output), 0) @@ -112,10 +106,7 @@ def test_core(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertGreater(len(output), 0) @@ -141,10 +132,7 @@ def test_core_with_cpu_ticks(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertGreater(len(output), 0) @@ -167,10 +155,7 @@ def test_load(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) @@ -193,10 +178,7 @@ def test_diskio(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertGreater(len(output), 0) @@ -219,10 +201,7 @@ def test_filesystem(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertGreater(len(output), 0) @@ -245,10 +224,7 @@ def test_fsstat(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) @@ -271,10 +247,7 @@ def test_memory(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) @@ -308,10 +281,7 @@ def test_network(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertGreater(len(output), 0) @@ -340,10 +310,7 @@ def test_process(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertGreater(len(output), 0) diff --git a/metricbeat/tests/system/test_zookeeper.py b/metricbeat/tests/system/test_zookeeper.py index 7975a1eda396..0dd3a4c191b9 100644 --- a/metricbeat/tests/system/test_zookeeper.py +++ b/metricbeat/tests/system/test_zookeeper.py @@ -29,10 +29,7 @@ def test_output(self): proc = self.start_beat() self.wait_until(lambda: self.output_lines() > 0) proc.check_kill_and_wait() - - # Ensure no errors or warnings exist in the log. - log = self.get_log() - self.assertNotRegexpMatches(log, "ERR|WARN") + self.assert_no_logged_warnings() output = self.read_output_json() self.assertEqual(len(output), 1) diff --git a/packetbeat/procs/procs_test.go b/packetbeat/procs/procs_test.go index 1cd2b775f85a..9deaa84d6aed 100644 --- a/packetbeat/procs/procs_test.go +++ b/packetbeat/procs/procs_test.go @@ -94,7 +94,7 @@ func TestFindPidsByCmdlineGrep(t *testing.T) { } // Create fake proc file system - pathPrefix, err := ioutil.TempDir("/tmp", "") + pathPrefix, err := ioutil.TempDir("", "find-pids") if err != nil { t.Error("TempDir failed:", err) return @@ -129,7 +129,7 @@ func TestRefreshPids(t *testing.T) { } // Create fake proc file system - pathPrefix, err := ioutil.TempDir("/tmp", "") + pathPrefix, err := ioutil.TempDir("", "refresh-pids") if err != nil { t.Error("TempDir failed:", err) return @@ -187,7 +187,7 @@ func TestFindSocketsOfPid(t *testing.T) { } // Create fake proc file system - pathPrefix, err := ioutil.TempDir("/tmp", "") + pathPrefix, err := ioutil.TempDir("", "find-sockets") if err != nil { t.Error("TempDir failed:", err) return diff --git a/packetbeat/tests/system/config/packetbeat.yml.j2 b/packetbeat/tests/system/config/packetbeat.yml.j2 index 916f4ee672fd..6c35c6e62382 100644 --- a/packetbeat/tests/system/config/packetbeat.yml.j2 +++ b/packetbeat/tests/system/config/packetbeat.yml.j2 @@ -111,12 +111,10 @@ packetbeat.protocols.thrift: ports: [{{ thrift_ports|default([9090])|join(", ") }}] transport_type: "{{ thrift_transport_type|default('socket') }}" {% if thrift_idl_files %} - idl_files: [ - {%- for file in thrift_idl_files -%} - "{{ beat.working_dir + '/' + file }}" - {%- if not loop.last %}, {% endif -%} - {%- endfor -%} - ] + idl_files: + {%- for file in thrift_idl_files %} + - '{{ beat.working_dir + '/' + file }}' + {%- endfor -%} {%- endif %} {% if thrift_send_request %} send_request: true{%- endif %} {% if thrift_send_response %} send_response: true{%- endif %} @@ -173,7 +171,7 @@ tags: [ geoip: paths: [ {%- for path in geoip_paths -%} - "{{ beat.working_dir + '/' + path }}" + '{{ beat.working_dir + '/' + path }}' {%- if not loop.last %}, {% endif -%} {%- endfor -%} ] diff --git a/packetbeat/tests/system/test_0011_geoip.py b/packetbeat/tests/system/test_0011_geoip.py index d1343102c95b..a990441263e4 100644 --- a/packetbeat/tests/system/test_0011_geoip.py +++ b/packetbeat/tests/system/test_0011_geoip.py @@ -1,5 +1,8 @@ -from packetbeat import BaseTest import os +import unittest +import sys + +from packetbeat import BaseTest """ Tests for reading the geoip files. @@ -43,6 +46,7 @@ def test_geoip_config_from_file(self): assert o["real_ip"] == "89.247.39.104" assert o["client_location"] == "52.528503, 13.410904" + @unittest.skipIf(sys.platform.startswith("win"), "requires unix for symlinks") def test_geoip_symlink(self): """ Should be able to follow symlinks to GeoIP libs. diff --git a/winlogbeat/checkpoint/checkpoint_test.go b/winlogbeat/checkpoint/checkpoint_test.go index 998d59122216..4ac9d2b3833b 100644 --- a/winlogbeat/checkpoint/checkpoint_test.go +++ b/winlogbeat/checkpoint/checkpoint_test.go @@ -27,7 +27,10 @@ func TestWriteMaxUpdates(t *testing.T) { }() file := filepath.Join(dir, "some", "new", "dir", ".winlogbeat.yml") - assert.False(t, fileExists(file), "%s should not exist", file) + if !assert.False(t, fileExists(file), "%s should not exist", file) { + return + } + cp, err := NewCheckpoint(file, 2, time.Hour) if err != nil { t.Fatal(err) @@ -39,18 +42,24 @@ func TestWriteMaxUpdates(t *testing.T) { time.Sleep(500 * time.Millisecond) _, found := cp.States()["App"] assert.True(t, found) + ps, err := cp.read() - assert.NoError(t, err) + if err != nil { + t.Fatal("read failed", err) + } assert.Len(t, ps.States, 0) // Send update - it is written to disk. cp.Persist("App", 2, time.Now()) - time.Sleep(500 * time.Millisecond) + time.Sleep(750 * time.Millisecond) ps, err = cp.read() - assert.NoError(t, err) - assert.Len(t, ps.States, 1) - assert.Equal(t, "App", ps.States[0].Name) - assert.Equal(t, uint64(2), ps.States[0].RecordNumber) + if err != nil { + t.Fatal("read failed", err) + } + if assert.Len(t, ps.States, 1, "state not written, could be a flush timing issue, retry") { + assert.Equal(t, "App", ps.States[0].Name) + assert.Equal(t, uint64(2), ps.States[0].RecordNumber) + } } // Test that a write is triggered when the maximum time period since the last @@ -68,7 +77,10 @@ func TestWriteTimedFlush(t *testing.T) { }() file := filepath.Join(dir, ".winlogbeat.yml") - assert.False(t, fileExists(file), "%s should not exist", file) + if !assert.False(t, fileExists(file), "%s should not exist", file) { + return + } + cp, err := NewCheckpoint(file, 100, time.Second) if err != nil { t.Fatal(err) @@ -80,10 +92,13 @@ func TestWriteTimedFlush(t *testing.T) { cp.Persist("App", 1, time.Now()) time.Sleep(1500 * time.Millisecond) ps, err := cp.read() - assert.NoError(t, err) - assert.Len(t, ps.States, 1) - assert.Equal(t, "App", ps.States[0].Name) - assert.Equal(t, uint64(1), ps.States[0].RecordNumber) + if err != nil { + t.Fatal("read failed", err) + } + if assert.Len(t, ps.States, 1) { + assert.Equal(t, "App", ps.States[0].Name) + assert.Equal(t, uint64(1), ps.States[0].RecordNumber) + } } // Test that createDir creates the directory with 0750 permissions. @@ -103,17 +118,24 @@ func TestCreateDir(t *testing.T) { file := filepath.Join(stateDir, ".winlogbeat.yml") cp := &Checkpoint{file: file} - assert.False(t, fileExists(stateDir), "%s should not exist", file) - assert.NoError(t, cp.createDir()) - assert.True(t, fileExists(stateDir), "%s should exist", file) + if !assert.False(t, fileExists(file), "%s should not exist", file) { + return + } + if err = cp.createDir(); err != nil { + t.Fatal("createDir", err) + } + if !assert.True(t, fileExists(stateDir), "%s should exist", file) { + return + } // mkdir on Windows does not pass the POSIX mode to the CreateDirectory // syscall so doesn't test the mode. if runtime.GOOS != "windows" { fileInfo, err := os.Stat(stateDir) - assert.NoError(t, err) - assert.Equal(t, true, fileInfo.IsDir()) - assert.Equal(t, os.FileMode(0750), fileInfo.Mode().Perm()) + if assert.NoError(t, err) { + assert.Equal(t, true, fileInfo.IsDir()) + assert.Equal(t, os.FileMode(0750), fileInfo.Mode().Perm()) + } } } @@ -134,7 +156,9 @@ func TestCreateDirAlreadyExists(t *testing.T) { file := filepath.Join(dir, ".winlogbeat.yml") cp := &Checkpoint{file: file} - assert.True(t, fileExists(dir), "%s should exist", file) + if !assert.True(t, fileExists(dir), "%s should exist", file) { + return + } assert.NoError(t, cp.createDir()) } diff --git a/winlogbeat/config/config_test.go b/winlogbeat/config/config_test.go index 961aab801b55..e5a8b88ba549 100644 --- a/winlogbeat/config/config_test.go +++ b/winlogbeat/config/config_test.go @@ -74,8 +74,7 @@ func TestConfigValidate(t *testing.T) { }, { MetricsConfig{BindAddress: "example.com"}, - "bind_address must be formatted as host:port but was " + - "'example.com' (missing port in address example.com)", + "bind_address must be formatted as host:port but was 'example.com'", }, { MetricsConfig{BindAddress: ":1"}, @@ -83,8 +82,7 @@ func TestConfigValidate(t *testing.T) { }, { MetricsConfig{BindAddress: "example.com:1024f"}, - "bind_address port value ('1024f') must be a number " + - "(strconv.ParseInt: parsing \"1024f\": invalid syntax)", + "bind_address port value ('1024f') must be a number", }, { MetricsConfig{BindAddress: "example.com:0"}, diff --git a/winlogbeat/tests/system/winlogbeat.py b/winlogbeat/tests/system/winlogbeat.py index e6f2a305357d..fe79757f624a 100644 --- a/winlogbeat/tests/system/winlogbeat.py +++ b/winlogbeat/tests/system/winlogbeat.py @@ -1,3 +1,5 @@ +import os +import platform import sys if sys.platform.startswith("win"): @@ -93,7 +95,7 @@ def read_events(self, config=None, expected_events=1): def assert_common_fields(self, evt, msg=None, eventID=10, sid=None, level="Information", extra=None): - assert evt["computer_name"].lower() == win32api.GetComputerName().lower() + assert evt["computer_name"].lower() == platform.node().lower() assert "record_number" in evt self.assertDictContainsSubset({ "event_id": eventID,