Skip to content

Commit

Permalink
cherry-picks of FAM test fixes for 6.15.z (#17164)
Browse files Browse the repository at this point in the history
* disable pytest plugin autoloading when running FAM tests (#16975)

pytest by default tries to load all plugins it finds on a system.
pulpcore ships with own pytest plugins, but we do not install their
dependencies (as we don't want to run pulpcore tests), which leads to
pytest failing to load those plugins and breaking overall execution:

    Traceback (most recent call last):
      File "/usr/bin/pytest-3.11", line 33, in <module>
        sys.exit(load_entry_point('pytest==7.2.0', 'console_scripts', 'pytest')())
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/site-packages/_pytest/config/__init__.py", line 190, in console_main
        code = main()
               ^^^^^^
      File "/usr/lib/python3.11/site-packages/_pytest/config/__init__.py", line 148, in main
        config = _prepareconfig(args, plugins)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/site-packages/_pytest/config/__init__.py", line 329, in _prepareconfig
        config = pluginmanager.hook.pytest_cmdline_parse(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/site-packages/pluggy/_hooks.py", line 265, in __call__
        return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 80, in _hookexec
        return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 55, in _multicall
        gen.send(outcome)
      File "/usr/lib/python3.11/site-packages/_pytest/helpconfig.py", line 103, in pytest_cmdline_parse
        config: Config = outcome.get_result()
                         ^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/site-packages/pluggy/_result.py", line 60, in get_result
        raise ex[1].with_traceback(ex[2])
      File "/usr/lib/python3.11/site-packages/pluggy/_callers.py", line 39, in _multicall
        res = hook_impl.function(*args)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1058, in pytest_cmdline_parse
        self.parse(args)
      File "/usr/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1346, in parse
        self._preparse(args, addopts=addopts)
      File "/usr/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1229, in _preparse
        self.pluginmanager.load_setuptools_entrypoints("pytest11")
      File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
        plugin = ep.load()
                 ^^^^^^^^^
      File "/usr/lib64/python3.11/importlib/metadata/__init__.py", line 202, in load
        module = import_module(match.group('module'))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
      File "/usr/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 168, in exec_module
        exec(co, module.__dict__)
      File "/usr/lib/python3.11/site-packages/pulp_ansible/pytest_plugin.py", line 3, in <module>
        import numpy as np
    ModuleNotFoundError: No module named 'numpy'

Disable the autoloading by setting the PYTEST_DISABLE_PLUGIN_AUTOLOAD
environment variable.

(cherry picked from commit 6a91dd9)

* simplify FAM test command (#16980)

- we don't need to export vars, setting them should be sufficient
- make can change directories for us, no need to cd

(cherry picked from commit fefe1ea)

* create a fake ntp module for FAM tests (#16997)

* use sat.put() instead of sat.execute(echo) to place puppet files

* allow passing in custom module code

* create a fake ntp module

the one in the repo is too old

(cherry picked from commit 39769a5)

* better logging of fam failures (#16967)

(cherry picked from commit 04976cc)
  • Loading branch information
evgeni authored Dec 13, 2024
1 parent 6f6f79e commit 2bb7b1e
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions tests/foreman/sys/test_fam.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,29 @@ def setup_fam(module_target_sat, module_sca_manifest, install_import_ansible_rol
f'''sed -i 's|subscription_manifest_path:.*|subscription_manifest_path: "data/{module_sca_manifest.name}"|g' {config_file}'''
)

repo_path = '/fake_puppet1/system/releases/p/puppetlabs/'
module_tarball = 'puppetlabs-ntp-3.0.3.tar.gz'
local_path = '/tmp'
module_target_sat.execute(
f'curl --output {local_path}/{module_tarball} {settings.robottelo.repos_hosting_url}{repo_path}{module_tarball}',
)
module_target_sat.execute(
f'puppet module install --ignore-dependencies {local_path}/{module_tarball}'
)

def create_fake_module(module_target_sat, module_name, module_classes):
base_dir = '/etc/puppetlabs/code/environments/production/modules'
module_dir = f'{base_dir}/{module_name}'
manifest_dir = f'{module_dir}/manifests'
module_target_sat.execute(f'mkdir -p {manifest_dir}')
for module_class in module_classes:
if isinstance(module_class, str):
module_code = '(){}'
else:
module_class, module_code = module_class
full_class = module_name if module_class == 'init' else f'{module_name}::{module_class}'
module_target_sat.execute(
f'echo "class {full_class}(){{}}" > {manifest_dir}/{module_class}.pp'
module_target_sat.put(
f'class {full_class}{module_code}',
f'{manifest_dir}/{module_class}.pp',
temp_file=True,
)

create_fake_module(
module_target_sat,
'ntp',
[('init', '($logfile, $config_dir, $servers, $burst, $stepout){}'), 'config'],
)

create_fake_module(
module_target_sat,
'prometheus',
Expand Down Expand Up @@ -190,7 +192,6 @@ def test_positive_run_modules_and_roles(module_target_sat, setup_fam, ansible_mo

# Execute test_playbook
result = module_target_sat.execute(
f'export NO_COLOR=True && cd {FAM_ROOT_DIR} && make livetest_{ansible_module} PYTHON_COMMAND="python3" PYTEST_COMMAND="pytest-3.11"'
f'NO_COLOR=1 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 make --directory {FAM_ROOT_DIR} livetest_{ansible_module} PYTHON_COMMAND="python3" PYTEST_COMMAND="pytest-3.11"'
)
assert 'PASSED' in result.stdout
assert result.status == 0
assert result.status == 0, f"{result.status=}\n{result.stdout=}\n{result.stderr=}"

0 comments on commit 2bb7b1e

Please sign in to comment.