Browse Source

Merge "Revert "validate-host: retry network tests and include unbound logs""

Zuul 5 months ago
parent
commit
879c37e62c

+ 33
- 1
roles/validate-host/library/zuul_debug_info.py View File

@@ -18,10 +18,15 @@
18 18
 import os
19 19
 import shlex
20 20
 import subprocess
21
+import traceback
21 22
 
22 23
 
23 24
 command_map = {
24 25
     'uname': 'uname -a',
26
+    'network_interfaces': 'ip address show',
27
+    'network_routing_v4': 'ip route show',
28
+    'network_routing_v6': 'ip -6 route show',
29
+    'network_neighbors': 'ip neighbor show',
25 30
 }
26 31
 
27 32
 
@@ -39,14 +44,16 @@ def main():
39 44
         argument_spec=dict(
40 45
             image_manifest=dict(required=False, type='str'),
41 46
             image_manifest_files=dict(required=False, type='list'),
47
+            traceroute_host=dict(required=False, type='str'),
42 48
         )
43 49
     )
44 50
 
45 51
     image_manifest = module.params['image_manifest']
52
+    traceroute_host = module.params['traceroute_host']
46 53
     image_manifest_files = module.params['image_manifest_files']
47 54
     if not image_manifest_files and image_manifest:
48 55
         image_manifest_files = [image_manifest]
49
-    ret = {'image_manifest_files': []}
56
+    ret = {'image_manifest_files': [], 'traceroute': None}
50 57
 
51 58
     for image_manifest in image_manifest_files:
52 59
         if image_manifest and os.path.exists(image_manifest):
@@ -56,6 +63,31 @@ def main():
56 63
                 'underline': len(image_manifest) * '-',
57 64
                 'content': open(image_manifest, 'r').read(),
58 65
             })
66
+    if traceroute_host:
67
+        passed = False
68
+        try:
69
+            ret['traceroute_v6'] = run_command(
70
+                'traceroute6 -n {host}'.format(host=traceroute_host))
71
+            passed = True
72
+        except (subprocess.CalledProcessError, OSError) as e:
73
+            ret['traceroute_v6_exception'] = traceback.format_exc(e)
74
+            ret['traceroute_v6_output'] = e.output
75
+            ret['traceroute_v6_return'] = e.returncode
76
+            pass
77
+        try:
78
+            ret['traceroute_v4'] = run_command(
79
+                'traceroute -n {host}'.format(host=traceroute_host))
80
+            passed = True
81
+        except (subprocess.CalledProcessError, OSError) as e:
82
+            ret['traceroute_v4_exception'] = traceback.format_exc(e)
83
+            ret['traceroute_v4_output'] = e.output
84
+            ret['traceroute_v4_return'] = e.returncode
85
+            pass
86
+        if not passed:
87
+            module.fail_json(
88
+                msg="No viable v4 or v6 route found to {traceroute_host}."
89
+                    " The build node is assumed to be invalid.".format(
90
+                        traceroute_host=traceroute_host), **ret)
59 91
 
60 92
     for key, command in command_map.items():
61 93
         try:

+ 0
- 118
roles/validate-host/library/zuul_network_validate.py View File

@@ -1,118 +0,0 @@
1
-#!/usr/bin/python
2
-
3
-# Copyright (c) 2018 Red Hat
4
-#
5
-# This module is free software: you can redistribute it and/or modify
6
-# it under the terms of the GNU General Public License as published by
7
-# the Free Software Foundation, either version 3 of the License, or
8
-# (at your option) any later version.
9
-#
10
-# This software is distributed in the hope that it will be useful,
11
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
-# GNU General Public License for more details.
14
-#
15
-# You should have received a copy of the GNU General Public License
16
-# along with this software.  If not, see <http://www.gnu.org/licenses/>.
17
-
18
-import os
19
-import shlex
20
-import subprocess
21
-import traceback
22
-
23
-
24
-command_map = {
25
-    'network_interfaces': 'ip address show',
26
-    'network_routing_v4': 'ip route show',
27
-    'network_routing_v6': 'ip -6 route show',
28
-    'network_neighbors': 'ip neighbor show',
29
-}
30
-
31
-
32
-def run_command(command):
33
-    env = os.environ.copy()
34
-    env['PATH'] = '{path}:/sbin:/usr/sbin'.format(path=env['PATH'])
35
-    return subprocess.check_output(
36
-        shlex.split(command),
37
-        stderr=subprocess.STDOUT,
38
-        env=env)
39
-
40
-
41
-def collect_unbound_logs():
42
-    '''Look for unbound logs
43
-
44
-    This looks for unbound logs in common places and returns the
45
-    contents.  Intended for the failure path to add more info if the
46
-    traceroutes have failed.
47
-    '''
48
-    ret = {}
49
-
50
-    # NOTE(ianw): keep this one first, the other exists but isn't
51
-    # populated on infra rpm images for ... reasons
52
-    if os.path.exists('/var/lib/unbound/unbound.log'):
53
-        unbound_log_file = '/var/lib/unbound/unbound.log'
54
-    elif os.path.exists('/var/log/unbound.log'):
55
-        unbound_log_file = '/var/log/unbound.log'
56
-    else:
57
-        return ret
58
-
59
-    with open(unbound_log_file) as f:
60
-        ret['unbound_log_file'] = unbound_log_file
61
-        # NOTE(ianw): At high verbosity this can be big ... but this
62
-        # is also intended to be used early which should limit it's
63
-        # size.  We could tail it ...
64
-        ret['unbound_log_file_content'] = f.read()
65
-
66
-    return ret
67
-
68
-
69
-def main():
70
-    module = AnsibleModule(
71
-        argument_spec=dict(
72
-            traceroute_host=dict(required=True, type='str'),
73
-        )
74
-    )
75
-
76
-    traceroute_host = module.params['traceroute_host']
77
-
78
-    ret = {}
79
-
80
-    for key, command in command_map.items():
81
-        try:
82
-            ret[key] = run_command(command)
83
-        except subprocess.CalledProcessError:
84
-            pass
85
-
86
-    passed = False
87
-    try:
88
-        ret['traceroute_v6'] = run_command(
89
-            'traceroute6 -n {host}'.format(host=traceroute_host))
90
-        passed = True
91
-    except (subprocess.CalledProcessError, OSError) as e:
92
-        ret['traceroute_v6_exception'] = traceback.format_exc(e)
93
-        ret['traceroute_v6_output'] = e.output
94
-        ret['traceroute_v6_return'] = e.returncode
95
-        pass
96
-    try:
97
-        ret['traceroute_v4'] = run_command(
98
-            'traceroute -n {host}'.format(host=traceroute_host))
99
-        passed = True
100
-    except (subprocess.CalledProcessError, OSError) as e:
101
-        ret['traceroute_v4_exception'] = traceback.format_exc(e)
102
-        ret['traceroute_v4_output'] = e.output
103
-        ret['traceroute_v4_return'] = e.returncode
104
-        pass
105
-    if not passed:
106
-        ret.update(collect_unbound_logs())
107
-        module.fail_json(
108
-            msg="No viable v4 or v6 route found to {traceroute_host}."
109
-            " The build node is assumed to be invalid.".format(
110
-                traceroute_host=traceroute_host), **ret)
111
-
112
-    module.exit_json(changed=False, _zuul_nolog_return=True, **ret)
113
-
114
-from ansible.module_utils.basic import *  # noqa
115
-from ansible.module_utils.basic import AnsibleModule
116
-
117
-if __name__ == '__main__':
118
-    main()

