Skip to content

Commit

Permalink
Merge branch 'master' into codecoverage_2173870
Browse files Browse the repository at this point in the history
  • Loading branch information
yanpliu authored May 6, 2024
2 parents 7b914fc + bba4931 commit 73d1c98
Show file tree
Hide file tree
Showing 453 changed files with 1,215 additions and 3,202 deletions.
7 changes: 2 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ repos:
exclude: tests/foreman/data/
- id: check-yaml
- id: debug-statements
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
rev: v0.4.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: local
hooks:
- id: fix-uuids
Expand Down
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Global Configurations for py.test runner"""

import pytest

pytest_plugins = [
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
http://sphinx-doc.org/config.html
"""

import builtins
import os
import sys
Expand Down
34 changes: 13 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
[tool.black]
line-length = 100
skip-string-normalization = true
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.venv
| _build
| buck-out
| build
| dist
)/
'''

[tool.ruff]
target-version = "py311"
# Allow lines to be as long as 100.
line-length = 100
exclude = [".git", ".hg", ".mypy_cache", ".venv", "_build", "buck-out", "build", "dist"]

[tool.ruff.format]
# Preserve quotes
quote-style = "preserve" # TODO: change to "single" when flake8-quotes is enabled

[tool.ruff.lint]
fixable = ["ALL"]

select = [
Expand All @@ -40,21 +32,21 @@ ignore = [
"PT005", # pytest no underscrore prefix for return fixtures
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
force-sort-within-sections = true
known-first-party = [
"robottelo",
]
combine-as-imports = true

[tool.ruff.flake8-pytest-style]
[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

[tool.ruff.flake8-quotes]
[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 20

[tool.pytest.ini_options]
Expand Down
4 changes: 3 additions & 1 deletion pytest_fixtures/component/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from nailgun import entities
import pytest

from robottelo import constants


@pytest.fixture(scope='session')
def default_os(
Expand All @@ -17,7 +19,7 @@ def default_os(
"""
os = getattr(request, 'param', None)
if os is None:
search_string = 'name="RedHat" AND (major="6" OR major="7" OR major="8")'
search_string = constants.DEFAULT_OS_SEARCH_QUERY
else:
version = os.split(' ')[1].split('.')
search_string = f'family="Redhat" AND major="{version[0]}" AND minor="{version[1]}"'
Expand Down
6 changes: 4 additions & 2 deletions pytest_fixtures/component/provision_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
AZURERM_RHEL7_FT_IMG_URN,
AZURERM_RHEL7_UD_IMG_URN,
DEFAULT_ARCHITECTURE,
DEFAULT_OS_SEARCH_QUERY,
)


Expand Down Expand Up @@ -38,8 +39,9 @@ def sat_azure_domain(sat_azure, sat_azure_loc, sat_azure_org):
@pytest.fixture(scope='module')
def sat_azure_default_os(sat_azure):
"""Default OS on the Satellite"""
search_string = 'name="RedHat" AND (major="6" OR major="7" OR major="8" OR major="9")'
return sat_azure.api.OperatingSystem().search(query={'search': search_string})[0].read()
return (
sat_azure.api.OperatingSystem().search(query={'search': DEFAULT_OS_SEARCH_QUERY})[0].read()
)


@pytest.fixture(scope='module')
Expand Down
13 changes: 2 additions & 11 deletions pytest_fixtures/component/provision_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from robottelo.config import settings
from robottelo.constants import (
DEFAULT_ARCHITECTURE,
DEFAULT_OS_SEARCH_QUERY,
DEFAULT_PTABLE,
FOREMAN_PROVIDERS,
GCE_RHEL_CLOUD_PROJECTS,
Expand Down Expand Up @@ -41,8 +42,7 @@ def sat_gce_domain(sat_gce, sat_gce_loc, sat_gce_org):
@pytest.fixture(scope='module')
def sat_gce_default_os(sat_gce):
"""Default OS on the Satellite"""
search_string = 'name="RedHat" AND (major="6" OR major="7" OR major="8" OR major="9")'
return sat_gce.api.OperatingSystem().search(query={'search': search_string})[0].read()
return sat_gce.api.OperatingSystem().search(query={'search': DEFAULT_OS_SEARCH_QUERY})[0].read()


@pytest.fixture(scope='session')
Expand Down Expand Up @@ -103,15 +103,6 @@ def gce_custom_cloudinit_uuid(googleclient, gce_cert):
return googleclient.get_template('customcinit', project=gce_cert['project_id']).uuid


@pytest.fixture(scope='session')
def session_default_os(session_target_sat):
"""Default OS on the Satellite"""
search_string = 'name="RedHat" AND (major="6" OR major="7" OR major="8")'
return (
session_target_sat.api.OperatingSystem().search(query={'search': search_string})[0].read()
)


@pytest.fixture(scope='module')
def module_gce_compute(sat_gce, sat_gce_org, sat_gce_loc, gce_cert):
return sat_gce.api.GCEComputeResource(
Expand Down
13 changes: 7 additions & 6 deletions pytest_fixtures/component/puppet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Puppet Environment fixtures
import pytest

from robottelo.constants import ENVIRONMENT
from robottelo import constants


@pytest.fixture(scope='session')
Expand Down Expand Up @@ -119,10 +119,9 @@ def session_puppet_enabled_proxy(session_puppet_enabled_sat):
@pytest.fixture(scope='session')
def session_puppet_default_os(session_puppet_enabled_sat):
"""Default OS on the puppet-enabled Satellite"""
search_string = 'name="RedHat" AND (major="6" OR major="7" OR major="8")'
return (
session_puppet_enabled_sat.api.OperatingSystem()
.search(query={'search': search_string})[0]
.search(query={'search': constants.DEFAULT_OS_SEARCH_QUERY})[0]
.read()
)

Expand All @@ -141,9 +140,11 @@ def module_puppet_lce_library(session_puppet_enabled_sat, module_puppet_org):
"""Returns the Library lifecycle environment from chosen organization"""
return (
session_puppet_enabled_sat.api.LifecycleEnvironment()
.search(query={'search': f'name={ENVIRONMENT} and organization_id={module_puppet_org.id}'})[
0
]
.search(
query={
'search': f'name={constants.ENVIRONMENT} and organization_id={module_puppet_org.id}'
}
)[0]
.read()
)

Expand Down
52 changes: 27 additions & 25 deletions pytest_fixtures/component/satellite_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from robottelo.hosts import IPAHost, SSOHost
from robottelo.utils.datafactory import gen_string
from robottelo.utils.installer import InstallerCommand
from robottelo.utils.issue_handlers import is_open

LOGGEDOUT = 'Logged out.'

Expand Down Expand Up @@ -282,42 +281,45 @@ def auth_data(request, ad_data, ipa_data):
@pytest.fixture(scope='module')
def enroll_configure_rhsso_external_auth(module_target_sat):
"""Enroll the Satellite6 Server to an RHSSO Server."""
module_target_sat.execute(
'yum -y --disableplugin=foreman-protector install '
'mod_auth_openidc keycloak-httpd-client-install'
module_target_sat.register_to_cdn()
# keycloak-httpd-client-install needs lxml but it's not an rpm dependency + is not documented
assert (
module_target_sat.execute(
'yum -y --disableplugin=foreman-protector install '
'mod_auth_openidc keycloak-httpd-client-install python3-lxml '
).status
== 0
)
# if target directory not given it is installing in /usr/local/lib64
module_target_sat.execute('python3 -m pip install lxml -t /usr/lib64/python3.6/site-packages')
module_target_sat.execute(
f'openssl s_client -connect {settings.rhsso.host_name} -showcerts </dev/null 2>/dev/null| '
f'sed "/BEGIN CERTIFICATE/,/END CERTIFICATE/!d" > {CERT_PATH}/rh-sso.crt'
)
module_target_sat.execute(
f'sshpass -p "{settings.rhsso.rhsso_password}" scp -o "StrictHostKeyChecking no" '
f'root@{settings.rhsso.host_name}:/root/ca_certs/*.crt {CERT_PATH}'
assert (
module_target_sat.execute(
f'openssl s_client -connect {settings.rhsso.host_name}:443 -showcerts </dev/null 2>/dev/null| '
f'sed "/BEGIN CERTIFICATE/,/END CERTIFICATE/!d" > {CERT_PATH}/rh-sso.crt'
).status
== 0
)
module_target_sat.execute('update-ca-trust')
module_target_sat.execute(
f'echo {settings.rhsso.rhsso_password} | keycloak-httpd-client-install \
assert (
module_target_sat.execute(
f'echo {settings.rhsso.rhsso_password} | keycloak-httpd-client-install \
--app-name foreman-openidc \
--keycloak-server-url {settings.rhsso.host_url} \
--keycloak-admin-username "admin" \
--keycloak-realm "{settings.rhsso.realm}" \
--keycloak-admin-realm master \
--keycloak-auth-role root-admin -t openidc -l /users/extlogin --force'
).status
== 0
)
if is_open('BZ:2113905'):
assert (
module_target_sat.execute(
r"sed -i -e '$aapache::default_mods:\n - authn_core' "
"/etc/foreman-installer/custom-hiera.yaml"
)
module_target_sat.execute(
f'satellite-installer --foreman-keycloak true '
f"--foreman-keycloak-app-name 'foreman-openidc' "
f"--foreman-keycloak-realm '{settings.rhsso.realm}' ",
timeout=1000000,
f'satellite-installer --foreman-keycloak true '
f"--foreman-keycloak-app-name 'foreman-openidc' "
f"--foreman-keycloak-realm '{settings.rhsso.realm}' ",
timeout=1000000,
).status
== 0
)
module_target_sat.execute('systemctl restart httpd')
assert module_target_sat.execute('systemctl restart httpd').status == 0


@pytest.fixture(scope='module')
Expand Down
6 changes: 1 addition & 5 deletions pytest_fixtures/component/virtwho_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ def org_module(request, default_org, module_sca_manifest_org):

@pytest.fixture
def org_session(request, session, session_sca):
if 'sca' in request.module.__name__.split('.')[-1]:
org_session = session_sca
else:
org_session = session
return org_session
return session_sca if 'sca' in request.module.__name__.split('.')[-1] else session


@pytest.fixture
Expand Down
1 change: 1 addition & 0 deletions pytest_fixtures/core/contenthosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
The functions in this module are read in the pytest_plugins/fixture_markers.py module
All functions in this module will be treated as fixtures that apply the contenthost mark
"""

from broker import Broker
import pytest

Expand Down
5 changes: 1 addition & 4 deletions pytest_fixtures/core/xdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ def align_to_satellite(request, worker_id, satellite_factory):
settings.set("server.hostname", None)
on_demand_sat = None

if worker_id in ['master', 'local']:
worker_pos = 0
else:
worker_pos = int(worker_id.replace('gw', ''))
worker_pos = 0 if worker_id in ["master", "local"] else int(worker_id.replace("gw", ""))

# attempt to add potential satellites from the broker inventory file
if settings.server.inventory_filter:
Expand Down
1 change: 0 additions & 1 deletion pytest_plugins/capsule_n-minus.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def pytest_addoption(parser):


def pytest_collection_modifyitems(items, config):

if not config.getoption('n_minus', False):
return

Expand Down
1 change: 0 additions & 1 deletion pytest_plugins/requirements/req_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class ReqUpdater:

# Installed package name as key and its counterpart in requirements file as value
package_deviates = {
'Betelgeuse': 'betelgeuse',
Expand Down
1 change: 1 addition & 0 deletions pytest_plugins/requirements/update_requirements.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plugin enables pytest to notify and update the requirements"""

from .req_updater import ReqUpdater

updater = ReqUpdater()
Expand Down
2 changes: 1 addition & 1 deletion pytest_plugins/sanity_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" A sanity testing plugin to assist in executing robottelo tests as sanity tests smartly
"""A sanity testing plugin to assist in executing robottelo tests as sanity tests smartly
1. Make installer test to run first which should set the hostname and all other tests then
should run after that
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ navmazing==1.2.2
productmd==1.38
pyotp==2.9.0
python-box==7.1.1
pytest==8.1.1
pytest==8.2.0
pytest-order==1.2.1
pytest-services==2.2.1
pytest-mock==3.14.0
Expand Down
1 change: 1 addition & 0 deletions robottelo/cli/acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
update Update an alternate content source.
"""

from robottelo.cli.base import Base


Expand Down
1 change: 1 addition & 0 deletions robottelo/cli/activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
subscriptions List associated subscriptions
update Update an activation key
"""

from robottelo.cli.base import Base


Expand Down
1 change: 1 addition & 0 deletions robottelo/cli/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Options:
-h, --help Print help
"""

from robottelo.cli.base import Base


Expand Down
1 change: 1 addition & 0 deletions robottelo/cli/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
roles Manage ansible roles
variables Manage ansible variables
"""

from robottelo.cli.base import Base


Expand Down
1 change: 1 addition & 0 deletions robottelo/cli/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
remove_operatingsystem Disassociate a resource
update Update an architecture.
"""

from robottelo.cli.base import Base


Expand Down
1 change: 1 addition & 0 deletions robottelo/cli/arfreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
list List ARF reports
"""

from robottelo.cli.base import Base


Expand Down
Loading

0 comments on commit 73d1c98

Please sign in to comment.