Skip to content

e2e tests example #36

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
/libvirt_exporter
libvirt-exporter
.venv
47 changes: 47 additions & 0 deletions ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
END 2 END tests
---------------

Tested on:
- macOS: 12.3.1
- Vagrant: 2.2.19
- VMware Fusion: 12.2.3

Installation
============

Prerequisites (Instructions for macOS):
- VMware Fusion (personal license): https://customerconnect.vmware.com/web/vmware/evalcenter?p=fusion-player-personal
- Vagrant: https://www.vagrantup.com/downloads
- VMware Fusion provider for vagrant: https://www.vagrantup.com/docs/providers/vmware/installation
- Vagrant VMware Utility: https://www.vagrantup.com/docs/providers/vmware/vagrant-vmware-utility

Ansible, molecule installation:
- create venv: ```cd ansible; mkdir .venv; python3 -m venv .venv```
- update pip: ```source .venv/bin/activate; pip3 install -U pip```
- install pip packages: ```pip install -r requirements.txt```

Ansible roles, collection installation:
- enter venv: ```source .venv/bin/activate```
- install roles,collections: ```ansible-galaxy role install -r requirements.yml```
- install collections: ```ansible-galaxy collection install -r requirements.yml```

Usage
=====

All commands must be executed inside venv.

Create test environment: ```molecule converge```
Run tests: ```molecule verify```

Contribute
==========

All tests located in verify playbook inside molecule tree. You can use variable ```libvirt_exporter_metrics``` to querry specific metrics and their values. Example:

```yaml
- name: Assert that 'libvirt_up' in metrics
assert:
that: "libvirt_exporter_metrics | selectattr('name', 'equalto', 'libvirt_up') | first"
```

In this example, we use assert ansible module (https://docs.ansible.com/ansible/latest/collections/ansible/builtin/assert_module.html) to verify that there is a element in ```libvirt_exporter_metrics``` array with property ```name``` equals to ```libvirt_up```. ```libvirt_exporter_metrics``` array is a parsed json response from libvirt-exporter.
36 changes: 36 additions & 0 deletions ansible/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---

- name: Converge
hosts: all
become: True
vars:
image_name: "localhost/alekseizakharov/libvirt-exporter:latest"
sources_remote_path: "/srv/sources"
sources_local_path: "{{ playbook_dir }}/../../../"
tasks:
- name: Copy local sources to remote dir
ansible.posix.synchronize:
src: "{{ sources_local_path }}"
dest: "{{ sources_remote_path }}"
rsync_opts:
- "--no-motd"
- "--exclude=.venv"

- name: Build libvirt-exporter image
containers.podman.podman_image:
name: "{{ image_name }}"
path: "{{ sources_remote_path }}"
build:
format: docker
annotation:
app: libvirt-exporter
info: metrics exporter for libvirt

- name: Run libvirt-exporter container
containers.podman.podman_container:
name: libvirt_exporter
image: "{{ image_name }}"
state: started
recreate: true
publish: "9177:9177"
volume: "/var/run/libvirt:/var/run/libvirt"
205 changes: 205 additions & 0 deletions ansible/molecule/default/metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
---

metrics:
- name: go_gc_duration_seconds
type: SUMMARY
- name: go_goroutines
type: GAUGE
- name: go_info
type: GAUGE
- name: go_memstats_alloc_bytes
type: GAUGE
- name: go_memstats_alloc_bytes_total
type: COUNTER
- name: go_memstats_buck_hash_sys_bytes
type: GAUGE
- name: go_memstats_frees_total
type: COUNTER
- name: go_memstats_gc_cpu_fraction
type: GAUGE
- name: go_memstats_gc_sys_bytes
type: GAUGE
- name: go_memstats_heap_alloc_bytes
type: GAUGE
- name: go_memstats_heap_idle_bytes
type: GAUGE
- name: go_memstats_heap_inuse_bytes
type: GAUGE
- name: go_memstats_heap_objects
type: GAUGE
- name: go_memstats_heap_released_bytes
type: GAUGE
- name: go_memstats_heap_sys_bytes
type: GAUGE
- name: go_memstats_last_gc_time_seconds
type: GAUGE
- name: go_memstats_lookups_total
type: COUNTER
- name: go_memstats_mallocs_total
type: COUNTER
- name: go_memstats_mcache_inuse_bytes
type: GAUGE
- name: go_memstats_mcache_sys_bytes
type: GAUGE
- name: go_memstats_mspan_inuse_bytes
type: GAUGE
- name: go_memstats_mspan_sys_bytes
type: GAUGE
- name: go_memstats_next_gc_bytes
type: GAUGE
- name: go_memstats_other_sys_bytes
type: GAUGE
- name: go_memstats_stack_inuse_bytes
type: GAUGE
- name: go_memstats_stack_sys_bytes
type: GAUGE
- name: go_memstats_sys_bytes
type: GAUGE
- name: go_threads
type: GAUGE
- name: libvirt_domain_block_meta
type: GAUGE
- name: libvirt_domain_block_stats_allocation
type: GAUGE
- name: libvirt_domain_block_stats_capacity_bytes
type: GAUGE
- name: libvirt_domain_block_stats_flush_requests_total
type: COUNTER
- name: libvirt_domain_block_stats_flush_time_seconds_total
type: COUNTER
- name: libvirt_domain_block_stats_limit_burst_length_read_requests_seconds
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_length_total_requests_seconds
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_length_write_requests_seconds
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_read_bytes
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_read_bytes_length_seconds
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_read_requests
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_total_bytes
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_total_bytes_length_seconds
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_total_requests
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_write_bytes
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_write_bytes_length_seconds
type: GAUGE
- name: libvirt_domain_block_stats_limit_burst_write_requests
type: GAUGE
- name: libvirt_domain_block_stats_limit_read_bytes
type: GAUGE
- name: libvirt_domain_block_stats_limit_read_requests
type: GAUGE
- name: libvirt_domain_block_stats_limit_total_bytes
type: GAUGE
- name: libvirt_domain_block_stats_limit_total_requests
type: GAUGE
- name: libvirt_domain_block_stats_limit_write_bytes
type: GAUGE
- name: libvirt_domain_block_stats_limit_write_requests
type: GAUGE
- name: libvirt_domain_block_stats_physicalsize_bytes
type: GAUGE
- name: libvirt_domain_block_stats_read_bytes_total
type: COUNTER
- name: libvirt_domain_block_stats_read_requests_total
type: COUNTER
- name: libvirt_domain_block_stats_read_time_seconds_total
type: COUNTER
- name: libvirt_domain_block_stats_size_iops_bytes
type: GAUGE
- name: libvirt_domain_block_stats_write_bytes_total
type: COUNTER
- name: libvirt_domain_block_stats_write_requests_total
type: COUNTER
- name: libvirt_domain_block_stats_write_time_seconds_total
type: COUNTER
- name: libvirt_domain_info_cpu_time_seconds_total
type: COUNTER
- name: libvirt_domain_info_maximum_memory_bytes
type: GAUGE
- name: libvirt_domain_info_memory_usage_bytes
type: GAUGE
- name: libvirt_domain_info_meta
type: GAUGE
- name: libvirt_domain_info_virtual_cpus
type: GAUGE
- name: libvirt_domain_info_vstate
type: GAUGE
- name: libvirt_domain_interface_meta
type: GAUGE
- name: libvirt_domain_interface_stats_receive_bytes_total
type: COUNTER
- name: libvirt_domain_interface_stats_receive_drops_total
type: COUNTER
- name: libvirt_domain_interface_stats_receive_errors_total
type: COUNTER
- name: libvirt_domain_interface_stats_receive_packets_total
type: COUNTER
- name: libvirt_domain_interface_stats_transmit_bytes_total
type: COUNTER
- name: libvirt_domain_interface_stats_transmit_drops_total
type: COUNTER
- name: libvirt_domain_interface_stats_transmit_errors_total
type: COUNTER
- name: libvirt_domain_interface_stats_transmit_packets_total
type: COUNTER
- name: libvirt_domain_memory_stats_actual_balloon_bytes
type: GAUGE
- name: libvirt_domain_memory_stats_available_bytes
type: GAUGE
- name: libvirt_domain_memory_stats_disk_cache_bytes
type: GAUGE
- name: libvirt_domain_memory_stats_major_fault_total
type: COUNTER
- name: libvirt_domain_memory_stats_minor_fault_total
type: COUNTER
- name: libvirt_domain_memory_stats_rss_bytes
type: GAUGE
- name: libvirt_domain_memory_stats_unused_bytes
type: GAUGE
- name: libvirt_domain_memory_stats_usable_bytes
type: GAUGE
- name: libvirt_domain_memory_stats_used_percent
type: GAUGE
- name: libvirt_domain_vcpu_cpu
type: GAUGE
- name: libvirt_domain_vcpu_state
type: GAUGE
- name: libvirt_domain_vcpu_time_seconds_total
type: COUNTER
- name: libvirt_domain_vcpu_wait_seconds_total
type: COUNTER
- name: libvirt_pool_info_allocation_bytes
type: GAUGE
- name: libvirt_pool_info_available_bytes
type: GAUGE
- name: libvirt_pool_info_capacity_bytes
type: GAUGE
- name: libvirt_up
type: GAUGE
- name: libvirt_versions_info
type: GAUGE
- name: process_cpu_seconds_total
type: COUNTER
- name: process_max_fds
type: GAUGE
- name: process_open_fds
type: GAUGE
- name: process_resident_memory_bytes
type: GAUGE
- name: process_start_time_seconds
type: GAUGE
- name: process_virtual_memory_bytes
type: GAUGE
- name: process_virtual_memory_max_bytes
type: GAUGE
- name: promhttp_metric_handler_requests_in_flight
type: GAUGE
- name: promhttp_metric_handler_requests_total
type: COUNTER
15 changes: 15 additions & 0 deletions ansible/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

prerun: False
driver:
name: vagrant
platforms:
- name: ubuntu
box: generic/ubuntu2010
config_options:
ssh.keep_alive: True
ssh.remote_user: 'vagrant'
provisioner:
name: ansible
verifier:
name: ansible
17 changes: 17 additions & 0 deletions ansible/molecule/default/pool.xml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<pool type='dir'>
<name>vms</name>
<uuid>28954164-9810-47bc-88f7-ab3d847c38df</uuid>
<capacity unit='bytes'>66844176384</capacity>
<allocation unit='bytes'>6587465728</allocation>
<available unit='bytes'>60256710656</available>
<source>
</source>
<target>
<path>/var/lib/libvirt/images</path>
<permissions>
<mode>0711</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>
Loading