Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: redhat-openstack/rhos-bootstrap
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.0.1
Choose a base ref
...
head repository: redhat-openstack/rhos-bootstrap
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 19 commits
  • 23 files changed
  • 2 contributors

Commits on Aug 10, 2021

  1. Update ci status url

    mwhahaha committed Aug 10, 2021
    Copy the full SHA
    253afb9 View commit details
  2. Fix rpm spec requires

    mwhahaha committed Aug 10, 2021
    Copy the full SHA
    07a1932 View commit details
  3. Copy the full SHA
    eda8b4f View commit details

Commits on Nov 3, 2021

  1. Copy the full SHA
    9c74943 View commit details

Commits on Nov 4, 2021

  1. Fix package_import_key arg

    It's fullaskcb not fullakscb
    mwhahaha committed Nov 4, 2021
    Copy the full SHA
    d68e590 View commit details
  2. Drop pbr for setuptools

    mwhahaha committed Nov 4, 2021
    Copy the full SHA
    a2be3ea View commit details
  3. Copy the full SHA
    23e1cd8 View commit details
  4. Add setup.py for packaging

    mwhahaha committed Nov 4, 2021
    Copy the full SHA
    cf9aa13 View commit details
  5. setuptools data_files

    mwhahaha committed Nov 4, 2021
    Copy the full SHA
    e1a56c7 View commit details
  6. Packaging updates

    mwhahaha committed Nov 4, 2021
    Copy the full SHA
    deac80e View commit details
  7. More setup changes

    mwhahaha committed Nov 4, 2021
    Copy the full SHA
    0fb12ee View commit details
  8. Copy the full SHA
    6167435 View commit details

Commits on Nov 5, 2021

  1. Fix missing utils from pip install

    The utils code wasn't being included when you pip install. Added it to
    the packages list.
    mwhahaha committed Nov 5, 2021
    Copy the full SHA
    0e64028 View commit details

Commits on Nov 11, 2021

  1. Some UX improvements

    * Fixed logging
    * Added log file /var/log/rhos-bootstrap.log
    mwhahaha committed Nov 11, 2021
    Copy the full SHA
    90c61da View commit details
  2. Merge pull request #1 from mwhahaha/ux-improvements

    Some UX improvements
    mwhahaha authored Nov 11, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    02ca25e View commit details

Commits on Jan 18, 2022

  1. Drop non-stream CentOS 8

    CentOS 8 is EOL now. Let's only define 8-stream.
    mwhahaha committed Jan 18, 2022
    Copy the full SHA
    79cb540 View commit details

Commits on Jan 19, 2022

  1. Merge pull request #2 from mwhahaha/drop-c8

    Drop non-stream CentOS 8
    mwhahaha authored Jan 19, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    024a88b View commit details
  2. Add centos9-stream support

    mwhahaha committed Jan 19, 2022
    Copy the full SHA
    a6ce371 View commit details

Commits on Jan 20, 2022

  1. Merge pull request #3 from mwhahaha/add-c9

    Add centos9-stream support
    cloudnull authored Jan 20, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    68b480d View commit details
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -4,5 +4,6 @@
.tox
.coverage
dist
build
AUTHORS
ChangeLog
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include *.rst
include LICENSE
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ rhos-bootstrap

|CI Status|

.. |CI Status| image:: https://github.com/mwhahaha/rhos-bootstrap/actions/workflows/py-tox.yml/badge.svg
:target: https://github.com/mwhahaha/rhos-bootstrap/actions
.. |CI Status| image:: https://github.com/redhat-openstack/rhos-bootstrap/actions/workflows/py-tox.yml/badge.svg
:target: https://github.com/redhat-openstack/rhos-bootstrap/actions

A bootstrap tool used to handle repository, dnf module configuration, and
tripleoclient installation in preparation for a Red Hat OpenStack installation.
6 changes: 4 additions & 2 deletions contrib/rhos-bootstrap.spec
Original file line number Diff line number Diff line change
@@ -17,12 +17,14 @@ Source: https://github.com/redhat-openstack/rhos-bootstrap/archive/%{ver

BuildArch: noarch

Requires: python3-libdnf
Requires: python3-dnf
Requires: python3-pyyaml
Requires: python3-requests

Suggests: subscription-manager

BuildRequires: python3-pbr >= 2.0.0
BuildRequires: python3-pyyaml
Requires: python3-requests

%{?python_provide:%python_provide python3-%{name}}

9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[build-system]
requires = [
"setuptools",
"setuptools_scm[toml]",
"wheel"
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0
PyYAML
requests
77 changes: 59 additions & 18 deletions rhos_bootstrap/cli.py
Original file line number Diff line number Diff line change
@@ -15,15 +15,18 @@
from __future__ import print_function
import argparse
import logging
import logging.config
import os
import sys

from rhos_bootstrap import distribution
from rhos_bootstrap.exceptions import DistroNotSupported
from rhos_bootstrap.utils.dnf import DnfManager
from rhos_bootstrap.utils.rhsm import SubscriptionManager
from . import distribution
from .exceptions import DistroNotSupported
from .utils.dnf import DnfManager
from .utils.rhsm import SubscriptionManager

LOG = logging.getLogger(__name__)
LOG_FORMAT = "[%(asctime)s] [%(levelname)s]: %(message)s"
LOG_FILE = "/var/log/rhos-bootstrap.log"


class BootstrapCli:
@@ -79,10 +82,8 @@ def parse_args(self):
action="store_true",
default=False,
help=(
"Perform a system update after "
"configuring the system "
"repositories and modules "
"configuration."
"Perform a system update after configuring the system "
"repositories and modules configuration."
),
)
self.parser.add_argument(
@@ -94,21 +95,57 @@ def parse_args(self):
self.parser.add_argument(
"--debug", action="store_true", default=False, help="Enable debug logging"
)
self.parser.add_argument(
"--skip-log-file",
action="store_false",
default=True,
help=f"Disable logging to {LOG_FILE}",
)

args = self.parser.parse_args()
return args

def configure_logger(self, log_file=True, debug=False):
log_level = logging.INFO
if debug:
log_level = logging.DEBUG
conf = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {"standard": {"format": LOG_FORMAT}},
"handlers": {
"default": {
"level": log_level,
"class": "logging.StreamHandler",
"formatter": "standard",
"stream": sys.stdout,
},
"log_file": {
"level": log_level,
"class": "logging.handlers.RotatingFileHandler",
"formatter": "standard",
"filename": LOG_FILE,
"maxBytes": 10485760,
"backupCount": 7,
},
},
"loggers": {
"": {
"handlers": ["default"],
"level": log_level,
"proagate": True,
}
},
}
if log_file:
conf["loggers"][""]["handlers"] = ["default", "log_file"]
logging.config.dictConfig(conf)


def main(): # pylint: disable=too-many-branches,too-many-statements
cli = BootstrapCli()
args = cli.parse_args()

log_level = logging.INFO
if args.debug:
log_level = logging.DEBUG

logging.basicConfig(
format="[%(asctime)s] [%(levelname)s]: %(message)s", level=log_level
)
cli.configure_logger(log_file=args.skip_log_file, debug=args.debug)

if os.getuid() != 0:
LOG.error("You must be root to run this command")
@@ -130,7 +167,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements

if not args.skip_repos:
repos = distro.get_repos(args.version, enable_ceph=not args.skip_ceph_install)
LOG.info("=== Configuring repositories....")
LOG.info("=== Configuring repositories...")

if "rhel" in distro.distro_id:
LOG.info("Disabling all existing configured repositories...")
@@ -146,10 +183,14 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
if not (
args.skip_modules and not args.update_packages and args.skip_client_install
):
LOG.info("=== Configuring dnf...")
# we don't need a manager if we're not calling it
manager = DnfManager.instance()
else:
LOG.info("=== Skipping dnf configuration...")

if not args.skip_modules:
# modules are only an 8 thing
if not args.skip_modules and int(distro.distro_major_version_id) < 9:
modules = distro.get_modules(args.version)
LOG.info("=== Configuring modules...")
for mod in modules:
25 changes: 22 additions & 3 deletions rhos_bootstrap/constants.py
Original file line number Diff line number Diff line change
@@ -16,22 +16,29 @@
import sys

RHOS_VERSIONS_SEARCH_PATHS = [
"/usr/share/rhos-bootstrap",
"/usr/local/share/rhos-bootstrap",
# pkg
os.path.join("/usr", "share", "rhos-bootstrap"),
# sudo pip install
os.path.join("/usr", "local", "share", "rhos-bootstrap"),
# pip install
os.path.join(sys.prefix, "share", "rhos-bootstrap"),
# setup.py build
os.path.join(sys.prefix, "share", "rhos_bootstrap"),
]

YUM_REPO_BASE_DIR = "/etc/yum.repos.d"

DEFAULT_MIRROR_MAP = {
"fedora": "https://mirrors.fedoraproject.org",
"centos": "http://mirror.centos.org",
"centos8-stream": "http://mirror.centos.org",
"centos9-stream": "http://mirror.stream.centos.org",
"ubi": "http://mirror.centos.org",
"rhel": "https://trunk.rdoproject.org",
"rdo": "https://trunk.rdoproject.org",
}

