Skip to content

Commit

Permalink
Add packaging tests for Heartbeat (#46)
Browse files Browse the repository at this point in the history
* Add packaging tests for Heartbeat
* Smoke tests using a simple HTTP monitor.
  • Loading branch information
tsg authored and andrewkroh committed Jan 16, 2017
1 parent 245cb8d commit 0022c19
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 35 deletions.
21 changes: 21 additions & 0 deletions roles/test-heartbeat-file/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- name: Ensure empty output directory
file: path={{workdir}}/output state=absent

- name: Minimal configuration file
template: src={{beat_name}}.yml dest={{beat_cfg}}
when: ansible_os_family in ["Debian", "RedHat"]

- name: Start Heartbeat (linux)
service: name={{beat_name}} state=restarted
when: ansible_os_family in ["Debian", "RedHat"]

- name: Start Heartbeat (darwin)
shell: chdir={{installdir}} ./{{beat_name}} -E output.elasticsearch.enabled=false -E output.file.path={{workdir}}/output
when: ansible_os_family == "Darwin"
async: 45
poll: 0 # run in bg

- name: Wait for the output file to be created, should contain HTTP pinging
wait_for: >
path={{workdir}}/output/{{beat_name}} timeout=30
search_regex='"scheme":"http"'
9 changes: 9 additions & 0 deletions roles/test-heartbeat-file/templates/heartbeat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
heartbeat.monitors:
- type: http
schedule: '@every 1s'
urls: ["http://localhost:12345"]

output:
file:
path: {{workdir}}/output
filename: heartbeat
6 changes: 6 additions & 0 deletions roles/test-linux-binary/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@
search_regex='"load"'
when: beat_name == "metricbeat"

- name: Wait for the output file to be created, should contain HTTP pinging
wait_for: >
path={{workdir}}/output/heartbeat timeout=5
search_regex='"scheme":"http"'
when: beat_name == "heartbeat`"

- name: Check if version number is correct
shell: chdir={{installdir}} ./{{beat_name}} -version | grep {{ version[0:5] }}
10 changes: 0 additions & 10 deletions roles/test-linux-binary/templates/filebeat.yml

This file was deleted.

9 changes: 0 additions & 9 deletions roles/test-linux-binary/templates/metricbeat.yml

This file was deleted.

7 changes: 0 additions & 7 deletions roles/test-linux-binary/templates/packetbeat.yml

This file was deleted.

7 changes: 0 additions & 7 deletions roles/test-linux-binary/templates/topbeat.yml

This file was deleted.

3 changes: 3 additions & 0 deletions roles/test-win-heartbeat-file/files/echo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Param($line, $file)

$line >> $file
9 changes: 9 additions & 0 deletions roles/test-win-heartbeat-file/files/heartbeat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
heartbeat.monitors:
- type: http
schedule: '@every 1s'
urls: ["http://localhost:12345"]

output:
file:
path: "c:/users/vagrant/output"
filename: heartbeat
4 changes: 4 additions & 0 deletions roles/test-win-heartbeat-file/files/replace.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Param($file, $regexp, $replace)

$content = Get-Content -path $file | Out-String
$content -Replace $regexp, $replace | Out-File $file
8 changes: 8 additions & 0 deletions roles/test-win-heartbeat-file/files/run_script.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Param($script)

#$dir = Split-Path $script
#$filename = Split-Path -leaf $script

#Push-Location $dir
invoke-expression -Command $script
#Pop-Location
3 changes: 3 additions & 0 deletions roles/test-win-heartbeat-file/files/sleep.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Param($duration)

Start-Sleep -s $duration
35 changes: 35 additions & 0 deletions roles/test-win-heartbeat-file/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
- name: Ensure empty output directory
win_file: path={{workdir}}\\output state=absent

- name: Replace configuration file (windows)
win_copy: src={{beat_name}}.yml dest={{installdir}}

- name: Install service
script: run_script.ps1 -script {{installdir}}\\install-service-{{beat_name}}.ps1

- name: Delete logs directory
win_file: path=c:\logs state=absent

- name: Start heartbeat
win_service: name={{beat_name}} state=started

- name: Sleep a little
script: sleep.ps1 -duration 10

- name: Stat output file
win_stat: path={{workdir}}\output\{{beat_name}}
register: output_stat

- debug: var=output_stat

- name: Check output file
assert:
that:
- "output_stat.stat.exists"
- "output_stat.stat.size > 250"

- name: Stop heartbeat
win_service: name={{beat_name}} state=stopped

- name: Uninstall service
script: run_script.ps1 -script {{installdir}}\\uninstall-service-{{beat_name}}.ps1
4 changes: 2 additions & 2 deletions run-settings-staging.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
url_base: http://staging.elastic.co/5.0.0-rc1-9db751df/downloads/beats
version: 5.0.0-rc1
url_base: https://staging.elastic.co/5.2.0-9bd7a99c/downloads/beats
version: 5.2.0
49 changes: 49 additions & 0 deletions site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@
- test-uninstall
- {role: test-linux-binary, when: ansible_system == "Linux"}

- name: Packaging tests Heartbeat
hosts:
- debian
- centos
- darwin
sudo: yes
tags:
- heartbeat
vars:
- beat_name: heartbeat
roles:
- common
- test-install
- test-heartbeat-file
- test-uninstall
- {role: test-linux-binary, when: ansible_system == "Linux"}


# windows
- name: Packaging windows x86 tests for Packetbeat
hosts:
Expand Down Expand Up @@ -142,6 +160,37 @@
- test-win-filebeat-file
- test-uninstall

- name: Packaging windows x86 tests for Heartbeat
hosts:
- windows
tags:
- heartbeat
- windows
vars:
- beat_name: heartbeat
- win_arch: x86
roles:
- common
- test-install
- test-win-heartbeat-file
- test-uninstall

- name: Packaging windows x86_64 tests for Heartbeat
hosts:
- windows
tags:
- heartbeat
- windows
vars:
- beat_name: heartbeat
- win_arch: x86_64
roles:
- common
- test-install
- test-win-heartbeat-file
- test-uninstall


- name: Packaging windows x86 tests for Winlogbeat
hosts:
- windows
Expand Down

0 comments on commit 0022c19

Please sign in to comment.