Skip to content

Commit

Permalink
Merge pull request #24 from datadope-io/fix/recursive_ppid
Browse files Browse the repository at this point in the history
  • Loading branch information
david-ns authored May 9, 2024
2 parents 949cb91 + c6dd6e6 commit 74600fc
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/repo-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- stable-2.13
- stable-2.14
- stable-2.15
- stable-2.16
- stable-2.17
- devel
python:
- '3.10'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/repo-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- stable-2.14
- stable-2.15
- stable-2.16
- stable-2.17
- devel
python:
- '3.10'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/repo-units.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- stable-2.13
- stable-2.14
- stable-2.15
- stable-2.16
- stable-2.17
- devel
python:
- '3.10'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.10.1

## Fixed

- Avoid loops when a pid has it's ppid as pid on its child at any depth.

# 1.10.0

## Features
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace: datadope
name: discovery

# The version of the collection. Must be compatible with semantic versioning
version: 1.10.0
version: 1.10.1

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
2 changes: 1 addition & 1 deletion plugins/action/software_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def _check_process_hierarchy(self, hierarchical_processes_by_pid, process, softw
ppid = process['ppid']
if int(ppid) > 0 and ppid not in tested_pids and ppid not in used_pids \
and ppid in hierarchical_processes_by_pid:
tested_pids.append(ppid)
found = self._check_process_hierarchy(hierarchical_processes_by_pid, hierarchical_processes_by_pid[ppid],
software_processes, tested_pids, used_pids)
if not found:
found = self._check_process_is_sw(hierarchical_processes_by_pid, process, software_processes, used_pids)
tested_pids.append(ppid)
return found

def _children_pids(self, process, pids):
Expand Down
84 changes: 84 additions & 0 deletions tests/sanity/ignore-2.18.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
tests/unit/plugins/action/auto/conftest.py pylint:disallowed-name
plugins/action_utils/software_facts/parsers/environ.py pylint:disallowed-name
plugins/action/software_facts.py pylint:raising-bad-type # Code is correct. Test is failing
plugins/module_utils/file_parser/apache_webserver/errors.py pylint!skip
plugins/module_utils/file_parser/apache_webserver/lexer.py pylint!skip
plugins/module_utils/file_parser/apache_webserver/loader.py pylint!skip
plugins/module_utils/file_parser/apache_webserver/parser.py pylint!skip
plugins/module_utils/file_parser/haproxy/lexer.py pylint!skip
plugins/module_utils/file_parser/haproxy/loader.py pylint!skip
plugins/module_utils/file_parser/haproxy/parser.py pylint!skip
plugins/module_utils/file_parser/keepalived/lexer.py pylint!skip
plugins/module_utils/file_parser/keepalived/loader.py pylint!skip
plugins/module_utils/file_parser/keepalived/parser.py pylint!skip
plugins/module_utils/file_parser/nginx/lexer.py pylint!skip
plugins/module_utils/file_parser/nginx/loader.py pylint!skip
plugins/module_utils/file_parser/nginx/parser.py pylint!skip
plugins/module_utils/file_parser/lex.py pylint!skip
plugins/module_utils/file_parser/yacc.py pylint!skip
plugins/action_utils/software_facts/xmltodict.py pylint!skip
plugins/action_utils/software_facts/compat/__init__.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/config/data.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/config/manager.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/constants.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/context.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/errors/yaml_strings.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/_collections_compat.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/_json_compat.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/arg_spec.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/collections.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/parameters.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/text/converters.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/text/formatters.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/validation.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/warnings.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/common/yaml.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/errors.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/module_utils/parsing/convert_bool.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/parsing/quoting.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/parsing/splitter.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/parsing/yaml/objects.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/release.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/color.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/context_objects.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/display.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/fqcn.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/native_jinja.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/path.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/py3compat.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/singleton.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/unicode.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/unsafe_proxy.py pylint!skip
plugins/action_utils/software_facts/compat/ansible/utils/vars.py pylint!skip
plugins/action_utils/software_facts/compat/filter.py pylint!skip
plugins/module_utils/file_parser/apache_webserver/errors.py pep8!skip
plugins/module_utils/file_parser/apache_webserver/lexer.py pep8!skip
plugins/module_utils/file_parser/apache_webserver/loader.py pep8!skip
plugins/module_utils/file_parser/apache_webserver/parser.py pep8!skip
plugins/module_utils/file_parser/haproxy/lexer.py pep8!skip
plugins/module_utils/file_parser/haproxy/loader.py pep8!skip
plugins/module_utils/file_parser/haproxy/parser.py pep8!skip
plugins/module_utils/file_parser/keepalived/lexer.py pep8!skip
plugins/module_utils/file_parser/keepalived/loader.py pep8!skip
plugins/module_utils/file_parser/keepalived/parser.py pep8!skip
plugins/module_utils/file_parser/nginx/lexer.py pep8!skip
plugins/module_utils/file_parser/nginx/loader.py pep8!skip
plugins/module_utils/file_parser/nginx/parser.py pep8!skip
plugins/module_utils/file_parser/lex.py pep8!skip
plugins/module_utils/file_parser/yacc.py pep8!skip
plugins/modules/check_connection.py replace-urlopen
plugins/module_utils/file_parser/apache_webserver/lexer.py use-compat-six
plugins/module_utils/file_parser/apache_webserver/loader.py use-compat-six
plugins/module_utils/file_parser/apache_webserver/parser.py use-compat-six
plugins/module_utils/file_parser/haproxy/lexer.py use-compat-six
plugins/module_utils/file_parser/haproxy/loader.py use-compat-six
plugins/module_utils/file_parser/haproxy/parser.py use-compat-six
plugins/module_utils/file_parser/keepalived/lexer.py use-compat-six
plugins/module_utils/file_parser/keepalived/loader.py use-compat-six
plugins/module_utils/file_parser/keepalived/parser.py use-compat-six
plugins/module_utils/file_parser/nginx/lexer.py use-compat-six
plugins/module_utils/file_parser/nginx/loader.py use-compat-six
plugins/module_utils/file_parser/nginx/parser.py use-compat-six
plugins/modules/win_package_facts.ps1 pslint:PSCustomUseLiteralPath
plugins/modules/snmp_facts.py validate-modules:undocumented-parameter
plugins/modules/snmp_facts.py validate-modules:doc-default-does-not-match-spec
11 changes: 6 additions & 5 deletions tests/unit/plugins/action/software/test_mariadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
from ansible.module_utils.six.moves import builtins # noqa
from pytest_lazyfixture import lazy_fixture

from ansible_collections.datadope.discovery.plugins.action.software_facts import ActionModule

Expand Down Expand Up @@ -186,12 +185,14 @@ def params_set_two_sw(sw_config, params_set_one_sw):

@pytest.mark.parametrize(argnames=['params_and_expected_result'],
argvalues=[
(lazy_fixture('params_set_one_sw'),),
(lazy_fixture('params_set_two_sw'),),
(lazy_fixture('params_set_no_sw'),)]
('params_set_one_sw',),
('params_set_two_sw',),
('params_set_no_sw',)]
)
def test_get_software_ok(normalize,
params_and_expected_result):
params_and_expected_result,
request):
params_and_expected_result = request.getfixturevalue(params_and_expected_result)
params, expected_result = params_and_expected_result
result = ActionModule(*[None] * 6).process_software(**params)
assert normalize(result) == normalize(expected_result)
11 changes: 6 additions & 5 deletions tests/unit/plugins/action/software/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
from ansible.module_utils.six.moves import builtins # noqa
from pytest_lazyfixture import lazy_fixture

from ansible_collections.datadope.discovery.plugins.action.software_facts import ActionModule

Expand Down Expand Up @@ -159,12 +158,14 @@ def params_set_two_sw(sw_config, params_set_one_sw):

@pytest.mark.parametrize(argnames=['params_and_expected_result'],
argvalues=[
(lazy_fixture('params_set_one_sw'),),
(lazy_fixture('params_set_two_sw'),),
(lazy_fixture('params_set_no_sw'),)]
('params_set_one_sw',),
('params_set_two_sw',),
('params_set_no_sw',)]
)
def test_get_software_ok(normalize,
params_and_expected_result):
params_and_expected_result,
request):
params_and_expected_result = request.getfixturevalue(params_and_expected_result)
params, expected_result = params_and_expected_result
result = ActionModule(*[None] * 6).process_software(**params)
assert normalize(result) == normalize(expected_result)
11 changes: 6 additions & 5 deletions tests/unit/plugins/action/software/test_nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
from ansible.module_utils.six.moves import builtins # noqa
from pytest_lazyfixture import lazy_fixture

from ansible_collections.datadope.discovery.plugins.action.software_facts import ActionModule

Expand Down Expand Up @@ -156,12 +155,14 @@ def params_set_two_sw(sw_config, params_set_one_sw):

@pytest.mark.parametrize(argnames=['params_and_expected_result'],
argvalues=[
(lazy_fixture('params_set_one_sw'),),
(lazy_fixture('params_set_two_sw'),),
(lazy_fixture('params_set_no_sw'),)]
('params_set_one_sw',),
('params_set_two_sw',),
('params_set_no_sw',)]
)
def test_get_software_ok(normalize,
params_and_expected_result):
params_and_expected_result,
request):
params_and_expected_result = request.getfixturevalue(params_and_expected_result)
params, expected_result = params_and_expected_result
result = ActionModule(*[None] * 6).process_software(**params)
assert normalize(result) == normalize(expected_result)
11 changes: 6 additions & 5 deletions tests/unit/plugins/action/software/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
from ansible.module_utils.six.moves import builtins # noqa
from pytest_lazyfixture import lazy_fixture

from ansible_collections.datadope.discovery.plugins.action.software_facts import ActionModule

Expand Down Expand Up @@ -597,12 +596,14 @@ def params_set_two_sw(sw_config, params_set_one_sw):

@pytest.mark.parametrize(argnames=['params_and_expected_result'],
argvalues=[
(lazy_fixture('params_set_one_sw'),),
(lazy_fixture('params_set_two_sw'),),
(lazy_fixture('params_set_no_sw'),)]
('params_set_one_sw',),
('params_set_two_sw',),
('params_set_no_sw',)]
)
def test_get_software_ok(normalize,
params_and_expected_result):
params_and_expected_result,
request):
params_and_expected_result = request.getfixturevalue(params_and_expected_result)
params, expected_result = params_and_expected_result
result = ActionModule(*[None] * 6).process_software(**params)
assert normalize(result) == normalize(expected_result)
10 changes: 5 additions & 5 deletions tests/unit/plugins/action/software/test_tomcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import pytest
from ansible.module_utils.six.moves import builtins # noqa
from pytest_lazyfixture import lazy_fixture

from ansible_collections.datadope.discovery.plugins.action.software_facts import ActionModule

Expand Down Expand Up @@ -229,11 +228,12 @@ def params_set_two_sw(sw_config, params_set_one_sw):

@pytest.mark.parametrize(argnames=['params_and_expected_result'],
argvalues=[
(lazy_fixture('params_set_one_sw'),),
(lazy_fixture('params_set_two_sw'),),
(lazy_fixture('params_set_no_sw'),)]
('params_set_one_sw',),
('params_set_two_sw',),
('params_set_no_sw',)]
)
def test_get_software_ok(normalize, params_and_expected_result):
def test_get_software_ok(normalize, params_and_expected_result, request):
params_and_expected_result = request.getfixturevalue(params_and_expected_result)
params, expected_result = params_and_expected_result
result = ActionModule(*[None] * 6).process_software(**params)
assert normalize(result) == normalize(expected_result)
22 changes: 12 additions & 10 deletions tests/unit/plugins/action/test_software_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import pytest
from ansible.errors import AnsibleError, AnsibleRuntimeError
from ansible.module_utils.six import iteritems
from pytest_lazyfixture import lazy_fixture

from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import call, patch, MagicMock, ANY
from ansible_collections.datadope.discovery.plugins.action.software_facts import ActionModule
Expand Down Expand Up @@ -1124,7 +1123,7 @@ def test_init(action_module):
argnames=('params', 'expected_result'),
argvalues=[
(
lazy_fixture('params_set_child_with_children'), True
'params_set_child_with_children', True
),
(
{
Expand Down Expand Up @@ -1186,7 +1185,9 @@ def test_init(action_module):
}, False
)
])
def test_validate_parameters(action_module, params, expected_result):
def test_validate_parameters(action_module, params, expected_result, request):
if isinstance(params, str):
params = request.getfixturevalue(params)
instance = action_module(ActionModule)
assert instance.validate_parameters(params[0] if isinstance(params, tuple) else params) is expected_result

Expand Down Expand Up @@ -1369,14 +1370,15 @@ def run(self, *args, **kwargs): # noqa

@pytest.mark.parametrize(argnames=['params_and_expected_result'],
argvalues=[
(lazy_fixture('params_set_child_with_children'),),
(lazy_fixture('params_set_child_without_children'),),
(lazy_fixture('params_set_parent_with_children'),),
(lazy_fixture('params_set_parent_without_children'),),
(lazy_fixture('params_set_dockers_with_children'),),
(lazy_fixture('params_set_dockers_without_children'),)]
('params_set_child_with_children',),
('params_set_child_without_children',),
('params_set_parent_with_children',),
('params_set_parent_without_children',),
('params_set_dockers_with_children',),
('params_set_dockers_without_children',)]
)
def test_get_software_ok(action_module, normalize, params_and_expected_result):
def test_get_software_ok(action_module, normalize, params_and_expected_result, request):
params_and_expected_result = request.getfixturevalue(params_and_expected_result)
params, expected_result = params_and_expected_result
result = action_module(ActionModule).process_software(**params)
assert normalize(result) == normalize(expected_result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
__metaclass__ = type

import pytest
from pytest_lazyfixture import lazy_fixture

from ansible_collections.datadope.discovery.plugins.action_utils.snmp_utils.utils import index_dependency

Expand Down Expand Up @@ -236,9 +235,10 @@ def params_index_dependency():

@pytest.mark.parametrize(argnames=['params_and_expected_result'],
argvalues=[
(lazy_fixture('params_index_dependency'),)]
('params_index_dependency',)]
)
def test_dependencies(params_and_expected_result):
def test_dependencies(params_and_expected_result, request):
params_and_expected_result = request.getfixturevalue(params_and_expected_result)
params, expected_result = params_and_expected_result
tagged_result = params['tagged_result']
for config in params['config_dependencies']:
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/plugins/action_utils/snmp_utils/test_post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


import pytest
from pytest_lazyfixture import lazy_fixture

from ansible_collections.datadope.discovery.plugins.action_utils.snmp_utils.post_process import post_process

Expand Down Expand Up @@ -47,13 +46,14 @@ def unknown_method():

@pytest.mark.parametrize(argnames=['params_and_expected_result'],
argvalues=[
(lazy_fixture('decode_hex'),),
(lazy_fixture('decode_mac'),),
(lazy_fixture('lookups_adminstatus'),),
(lazy_fixture('lookup_operstatus'),),
(lazy_fixture('unknown_method'),)]
('decode_hex',),
('decode_mac',),
('lookups_adminstatus',),
('lookup_operstatus',),
('unknown_method',)]
)
def test_post_process(params_and_expected_result):
def test_post_process(params_and_expected_result, request):
params_and_expected_result = request.getfixturevalue(params_and_expected_result)
params, expected_result = params_and_expected_result
for i in range(len(params[1])):
process_method = post_process(params[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
__metaclass__ = type

import pytest
from pytest_lazyfixture import lazy_fixture

from ansible_collections.datadope.discovery.plugins.action_utils.snmp_utils.utils import processed_templating_result

Expand Down Expand Up @@ -270,9 +269,10 @@ def params_processed_template():

@pytest.mark.parametrize(argnames=['params_and_expected_result'],
argvalues=[
(lazy_fixture('params_processed_template'),)]
('params_processed_template',)]
)
def test_util_process_templating(params_and_expected_result):
def test_util_process_templating(params_and_expected_result, request):
params_and_expected_result = request.getfixturevalue(params_and_expected_result)
params, expected_result = params_and_expected_result
result = processed_templating_result(
snmp_template=params['snmp_template'],
Expand Down
Loading

0 comments on commit 74600fc

Please sign in to comment.