Combine new modules into a single package

- Make newly added get_hash and yum_config modules part of
  triple_repos package.
- add simple packaging testing environment, which should validate
  installation of the command line
- moves tests/docs/examples in official location required by
  ansible-test
- includes required fix for looking up for local config.yaml

Change-Id: I134ef8ac4c31b98dc25d17ab058af1ed34e27f32
This commit is contained in:
Sorin Sbarnea 2021-07-16 09:27:20 +01:00
parent 06f41a630f
commit 0ecc6e0bbb
47 changed files with 112 additions and 192 deletions

View File

@ -1,3 +1,3 @@
[DEFAULT] [DEFAULT]
test_path=./tripleo_repos/tests test_path=./tests/unit
top_dir=./ top_dir=./

2
MANIFEST.in Normal file
View File

@ -0,0 +1,2 @@
global-exclude *.py[cod]
global-exclude __pycache__

View File

@ -10,12 +10,12 @@ information, including the commit, distro and full hashes where available.
It includes a simple command line interface. If you clone the source you can It includes a simple command line interface. If you clone the source you can
try it out of the box without installation invoking it as a module: try it out of the box without installation invoking it as a module:
``` ```
python -m tripleo_get_hash # by default centos8, master, current-tripleo. tripleo-get-hash # by default centos8, master, current-tripleo.
python -m tripleo_get_hash --component tripleo --release victoria --os-version centos8 tripleo-get-hash --component tripleo --release victoria --os-version centos8
python -m tripleo_get_hash --release master --os-version centos7 tripleo-get-hash --release master --os-version centos7
python -m tripleo_get_hash --release train # by default centos8 tripleo-get-hash --release train # by default centos8
python -m tripleo_get_hash --os-version rhel8 --release osp16-2 --dlrn-url http://osp-trunk.hosted.upshift.rdu2.redhat.com tripleo-get-hash --os-version rhel8 --release osp16-2 --dlrn-url http://osp-trunk.hosted.upshift.rdu2.redhat.com
python -m tripleo_get_hash --help tripleo-get-hash --help
``` ```
## Quick start ## Quick start
@ -38,10 +38,10 @@ is placed in /usr/local/etc:
#### Install using pip #### Install using pip
You can also install using python pip - you can see the You can also install using python pip - you can see the
[tripleo-get-hash module here](https://pypi.org/project/tripleo-get-hash/) [tripleo-get-hash module here](https://pypi.org/project/tripleo-repos/)
``` ```
pip install tripleo-get-hash --user pip install tripleo-repos --user
``` ```
After installation you can invoke tripleo-get-hash --help to see the various After installation you can invoke tripleo-get-hash --help to see the various

View File

@ -1,4 +1,4 @@
# tripleo-yum-config # tripleo_repos.yum_config
*tripleo-yum-config* utility was designed to simplify the way that TripleO *tripleo-yum-config* utility was designed to simplify the way that TripleO
deployments manage their yum configuration. This tool helps on updating deployments manage their yum configuration. This tool helps on updating
@ -32,10 +32,10 @@ its repository and invoking in command line:
Examples: Examples:
``` ```
sudo python -m tripleo_yum_config module remove tomcat sudo tripleo-yum-config module remove tomcat
sudo python -m tripleo_yum_config module disable tomcat sudo tripleo-yum-config module disable tomcat
sudo python -m tripleo_yum_config module enable nginx --stream mainline sudo tripleo-yum-config module enable nginx --stream mainline
sudo python -m tripleo_yum_config module install nginx --profile common sudo tripleo-yum-config module install nginx --profile common
``` ```
* **global** * **global**
@ -60,9 +60,9 @@ sudo python setup.py install
#### Install using pip #### Install using pip
Alternatively you can install tripleo-yum-config with python pip: Alternatively you can install tripleo-yum-config with python pip:
``` ```
pip install tripleo-yum-config --user pip install tripleo-repos --user
``` ```
See PyPI [tripleo-yum-config](https://pypi.org/project/tripleo-yum-config/) See PyPI [tripleo-repos](https://pypi.org/project/tripleo-repos/)
project for more details. project for more details.
## Usage ## Usage

View File

@ -4,3 +4,4 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0 pbr!=2.1.0,>=2.0.0 # Apache-2.0
requests>=2.10.0 # Apache-2.0 requests>=2.10.0 # Apache-2.0
PyYAML>=3.12 # MIT

View File

@ -24,7 +24,14 @@ classifier =
[files] [files]
packages = packages =
tripleo_repos tripleo_repos
data_files =
etc/tripleo_get_hash/ = tripleo_repos/get_hash/config.yaml
# Temporary until we get a proper Ansible collection:
share/ansible/plugins/modules/ = tripleo_repos/yum_config/tripleo_yum_config.py
share/ansible/plugins/modules/ = tripleo_repos/get_hash/tripleo_get_hash.py
[entry_points] [entry_points]
console_scripts = console_scripts =
tripleo-repos = tripleo_repos.main:main tripleo-repos = tripleo_repos.main:main
tripleo-yum-config = tripleo_repos.yum_config.__main__:cli_entrypoint
tripleo-get-hash = tripleo_repos.get_hash.__main__:cli_entrypoint

View File

@ -13,3 +13,4 @@ testscenarios>=0.4 # Apache-2.0/BSD
testtools>=1.4.0 # MIT testtools>=1.4.0 # MIT
stestr>=2.0.0 # Apache-2.0 stestr>=2.0.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD fixtures>=3.0.0 # Apache-2.0/BSD
requests_mock>=1.8.0 # Apache-2.0

View File

@ -21,9 +21,9 @@ from unittest import mock
from unittest.mock import mock_open from unittest.mock import mock_open
import yaml import yaml
import tripleo_get_hash.exceptions as exc import tripleo_repos.get_hash.exceptions as exc
import tripleo_get_hash.__main__ as tgh import tripleo_repos.get_hash.__main__ as tgh
import test.fakes as test_fakes from . import fakes as test_fakes
@mock.patch( @mock.patch(

View File

@ -15,9 +15,9 @@
# #
import unittest import unittest
import tripleo_get_hash.tripleo_hash_info as thi import tripleo_repos.get_hash.tripleo_hash_info as thi
import tripleo_get_hash.exceptions as exc import tripleo_repos.get_hash.exceptions as exc
import test.fakes as test_fakes from . import fakes as test_fakes
import requests_mock import requests_mock
from unittest import mock from unittest import mock
from unittest.mock import mock_open from unittest.mock import mock_open

View File

@ -14,8 +14,8 @@
import ddt import ddt
from unittest import mock from unittest import mock
import test.test_main as test_main from . import test_main
import tripleo_yum_config.dnf_manager as dnf_mgr import tripleo_repos.yum_config.dnf_manager as dnf_mgr
@ddt.ddt @ddt.ddt

View File

@ -17,11 +17,11 @@ import sys
import unittest import unittest
from unittest import mock from unittest import mock
import test.fakes as fakes from . import fakes
import test.mock_modules # noqa: F401 from . import mock_modules # noqa: F401
import tripleo_yum_config.__main__ as main import tripleo_repos.yum_config.__main__ as main
import tripleo_yum_config.yum_config as yum_cfg import tripleo_repos.yum_config.yum_config as yum_cfg
import tripleo_yum_config.dnf_manager as dnf_mgr import tripleo_repos.yum_config.dnf_manager as dnf_mgr
class TestTripleoYumConfigBase(unittest.TestCase): class TestTripleoYumConfigBase(unittest.TestCase):

View File

@ -18,11 +18,11 @@ import ddt
import os import os
from unittest import mock from unittest import mock
import test.fakes as fakes from . import fakes
import test.test_main as test_main from . import test_main
import tripleo_yum_config.constants as const import tripleo_repos.yum_config.constants as const
import tripleo_yum_config.exceptions as exc import tripleo_repos.yum_config.exceptions as exc
import tripleo_yum_config.yum_config as yum_cfg import tripleo_repos.yum_config.yum_config as yum_cfg
@ddt.ddt @ddt.ddt

38
tox.ini
View File

@ -1,22 +1,17 @@
[tox] [tox]
minversion = 3.1.1 minversion = 3.1.1
skipsdist = True skipsdist = True
envlist = py,pep8 envlist = py,pep8,packaging
[testenv] [testenv]
usedevelop = True usedevelop = True
basepython = python3
setenv = VIRTUAL_ENV={envdir} setenv = VIRTUAL_ENV={envdir}
deps = deps =
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
-r{toxinidir}/tripleo-get-hash/requirements.txt
-r{toxinidir}/tripleo-get-hash/test-requirements.txt
commands = commands =
stestr run --slowest {posargs} stestr run --slowest {posargs}
stestr run --combine --slowest {posargs} --test-path ./tripleo-get-hash/test --top-dir ./tripleo-get-hash
stestr run --combine --slowest {posargs} --test-path ./tripleo-yum-config/test --top-dir ./tripleo-yum-config
[testenv:venv] [testenv:venv]
commands = {posargs} commands = {posargs}
@ -43,6 +38,37 @@ commands =
coverage html -d cover coverage html -d cover
coverage xml -o cover/coverage.xml coverage xml -o cover/coverage.xml
[testenv:packaging]
description =
Build package, verify metadata, install package and assert basic behavior
deps =
build
twine
skip_install = true
commands =
# build wheel and sdist using PEP-517
{envpython} -c 'import os.path, shutil, sys; \
dist_dir = os.path.join("{toxinidir}", "dist"); \
os.path.isdir(dist_dir) or sys.exit(0); \
print("Removing \{!s\} contents...".format(dist_dir), file=sys.stderr); \
shutil.rmtree(dist_dir)'
{envpython} -m build \
--sdist \
--wheel \
--outdir {toxinidir}/dist/ \
{toxinidir}
# Validate metadata using twine
twine check {toxinidir}/dist/*
# Install the wheel
sh -c "python3 -m pip install {toxinidir}/dist/*.whl"
# Assure that CLIs were installed
tripleo-repos --help
tripleo-get-hash --help
tripleo-yum-config --help
whitelist_externals =
sh
[flake8] [flake8]
ignore = H803 ignore = H803
show-source = True show-source = True

View File

@ -1,13 +0,0 @@
Copyright 2021 Red Hat, Inc.
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.

View File

@ -1,2 +0,0 @@
PyYAML
requests

View File

@ -1,34 +0,0 @@
[metadata]
name = tripleo-get-hash
author = Marios Andreou
author_email = openstack-discuss@lists.openstack.org
description = Get the tripleo build hash for a known RDO named tag. See https://opendev.org/openstack/tripleo-repos/src/branch/master/tripleo-get-hash/README.md#what-is-tripleo-get-hash for more information.
long_description = file: README.md LICENSE
long_description_content_type = text/markdown
url = https://opendev.org/openstack/tripleo-repos/src/branch/master/tripleo-get-hash
project_urls =
Bug Tracker = https://launchpad.net/tripleo
license_file = LICENSE
license = Apache-2.0
classifiers =
Programming Language :: Python
[options]
package_dir =
= .
packages = find:
python_requires = >=3.6
install_requires =
pyyaml
requests
tests_require =
requests_mock
[options.entry_points]
console_scripts =
tripleo-get-hash = tripleo_get_hash.__main__:cli_entrypoint
[files]
data_files =
etc/tripleo_get_hash/ = config.yaml
share/ansible/plugins/modules/ = tripleo_get_hash.py

View File

@ -1,19 +0,0 @@
# Copyright 2021 Red Hat, Inc.
#
# 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 setuptools
setuptools.setup(setup_requires=['pbr'], pbr=True)

View File

@ -1 +0,0 @@
requests_mock

View File

@ -1,13 +0,0 @@
Copyright 2021 Red Hat, Inc.
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.

View File

@ -1,28 +0,0 @@
[metadata]
name = tripleo-yum-config
author = Douglas Viroel
author_email = openstack-discuss@lists.openstack.org
description = Updates yum configuration files (repo, modules, global configuration).
long_description = file: README.md LICENSE
long_description_content_type = text/markdown
url = https://opendev.org/openstack/tripleo-repos/src/branch/master/tripleo-yum-config
project_urls =
Bug Tracker = https://launchpad.net/tripleo
license_file = LICENSE
license = Apache-2.0
classifiers =
Programming Language :: Python
[options]
package_dir =
= .
packages = find:
python_requires = >=3.6
[options.entry_points]
console_scripts =
tripleo-yum-config = tripleo_yum_config.__main__:cli_entrypoint
[files]
data_files =
share/ansible/plugins/modules/ = tripleo_yum_config.py

View File

@ -1,19 +0,0 @@
# Copyright 2021 Red Hat, Inc.
#
# 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 setuptools
setuptools.setup(setup_requires=['pbr'], pbr=True)

View File

@ -17,8 +17,8 @@
import argparse import argparse
import logging import logging
import sys import sys
from tripleo_get_hash.tripleo_hash_info import TripleOHashInfo from tripleo_repos.get_hash.tripleo_hash_info import TripleOHashInfo
import tripleo_get_hash.exceptions as exc import tripleo_repos.get_hash.exceptions as exc
def _validate_args(parsed_args): def _validate_args(parsed_args):

View File

@ -14,7 +14,7 @@
# under the License. # under the License.
# #
from tripleo_get_hash.tripleo_hash_info import TripleOHashInfo from tripleo_repos.get_hash.tripleo_hash_info import TripleOHashInfo
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
DOCUMENTATION = r''' DOCUMENTATION = r'''

View File

@ -19,8 +19,8 @@ import sys
import yaml import yaml
import os import os
import requests import requests
import tripleo_get_hash.constants as const import tripleo_repos.get_hash.constants as const
import tripleo_get_hash.exceptions as exc import tripleo_repos.get_hash.exceptions as exc
class TripleOHashInfo: class TripleOHashInfo:
@ -91,16 +91,18 @@ class TripleOHashInfo:
return False return False
def _resolve_local_config_path(): def _resolve_local_config_path():
""" For running from source checkout, try ../config.yaml. For """ Load local config from disk from expected locations. """
pip install (--user) try ../local/etc/tripleo_get_hash/ paths = [
""" # pip install --user
for _path in ['config.yaml', os.path.expanduser(
'usr/local/etc/tripleo_get_hash/config.yaml']: "~/.local/etc/tripleo_get_hash/config.yaml"),
_local_config = os.path.join( # root install
os.path.split(os.path.split( "/etc/tripleo_get_hash/config.yaml",
os.path.abspath(__file__) # embedded config.yaml as fallback
)[0])[0], "{}".format(_path) os.path.join(
) os.path.dirname(os.path.abspath(__file__)), "config.yaml")
]
for _local_config in paths:
if _check_read_file(_local_config): if _check_read_file(_local_config):
return _local_config return _local_config

View File

@ -17,6 +17,7 @@
from __future__ import print_function from __future__ import print_function
import argparse import argparse
import os import os
import platform
import re import re
import subprocess import subprocess
import sys import sys
@ -115,6 +116,11 @@ def _get_distro():
returns: distro_id, distro_major_version_id, distro_name returns: distro_id, distro_major_version_id, distro_name
""" """
# Avoids a crash on unsupported platforms which would prevent even
# running with `--help`.
if not os.path.exists('/etc/os-release'):
return platform.system(), 'unknown', 'unknown'
output = subprocess.Popen( output = subprocess.Popen(
'source /etc/os-release && echo -e -n "$ID\n$VERSION_ID\n$NAME"', 'source /etc/os-release && echo -e -n "$ID\n$VERSION_ID\n$NAME"',
shell=True, shell=True,
@ -155,7 +161,7 @@ def _parse_args(distro_id, distro_major_version_id):
distro = "{}{}".format(distro_id, distro_major_version_id) distro = "{}{}".format(distro_id, distro_major_version_id)
# Calculating arguments default from constants # Calculating arguments default from constants
default_mirror = DEFAULT_MIRROR_MAP[distro_id] default_mirror = DEFAULT_MIRROR_MAP.get(distro_id, None)
distro_choices = ["".join(distro_pair) distro_choices = ["".join(distro_pair)
for distro_pair in SUPPORTED_DISTROS] for distro_pair in SUPPORTED_DISTROS]

View File

View File

@ -17,8 +17,8 @@ import argparse
import logging import logging
import sys import sys
import tripleo_yum_config.yum_config as cfg import tripleo_repos.yum_config.yum_config as cfg
import tripleo_yum_config.dnf_manager as dnf_mgr import tripleo_repos.yum_config.dnf_manager as dnf_mgr
def options_to_dict(options): def options_to_dict(options):

View File

@ -13,13 +13,14 @@
# under the License. # under the License.
import logging import logging
import dnf
class DnfModuleManager: class DnfModuleManager:
"""Class that manages dnf modules.""" """Class that manages dnf modules."""
def __init__(self): def __init__(self):
# lazy import to allow CLI to start without dnf
import dnf
self.base = dnf.Base() self.base = dnf.Base()
self.base.conf.read() self.base.conf.read()
self.base.conf.best = True self.base.conf.best = True

View File

@ -15,8 +15,8 @@
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
import tripleo_yum_config.dnf_manager as dnf_mgr import tripleo_repos.yum_config.dnf_manager as dnf_mgr
import tripleo_yum_config.yum_config as cfg import tripleo_repos.yum_config.yum_config as cfg
DOCUMENTATION = r''' DOCUMENTATION = r'''
--- ---

View File

@ -18,8 +18,8 @@ import logging
import os import os
import sys import sys
import tripleo_yum_config.constants as const import tripleo_repos.yum_config.constants as const
import tripleo_yum_config.exceptions as exc import tripleo_repos.yum_config.exceptions as exc
class TripleOYumConfig: class TripleOYumConfig:

View File

@ -5,6 +5,9 @@
- openstack-python3-wallaby-jobs - openstack-python3-wallaby-jobs
check: check:
jobs: &cjobs jobs: &cjobs
- openstack-tox-pep8:
vars:
tox_envlist: pep8,packaging
- openstack-tox-py39 - openstack-tox-py39
- tripleo-buildimage-overcloud-full-centos-8: - tripleo-buildimage-overcloud-full-centos-8:
dependencies: &deps_unit_lint_cprovider dependencies: &deps_unit_lint_cprovider