8
8
import uuid
9
9
from jinja2 import Environment , BaseLoader
10
10
from lago import sdk
11
+ from lago .utils import run_command
11
12
12
13
13
14
@pytest .fixture (scope = 'module' )
14
15
def init_str (images ):
15
16
init_template = textwrap .dedent (
16
17
"""
17
18
domains:
18
- {% for vm_name, template in images.iteritems () %}
19
+ {% for vm_name, template in images.viewitems () %}
19
20
{{ vm_name }}:
20
21
memory: 1024
21
22
nics:
@@ -33,6 +34,7 @@ def init_str(images):
33
34
- /etc/resolv.conf
34
35
- /etc/sysconfig
35
36
- /etc/NetworkManager
37
+ groups: group{{ loop.index % 2 }}
36
38
{% endfor %}
37
39
38
40
nets:
@@ -205,3 +207,37 @@ def test_load_env_up(env, vms, tmp_workdir):
205
207
assert vm .state () == 'running'
206
208
for vm in loaded_env .get_vms ().values ():
207
209
assert vm .ssh_reachable (tries = 200 )
210
+
211
+
212
+ @pytest .mark .check_merged
213
+ def test_ansible_inventory (monkeypatch , env , test_results , vms ):
214
+
215
+ # ansible returns the results in a bulk to stdout. Ideally we would test
216
+ # forthe hostname of each machine, but that is broken on debian.
217
+ # Instead, we let it compute something and count the unique occurences.
218
+
219
+ cmd = 'echo __abcd$(( 24 + 12 ))efgh___'
220
+ expected = '__abcd36efgh__'
221
+ results = []
222
+
223
+ with env .ansible_inventory_temp_file (keys = ['groups' ]) as inv :
224
+ for group in ['group0' , 'group1' ]:
225
+ logfile = os .path .join (
226
+ test_results , 'ansible-{0}.log' .format (group )
227
+ )
228
+ monkeypatch .setenv ('ANSIBLE_LOG_PATH' , logfile )
229
+ monkeypatch .setenv ('ANSIBLE_HOST_KEY_CHECKING' , 'False' )
230
+ res = run_command (
231
+ [
232
+ 'ansible' , 'groups={0}' .format (group ), '-v' , '-u' , 'root' ,
233
+ '-i' , inv .name , '-m' , 'raw' , '-a' , cmd
234
+ ]
235
+ )
236
+
237
+ assert res .code == 0
238
+ assert res .out is not None
239
+ results .append (res )
240
+
241
+ occurences = sum ([result .out .count (expected ) for result in results ])
242
+
243
+ assert occurences == len (vms .keys ())
0 commit comments