Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database_view_info: Query database_view #195

Conversation

toni-moreno
Copy link
Contributor

SUMMARY

Add new module to query any existing database view.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

database_view_info

ADDITIONAL INFORMATION

Example of module usage

- name: Query table with relationship between cmdb_ci_appl_ora_tns and cmdb_ci_service_discovered (previously defined)
      servicenow.itsm.database_view_info:
        database_view: u_cmdb_ora_tns_service
        return_fields:
          - tns_name
          - tns_sys_id
          - tns_operational_status
          - ms_name
          - ms_sys_id
      register: result

    - name: Debug test 2
      debug:
        var: result

The output will be

{"result": {
        "changed": false,
        "failed": false,
        "records": [
            {
                "ms_name": "MY_SERVICE_1",
                "ms_sys_id": "762ed2a807e01110befff6fd7c1ed0bf",
                "tns_name": "AAACDB2-PDB22-DB1",
                "tns_operational_status": "1",
                "tns_sys_id": "6a29040107a01110befff6fd7c1ed070"
            },
            {
                "ms_name": "MY_SERVICE_1",
                "ms_sys_id": "762ed2a807e01110befff6fd7c1ed0bf",
                "tns_name": "AAACDB1-PDB11-DB2",
                "tns_operational_status": "1",
                "tns_sys_id": "9bb1fee807241110befff6fd7c1ed089"
            },
            {
                "ms_name": "MY_SERVICE_1",
                "ms_sys_id": "762ed2a807e01110befff6fd7c1ed0bf",
                "tns_name": "AAACDB1-PDB12-DB3",
                "tns_operational_status": "1",
                "tns_sys_id": "fac2be2c07241110befff6fd7c1ed0a9"
            }
        ]
    }
}

note that my database view have been defined as described in the picture.

image

@softwarefactory-project-zuul
Copy link

Build failed.

✔️ build-ansible-collection SUCCESS in 3m 00s
ansible-test-sanity-docker-devel FAILURE in 7m 07s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 6m 04s
ansible-test-sanity-docker-stable-2.9 FAILURE in 9m 57s
ansible-test-sanity-docker-stable-2.10 FAILURE in 8m 41s
ansible-test-sanity-docker-stable-2.11 FAILURE in 9m 37s
ansible-test-sanity-docker-stable-2.12 FAILURE in 6m 26s
✔️ ansible-test-units-servicenow-itsm-python27 SUCCESS in 4m 24s
✔️ ansible-test-units-servicenow-itsm-python36 SUCCESS in 5m 32s
✔️ ansible-test-units-servicenow-itsm-python37 SUCCESS in 5m 23s
✔️ ansible-test-units-servicenow-itsm-python38 SUCCESS in 4m 35s
✔️ ansible-galaxy-importer SUCCESS in 3m 31s

@toni-moreno
Copy link
Contributor Author

Sorry @tima , I have just pushed this PR , but something extrange happened on the validation test.

image

Let me understand what is happening I'm seeing errors on the validation code not my module code. Could you please help me understand what is the matter?

@toni-moreno toni-moreno force-pushed the added_database_view_info_module branch from a0fb009 to 145ed8e Compare August 5, 2022 09:41
@softwarefactory-project-zuul
Copy link

Build failed.

✔️ build-ansible-collection SUCCESS in 2m 58s
ansible-test-sanity-docker-devel FAILURE in 6m 59s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 6m 38s
ansible-test-sanity-docker-stable-2.9 FAILURE in 8m 36s
ansible-test-sanity-docker-stable-2.10 FAILURE in 8m 03s
ansible-test-sanity-docker-stable-2.11 FAILURE in 10m 20s
ansible-test-sanity-docker-stable-2.12 FAILURE in 6m 48s
✔️ ansible-test-units-servicenow-itsm-python27 SUCCESS in 5m 38s
✔️ ansible-test-units-servicenow-itsm-python36 SUCCESS in 4m 54s
✔️ ansible-test-units-servicenow-itsm-python37 SUCCESS in 5m 08s
✔️ ansible-test-units-servicenow-itsm-python38 SUCCESS in 4m 35s
✔️ ansible-galaxy-importer SUCCESS in 3m 54s

@toni-moreno
Copy link
Contributor Author

Sorry @tima , I have just pushed this PR , but something extrange happened on the validation test.

