Add debug-info role from zuul-jobs as validate-host
Move the role to openstack-zuul-roles so that we can use it in the base job in project-config. Depends-On: I82289ec0b66502995278eb897257f345b6c44878 Change-Id: If4a599e022fe1a502a904b8ee55c5186a6e9ae8b
This commit is contained in:
parent
f22040bb86
commit
f8eadc62b1
|
@ -0,0 +1,3 @@
|
|||
Output all of the Ansible variables for the host
|
||||
|
||||
This is unsafe to run in Trusted jobs as it will write any secrets to the log.
|
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Copyright (c) 2017 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
|
||||
|
||||
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',
|
||||
}
|
||||
|
||||
|
||||
def run_command(command):
|
||||
env = os.environ.copy()
|
||||
env['PATH'] = '{path}:/sbin'.format(path=env['PATH'])
|
||||
return subprocess.check_output(
|
||||
shlex.split(command),
|
||||
stderr=subprocess.STDOUT,
|
||||
env=env)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
image_manifest=dict(required=False, type='str'),
|
||||
traceroute_host=dict(required=False, type='str'),
|
||||
)
|
||||
)
|
||||
|
||||
image_manifest = module.params['image_manifest']
|
||||
traceroute_host = module.params['traceroute_host']
|
||||
ret = {'image_manifest': None, 'traceroute': None}
|
||||
|
||||
if image_manifest and os.path.exists(image_manifest):
|
||||
ret['image_manifest'] = 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:
|
||||
pass
|
||||
try:
|
||||
ret['traceroute_v4'] = run_command(
|
||||
'traceroute -n {host}'.format(host=traceroute_host))
|
||||
passed = True
|
||||
except subprocess.CalledProcessError:
|
||||
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))
|
||||
|
||||
for key, command in command_map.items():
|
||||
try:
|
||||
ret[key] = run_command(command)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
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()
|
|
@ -0,0 +1,27 @@
|
|||
- set_fact:
|
||||
zuul_info_dir: "{{ zuul.executor.log_root }}/zuul-info"
|
||||
|
||||
- name: Ensure Zuul Ansible directory exists
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
file:
|
||||
path: "{{ zuul_info_dir }}"
|
||||
state: directory
|
||||
|
||||
- name: Write out all ansible variables/facts known for each host
|
||||
delegate_to: localhost
|
||||
template:
|
||||
dest: "{{ zuul_info_dir }}/ansible-hostvars.{{ inventory_hostname }}.yaml"
|
||||
src: templates/ansible-hostvars.j2
|
||||
|
||||
- name: Collect information about zuul worker
|
||||
zuul_debug_info:
|
||||
image_manifest: "{{ zuul_image_manifest|default(omit) }}"
|
||||
traceroute_host: "{{ zuul_traceroute_host|default(omit) }}"
|
||||
register: zdi
|
||||
|
||||
- name: Write out all zuul information for each host
|
||||
delegate_to: localhost
|
||||
template:
|
||||
dest: "{{ zuul_info_dir }}/zuul-info.{{ inventory_hostname }}.txt"
|
||||
src: templates/zuul-info.j2
|
|
@ -0,0 +1 @@
|
|||
{{ hostvars[inventory_hostname] | to_nice_yaml(indent=2) }}
|
|
@ -0,0 +1,49 @@
|
|||
{% if 'image_manifest' in zdi %}
|
||||
Image Information
|
||||
=================
|
||||
{{ zdi.image_manifest }}
|
||||
{% endif %}
|
||||
|
||||
{% if 'uname' in zdi %}
|
||||
Host & kernel
|
||||
=============
|
||||
{{ zdi.uname }}
|
||||
{% endif %}
|
||||
|
||||
{% if 'network_interfaces' in zdi %}
|
||||
Network interface addresses
|
||||
===========================
|
||||
{{ zdi.network_interfaces }}
|
||||
{% endif %}
|
||||
|
||||
{% if 'network_routing_v4' in zdi %}
|
||||
Network routing tables v4
|
||||
=========================
|
||||
{{ zdi.network_routing_v4 }}
|
||||
{% endif %}
|
||||
|
||||
{% if 'network_routing_v6' in zdi %}
|
||||
Network routing tables v6
|
||||
=========================
|
||||
{{ zdi.network_routing_v6 }}
|
||||
{% endif %}
|
||||
|
||||
{% if 'network_neighbors' in zdi %}
|
||||
Network neighbors
|
||||
=================
|
||||
{{ zdi.network_neighbors }}
|
||||
{% endif %}
|
||||
|
||||
{% if 'traceroute_v4' in zdi %}
|
||||
Route to Known Host v4
|
||||
======================
|
||||
Known Host: {{ zuul_traceroute_host }}
|
||||
{{ zdi.traceroute_v4 }}
|
||||
{% endif %}
|
||||
|
||||
{% if 'traceroute_v6' in zdi %}
|
||||
Route to Known Host v6
|
||||
======================
|
||||
Known Host: {{ zuul_traceroute_host }}
|
||||
{{ zdi.traceroute_v6 }}
|
||||
{% endif %}
|
Loading…
Reference in New Issue