Add a playbook that tests collectd 6 vs collectd5
[barometer.git] / docker / ansible / collectd6_test.yml
1 ---
2 # ansible-playbook -e PR=<PRID> -e new_plugin=<plugin> collectd6_test.yml
3
4 # As well as passing a PRID, a config command should be passable too since
5 # a lot of the plugins have been explicitly disabled in the build.
6 - hosts: localhost
7   become: true
8   tasks:
9     - name: Set names for containers to be used for testing
10       set_fact:
11         collectd5_container_name: "bar-collectd-latest"
12         collectd6_container_name: "bar-collectd-6{{ '-' + PR if PR is defined }}"
13         flask_container_name: "test-collectd-5-v-6"
14
15     - name: Remove existing containers
16       docker_container:
17         name: "{{ item }}"
18         state: absent
19         force_kill: yes
20       with_items:
21         - "{{ collectd5_container_name }}"
22         - "{{ collectd6_container_name }}"
23         - "{{ flask_container_name }}"
24
25     - name: Get a list of containers
26       command:
27         docker ps -a
28       register: output
29
30     - name: Confirm that existing test containers were removed
31       assert:
32         that:
33           - 'not "{{ collectd5_container_name }}" in output.stdout'
34           - 'not "{{ collectd6_container_name }}" in output.stdout'
35           - 'not "{{ flask_container_name }}" in output.stdout'
36
37     - name: Build collectd containers
38       include_role:
39         name: build_collectd
40       args:
41         apply:
42           tags:
43             - latest
44             - collectd-6
45             - flask_test
46       vars:
47         COLLECTD_PULL_REQUESTS: "{{ PR | default() }}"
48         COLLECTD_CONFIG_CMD_ARGS: "{{ '--enable-' + new_plugin if new_plugin is defined }}"
49
50     - name: "Set up config for write_http plugin"
51       set_fact:
52         collectd_plugins: "{{ collectd_plugins | default([]) | union(['write_http']) }}"
53         collectd_plugin_write_http_nodes:
54           flask:
55             url: http://localhost:5000
56             format: "Command"
57
58     - name: Generate collectd configs
59       include_role:
60         name: config_files
61
62     # Since I can't skip-tags here, I have to remove the plugins later
63     # TODO(efoley) Add a disable_plugins and enable_plugins list to
64     # roles/config_files, as an alternative to tags.
65     # This alternative is kinda needed anyway, so that it's easier to add extra
66     # plugins instead of using.
67     # ``{{ collectd_plugins | default([]) | union(['the_plugin_i_want_to_enable'])}}``
68     # Tags can stay, since they are convenient, and easier to pass to the
69     # command line than a list of plugins
70     - name: "Remove plugin configs"
71       file:
72         path: "/opt/collectd/etc/collectd.conf.d/{{ item }}.conf"
73         state: absent
74       with_items:
75         - snmp_agent
76         - intel_pmu
77
78     # TODO(efoley): The path here should be parameterised, to a degree, I don't
79     # want it to be repeated. And I shouldn't assume that this is always going
80     # to be the value (unless it is in vars/main instead of defaults/main)
81     - name: "Remove plugin configs (collectd 6)"
82       file:
83         path: "/opt/collectd/etc/collectd.conf.d/{{ item }}.conf"
84         state: absent
85       with_items:
86         - csv
87         - network
88         - rrdtool
89         - write_kafka
90         - write_prometheus
91         - logfile
92
93     - debug:
94         var: PR
95
96     - name: Run the collectd-6 container
97       include_role:
98         name: run_collectd
99       vars:
100         collectd_image_name: "opnfv/barometer-collectd-6{{ '-' + PR if PR is defined }}"
101         collectd_container_name: "{{ collectd6_container_name }}"
102
103     - name: Run the collectd-latest container
104       include_role:
105         name: run_collectd
106       vars:
107         collectd_image_name: opnfv/barometer-collectd-latest
108         collectd_container_name: "{{ collectd5_container_name }}"
109
110     - name: Run the flask test container
111       docker_container:
112         name: "{{ flask_container_name }}"
113         image: test-collectd-write_http
114         detach: yes
115         state: started
116           #network_mode: host
117         published_ports: 5000:5000
118
119     - name: Check output for flask app
120       become: true
121       shell: |
122         docker logs {{ flask_container_name }} {{ '| grep "' + new_plugin + '"' if new_plugin is defined  }} | tail -200
123       register: output
124
125     - debug:
126         var: output.stdout_lines
127
128     - name: Get a list of running containers
129       become: true
130       command:
131         docker ps
132       register: output
133
134     - name: Make sure that the expected containers are running
135       assert:
136         that:
137           - '"{{ collectd6_container_name }}" in output.stdout'
138           - '"{{ collectd5_container_name }}" in output.stdout'
139           - '"{{ flask_container_name }}" in output.stdout'
140
141 # Create a small report at the end for collectd versions...
142 # Update Apply PRs to check out a branch when it is a single PR
143 # OR update these playbooks to use the tag way of checking out a PR