summaryrefslogtreecommitdiff
path: root/playbooks/zuul-stream/functional.yaml
blob: 1d03e650bb9f01f646628931a5f67113ee3b6843 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
- hosts: controller
  tasks:
    - name: Set python path fact
      set_fact:
        # This value is used by Ansible to find the zuul.ansible code
        # that Zuul's ansible plugins consume. It must be updated when
        # the python version of the platform is changed.
        python_path: "/usr/local/lib/python3.10/dist-packages"

    - name: Run ansible that should succeed against testing console
      command: >
        /usr/lib/zuul/ansible/{{ zuul_ansible_version }}/bin/ansible-playbook
        -e "new_console=true"
        src/opendev.org/zuul/zuul/playbooks/zuul-stream/fixtures/test-stream.yaml
      environment:
        # Setup by test-stream.yaml so we start a new zuul_console
        # from this checkout.
        ZUUL_CONSOLE_PORT: 19887
        ZUUL_JOB_LOG_CONFIG: "{{ ansible_user_dir}}/logging.json"
        ZUUL_JOBDIR: "{{ ansible_user_dir}}"
        PYTHONPATH: "{{ python_path }}"
      register: _success_output

    - name: Save raw output to file
      copy:
        content: '{{ _success_output.stdout }}'
        dest: 'console-job-output-success-19887.txt'

    - name: Save output
      shell: |
          mv job-output.txt job-output-success-19887.txt
          mv job-output.json job-output-success-19887.json

    - name: Check protocol version
      assert:
        that:
          - "'[node1] Reports streaming version: 1' in _success_output.stdout"

    # Streamer puts out a line like
    #  [node1] Starting to log 916b2084-4bbb-80e5-248e-000000000016-1-node1 for task TASK: Print binary data
    # One of the tasks in job-output shows find: results;
    # the console file for this task should not be there.
    - name: Validate temporary files removed
      shell: |
        for f in $(grep 'Starting to log' console-job-output-success-19887.txt | awk '{print $5}'); do
          echo "Checking ${f}"
          if grep -q '"path": "/tmp/console-'${f}'.log"' job-output-success-19887.txt; then
            echo "*** /tmp/${f}.log still exists"
            exit 1
          fi
        done

    # NOTE(ianw) 2022-07 : we deliberatly have this second step to run
    # against the console setup by the infrastructure executor in the
    # job pre playbooks as a backwards compatability sanity check.
    - name: Run ansible that should succeed against extant console
      command: >
        /usr/lib/zuul/ansible/{{ zuul_ansible_version }}/bin/ansible-playbook
        -e "new_console=false"
        src/opendev.org/zuul/zuul/playbooks/zuul-stream/fixtures/test-stream.yaml
      environment:
        ZUUL_JOB_LOG_CONFIG: "{{ ansible_user_dir}}/logging.json"
        ZUUL_JOBDIR: "{{ ansible_user_dir}}"
        PYTHONPATH: "{{ python_path }}"
      register: _success_output

    - name: Save raw output to file
      copy:
        content: '{{ _success_output.stdout }}'
        dest: 'console-job-output-success-19885.txt'

    - name: Save output
      shell: |
          mv job-output.txt job-output-success-19885.txt
          mv job-output.json job-output-success-19885.json

    - name: Validate text outputs
      include_tasks: validate.yaml
      loop:
        - { node: 'node1', filename: 'job-output-success-19887.txt' }
        - { node: 'node2', filename: 'job-output-success-19887.txt' }
        - { node: 'node1', filename: 'job-output-success-19885.txt' }
        - { node: 'node2', filename: 'job-output-success-19885.txt' }

    # This shows that zuul_console_disabled has activated and set the
    # UUID to "skip"
    - name: Validate json output
      shell: |
        egrep 'zuul_log_id": "skip"' job-output-success-19885.json
        egrep 'zuul_log_id": "skip"' job-output-success-19887.json

    # failure case

    - name: Run ansible playbook that should fail
      command: >
        /usr/lib/zuul/ansible/{{ zuul_ansible_version }}/bin/ansible-playbook
        src/opendev.org/zuul/zuul/playbooks/zuul-stream/fixtures/test-stream-failure.yaml
      register: failed_results
      failed_when: "failed_results.rc != 2"
      environment:
        ZUUL_CONSOLE_PORT: 19887
        ZUUL_JOB_LOG_CONFIG: "{{ ansible_user_dir}}/logging.json"
        ZUUL_JOBDIR: "{{ ansible_user_dir}}"
        PYTHONPATH: "{{ python_path }}"

    - name: Save output
      shell: |
          mv job-output.txt job-output-failure.txt
          mv job-output.json job-output-failure.json

    - name: Validate output - failure shell task with exception
      shell: |
        egrep "^.+\| node1 \| Exception: Test module failure exception fail-task" job-output-failure.txt
        egrep "^.+\| node2 \| Exception: Test module failure exception fail-task" job-output-failure.txt

    - name: Validate output - failure item loop with exception
      shell: |
        egrep "^.+\| node1 \| Exception: Test module failure exception fail-loop" job-output-failure.txt
        egrep "^.+\| node2 \| Exception: Test module failure exception fail-loop" job-output-failure.txt