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

Add test coverage for BZ:2192939 #14025

Merged
merged 2 commits into from
Feb 12, 2024

Conversation

Gauravtalreja1
Copy link
Collaborator

Problem Statement

Missing test coverage for BZ:2192939, which verifies config report generated for host gets Puppet origin correctly, when reports are without any messages.

Solution

  1. Add test to validate config reports gets generated for host and has Puppet origin set correctly, when reports are without any messages.
  2. Updating configure_puppet helper to not run puppet agent if run_puppet_agent=False, after we sign agent's certificate.
  3. Furthermore, additional validation is added for the 'puppetmaster_fqdn' host fact, when puppetmaster is Sat/Cap server, and existing tests are updated accordingly.

@Gauravtalreja1 Gauravtalreja1 added QETestCoverage Issues and PRs relating to a Satellite bug CherryPick PR needs CherryPick to previous branches AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing 6.13.z Introduced in or relating directly to Satellite 6.13 6.14.z Introduced in or relating directly to Satellite 6.14 6.15.z Introduced in or relating directly to Satellite 6.15 labels Feb 8, 2024
@Gauravtalreja1 Gauravtalreja1 self-assigned this Feb 8, 2024
@Gauravtalreja1 Gauravtalreja1 requested review from a team as code owners February 8, 2024 18:24
@Gauravtalreja1 Gauravtalreja1 force-pushed the closeloop-2192939 branch 2 times, most recently from 1f1ff97 to d2f8dcc Compare February 9, 2024 07:14
@Gauravtalreja1
Copy link
Collaborator Author

trigger: test-robottelo
pytest: tests/foreman/cli/test_report.py

Copy link
Member

@jyejare jyejare left a comment

Choose a reason for hiding this comment

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

ACK with curious question for myself.

tests/foreman/cli/test_report.py Show resolved Hide resolved
@Gauravtalreja1
Copy link
Collaborator Author

trigger: test-robottelo
pytest: tests/foreman/cli/test_report.py::test_positive_run_puppet_agent_generate_report_when_no_message

Signed-off-by: Gaurav Talreja <[email protected]>
@Gauravtalreja1
Copy link
Collaborator Author

trigger: test-robottelo
pytest: tests/foreman/cli/test_report.py::test_positive_run_puppet_agent_generate_report_when_no_message

@shubhamsg199 shubhamsg199 merged commit 97d9117 into SatelliteQE:master Feb 12, 2024
6 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 12, 2024
* Add test coverage for BZ:2192939

Signed-off-by: Gaurav Talreja <[email protected]>

* Add :parametrized: keyword to test metadata

Co-authored-by: Shubham Ganar <[email protected]>

---------

Signed-off-by: Gaurav Talreja <[email protected]>
Co-authored-by: Shubham Ganar <[email protected]>
(cherry picked from commit 97d9117)
github-actions bot pushed a commit that referenced this pull request Feb 12, 2024
* Add test coverage for BZ:2192939

Signed-off-by: Gaurav Talreja <[email protected]>

* Add :parametrized: keyword to test metadata

Co-authored-by: Shubham Ganar <[email protected]>

---------

Signed-off-by: Gaurav Talreja <[email protected]>
Co-authored-by: Shubham Ganar <[email protected]>
(cherry picked from commit 97d9117)
github-actions bot pushed a commit that referenced this pull request Feb 12, 2024
* Add test coverage for BZ:2192939

Signed-off-by: Gaurav Talreja <[email protected]>

* Add :parametrized: keyword to test metadata

Co-authored-by: Shubham Ganar <[email protected]>

---------

Signed-off-by: Gaurav Talreja <[email protected]>
Co-authored-by: Shubham Ganar <[email protected]>
(cherry picked from commit 97d9117)
Copy link
Contributor

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

I was out for a few days so a bit late to the party, but I think this needs some work. At least how puppet agent is invoked is wrong and needs to change.