+ 1
- 8
roles/validate-host/tasks/main.yaml View File

@@ -23,15 +23,8 @@
23 23
   zuul_debug_info:
24 24
     image_manifest: "{{ zuul_site_image_manifest|default(omit) }}"
25 25
     image_manifest_files: "{{ zuul_site_image_manifest_files|default(omit) }}"
26
-  register: zdi
27
-
28
-- name: Collect network information from zuul worker
29
-  zuul_network_validate:
30 26
     traceroute_host: "{{ zuul_site_traceroute_host|default(omit) }}"
31
-  register: znetinfo
32
-  retries: 3
33
-  delay: 5
34
-  until: znetinfo.failed == False
27
+  register: zdi
35 28
 
36 29
 - name: Write out all zuul information for each host
37 30
   delegate_to: localhost

+ 12
- 12
roles/validate-host/templates/zuul-info.j2 View File

@@ -15,40 +15,40 @@ Host & kernel
15 15
 {{ zdi.uname }}
16 16
 
17 17
 {% endif %}
18
-{% if 'network_interfaces' in znetinfo %}
18
+{% if 'network_interfaces' in zdi %}
19 19
 Network interface addresses
20 20
 ===========================
21
-{{ znetinfo.network_interfaces }}
21
+{{ zdi.network_interfaces }}
22 22
 
23 23
 {% endif %}
24
-{% if 'network_routing_v4' in znetinfo %}
24
+{% if 'network_routing_v4' in zdi %}
25 25
 Network routing tables v4
26 26
 =========================
27
-{{ znetinfo.network_routing_v4 }}
27
+{{ zdi.network_routing_v4 }}
28 28
 
29 29
 {% endif %}
30
-{% if 'network_routing_v6' in znetinfo %}
30
+{% if 'network_routing_v6' in zdi %}
31 31
 Network routing tables v6
32 32
 =========================
33
-{{ znetinfo.network_routing_v6 }}
33
+{{ zdi.network_routing_v6 }}
34 34
 
35 35
 {% endif %}
36
-{% if 'network_neighbors' in znetinfo %}
36
+{% if 'network_neighbors' in zdi %}
37 37
 Network neighbors
38 38
 =================
39
-{{ znetinfo.network_neighbors }}
39
+{{ zdi.network_neighbors }}
40 40
 
41 41
 {% endif %}
42
-{% if 'traceroute_v4' in znetinfo %}
42
+{% if 'traceroute_v4' in zdi %}
43 43
 Route to Known Host v4
44 44
 ======================
45 45
 Known Host: {{ zuul_site_traceroute_host }}
46
-{{ znetinfo.traceroute_v4 }}
46
+{{ zdi.traceroute_v4 }}
47 47
 
48 48
 {% endif %}
49
-{% if 'traceroute_v6' in znetinfo %}
49
+{% if 'traceroute_v6' in zdi %}
50 50
 Route to Known Host v6
51 51
 ======================
52 52
 Known Host: {{ zuul_site_traceroute_host }}
53
-{{ znetinfo.traceroute_v6 }}
53
+{{ zdi.traceroute_v6 }}
54 54
 {% endif %}

Loading…
Cancel
Save