Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Use 'locate' command to find jboss-modules.jar
Browse files Browse the repository at this point in the history
This lets us scan the whole filesystem (or at least the locate
database) when it's been preindexed.
  • Loading branch information
Noah Lavine committed Nov 1, 2017
1 parent 816e83a commit f041d1e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
30 changes: 30 additions & 0 deletions library/spit_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,35 @@ def process_jboss_eap_packages(fact_names, host_vars):
'{0} JBoss-related packages found'.format(num_packages)}


JBOSS_EAP_LOCATE_JBOSS_MODULES_JAR = 'jboss.eap.locate-jboss-modules-jar'


def process_jboss_eap_locate(fact_names, host_vars):
"""Process the results of 'locate jboss-modules.jar'.
:returns: a dict of key, value pairs to add to the output.
"""

err, output = raw_output_present(fact_names, host_vars,
JBOSS_EAP_LOCATE_JBOSS_MODULES_JAR,
'jboss_eap_locate_jboss_modules_jar',
'locate jboss-modules.jar')
if err is not None:
return err

if not output['rc'] and output['stdout_lines']:
return {JBOSS_EAP_LOCATE_JBOSS_MODULES_JAR:
';'.join(output['stdout_lines'])}

if output['rc'] and not output['stdout_lines']:
return {JBOSS_EAP_LOCATE_JBOSS_MODULES_JAR:
'jboss-modules.jar not found'}

return {JBOSS_EAP_LOCATE_JBOSS_MODULES_JAR:
"Error code {0} running 'locate jboss-modules.jar': {1}".format(
output['rc'], output['stdout'])}


def escape_characters(data):
""" Processes input data values and strips out any newlines or commas
"""
Expand Down Expand Up @@ -745,6 +774,7 @@ def write_to_csv(self):
host_vals.update(process_jboss_eap_common_files(keys, host_vars))
host_vals.update(process_jboss_eap_processes(keys, host_vars))
host_vals.update(process_jboss_eap_packages(keys, host_vars))
host_vals.update(process_jboss_eap_locate(keys, host_vars))

# Process System ID.
for data in self.vals:
Expand Down
3 changes: 3 additions & 0 deletions rho/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def new_fact(fact_name, description, is_default=None,
new_fact('jboss.eap.installed-versions',
'List of installed versions of JBoss EAP',
is_default=False)
new_fact('jboss.eap.locate-jboss-modules-jar',
'Use locate to find jboss-modules.jar',
is_default=True)
new_fact('jboss.eap.jboss-user', "Whether a user called 'jboss' exists",
is_default=True, categories=[JBOSS_FACTS])
new_fact('jboss.eap.packages', 'Installed RPMs that look like JBoss',
Expand Down
5 changes: 5 additions & 0 deletions roles/jboss_eap/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@
register: jboss.eap.packages
ignore_errors: yes
when: '"jboss.eap.packages" in facts_to_collect'
- name: use locate to look for jboss-modules.jar
raw: locate jboss-modules.jar
register: jboss_eap_locate_jboss_modules_jar
ignore_errors: yes
when: '"jboss.eap.locate-jboss-modules-jar" in facts_to_collect'
37 changes: 37 additions & 0 deletions test/test_spit_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,40 @@ def test_rpm_packages_no_rpm(self):
self.assertEqual(results['redhat-packages.gpg.last_installed'], '')
self.assertIn('redhat-packages.gpg.last_built', results)
self.assertEqual(results['redhat-packages.gpg.last_built'], '')


class TestProcessJbossLocateJbossModulesJar(unittest.TestCase):
def run_expect_well_formed(self, output):
val = spit_results.process_jboss_eap_locate(
[spit_results.JBOSS_EAP_LOCATE_JBOSS_MODULES_JAR],
{'jboss_eap_locate_jboss_modules_jar': output})

self.assertIsInstance(val, dict)
self.assertEqual(len(val), 1)
self.assertIn(spit_results.JBOSS_EAP_LOCATE_JBOSS_MODULES_JAR, val)

return val[spit_results.JBOSS_EAP_LOCATE_JBOSS_MODULES_JAR]

# Most of the error handling is in
# spit_results.raw_output_present, which is tested elsewhere, so
# we don't need to repeat those tests here.

def test_success(self):
self.assertEqual(
self.run_expect_well_formed(
{'rc': 0, 'stdout_lines': ['a', 'b', 'c']}),
'a;b;c')

def test_not_found(self):
self.assertEqual(
self.run_expect_well_formed(
{'rc': 1, 'stdout_lines': []}),
'jboss-modules.jar not found')

def test_bad_output(self):
self.assertEqual(
self.run_expect_well_formed(
{'rc': 1, 'stdout': "Command 'locate' not found",
'stdout_lines': ["Command 'locate' not found"]}),
"Error code 1 running 'locate jboss-modules.jar': "
"Command 'locate' not found")

0 comments on commit f041d1e

Please sign in to comment.