@@ -1023,12 +1023,14 @@ def configure_puppet(self, proxy_hostname=None):
self.execute('/opt/puppetlabs/bin/puppet agent -t')
Copy link
Contributor

Choose a reason for hiding this comment

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

Nowadays (since Puppet 6) if you want to bootstrap you use puppet ssl bootstrap. Then you can sign it. You may want to pass --waitforcert 0 as well to prevent it waiting for the server to sign it.

# This particular puppet run would create the host entity under
# 'All Hosts' and let's redirect stderr to /dev/null as errors at
# this stage can be ignored.
result = self.execute('/opt/puppetlabs/bin/puppet agent -t 2> /dev/null')
Copy link
Contributor

Choose a reason for hiding this comment

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

Using -t isn't quite a good test. While testing the original BZ I noticed it is NOT a reproducer for the issue.

-t (or --test) is a short hand for multiple options. Quoting the man page:

* --test:
  Enable the most common options used for testing. These are 'onetime',
  'verbose', 'no-daemonize', 'no-usecacheonfailure', 'detailed-exitcodes',
  'no-splay', and 'show_diff'.

The --verbose part always creates entries in the report. If you only want to run puppet it should be sufficient to use puppet agent --onetime --no-daemonize --no-splay.

client.configure_puppet(proxy_hostname=sat.hostname, run_puppet_agent=False)
# Run either 'puppet agent --detailed-exitcodes' or 'systemctl restart puppet'
# to generate Puppet config report for host without any messages
assert client.execute('/opt/puppetlabs/bin/puppet agent --detailed-exitcodes').status == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

This starts a daemon. You want to use --onetime --no-daemonize --no-splay as arguments to prevent that.

timeout=300,
delay=30,
)
report = sat.cli.ConfigReport.list({'search': f'host~{client.hostname}'})
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a list of reports while the name implies it is a singular entity. I'd name it reports

)
report = sat.cli.ConfigReport.list({'search': f'host~{client.hostname}'})
assert len(report)
assert report[0]['origin'] == 'Puppet'
Copy link
Contributor

Choose a reason for hiding this comment

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

This will pass if there a report with the origin puppet. How about asserting every report has an origin instead?

assert None not in [report['origin'] for report in reports]

)
assert len(report)
assert report[0]['origin'] == 'Puppet'
facts = session_puppet_enabled_sat.cli.Fact.list({'search': f'host~{client.hostname}'})
assert len(facts)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a rather useless assertion. There's no guarantee that the puppetmaster_fqdn fact is present.

)
assert len(report)
assert report[0]['origin'] == 'Puppet'
facts = session_puppet_enabled_sat.cli.Fact.list({'search': f'host~{client.hostname}'})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not search specifically for the puppetmaster_fqdn fact?

Comment on lines +92 to +94
assert [f for f in facts if f['fact'] == 'puppetmaster_fqdn'][0][
'value'
] == puppet_proxy.hostname
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd write this as:

assert [f['value'] for f in facts if f['fact'] == 'puppetmaster_fqdn'] == [puppet_proxy.hostname]

This won't fail with an IndexError if the puppetmaster_fqdn fact isn't present.

shweta83 pushed a commit to shweta83/robottelo that referenced this pull request Apr 10, 2024
* Add test coverage for BZ:2192939

Signed-off-by: Gaurav Talreja <[email protected]>

* Add :parametrized: keyword to test metadata

Co-authored-by: Shubham Ganar <[email protected]>

---------

Signed-off-by: Gaurav Talreja <[email protected]>
Co-authored-by: Shubham Ganar <[email protected]>
@Gauravtalreja1 Gauravtalreja1 deleted the closeloop-2192939 branch April 13, 2024 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.13.z Introduced in or relating directly to Satellite 6.13 6.14.z Introduced in or relating directly to Satellite 6.14 6.15.z Introduced in or relating directly to Satellite 6.15 AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing CherryPick PR needs CherryPick to previous branches QETestCoverage Issues and PRs relating to a Satellite bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants