Port ara.setup helper modules from 0.x to 1.0
0.x has helper modules to easily find the path where things are located. These weren't originally in 1.0 mostly because ara-plugins was split into another project. We can add those back in for convenience now. Change-Id: I8272fd6f43b08f71e0bce3626dbcee3ca1fc85ac
This commit is contained in:
parent
4e27887ade
commit
06dbe6a43e
@ -29,8 +29,7 @@ Here's how you can get started from scratch with default settings:
|
|||||||
pip install ansible git+https://github.com/openstack/ara@feature/1.0
|
pip install ansible git+https://github.com/openstack/ara@feature/1.0
|
||||||
|
|
||||||
# Tell Ansible to use the ARA callback plugin
|
# Tell Ansible to use the ARA callback plugin
|
||||||
# "python -m ara.plugins" provides the path to the ARA plugins directory
|
export ANSIBLE_CALLBACK_PLUGINS="$(python -m ara.setup.callback_plugins)"
|
||||||
export ANSIBLE_CALLBACK_PLUGINS="$(python -m ara.plugins)/callback"
|
|
||||||
|
|
||||||
# Run your playbook as your normally would
|
# Run your playbook as your normally would
|
||||||
ansible-playbook playbook.yml
|
ansible-playbook playbook.yml
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
LOCATION = os.path.abspath(os.path.dirname(__file__))
|
|
5
ara/setup/README.rst
Normal file
5
ara/setup/README.rst
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
This directory contains scripts meant to help configuring ARA with Ansible.
|
||||||
|
|
||||||
|
For more information, visit the documentation_.
|
||||||
|
|
||||||
|
.. _documentation: http://ara.readthedocs.io/en/latest/configuration.html
|
25
ara/setup/__init__.py
Normal file
25
ara/setup/__init__.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Copyright (c) 2018 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# This file is part of ARA Records Ansible.
|
||||||
|
#
|
||||||
|
# ARA 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.
|
||||||
|
#
|
||||||
|
# ARA 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 ARA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
# The path where ARA is installed (parent directory)
|
||||||
|
path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||||
|
|
||||||
|
plugins = os.path.abspath(os.path.join(path, "plugins"))
|
||||||
|
action_plugins = os.path.abspath(os.path.join(plugins, "actions"))
|
||||||
|
callback_plugins = os.path.abspath(os.path.join(plugins, "callbacks"))
|
23
ara/setup/action_plugins.py
Normal file
23
ara/setup/action_plugins.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Copyright (c) 2019 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# This file is part of ARA Records Ansible.
|
||||||
|
#
|
||||||
|
# ARA 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.
|
||||||
|
#
|
||||||
|
# ARA 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 ARA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from . import action_plugins
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(action_plugins)
|
31
ara/setup/ansible.py
Normal file
31
ara/setup/ansible.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Copyright (c) 2019 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# This file is part of ARA Records Ansible.
|
||||||
|
#
|
||||||
|
# ARA 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.
|
||||||
|
#
|
||||||
|
# ARA 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 ARA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from . import action_plugins, callback_plugins
|
||||||
|
|
||||||
|
config = """
|
||||||
|
[defaults]
|
||||||
|
callback_plugins={}
|
||||||
|
action_plugins={}
|
||||||
|
""".format(
|
||||||
|
callback_plugins, action_plugins
|
||||||
|
)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(config.strip())
|
23
ara/setup/callback_plugins.py
Normal file
23
ara/setup/callback_plugins.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Copyright (c) 2019 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# This file is part of ARA Records Ansible.
|
||||||
|
#
|
||||||
|
# ARA 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.
|
||||||
|
#
|
||||||
|
# ARA 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 ARA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from . import callback_plugins
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(callback_plugins)
|
48
ara/setup/env.py
Normal file
48
ara/setup/env.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# Copyright (c) 2019 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# This file is part of ARA Records Ansible.
|
||||||
|
#
|
||||||
|
# ARA 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.
|
||||||
|
#
|
||||||
|
# ARA 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 ARA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import os
|
||||||
|
from distutils.sysconfig import get_python_lib
|
||||||
|
|
||||||
|
from . import action_plugins, callback_plugins
|
||||||
|
|
||||||
|
exports = """
|
||||||
|
export ANSIBLE_CALLBACK_PLUGINS={}
|
||||||
|
export ANSIBLE_ACTION_PLUGINS={}
|
||||||
|
""".format(
|
||||||
|
callback_plugins, action_plugins
|
||||||
|
)
|
||||||
|
|
||||||
|
if "VIRTUAL_ENV" in os.environ:
|
||||||
|
""" PYTHONPATH may be exported when 'ara' module is installed in a
|
||||||
|
virtualenv and ansible is installed on system python to avoid ansible
|
||||||
|
failure to find ara module.
|
||||||
|
"""
|
||||||
|
# inspired by https://stackoverflow.com/a/122340/99834
|
||||||
|
lib = get_python_lib()
|
||||||
|
if "PYTHONPATH" in os.environ:
|
||||||
|
python_paths = os.environ["PYTHONPATH"].split(os.pathsep)
|
||||||
|
else:
|
||||||
|
python_paths = []
|
||||||
|
if lib not in python_paths:
|
||||||
|
python_paths.append(lib)
|
||||||
|
exports += "export PYTHONPATH=%s\n" % os.pathsep.join(python_paths)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(exports.strip())
|
@ -1,6 +1,6 @@
|
|||||||
# Copyright (c) 2018 Red Hat, Inc.
|
# Copyright (c) 2019 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
# This file is part of ARA: Ansible Run Analysis.
|
# This file is part of ARA Records Ansible.
|
||||||
#
|
#
|
||||||
# ARA is free software: you can redistribute it and/or modify
|
# ARA is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -15,7 +15,9 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with ARA. If not, see <http://www.gnu.org/licenses/>.
|
# along with ARA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from ara.plugins import LOCATION
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from . import path
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(LOCATION)
|
print(path)
|
23
ara/setup/plugins.py
Normal file
23
ara/setup/plugins.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Copyright (c) 2019 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# This file is part of ARA Records Ansible.
|
||||||
|
#
|
||||||
|
# ARA 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.
|
||||||
|
#
|
||||||
|
# ARA 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 ARA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from . import plugins
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(plugins)
|
@ -68,15 +68,15 @@
|
|||||||
virtualenv_python: python3
|
virtualenv_python: python3
|
||||||
|
|
||||||
- name: Get ARA plugins directory
|
- name: Get ARA plugins directory
|
||||||
command: "{{ ara_tests_virtualenv }}/bin/python -m ara.plugins"
|
command: "{{ ara_tests_virtualenv }}/bin/python -m ara.setup.plugins"
|
||||||
register: ara_plugins
|
register: ara_setup_plugins
|
||||||
|
|
||||||
# These aren't in the same task (i.e, with loop) so we can tell individual test
|
# These aren't in the same task (i.e, with loop) so we can tell individual test
|
||||||
# runs apart easily rather than keeping all the output bundled in a single task.
|
# runs apart easily rather than keeping all the output bundled in a single task.
|
||||||
# TODO: Add validation for the tests
|
# TODO: Add validation for the tests
|
||||||
- environment:
|
- environment:
|
||||||
ANSIBLE_CALLBACK_PLUGINS: "{{ ara_plugins.stdout }}/callback"
|
ANSIBLE_CALLBACK_PLUGINS: "{{ ara_setup_plugins.stdout }}/callback"
|
||||||
ANSIBLE_ACTION_PLUGINS: "{{ ara_plugins.stdout }}/action"
|
ANSIBLE_ACTION_PLUGINS: "{{ ara_setup_plugins.stdout }}/action"
|
||||||
ARA_DEBUG: true
|
ARA_DEBUG: true
|
||||||
ARA_LOG_LEVEL: DEBUG
|
ARA_LOG_LEVEL: DEBUG
|
||||||
ARA_BASE_DIR: "{{ ara_tests_data }}"
|
ARA_BASE_DIR: "{{ ara_tests_data }}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user