Make ironic-python-agent-builder packaging-friendly

* Install dib files to /usr/share (tinyipa TBD later)
* Add an executable that can be installed into /usr/bin

Since we now have python code, make pep8 operational.

Change-Id: I9235885485833c4011e42da6db01e150821bd8da
This commit is contained in:
Dmitry Tantsur 2019-08-12 14:43:48 +02:00
parent b29326a499
commit c56bffbefe
7 changed files with 96 additions and 3 deletions

View File

@ -5,4 +5,12 @@ Administrators guide
This guide describes how to build an `Ironic Python Agent`_-based image using
the builders provided in the **ironic-python-agent-builder** project.
diskimage-builder image
-----------------------
To build an image using diskimage-builder_, run::
ironic-python-agent-builder <distribution, e.g. ubuntu>
.. _Ironic Python Agent: https://docs.openstack.org/ironic-python-agent
.. _diskimage-builder: https://docs.openstack.org/diskimage-builder

View File

@ -4,5 +4,7 @@ Installing Ironic Python Agent Builder
Download the ``ironic-python-agent-builder`` package from
`tarballs.openstack.org
<https://tarballs.openstack.org/ironic-python-agent-builder/>`_ or install it
from your distribution's repositories.
<https://tarballs.openstack.org/ironic-python-agent-builder/>`_, install it
from your distribution's repositories or use pip::
pip install --user diskimage-builder ironic-python-agent-builder

View File

@ -0,0 +1,52 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import os
import subprocess
import sys
LOCATIONS = [
'.',
os.path.join(sys.prefix, 'share', 'ironic-python-agent-builder'),
]
def find_elements_path():
for basedir in LOCATIONS:
final = os.path.join(basedir, 'dib')
if os.path.exists(os.path.join(final, 'ironic-python-agent-ramdisk')):
return final
sys.exit('ironic-python-agent-ramdisk element has not been found in any '
'of the following locations: %s' % ', '.join(LOCATIONS))
def main():
parser = argparse.ArgumentParser()
parser.add_argument("distribution", help="Distribution to use")
parser.add_argument("-o", "--output", help="Output base file name",
default="ironic-python-agent")
parser.add_argument("-e", "--element", action='append', default=[],
help="Additional DIB element to use")
# TODO(dtantsur): handle distribution == tinyipa
os.environ['ELEMENTS_PATH'] = find_elements_path()
args = parser.parse_args()
try:
subprocess.check_call(['disk-image-create', '-o', args.output,
'ironic-python-agent-ramdisk',
args.distribution] + args.element)
except (EnvironmentError, subprocess.CalledProcessError) as exc:
sys.exit(str(exc))
except KeyboardInterrupt:
sys.exit(127)

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
diskimage-builder>=1.0,!=1.6.0,!=1.7.0,!=1.7.1 # Apache-2.0

View File

@ -13,6 +13,15 @@ classifier =
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
[entry_points]
console_scripts =
ironic-python-agent-builder = ironic_python_agent_builder:main
[files]
# TODO(dtantsur): figure out a sane way to distribute tinyipa scripts
data_files =
share/ironic-python-agent-builder/dib = dib/*
[build_sphinx]
all-files = 1
warning-is-error = 1

View File

@ -2,6 +2,10 @@
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
# pep8
hacking>=1.0.0,<1.2.0 # Apache-2.0
flake8-import-order>=0.13 # LGPLv3
# documentation
doc8>=0.6.0 # Apache-2.0
sphinx!=1.6.6,!=1.6.7,>=1.6.2,<2.0.0;python_version=='2.7' # BSD
sphinx!=1.6.6,!=1.6.7,>=1.6.2;python_version>='3.4' # BSD

16
tox.ini
View File

@ -13,7 +13,9 @@ deps = -r{toxinidir}/test-requirements.txt
[testenv:pep8]
basepython = python3
commands = doc8 doc/source README.rst CONTRIBUTING.rst
commands =
flake8 ironic_python_agent_builder
doc8 doc/source README.rst CONTRIBUTING.rst
[testenv:venv]
basepython = python3
@ -27,3 +29,15 @@ commands = python setup.py build_sphinx
basepython = python3
commands =
sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
[flake8]
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,imagebuild/tinyipa/tinyipafinal,imagebuild/tinyipa/tinyipabuild
import-order-style = pep8
application-import-names = ironic_python_agent_builder
# [H106] Don't put vim configuration in source files.
# [H203] Use assertIs(Not)None to check for None.
# [H204] Use assert(Not)Equal to check for equality.
# [H205] Use assert(Greater|Less)(Equal) for comparison.
# [H210] Require 'autospec', 'spec', or 'spec_set' in mock.patch/mock.patch.object calls
# [H904] Delay string interpolations at logging calls.
enable-extensions=H106,H203,H204,H205,H210,H904