image

Let me understand what is happening I'm seeing errors on the validation code not my module code. Could you please help me understand what is the matter?

I've just rebased to the last main commit and still failing validation code, .. could somebody help me to understand this error please?

@juremedvesek
Copy link
Contributor

Hi @toni-moreno. It looks like doc in some module can not be parsed to yaml. Can you check if all docs that you are created are valid yaml files.

@juremedvesek
Copy link
Contributor

Use command make sanity localy and you will get a lot better error.

Running sanity test "ansible-doc"
ERROR: Command "ansible-doc -t module servicenow.itsm.attachment servicenow.itsm.change_request servicenow.itsm.change_request_info servicenow.itsm.change_request_task servicenow.itsm.change_request_task_info servicenow.itsm.configuration_item servicenow.itsm.configuration_item_batch servicenow.itsm.configuration_item_info servicenow.itsm.database_view_info servicenow.itsm.incident servicenow.itsm.incident_info servicenow.itsm.problem servicenow.itsm.problem_info servicenow.itsm.problem_task servicenow.itsm.problem_task_info" returned exit status 1.
>>> Standard Error
[WARNING]: While constructing a mapping from /root/ansible_collections/servicen
ow/itsm/plugins/modules/database_view_info.py, line 3, column 3, found a
duplicate dict key (type). Using last defined value only.
ERROR! Unable to retrieve documentation from 'servicenow.itsm.database_view_info' due to: 'NoneType' object is not iterable. 'NoneType' object is not iterable

Also make format will automatically reformat the code, so it will not break any black rule.

Copy link
Contributor

@juremedvesek juremedvesek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use make sanity in your development process. It just executes sanity test. In yours case there were some small errors inside docs, that must be fixed.

- use return_fields to limit the fields to be returned.
type: list
returned: success
type: list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of type: list element

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @juremedvesek than you very much for you help. I'm new coding ansible modules and , I think I have not build my development environment properly.

When I exec make sanity I have this message

toni@desktop01:/servicenow.itsm$ make sanity
Makefile:12: *** Place collection at <WHATEVER>/ansible_collections/servicenow/itsm.  Alto.

I've seen what is suposed to to looking the Makefile.

.PHONY: sanity
sanity:  ## Run sanity tests
	pip install -r sanity.requirements
	black -t py27 --check --diff --color plugins tests/unit
	flake8
	ansible-test sanity --docker

if I exec black -t py27 --check --diff --color plugins tests/unit this is my output.

Traceback (most recent call last):
  File "/home/toni/.local/bin/black", line 8, in <module>
    sys.exit(patched_main())
  File "/home/toni/.local/lib/python3.8/site-packages/black/__init__.py", line 1372, in patched_main
    patch_click()
  File "/home/toni/.local/lib/python3.8/site-packages/black/__init__.py", line 1358, in patch_click
    from click import _unicodefun
ImportError: cannot import name '_unicodefun' from 'click' (/home/toni/.local/lib/python3.8/site-packages/click/__init__.py)

Let me know if there is any document with information to build a good developer environment , to run these checks , please.

Thank you very much and sorry for my poor skills on this kind of working

plugins/modules/database_view_info.py Outdated Show resolved Hide resolved
@toni-moreno toni-moreno force-pushed the added_database_view_info_module branch from 145ed8e to f57a704 Compare August 5, 2022 14:30
@softwarefactory-project-zuul
Copy link

Build failed.

✔️ build-ansible-collection SUCCESS in 3m 01s
ansible-test-sanity-docker-devel FAILURE in 6m 06s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 10m 06s
ansible-test-sanity-docker-stable-2.9 FAILURE in 9m 57s
ansible-test-sanity-docker-stable-2.10 FAILURE in 9m 00s
ansible-test-sanity-docker-stable-2.11 FAILURE in 9m 14s
ansible-test-sanity-docker-stable-2.12 FAILURE in 6m 56s
✔️ ansible-test-units-servicenow-itsm-python27 SUCCESS in 6m 05s
✔️ ansible-test-units-servicenow-itsm-python36 SUCCESS in 5m 43s
✔️ ansible-test-units-servicenow-itsm-python37 SUCCESS in 4m 02s
✔️ ansible-test-units-servicenow-itsm-python38 SUCCESS in 5m 48s
✔️ ansible-galaxy-importer SUCCESS in 4m 59s

