Skip to content

Commit

Permalink
Enable system tests for auditbeat (#5945)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ruflin authored and andrewkroh committed Mar 13, 2018
1 parent 4e9f33b commit 3bb5cb6
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 16 deletions.
17 changes: 17 additions & 0 deletions auditbeat/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.9.2
MAINTAINER Nicolas Ruflin <ruflin@elastic.co>

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
8 changes: 5 additions & 3 deletions auditbeat/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 24 additions & 0 deletions auditbeat/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions auditbeat/module/file_integrity/monitor/filetree_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !integration

package monitor

import (
Expand Down
2 changes: 2 additions & 0 deletions auditbeat/module/file_integrity/monitor/monitor_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !integration

package monitor

import (
Expand Down
8 changes: 4 additions & 4 deletions auditbeat/tests/system/auditbeat.py
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 11 additions & 9 deletions auditbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"])
Expand Down

0 comments on commit 3bb5cb6

Please sign in to comment.