Skip to content

Commit

Permalink
Merge branch 'master' into issues/525-2
Browse files Browse the repository at this point in the history
  • Loading branch information
kholdaway committed Feb 2, 2018
2 parents c40a4ff + a29ae77 commit 4231045
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 0 deletions.
2 changes: 2 additions & 0 deletions quipucords/scanner/network/processing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
from . import eap
from . import brms
from . import karaf
from . import cpu
from . import date
74 changes: 74 additions & 0 deletions quipucords/scanner/network/processing/cpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 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.

"""Initial processing of the shell output from the cpu role."""

import logging
from scanner.network.processing import process

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

# pylint: disable=too-few-public-methods

# #### Processors ####


class ProcessCpuModelVer(process.Processor):
"""Process the model version of the cpu."""

KEY = 'cpu_model_ver'

@staticmethod
def process(output):
"""Pass the output back through."""
return output['stdout_lines']


class ProcessCpuCpuFamily(process.Processor):
"""Process the cpu family."""

KEY = 'cpu_cpu_family'

@staticmethod
def process(output):
"""Pass the output back through."""
return output['stdout_lines']


class ProcessCpuVendorId(process.Processor):
"""Process the vendor id of the cpu."""

KEY = 'cpu_vendor_id'

@staticmethod
def process(output):
"""Pass the output back through."""
return output['stdout_lines']


class ProcessCpuModelName(process.Processor):
"""Process the model name of the cpu."""

KEY = 'cpu_model_name'

@staticmethod
def process(output):
"""Pass the output back through."""
return output['stdout_lines']


class ProcessCpuBogomips(process.Processor):
"""Process the bogomips of the cpu."""

KEY = 'cpu_bogomips'

@staticmethod
def process(output):
"""Pass the output back through."""
return output['stdout_lines']
52 changes: 52 additions & 0 deletions quipucords/scanner/network/processing/date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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.

"""Initial processing of the shell output from the date role."""

import logging
from scanner.network.processing import process

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

# pylint: disable=too-few-public-methods

# #### Processors ####


class ProcessDateDate(process.Processor):
"""Process the date fact."""

KEY = 'date_date'

@staticmethod
def process(output):
"""Pass the output back through."""
return output['stdout_lines']


class ProcessDateFilesystemCreate(process.Processor):
"""Process the date filesystem create fact."""

KEY = 'date_filesystem_create'

@staticmethod
def process(output):
"""Pass the output back through."""
return output['stdout_lines']


class ProcessDateMachineId(process.Processor):
"""Process the date machine id fact."""

KEY = 'date_machine_id'

@staticmethod
def process(output):
"""Pass the output back through."""
return output['stdout_lines']
24 changes: 24 additions & 0 deletions quipucords/scanner/network/processing/eap.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,27 @@ class ProcessEapHomeBinForFuse(IndicatorFileFinder):
KEY = 'eap_home_bin'

INDICATOR_FILES = ['fuseconfig.sh', 'fusepatch.sh']


class ProcessEapHomeLayers(process.Processor):
"""Process the output of eap home layers."""

KEY = 'eap_home_layers'

@staticmethod
def process(output):
"""Pass the output back through."""
return {result['item']: result['rc'] == 0
for result in output['results']}


class ProcessEapHomeLayersConf(process.Processor):
"""Process the output of eap home layers conf."""

KEY = 'eap_home_layers_conf'

@staticmethod
def process(output):
"""Pass the output back through."""
return {result['item']: result['rc'] == 0
for result in output['results']}
12 changes: 12 additions & 0 deletions quipucords/scanner/network/processing/karaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ def process(output):
"""Pass the output back through."""
return {result['item']: result['rc'] == 0
for result in output['results']}


class ProcessKarafHomeSystemOrgJboss(process.Processor):
"""Process the karaf_home_system_org_jboss fact."""

KEY = 'karaf_home_system_org_jboss'

@staticmethod
def process(output):
"""Pass the output back through."""
return {str(result['stdout_lines']): result['rc'] == 0
for result in output['results']}
18 changes: 18 additions & 0 deletions quipucords/scanner/network/processing/test_karaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,21 @@ def test_not_found(self):
karaf.ProcessKarafHomeBinFuse.process(ansible_results(
[{'item': 'foo', 'stdout': '', 'rc': 1}])),
{'foo': False})


class TestProcessKarafHomeSystemOrgJboss(unittest.TestCase):
"""Test using locate to find karaf home bin fuse."""

def test_success(self):
"""Found karaf.jar."""
self.assertEqual(
karaf.ProcessKarafHomeSystemOrgJboss.process(ansible_results(
[{'item': 'foo', 'stdout': 'bar'}])),
{str(['bar']): True})

def test_not_found(self):
"""Did not find karaf home bin fuse."""
self.assertEqual(
karaf.ProcessKarafHomeSystemOrgJboss.process(ansible_results(
[{'item': 'foo', 'stdout': '', 'rc': 1}])),
{'[]': False})
106 changes: 106 additions & 0 deletions quipucords/scanner/network/processing/tests_cpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright (c) 2018 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). 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 GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.


"""Unit tests for initial processing of cpu facts."""


import unittest
from scanner.network.processing import cpu
from scanner.network.processing.test_util import ansible_result


class TestProcessCpuModelVer(unittest.TestCase):
"""Test ProcessCpuModelVer."""

def test_success_case(self):
"""Found cpu model ver."""
self.assertEqual(
cpu.ProcessCpuModelVer.process(
ansible_result('a\nb\nc')),
['a', 'b', 'c'])

def test_not_found(self):
"""Did not find cpu model ver."""
self.assertEqual(
cpu.ProcessCpuModelVer.process(
ansible_result('')),
[])


class TestProcessCpuCpuFamily(unittest.TestCase):
"""Test ProcessCpuCpuFamily."""

def test_success_case(self):
"""Found cpu family."""
self.assertEqual(
cpu.ProcessCpuCpuFamily.process(
ansible_result('a\nb\nc')),
['a', 'b', 'c'])

def test__not_found(self):
"""Did not find cpu family."""
self.assertEqual(
cpu.ProcessCpuCpuFamily.process(
ansible_result('')),
[])


class TestProcessCpuVendorId(unittest.TestCase):
"""Test ProcessCpuVendorId."""

def test_success_case(self):
"""Found cpu vendor id."""
self.assertEqual(
cpu.ProcessCpuVendorId.process(
ansible_result('a\nb\nc')),
['a', 'b', 'c'])

def test__not_found(self):
"""Did not find cpu vendor id."""
self.assertEqual(
cpu.ProcessCpuVendorId.process(
ansible_result('')),
[])


class TestProcessCpuModelName(unittest.TestCase):
"""Test ProcessCpuModelName."""

def test_success_case(self):
"""Found cpu model name."""
self.assertEqual(
cpu.ProcessCpuModelName.process(
ansible_result('a\nb\nc')),
['a', 'b', 'c'])

def test__not_found(self):
"""Did not find cpu model name."""
self.assertEqual(
cpu.ProcessCpuModelName.process(
ansible_result('')),
[])


class TestProcessCpuBogomips(unittest.TestCase):
"""Test ProcessCpuBogomips."""

def test_success_case(self):
"""Found cpu bogomips."""
self.assertEqual(
cpu.ProcessCpuBogomips.process(
ansible_result('a\nb\nc')),
['a', 'b', 'c'])

def test__not_found(self):
"""Did not find cpu bogomips."""
self.assertEqual(
cpu.ProcessCpuBogomips.process(
ansible_result('')),
[])
70 changes: 70 additions & 0 deletions quipucords/scanner/network/processing/tests_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright (c) 2018 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). 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 GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.


"""Unit tests for initial processing of date facts."""


import unittest
from scanner.network.processing import date
from scanner.network.processing.test_util import ansible_result


class TestProcessDateDate(unittest.TestCase):
"""Test ProcessDateDate."""

def test_success_case(self):
"""Found date."""
self.assertEqual(
date.ProcessDateDate.process(
ansible_result('a\nb\nc')),
['a', 'b', 'c'])

def test_not_found(self):
"""Did not find date."""
self.assertEqual(
date.ProcessDateDate.process(
ansible_result('')),
[])


class ProcessDateFilesystemCreate(unittest.TestCase):
"""Test ProcessDateFilesystemCreate."""

def test_success_case(self):
"""Found date file system create."""
self.assertEqual(
date.ProcessDateFilesystemCreate.process(
ansible_result('a\nb\nc')),
['a', 'b', 'c'])

def test_not_found(self):
"""Did not find date file system create."""
self.assertEqual(
date.ProcessDateFilesystemCreate.process(
ansible_result('')),
[])


class ProcessDateMachineId(unittest.TestCase):
"""Test ProcessDateFilesystemCreate."""

def test_success_case(self):
"""Found date machine id."""
self.assertEqual(
date.ProcessDateMachineId.process(
ansible_result('a\nb\nc')),
['a', 'b', 'c'])

def test_not_found(self):
"""Did not find date file system create."""
self.assertEqual(
date.ProcessDateMachineId.process(
ansible_result('')),
[])
Loading

0 comments on commit 4231045

Please sign in to comment.