From 3bb5cb60a4366665892cdd43c12c1061a4a9eba4 Mon Sep 17 00:00:00 2001 From: Nicolas Ruflin Date: Tue, 13 Mar 2018 13:06:14 +0100 Subject: [PATCH] Enable system tests for auditbeat (#5945) * Enable system tests for auditbeat * There were system tests and system integration tests for auditbeat but so far they were not run. * Integration tests enabled * Module config changed to module that works on more systems. Limitation for linux removed. Change noxpack path readd es_beats path remove kibana snapshot file one more check for xpack0 to see if timeout becomes less of a problem readd go packages unify metricbeat / auditbeat to find problem update travis, rename beat-path as double used remove kibana because not needed modify build flag to run as unit test add file tree test to unit tests add ? for test env * go to version 2 * switch to 2.1 --- auditbeat/Dockerfile | 17 +++++++++++++ auditbeat/Makefile | 8 ++++--- auditbeat/docker-compose.yml | 24 +++++++++++++++++++ .../file_integrity/monitor/filetree_test.go | 2 ++ .../file_integrity/monitor/monitor_test.go | 2 ++ auditbeat/tests/system/auditbeat.py | 8 +++---- auditbeat/tests/system/test_base.py | 20 +++++++++------- 7 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 auditbeat/Dockerfile create mode 100644 auditbeat/docker-compose.yml diff --git a/auditbeat/Dockerfile b/auditbeat/Dockerfile new file mode 100644 index 00000000000..208c9e660a6 --- /dev/null +++ b/auditbeat/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.9.2 +MAINTAINER Nicolas Ruflin + +RUN set -x && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + netcat python-pip virtualenv && \ + apt-get clean + +RUN pip install --upgrade setuptools + +# Setup work environment +ENV AUDITBEAT_PATH /go/src/github.com/elastic/beats/auditbeat + +RUN mkdir -p $AUDITBEAT_PATH/build/coverage +WORKDIR $AUDITBEAT_PATH +HEALTHCHECK CMD exit 0 diff --git a/auditbeat/Makefile b/auditbeat/Makefile index f4e8221888d..d1782161107 100644 --- a/auditbeat/Makefile +++ b/auditbeat/Makefile @@ -1,13 +1,15 @@ BEAT_NAME=auditbeat BEAT_TITLE=Auditbeat BEAT_DESCRIPTION=Audit the activities of users and processes on your system. -SYSTEM_TESTS=false -TEST_ENVIRONMENT=false +SYSTEM_TESTS=true +TEST_ENVIRONMENT?=true GOX_OS?=linux windows ## @Building List of all OS to be supported by "make crosscompile". DEV_OS?=linux +TESTING_ENVIRONMENT?=snapshot-noxpack +ES_BEATS?=.. # Path to the libbeat Makefile --include ../libbeat/scripts/Makefile +include ${ES_BEATS}/libbeat/scripts/Makefile # This is called by the beats packer before building starts .PHONY: before-build diff --git a/auditbeat/docker-compose.yml b/auditbeat/docker-compose.yml new file mode 100644 index 00000000000..6ba1a7cc703 --- /dev/null +++ b/auditbeat/docker-compose.yml @@ -0,0 +1,24 @@ +version: '2.1' +services: + beat: + build: ${PWD}/. + depends_on: + - proxy_dep + env_file: + - ${PWD}/build/test.env + working_dir: /go/src/github.com/elastic/beats/auditbeat + volumes: + - ${PWD}/..:/go/src/github.com/elastic/beats/ + command: make + + # This is a proxy used to block beats until all services are healthy. + # See: https://github.com/docker/compose/issues/4369 + proxy_dep: + image: busybox + depends_on: + elasticsearch: { condition: service_healthy } + + elasticsearch: + extends: + file: ../testing/environments/${TESTING_ENVIRONMENT}.yml + service: elasticsearch diff --git a/auditbeat/module/file_integrity/monitor/filetree_test.go b/auditbeat/module/file_integrity/monitor/filetree_test.go index 710c4bc0c51..5f50157882d 100644 --- a/auditbeat/module/file_integrity/monitor/filetree_test.go +++ b/auditbeat/module/file_integrity/monitor/filetree_test.go @@ -1,3 +1,5 @@ +// +build !integration + package monitor import ( diff --git a/auditbeat/module/file_integrity/monitor/monitor_test.go b/auditbeat/module/file_integrity/monitor/monitor_test.go index 283c6ac4de2..9dd15961115 100644 --- a/auditbeat/module/file_integrity/monitor/monitor_test.go +++ b/auditbeat/module/file_integrity/monitor/monitor_test.go @@ -1,3 +1,5 @@ +// +build !integration + package monitor import ( diff --git a/auditbeat/tests/system/auditbeat.py b/auditbeat/tests/system/auditbeat.py index de1af6573c5..8af6e0b0fde 100644 --- a/auditbeat/tests/system/auditbeat.py +++ b/auditbeat/tests/system/auditbeat.py @@ -1,14 +1,14 @@ import os import sys -sys.path.append('../../../libbeat/tests/system') -from beat.beat import TestCase +sys.path.append('../../../metricbeat/tests/system') +from metricbeat import BaseTest as MetricbeatTest -class BaseTest(TestCase): +class BaseTest(MetricbeatTest): @classmethod def setUpClass(self): self.beat_name = "auditbeat" self.beat_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "../../")) - super(BaseTest, self).setUpClass() + super(MetricbeatTest, self).setUpClass() diff --git a/auditbeat/tests/system/test_base.py b/auditbeat/tests/system/test_base.py index 8e622bbc00f..ef19427e449 100644 --- a/auditbeat/tests/system/test_base.py +++ b/auditbeat/tests/system/test_base.py @@ -7,15 +7,18 @@ class Test(BaseTest): - @unittest.skipUnless(re.match("(?i)linux", sys.platform), "os") def test_start_stop(self): """ Auditbeat starts and stops without error. """ - self.render_config_template(modules=[{ - "name": "audit", - "metricsets": ["kernel"], - }]) + self.render_config_template( + modules=[{ + "name": "file_integrity", + "extras": { + "paths": ["file.example"], + } + }], + ) proc = self.start_beat() self.wait_until(lambda: self.log_contains("start running")) proc.check_kill_and_wait() @@ -35,11 +38,10 @@ def test_template(self): self.render_config_template( modules=[{ - "name": "audit", - "metricsets": ["file"], + "name": "file_integrity", "extras": { - "file.paths": ["file.example"], - }, + "paths": ["file.example"], + } }], elasticsearch={"host": self.get_elasticsearch_url()}) exit_code = self.run_beat(extra_args=["setup", "--template"])