@toni-moreno
Copy link
Contributor Author

@juremedvesek , I've just discovered the docs/hacking.md ( sorry for not to see it before) .

After creating my venv I still have this error after running make sanity. How can I fix it?

(venv) toni@desktop01:/home/toni/servicenow-itsm/ansible_collections/servicenow/itsm$ make sanity
pip install -r sanity.requirements
Collecting black<=21.12b0
  Using cached black-21.12b0-py3-none-any.whl (156 kB)
Collecting flake8
  Downloading flake8-5.0.4-py2.py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 164 kB/s 
Collecting pathspec<1,>=0.9.0
  Using cached pathspec-0.9.0-py2.py3-none-any.whl (31 kB)
Collecting click>=7.1.2
  Using cached click-8.1.3-py3-none-any.whl (96 kB)
Collecting tomli<2.0.0,>=0.2.6
  Using cached tomli-1.2.3-py3-none-any.whl (12 kB)
Collecting platformdirs>=2
  Using cached platformdirs-2.5.2-py3-none-any.whl (14 kB)
Collecting mypy-extensions>=0.4.3
  Using cached mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
Collecting typing-extensions>=3.10.0.0
  Downloading typing_extensions-4.3.0-py3-none-any.whl (25 kB)
Collecting pyflakes<2.6.0,>=2.5.0
  Downloading pyflakes-2.5.0-py2.py3-none-any.whl (66 kB)
     |████████████████████████████████| 66 kB 1.7 MB/s 
Collecting pycodestyle<2.10.0,>=2.9.0
  Downloading pycodestyle-2.9.1-py2.py3-none-any.whl (41 kB)
     |████████████████████████████████| 41 kB 115 kB/s 
Collecting mccabe<0.8.0,>=0.7.0
  Downloading mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB)
Installing collected packages: pathspec, click, tomli, platformdirs, mypy-extensions, typing-extensions, black, pyflakes, pycodestyle, mccabe, flake8
Successfully installed black-21.12b0 click-8.1.3 flake8-5.0.4 mccabe-0.7.0 mypy-extensions-0.4.3 pathspec-0.9.0 platformdirs-2.5.2 pycodestyle-2.9.1 pyflakes-2.5.0 tomli-1.2.3 typing-extensions-4.3.0
black -t py27 --check --diff --color plugins tests/unit
Traceback (most recent call last):
  File "/home/toni/proyectos/bs/servicenow-itsm/venv/bin/black", line 8, in <module>
    sys.exit(patched_main())
  File "/home/toni/proyectos/bs/servicenow-itsm/venv/lib/python3.8/site-packages/black/__init__.py", line 1372, in patched_main
    patch_click()
  File "/home/toni/proyectos/bs/servicenow-itsm/venv/lib/python3.8/site-packages/black/__init__.py", line 1358, in patch_click
    from click import _unicodefun
ImportError: cannot import name '_unicodefun' from 'click' (/home/toni/proyectos/bs/servicenow-itsm/venv/lib/python3.8/site-packages/click/__init__.py)
make: *** [Makefile:55: sanity] Error 1

@toni-moreno toni-moreno force-pushed the added_database_view_info_module branch from f57a704 to c17b7d2 Compare August 5, 2022 15:03
@softwarefactory-project-zuul
Copy link

Build failed.

✔️ build-ansible-collection SUCCESS in 3m 02s
ansible-test-sanity-docker-devel FAILURE in 6m 34s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 6m 53s
ansible-test-sanity-docker-stable-2.9 FAILURE in 9m 43s
ansible-test-sanity-docker-stable-2.10 FAILURE in 7m 38s
ansible-test-sanity-docker-stable-2.11 FAILURE in 9m 30s
ansible-test-sanity-docker-stable-2.12 FAILURE in 7m 46s
✔️ ansible-test-units-servicenow-itsm-python27 SUCCESS in 4m 49s
✔️ ansible-test-units-servicenow-itsm-python36 SUCCESS in 4m 41s
✔️ ansible-test-units-servicenow-itsm-python37 SUCCESS in 4m 28s
✔️ ansible-test-units-servicenow-itsm-python38 SUCCESS in 5m 54s
✔️ ansible-galaxy-importer SUCCESS in 3m 45s

