Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/quipucords/quipucords int…
Browse files Browse the repository at this point in the history
…o iss/542
  • Loading branch information
abaiken committed Jan 31, 2018
2 parents 8be4652 + 68c2326 commit 20499c0
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 46 deletions.
8 changes: 6 additions & 2 deletions quipucords/scanner/network/processing/eap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""Initial processing of raw shell output from Ansible commands."""

import logging
from scanner.network.processing import process
from scanner.network.processing import process, util

logger = logging.getLogger(__name__) # pylint: disable=invalid-name

Expand Down Expand Up @@ -169,16 +169,20 @@ def process(output):
return matches


class ProcessJbossEapChkconfig(InitLineFinder):
class ProcessJbossEapChkconfig(util.InitLineFinder):
"""Process the output of 'chkconfig'."""

DEPS = ['have_chkconfig']
KEY = 'jboss_eap_chkconfig'
KEYWORDS = ['jboss', 'eap']


class ProcessJbossEapSystemctl(InitLineFinder):
"""Process the output of 'systemctl list-unit-files'."""

DEPS = ['have_systemctl']
KEY = 'jboss_eap_systemctl_unit_files'
KEYWORDS = ['jboss', 'eap']


class IndicatorFileFinder(process.Processor):
Expand Down
38 changes: 7 additions & 31 deletions quipucords/scanner/network/processing/karaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""Initial processing of the shell output from the jboss_fuse_on_karaf role."""

import logging
from scanner.network.processing import process
from scanner.network.processing import process, util

logger = logging.getLogger(__name__) # pylint: disable=invalid-name

Expand Down Expand Up @@ -63,44 +63,20 @@ def process(output):
return output['stdout_lines']


class InitLineFinder(process.Processor):
"""Process the output of an init system.
For both chkconfig and systemctl list-unit-files, we look for
lines where the first (whitespace-delineated) element contains
'jboss' or 'fuse'.
"""

# This same code is in eap but I wasn't sure how to make the keyword an
# argument since it is in a class (without doing an __init__)
KEY = None

@staticmethod
def process(output):
"""Find lines where the first element contains 'jboss' or 'fuse'."""
matches = []

for line in output['stdout_lines']:
if not line:
continue

start = line.split()[0]
if 'jboss' in start or 'fuse' in start:
matches.append(line.strip())

return matches


class ProcessJbossFuseChkconfig(InitLineFinder):
class ProcessJbossFuseChkconfig(util.InitLineFinder):
"""Process the output of 'chkconfig'."""

DEPS = ['have_chkconfig']
KEY = 'jboss_fuse_chkconfig'
KEYWORDS = ['jboss', 'fuse']


class ProcessJbossFuseSystemctl(InitLineFinder):
class ProcessJbossFuseSystemctl(util.InitLineFinder):
"""Process the output of 'systemctl list-unit-files'."""

DEPS = ['have_systemctl']
KEY = 'jboss_fuse_systemctl_unit_files'
KEYWORDS = ['jboss', 'fuse']


class ProcessKarafHomeBinFuse(process.Processor):
Expand Down
41 changes: 41 additions & 0 deletions quipucords/scanner/network/processing/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2018 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 3 (GPLv3). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv3
# along with this software; if not, see
# https://www.gnu.org/licenses/gpl-3.0.txt.

"""Utilities for processing Ansible task outputs."""

from scanner.network.processing import process


# pylint: disable=too-few-public-methods
class InitLineFinder(process.Processor):
"""Process the output of an init system.
For both chkconfig and systemctl list-unit-files, we look for
lines where the first (whitespace-delineated) element contains
keywords.
"""

KEY = None
KEYWORDS = None # A list of keywords to search for

@classmethod
def process(cls, output):
"""Find lines where the first element contains a keyword."""
matches = []

for line in output['stdout_lines']:
if not line:
continue

start = line.split()[0]
# pylint: disable=not-an-iterable
if any((keyword in start for keyword in cls.KEYWORDS)):
matches.append(line.strip())

return matches
16 changes: 8 additions & 8 deletions roles/check_dependencies/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,23 @@
set_fact:
have_locate: "{{ internal_have_locate_cmd.get('rc') == 0 }}"

- name: gather internal_have_systemctl
- name: gather internal_have_systemctl_cmd
raw: command -v systemctl
register: internal_have_systemctl
register: internal_have_systemctl_cmd
ignore_errors: yes

- name: set internal_have_systemctl
- name: set have_systemctl
set_fact:
internal_have_systemctl: "{{ internal_have_systemctl.get('rc') == 0 }}"
have_systemctl: "{{ internal_have_systemctl_cmd.get('rc') == 0 }}"

- name: gather internal_have_chkconfig
- name: gather internal_have_chkconfig_cmd
raw: command -v chkconfig
register: internal_have_chkconfig
register: internal_have_chkconfig_cmd
ignore_errors: yes

- name: set internal_have_chkconfig
- name: set have_chkconfig
set_fact:
internal_have_chkconfig: "{{ internal_have_chkconfig.get('rc') == 0 }}"
have_chkconfig: "{{ internal_have_chkconfig_cmd.get('rc') == 0 }}"

- name: gather internal_have_ifconfig_cmd
raw: command -v ifconfig
Expand Down
6 changes: 3 additions & 3 deletions roles/jboss_eap/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@
register: jboss_eap_systemctl_unit_files
ignore_errors: yes
become: true
when: 'jboss_eap'
when: 'jboss_eap and have_systemctl'

- name: look for jboss in chkconfig
raw: chkconfig
raw: chkconfig --list
register: jboss_eap_chkconfig
ignore_errors: yes
become: true
when: 'jboss_eap'
when: 'jboss_eap and have_chkconfig'
4 changes: 2 additions & 2 deletions roles/jboss_fuse_on_karaf/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@
# KARAF_HOME (or even whether it's Fuse-on-Karaf or Fuse-on-EAP).

- name: look for fuse systemd service
raw: systemctl list-unit-files | grep fuse
raw: systemctl list-unit-files --no-pager
register: jboss_fuse_systemctl_unit_files
ignore_errors: yes
become: true
when: 'jboss_fuse'

- name: look for fuse in chkconfig
raw: chkconfig 2> /dev/null | grep fuse
raw: chkconfig --list
register: jboss_fuse_chkconfig
ignore_errors: yes
become: true
Expand Down

0 comments on commit 20499c0

Please sign in to comment.