CENTOS_RELEASE_MAP = {"centos8": "8", "centos8-stream": "8-stream"}
CENTOS_RELEASE_MAP = {"centos8-stream": "8-stream", "centos9-stream": "9-stream"}

CENTOS_REPO_MAP = {
"baseos": "BaseOS",
@@ -41,8 +48,20 @@
"powertools": "PowerTools",
"rt": "RT",
"virt": "virt",
"crb": "CRB",
}

# SIG related repo list which is used in path for 9-stream+
CENTOS_SIG_LIST = [
"extras",
"hyperscale",
"infra",
"kmods",
"messaging",
"nfv",
"storage",
]

SUPPORTED_REPOS = [
"ansible",
"ceph",
6 changes: 3 additions & 3 deletions rhos_bootstrap/distribution.py
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ def __init__(
universal_newlines=True,
) as proc:
output = proc.communicate()
print(output)
LOG.debug("os-release info: %s", output)
_id, _version_id, _name = output[0].split("\n")

self._distro_id = distro_id or _id
@@ -65,7 +65,7 @@ def _load_data(self):
LOG.debug("%s does not exist", data_path)
continue
LOG.debug("Found distro data in %s", data_path)
with open(data_path, "r") as data:
with open(data_path, "r", encoding="utf-8") as data:
self._distro_data = yaml.safe_load(data.read())
return
LOG.error("Unable to find a %s.yaml", self.distro_id)
@@ -150,7 +150,7 @@ def validate_distro(self, version) -> bool:
ver = f"{self.distro_major_version_id}.{self.distro_minor_version_id}"
# The output will be "Release not set" or "Release: X.Y"
if "not set" in out or f": {ver}" not in out:
LOG.warning(
LOG.error(
"System not currently locked to the correct release. "
"Please run subscription-manager release --set=%s",
ver,
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@

sys.modules["dnf"] = mock.MagicMock()
sys.modules["dnf.cli.cli"] = mock.MagicMock()
sys.modules["dnf.cli.progress"] = mock.MagicMock()
sys.modules["dnf.exceptions"] = mock.MagicMock()
sys.modules["dnf.logging"] = mock.MagicMock()
sys.modules["libdnf"] = mock.MagicMock()
@@ -98,7 +99,9 @@ def test_data(self, exists_mock):
"builtins.open", mock.mock_open(read_data=DUMMY_CENTOS_DATA)
) as open_mock:
obj = distribution.DistributionInfo("centos", "8", "CentOS Stream")
open_mock.assert_called_with("/usr/share/rhos-bootstrap/centos.yaml", "r")
open_mock.assert_called_with(
"/usr/share/rhos-bootstrap/centos.yaml", "r", encoding="utf-8"
)
self.assertEqual(obj.distro_data, dummy_data)
self.assertEqual(obj.distro_id, "centos")
self.assertEqual(obj.distro_version_id, "8")
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -18,8 +18,11 @@

sys.modules["dnf"] = mock.MagicMock()
sys.modules["dnf.cli.cli"] = mock.MagicMock()
sys.modules["dnf.cli.progress"] = mock.MagicMock()
sys.modules["dnf.exceptions"] = mock.MagicMock()
sys.modules["dnf.logging"] = mock.MagicMock()
sys.modules["dnf.transaction"] = mock.MagicMock()
sys.modules["dnf.yum.rpmtrans"] = mock.MagicMock()
sys.modules["libdnf"] = mock.MagicMock()
from rhos_bootstrap.utils import dnf

Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ def test_save(self, isdir_mock, isfile_mock, access_mock):
with mock.patch("builtins.open", mock.mock_open()) as file_mock:
obj.save()
calls = [
mock.call("/etc/yum.repos.d/foo.repo", "w"),
mock.call("/etc/yum.repos.d/foo.repo", "w", encoding="utf-8"),
mock.call().__enter__(),
mock.call().write(str(obj)),
mock.call().__exit__(None, None, None),
@@ -178,7 +178,9 @@ def test_save(self, isdir_mock, isfile_mock, access_mock):
obj.save()
calls = [
mock.call(
"/etc/yum.repos.d/tripleo-delorean-current-tripleo.repo", "w"
"/etc/yum.repos.d/tripleo-delorean-current-tripleo.repo",
"w",
encoding="utf-8",
),
mock.call().__enter__(),
mock.call().write(str(obj)),
File renamed without changes.
Loading