File: test_run_once.py

package info (click to toggle)
ansible-core 2.19.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,944 kB
  • sloc: python: 181,408; cs: 4,929; sh: 4,661; xml: 34; makefile: 21
file content (36 lines) | stat: -rwxr-xr-x 843 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
from __future__ import annotations

import io
import os
import sys

import pexpect


env_vars = {
    'ANSIBLE_NOCOLOR': 'True',
    'ANSIBLE_RETRY_FILES_ENABLED': 'False',
}

env = os.environ.copy()
env.update(env_vars)

with io.BytesIO() as logfile:
    debugger_test_test = pexpect.spawn(
        'ansible-playbook',
        args=['test_run_once_playbook.yml'] + sys.argv[1:],
        timeout=10,
        env=env
    )

    debugger_test_test.logfile = logfile

    debugger_test_test.expect_exact('TASK: Task 1 (debug)> ')
    debugger_test_test.send('task.args["that"] = []\r')
    debugger_test_test.expect_exact('TASK: Task 1 (debug)> ')
    debugger_test_test.send('r\r')
    debugger_test_test.expect(pexpect.EOF)
    debugger_test_test.close()

    assert str(logfile.getvalue()).count('Task 2 executed') == 2