Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare puppet classes needed for FAM tests in setup_fam #16728

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/foreman/sys/test_fam.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,38 @@ 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):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jameer asked via Slack what's exactly happening here, and I think we can write it down here in the PR for anyone who will come back and read it later:

I need puppet modules for the tests. 1/ the prometheus module (with those exporter subclasses) and 2/ "some rando module, just something that can be imported"
in both cases, I don't actually care about them to have any working puppet code in them, as long as the names (of modules/classes) are as I want them to

a trivial Puppet class definition is:

class some_name(){
}

or also

class some_name(){}

if I want to ignore newlines/readability

so the code (create_fake_module) goes and given the name of a module (e.g. prometheus) and classes inside that module (e.g. ['init', 'haproxy_exporter', 'redis_exporter', 'statsd_exporter']) it:

  1. creates the folder where these files would live (/etc/puppetlabs/code/environments/production/modules/prometheus/manifests) (and it's parents, mkdir -p does that for us)
  2. in this folder it creates "empty" class files, an init.pp with class prometheus(){}, a haproxy_exporter.pp with class prometheus::haproxy_exporter(){}, etc…

For Puppet/Foreman this looks like totally legit normal Puppet modules, they can be imported into Foreman and applied to Hosts/Hostsgroups, and that's all we care about

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:
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'
)

create_fake_module(
module_target_sat,
'prometheus',
['init', 'haproxy_exporter', 'redis_exporter', 'statsd_exporter'],
)

smart_proxy = module_target_sat.nailgun_smart_proxy.read()
smart_proxy.import_puppetclasses()

create_fake_module(module_target_sat, 'fakemodule', ['init'])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could argue this should rather happen inside test_positive_run_modules_and_roles when testing the puppetclasses_import module.



@pytest.mark.pit_server
@pytest.mark.run_in_one_thread
Expand Down
Loading