From 6685c546169d726e09cac28af34952dbef6e6072 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Mon, 19 Nov 2018 21:43:40 +0000 Subject: [PATCH] Revert "validate-host: retry network tests and include unbound logs" This reverts commit 7e00ba32dab04ac6a3f952d84dfd9eef1e021e47. Change-Id: I2c1aa1e834d408de14ad4818ff5c9b58145f44b0 --- .../validate-host/library/zuul_debug_info.py | 34 ++++- .../library/zuul_network_validate.py | 118 ------------------ roles/validate-host/tasks/main.yaml | 9 +- roles/validate-host/templates/zuul-info.j2 | 24 ++-- 4 files changed, 46 insertions(+), 139 deletions(-) delete mode 100644 roles/validate-host/library/zuul_network_validate.py diff --git a/roles/validate-host/library/zuul_debug_info.py b/roles/validate-host/library/zuul_debug_info.py index e3db74b50..8fc85d3e8 100644 --- a/roles/validate-host/library/zuul_debug_info.py +++ b/roles/validate-host/library/zuul_debug_info.py @@ -18,10 +18,15 @@ import os import shlex import subprocess +import traceback command_map = { 'uname': 'uname -a', + 'network_interfaces': 'ip address show', + 'network_routing_v4': 'ip route show', + 'network_routing_v6': 'ip -6 route show', + 'network_neighbors': 'ip neighbor show', } @@ -39,14 +44,16 @@ def main(): argument_spec=dict( image_manifest=dict(required=False, type='str'), image_manifest_files=dict(required=False, type='list'), + traceroute_host=dict(required=False, type='str'), ) ) image_manifest = module.params['image_manifest'] + traceroute_host = module.params['traceroute_host'] image_manifest_files = module.params['image_manifest_files'] if not image_manifest_files and image_manifest: image_manifest_files = [image_manifest] - ret = {'image_manifest_files': []} + ret = {'image_manifest_files': [], 'traceroute': None} for image_manifest in image_manifest_files: if image_manifest and os.path.exists(image_manifest): @@ -56,6 +63,31 @@ def main(): 'underline': len(image_manifest) * '-', 'content': open(image_manifest, 'r').read(), }) + if traceroute_host: + passed = False + try: + ret['traceroute_v6'] = run_command( + 'traceroute6 -n {host}'.format(host=traceroute_host)) + passed = True + except (subprocess.CalledProcessError, OSError) as e: + ret['traceroute_v6_exception'] = traceback.format_exc(e) + ret['traceroute_v6_output'] = e.output + ret['traceroute_v6_return'] = e.returncode + pass + try: + ret['traceroute_v4'] = run_command( + 'traceroute -n {host}'.format(host=traceroute_host)) + passed = True + except (subprocess.CalledProcessError, OSError) as e: + ret['traceroute_v4_exception'] = traceback.format_exc(e) + ret['traceroute_v4_output'] = e.output + ret['traceroute_v4_return'] = e.returncode + pass + if not passed: + module.fail_json( + msg="No viable v4 or v6 route found to {traceroute_host}." + " The build node is assumed to be invalid.".format( + traceroute_host=traceroute_host), **ret) for key, command in command_map.items(): try: diff --git a/roles/validate-host/library/zuul_network_validate.py b/roles/validate-host/library/zuul_network_validate.py deleted file mode 100644 index 5038eb7ca..000000000 --- a/roles/validate-host/library/zuul_network_validate.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/python - -# Copyright (c) 2018 Red Hat -# -# This module is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software. If not, see . - -import os -import shlex -import subprocess -import traceback - - -command_map = { - 'network_interfaces': 'ip address show', - 'network_routing_v4': 'ip route show', - 'network_routing_v6': 'ip -6 route show', - 'network_neighbors': 'ip neighbor show', -} - - -def run_command(command): - env = os.environ.copy() - env['PATH'] = '{path}:/sbin:/usr/sbin'.format(path=env['PATH']) - return subprocess.check_output( - shlex.split(command), - stderr=subprocess.STDOUT, - env=env) - - -def collect_unbound_logs(): - '''Look for unbound logs - - This looks for unbound logs in common places and returns the - contents. Intended for the failure path to add more info if the - traceroutes have failed. - ''' - ret = {} - - # NOTE(ianw): keep this one first, the other exists but isn't - # populated on infra rpm images for ... reasons - if os.path.exists('/var/lib/unbound/unbound.log'): - unbound_log_file = '/var/lib/unbound/unbound.log' - elif os.path.exists('/var/log/unbound.log'): - unbound_log_file = '/var/log/unbound.log' - else: - return ret - - with open(unbound_log_file) as f: - ret['unbound_log_file'] = unbound_log_file - # NOTE(ianw): At high verbosity this can be big ... but this - # is also intended to be used early which should limit it's - # size. We could tail it ... - ret['unbound_log_file_content'] = f.read() - - return ret - - -def main(): - module = AnsibleModule( - argument_spec=dict( - traceroute_host=dict(required=True, type='str'), - ) - ) - - traceroute_host = module.params['traceroute_host'] - - ret = {} - - for key, command in command_map.items(): - try: - ret[key] = run_command(command) - except subprocess.CalledProcessError: - pass - - passed = False - try: - ret['traceroute_v6'] = run_command( - 'traceroute6 -n {host}'.format(host=traceroute_host)) - passed = True - except (subprocess.CalledProcessError, OSError) as e: - ret['traceroute_v6_exception'] = traceback.format_exc(e) - ret['traceroute_v6_output'] = e.output - ret['traceroute_v6_return'] = e.returncode - pass - try: - ret['traceroute_v4'] = run_command( - 'traceroute -n {host}'.format(host=traceroute_host)) - passed = True - except (subprocess.CalledProcessError, OSError) as e: - ret['traceroute_v4_exception'] = traceback.format_exc(e) - ret['traceroute_v4_output'] = e.output - ret['traceroute_v4_return'] = e.returncode - pass - if not passed: - ret.update(collect_unbound_logs()) - module.fail_json( - msg="No viable v4 or v6 route found to {traceroute_host}." - " The build node is assumed to be invalid.".format( - traceroute_host=traceroute_host), **ret) - - module.exit_json(changed=False, _zuul_nolog_return=True, **ret) - -from ansible.module_utils.basic import * # noqa -from ansible.module_utils.basic import AnsibleModule - -if __name__ == '__main__': - main() diff --git a/roles/validate-host/tasks/main.yaml b/roles/validate-host/tasks/main.yaml index 7f52a1b8c..08cadfcf0 100644 --- a/roles/validate-host/tasks/main.yaml +++ b/roles/validate-host/tasks/main.yaml @@ -23,15 +23,8 @@ zuul_debug_info: image_manifest: "{{ zuul_site_image_manifest|default(omit) }}" image_manifest_files: "{{ zuul_site_image_manifest_files|default(omit) }}" - register: zdi - -- name: Collect network information from zuul worker - zuul_network_validate: traceroute_host: "{{ zuul_site_traceroute_host|default(omit) }}" - register: znetinfo - retries: 3 - delay: 5 - until: znetinfo.failed == False + register: zdi - name: Write out all zuul information for each host delegate_to: localhost diff --git a/roles/validate-host/templates/zuul-info.j2 b/roles/validate-host/templates/zuul-info.j2 index e8d611b7e..eb3dce097 100644 --- a/roles/validate-host/templates/zuul-info.j2 +++ b/roles/validate-host/templates/zuul-info.j2 @@ -15,40 +15,40 @@ Host & kernel {{ zdi.uname }} {% endif %} -{% if 'network_interfaces' in znetinfo %} +{% if 'network_interfaces' in zdi %} Network interface addresses =========================== -{{ znetinfo.network_interfaces }} +{{ zdi.network_interfaces }} {% endif %} -{% if 'network_routing_v4' in znetinfo %} +{% if 'network_routing_v4' in zdi %} Network routing tables v4 ========================= -{{ znetinfo.network_routing_v4 }} +{{ zdi.network_routing_v4 }} {% endif %} -{% if 'network_routing_v6' in znetinfo %} +{% if 'network_routing_v6' in zdi %} Network routing tables v6 ========================= -{{ znetinfo.network_routing_v6 }} +{{ zdi.network_routing_v6 }} {% endif %} -{% if 'network_neighbors' in znetinfo %} +{% if 'network_neighbors' in zdi %} Network neighbors ================= -{{ znetinfo.network_neighbors }} +{{ zdi.network_neighbors }} {% endif %} -{% if 'traceroute_v4' in znetinfo %} +{% if 'traceroute_v4' in zdi %} Route to Known Host v4 ====================== Known Host: {{ zuul_site_traceroute_host }} -{{ znetinfo.traceroute_v4 }} +{{ zdi.traceroute_v4 }} {% endif %} -{% if 'traceroute_v6' in znetinfo %} +{% if 'traceroute_v6' in zdi %} Route to Known Host v6 ====================== Known Host: {{ zuul_site_traceroute_host }} -{{ znetinfo.traceroute_v6 }} +{{ zdi.traceroute_v6 }} {% endif %}