@toni-moreno
Copy link
Contributor Author

@juremedvesek , it seems that error importError: cannot import name '_unicodefun' from 'click' (/home/toni/.local/lib/python3.8/site-packages/click/__init__.py) depends on the black >= 22.3.0 package version as described here

But sanity.requierements needs for black <=21.12b0 ... What to do?

@toni-moreno toni-moreno force-pushed the added_database_view_info_module branch from c17b7d2 to 8b26f8f Compare August 5, 2022 15:26
@softwarefactory-project-zuul
Copy link

Build failed.

✔️ build-ansible-collection SUCCESS in 2m 57s
ansible-test-sanity-docker-devel FAILURE in 7m 19s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 7m 18s
ansible-test-sanity-docker-stable-2.9 FAILURE in 9m 34s
ansible-test-sanity-docker-stable-2.10 FAILURE in 8m 03s
ansible-test-sanity-docker-stable-2.11 FAILURE in 9m 13s
ansible-test-sanity-docker-stable-2.12 FAILURE in 7m 26s
✔️ ansible-test-units-servicenow-itsm-python27 SUCCESS in 4m 49s
✔️ ansible-test-units-servicenow-itsm-python36 SUCCESS in 5m 28s
✔️ ansible-test-units-servicenow-itsm-python37 SUCCESS in 5m 37s
✔️ ansible-test-units-servicenow-itsm-python38 SUCCESS in 4m 35s
✔️ ansible-galaxy-importer SUCCESS in 3m 59s

@toni-moreno toni-moreno force-pushed the added_database_view_info_module branch from 8b26f8f to 90d70f7 Compare August 5, 2022 15:43
@softwarefactory-project-zuul
Copy link

Build failed.

✔️ build-ansible-collection SUCCESS in 2m 58s
ansible-test-sanity-docker-devel FAILURE in 7m 55s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 6m 37s
ansible-test-sanity-docker-stable-2.9 FAILURE in 9m 34s
ansible-test-sanity-docker-stable-2.10 FAILURE in 8m 13s
ansible-test-sanity-docker-stable-2.11 FAILURE in 9m 18s
ansible-test-sanity-docker-stable-2.12 FAILURE in 7m 44s
✔️ ansible-test-units-servicenow-itsm-python27 SUCCESS in 4m 55s
✔️ ansible-test-units-servicenow-itsm-python36 SUCCESS in 4m 58s
✔️ ansible-test-units-servicenow-itsm-python37 SUCCESS in 4m 57s
✔️ ansible-test-units-servicenow-itsm-python38 SUCCESS in 4m 57s
✔️ ansible-galaxy-importer SUCCESS in 3m 57s

@toni-moreno toni-moreno force-pushed the added_database_view_info_module branch from 90d70f7 to 8c0598f Compare August 5, 2022 16:04
@softwarefactory-project-zuul
Copy link

Build succeeded.

✔️ build-ansible-collection SUCCESS in 2m 59s
✔️ ansible-test-sanity-docker-devel SUCCESS in 8m 05s (non-voting)
✔️ ansible-test-sanity-docker-milestone SUCCESS in 7m 17s
✔️ ansible-test-sanity-docker-stable-2.9 SUCCESS in 9m 53s
✔️ ansible-test-sanity-docker-stable-2.10 SUCCESS in 8m 30s
✔️ ansible-test-sanity-docker-stable-2.11 SUCCESS in 9m 23s
✔️ ansible-test-sanity-docker-stable-2.12 SUCCESS in 8m 59s
✔️ ansible-test-units-servicenow-itsm-python27 SUCCESS in 4m 41s
✔️ ansible-test-units-servicenow-itsm-python36 SUCCESS in 5m 58s
✔️ ansible-test-units-servicenow-itsm-python37 SUCCESS in 4m 31s
✔️ ansible-test-units-servicenow-itsm-python38 SUCCESS in 4m 38s
✔️ ansible-galaxy-importer SUCCESS in 3m 39s

@toni-moreno
Copy link
Contributor Author

hello @juremedvesek I finally could build my working env , I have open a PR with the fix here (#197)

@Akasurde Akasurde changed the title added new module database_view_info database_view_info: Query database_view Aug 10, 2022
plugins/modules/database_view_info.py Outdated Show resolved Hide resolved
plugins/modules/database_view_info.py Outdated Show resolved Hide resolved
plugins/modules/database_view_info.py Outdated Show resolved Hide resolved
plugins/modules/database_view_info.py Outdated Show resolved Hide resolved
plugins/modules/database_view_info.py Show resolved Hide resolved
@Akasurde Akasurde self-assigned this Aug 10, 2022
@Akasurde Akasurde added the type/enhancement New feature or request label Aug 10, 2022
@Akasurde Akasurde added this to the 2.1 milestone Aug 17, 2022
@toni-moreno toni-moreno force-pushed the added_database_view_info_module branch 3 times, most recently from 4e2e72f to 877d4ea Compare August 22, 2022 10:20
@softwarefactory-project-zuul
Copy link

Build failed.

✔️ build-ansible-collection SUCCESS in 2m 58s
ansible-test-sanity-docker-devel FAILURE in 7m 34s (non-voting)
ansible-test-sanity-docker-milestone FAILURE in 7m 06s
ansible-test-sanity-docker-stable-2.9 FAILURE in 9m 18s
ansible-test-sanity-docker-stable-2.10 FAILURE in 7m 14s
ansible-test-sanity-docker-stable-2.11 FAILURE in 9m 08s
ansible-test-sanity-docker-stable-2.12 FAILURE in 6m 54s
✔️ ansible-test-units-servicenow-itsm-python27 SUCCESS in 5m 00s
✔️ ansible-test-units-servicenow-itsm-python36 SUCCESS in 5m 47s
✔️ ansible-test-units-servicenow-itsm-python37 SUCCESS in 4m 31s
✔️ ansible-test-units-servicenow-itsm-python38 SUCCESS in 4m 50s
✔️ ansible-galaxy-importer SUCCESS in 4m 57s

@toni-moreno
Copy link
Contributor Author

@Akasurde there is something extrange in the sanity check . I didn't added anything about documentation but this error happened in last check.

ERROR: Found 1 validate-modules issue(s) which need to be resolved:
ERROR: plugins/modules/database_view_info.py:0:0: nonexistent-parameter-documented: Argument 'sysparm_query' is listed in DOCUMENTATION.options, but not accepted by the module argument_spec

the fact is there is there is no sysparm_query option in the documentation.

Could you help me to understant what is happening?

image

@toni-moreno toni-moreno force-pushed the added_database_view_info_module branch from 877d4ea to 47e462a Compare August 26, 2022 10:14
@toni-moreno
Copy link
Contributor Author

Hello @Akasurde I've rebased and added sysparm_query parameter option to the database_view_info module

@softwarefactory-project-zuul
Copy link

Build succeeded.

✔️ build-ansible-collection SUCCESS in 3m 11s
✔️ ansible-test-sanity-docker-devel SUCCESS in 7m 52s (non-voting)
✔️ ansible-test-sanity-docker-milestone SUCCESS in 7m 48s
✔️ ansible-test-sanity-docker-stable-2.9 SUCCESS in 11m 02s
✔️ ansible-test-sanity-docker-stable-2.10 SUCCESS in 8m 28s
✔️ ansible-test-sanity-docker-stable-2.11 SUCCESS in 10m 20s
✔️ ansible-test-sanity-docker-stable-2.12 SUCCESS in 8m 04s
✔️ ansible-test-units-servicenow-itsm-python27 SUCCESS in 5m 54s
✔️ ansible-test-units-servicenow-itsm-python36 SUCCESS in 6m 12s
✔️ ansible-test-units-servicenow-itsm-python37 SUCCESS in 5m 54s
✔️ ansible-test-units-servicenow-itsm-python38 SUCCESS in 5m 22s
✔️ ansible-galaxy-importer SUCCESS in 3m 55s

@Akasurde Akasurde added this to Pending in review in v2.5.0 via automation Mar 7, 2024
@Akasurde Akasurde removed this from the 2.1 milestone Mar 7, 2024
@mhjacks
Copy link
Collaborator

mhjacks commented May 16, 2024

Thanks for your interest in the project, but this issue has been idle for a long time, so we are closing it. If you would still like this considered for inclusion in the project, please feel free to re-open the PR and rebase it agaiinst current main, and we can pick up the conversation.

@mhjacks mhjacks closed this May 16, 2024
v2.5.0 automation moved this from Pending in review to Done May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants