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 nrpe check tests for manila-ganesha charm #806

Conversation

chanchiwai-ray
Copy link
Contributor

@chanchiwai-ray chanchiwai-ray commented Jun 30, 2022

This PR adds nrpe check tests for manila-ganesha charm. It's accompanied by the new features proposed in https://review.opendev.org/c/openstack/charm-manila-ganesha/+/848219

- Check if the custom plugins are being installed
- Check if the custom cronjobs are being installed
- Check if the NRPE services are being added.
- The tests will not be ran if nrpe does not exists.
Copy link
Contributor

@ajkavanagh ajkavanagh left a comment

Choose a reason for hiding this comment

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

Please see inline; also note that the PR description needs filling out too. Thanks.

Comment on lines 67 to 68
logging.warn("Skipping as nrpe is not deployed.")
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use self.skipTest(...) to skip a test.

try:
zaza.model.get_application("nrpe")
except KeyError:
logging.warn("Skipping as nrpe is not deployed.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use self.skipTest(...) to skip a test.

zaza.model.get_application("nrpe")
except KeyError:
logging.warn("Skipping as nrpe is not deployed.")
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use self.skipTest(...) to skip a test.

Comment on lines 73 to 75
cmds = []
for check_name in plugins:
cmds.append(f'ls /usr/local/lib/nagios/plugins/{check_name}')
Copy link
Contributor

Choose a reason for hiding this comment

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

It's nicer (and more efficient) to use a list comprehension here:

cmds = [f'ls ... {check_name}' for check_name in plugins]

Comment on lines 97 to 99
cmds = []
for check_name in plugins:
cmds.append(f'ls /etc/cron.d/nagios-check_{check_name}')
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, please think of a list comprehension here.

Comment on lines 121 to 126
cmds = []
for check_name in services:
cmds.append(
'egrep -oh /usr/local.* /etc/nagios/nrpe.d/'
'check_{}.cfg'.format(check_name)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

As above.

Comment on lines 77 to 84
for attempt in tenacity.Retrying(
wait=tenacity.wait_fixed(20),
stop=tenacity.stop_after_attempt(2),
reraise=True
):
with attempt:
ret = generic_utils.check_commands_on_units(cmds, units)
self.assertIsNone(ret, msg=ret)
Copy link
Contributor

Choose a reason for hiding this comment

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

This pattern is repeated 3 times; please consider a refactor to pull this into a helper function.

@chanchiwai-ray
Copy link
Contributor Author

chanchiwai-ray commented Jul 2, 2022

Thanks for the comments. I have refactored the code and updated the description of the PR, please have a look again.

@chanchiwai-ray chanchiwai-ray changed the title Add nrpe check manila ganesha Add nrpe check tests for manila-ganesha charm Jul 2, 2022
Copy link
Contributor

@ajkavanagh ajkavanagh left a comment

Choose a reason for hiding this comment

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

LGTM; that's a really nice refactor of the original patch and it is much easier to understand now. Thanks.

]

commands = [
f"ls /usr/local/lib/nagios/plugins/{plugin}"
Copy link
Contributor

Choose a reason for hiding this comment

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

From the py35 test run:

zaza/openstack/charm_tests/manila_ganesha/tests.py:88:56: E999 SyntaxError: invalid syntax

Py3.5.sadly doesn't support f-strings. You'll need to use .format(...) here instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks for the hints!

Copy link
Contributor

@ajkavanagh ajkavanagh left a comment

Choose a reason for hiding this comment

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

See inline; unfortunately f-strings are not compatible with Python 3.5

Copy link
Contributor

@ajkavanagh ajkavanagh left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the update to fix the pep8 error.

@ajkavanagh ajkavanagh merged commit 31d806c into openstack-charmers:master Jul 5, 2022
openstack-mirroring pushed a commit to openstack/charm-manila-ganesha that referenced this pull request Jul 5, 2022
- added 3 basic checks to check: nfs connection, nfs services, and nfs shares
- updated test bundles to include nrpe and nrpe-external-master for
  functional tests.

func-test-pr: openstack-charmers/zaza-openstack-tests#806

Closes-bug: #1925975
Change-Id: I4d3736300f75b9811f4f6525b5454c7e495ef566
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Jul 5, 2022
* Update charm-manila-ganesha from branch 'master'
  to 65ca408318ac637ef4787e61d5ec48f4d4477502
  - Added NRPE checks for manila-ganesha charm.
    
    - added 3 basic checks to check: nfs connection, nfs services, and nfs shares
    - updated test bundles to include nrpe and nrpe-external-master for
      functional tests.
    
    func-test-pr: openstack-charmers/zaza-openstack-tests#806
    
    Closes-bug: #1925975
    Change-Id: I4d3736300f75b9811f4f6525b5454c7e495ef566
@chanchiwai-ray chanchiwai-ray deleted the add_nrpe_check_manila_ganesha branch July 5, 2022 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants