community.general icon indicating copy to clipboard operation
community.general copied to clipboard

Implement usb_facts module

Open Maxopoly opened this issue 1 year ago • 6 comments

SUMMARY

Implements a module for retrieving information about connected usb devices.

ISSUE TYPE
  • New Module/Plugin Pull Request
COMPONENT NAME

usb_facts

ADDITIONAL INFORMATION

So far, obtaining information about usb devices was only possible by running lsusb as command and parsing its output. This module implements exactly that and returns information regarding connected usb devices as data structure.

More information about usb devices could be made available by increasing the verbosity of lsusb and parsing that, but just this should be sufficient for most use cases.

Two test cases for the parsing of a single lsusb output and multiple at once are included.

Maxopoly avatar Mar 09 '24 14:03 Maxopoly

The test ansible-test sanity --test pylint [explain] failed with 2 errors:

tests/unit/plugins/modules/test_usb_facts.py:101:111: trailing-whitespace: Trailing whitespace
tests/unit/plugins/modules/test_usb_facts.py:102:0: missing-final-newline: Final newline missing

The test ansible-test sanity --test pep8 [explain] failed with 9 errors:

tests/unit/plugins/modules/test_usb_facts.py:16:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:21:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:52:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:56:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:57:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:58:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:82:38: E211: whitespace before '['
tests/unit/plugins/modules/test_usb_facts.py:101:112: W291: trailing whitespace
tests/unit/plugins/modules/test_usb_facts.py:102:77: W292: no newline at end of file

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

plugins/modules/usb_facts.py:0:0: invalid-documentation: DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got 'Max Maxopoly ([email protected])'

The test ansible-test sanity --test pylint [explain] failed with 2 errors:

tests/unit/plugins/modules/test_usb_facts.py:101:111: trailing-whitespace: Trailing whitespace
tests/unit/plugins/modules/test_usb_facts.py:102:0: missing-final-newline: Final newline missing

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

plugins/modules/usb_facts.py:0:0: invalid-documentation: DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got 'Max Maxopoly ([email protected])'

The test ansible-test sanity --test pylint [explain] failed with 2 errors:

tests/unit/plugins/modules/test_usb_facts.py:101:111: trailing-whitespace: Trailing whitespace
tests/unit/plugins/modules/test_usb_facts.py:102:0: missing-final-newline: Final newline missing

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

plugins/modules/usb_facts.py:0:0: invalid-documentation: DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got 'Max Maxopoly ([email protected])'

The test ansible-test sanity --test pep8 [explain] failed with 9 errors:

tests/unit/plugins/modules/test_usb_facts.py:16:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:21:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:52:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:56:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:57:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:58:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:82:38: E211: whitespace before '['
tests/unit/plugins/modules/test_usb_facts.py:101:112: W291: trailing whitespace
tests/unit/plugins/modules/test_usb_facts.py:102:77: W292: no newline at end of file

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

plugins/modules/usb_facts.py:0:0: invalid-documentation: DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got 'Max Maxopoly ([email protected])'

The test botmeta failed with 1 error:

.github/BOTMETA.yml:0:0: No (active or inactive) maintainer mentioned for plugins/modules/usb_facts.py

The test ansible-test sanity --test pylint [explain] failed with 2 errors:

tests/unit/plugins/modules/test_usb_facts.py:101:111: trailing-whitespace: Trailing whitespace
tests/unit/plugins/modules/test_usb_facts.py:102:0: missing-final-newline: Final newline missing

The test ansible-test sanity --test pep8 [explain] failed with 9 errors:

tests/unit/plugins/modules/test_usb_facts.py:16:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:21:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:52:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:56:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:57:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:58:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:82:38: E211: whitespace before '['
tests/unit/plugins/modules/test_usb_facts.py:101:112: W291: trailing whitespace
tests/unit/plugins/modules/test_usb_facts.py:102:77: W292: no newline at end of file

The test ansible-test sanity --test pep8 [explain] failed with 9 errors:

tests/unit/plugins/modules/test_usb_facts.py:16:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:21:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:52:1: E302: expected 2 blank lines, found 1
tests/unit/plugins/modules/test_usb_facts.py:56:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:57:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:58:50: E128: continuation line under-indented for visual indent
tests/unit/plugins/modules/test_usb_facts.py:82:38: E211: whitespace before '['
tests/unit/plugins/modules/test_usb_facts.py:101:112: W291: trailing whitespace
tests/unit/plugins/modules/test_usb_facts.py:102:77: W292: no newline at end of file

click here for bot help

ansibullbot avatar Mar 09 '24 14:03 ansibullbot

As far as I can tell the only check failing is Author maxopoly not mentioned as active or inactive maintainer for plugins/modules/usb_facts.py (mentioned are: )

What/who should I be putting as maintainer?

Maxopoly avatar Mar 09 '24 15:03 Maxopoly

The test botmeta failed with 2 errors:

.github/BOTMETA.yml:0:0: Author maxopoly not mentioned as active or inactive maintainer for plugins/modules/usb_facts.py (mentioned are: )
.github/BOTMETA.yml:0:0: No (active or inactive) maintainer mentioned for plugins/modules/usb_facts.py

click here for bot help

ansibullbot avatar Mar 09 '24 15:03 ansibullbot

If I may suggest, give it a try to andebox by yours truly:

https://pypi.org/project/andebox/

You can run this sanity test easily in your local machine by simply running:

$ andebox test -- sanity --docker default --python 3.10 plugins/modules/your_module.py

russoz avatar Mar 10 '24 09:03 russoz

As far as I can tell the only check failing is Author maxopoly not mentioned as active or inactive maintainer for plugins/modules/usb_facts.py (mentioned are: )

What/who should I be putting as maintainer?

Did you check out the part in CONTRIBUTING.md about adding new modules and plugins? It explicitly mentions .github/BOTMETA.yml.

felixfontein avatar Mar 10 '24 11:03 felixfontein

If I may suggest, give it a try to andebox by yours truly:

Didn't know about that, very cool. Thanks for the tip!

Did you check out the part in CONTRIBUTING.md about adding new modules and plugins? It explicitly mentions .github/BOTMETA.yml.

Skimmed over it, but apparently not thoroughly enough. My bad for failing to read instructions. Should be good now.


I implemented all suggestions as provided, should be good to go.

Maxopoly avatar Mar 11 '24 19:03 Maxopoly

Backport to stable-8: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-8/6298ad4faa851b44db8926e4c52252cda9ed1d9a/pr-8076

Backported as https://github.com/ansible-collections/community.general/pull/8115

🤖 @patchback I'm built with octomachinery and my source is open — https://github.com/sanitizers/patchback-github-app.

patchback[bot] avatar Mar 18 '24 20:03 patchback[bot]

@Maxopoly thanks for contributing this! @russoz thanks for reviewing!

felixfontein avatar Mar 18 '24 20:03 felixfontein