Skip to content

Commit

Permalink
Add a content_view_info module
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms authored and evgeni committed Mar 11, 2021
1 parent a1a0c3c commit c9418f5
Show file tree
Hide file tree
Showing 5 changed files with 479 additions and 0 deletions.
81 changes: 81 additions & 0 deletions plugins/modules/content_view_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2021 Eric Helms
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import absolute_import, division, print_function
__metaclass__ = type


DOCUMENTATION = '''
---
module: content_view_info
version_added: 2.1.0
short_description: Fetch information about Content Views
description:
- Fetch information about Content Views
author:
- "Eric Helms (@ehelms)"
extends_documentation_fragment:
- theforeman.foreman.foreman
- theforeman.foreman.foreman.infomodule
'''

EXAMPLES = '''
- name: "Show a content_view"
theforeman.foreman.content_view_info:
username: "admin"
password: "changeme"
server_url: "https://foreman.example.com"
name: "CentOS 8"
- name: "Show all content_views with name CentOS 8"
theforeman.foreman.content_view_info:
username: "admin"
password: "changeme"
server_url: "https://foreman.example.com"
search: 'name = "CentOS 8"'
'''

RETURN = '''
content_view:
description: Details about the found content_view
returned: success and I(name) was passed
type: dict
content_views:
description: List of all found content_views and their details
returned: success and I(search) was passed
type: list
elements: dict
'''

from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import (
ForemanInfoAnsibleModule,
)


class KatelloContentViewInfo(ForemanInfoAnsibleModule):
pass


def main():
module = KatelloContentViewInfo()

with module.api_connection():
module.run()


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions tests/fixtures/apidoc/content_view_info.json
93 changes: 93 additions & 0 deletions tests/test_playbooks/content_view_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
- hosts: localhost
collections:
- theforeman.foreman
gather_facts: false
vars_files:
- vars/server.yml
tasks:
- include: tasks/organization.yml
vars:
organization_state: present
- include: tasks/product.yml
vars:
product_state: present
- include: tasks/repository.yml
vars:
repository_state: present
- include: tasks/product.yml
vars:
product_name: "Test Product 2"
product_state: present
- include: tasks/repository.yml
vars:
product_name: "Test Product 2"
repository_state: present
- include: tasks/content_view.yml
vars:
content_view_name: "Test Composite Content View"
content_view_state: absent
- name: Create content view
include: tasks/content_view.yml
vars:
content_view_state: present
expected_change: true
repositories:
- name: "Test Repository"
product: "Test Product"

- hosts: tests
collections:
- theforeman.foreman
gather_facts: false
vars_files:
- vars/server.yml
tasks:
- name: fetch content_view info
content_view_info:
username: "{{ foreman_username }}"
password: "{{ foreman_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
name: "Test Content View"
register: content_view_info
- name: check content_view details
assert:
that:
- content_view_info['content_view']['name'] == "Test Content View"
- content_view_info['content_view']['repositories'][0]['name'] == "Test Repository"

- name: search content_view info
content_view_info:
username: "{{ foreman_username }}"
password: "{{ foreman_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
search: 'name = "Test Content View"'
register: content_view_info
- name: check content_view details
assert:
that:
- content_view_info['content_views'][0]['name'] == "Test Content View"

- hosts: localhost
collections:
- theforeman.foreman
gather_facts: false
vars_files:
- vars/server.yml
tasks:
- include: tasks/content_view.yml
vars:
content_view_state: absent
- include: tasks/repository.yml
vars:
product_name: "Test Product 2"
repository_state: absent
- include: tasks/product.yml
vars:
product_name: "Test Product 2"
product_state: absent
- include: tasks/organization.yml
vars:
organization_state: absent
183 changes: 183 additions & 0 deletions tests/test_playbooks/fixtures/content_view_info-0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json;version=2
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/api/status
response:
body:
string: '{"result":"ok","status":200,"version":"2.5.0-develop","api_version":2}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
style-src ''unsafe-inline'' ''self'''
Content-Type:
- application/json; charset=utf-8
Foreman_api_version:
- '2'
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.5.0-develop
Keep-Alive:
- timeout=15, max=100
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- sameorigin
X-Permitted-Cross-Domain-Policies:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '70'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json;version=2
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/katello/api/content_views?search=name%3D%22Test+Content+View%22&per_page=4294967296
response:
body:
string: '{"total":4,"subtotal":1,"page":1,"per_page":"4294967296","error":null,"search":"name=\"Test
Content View\"","sort":{"by":"name","order":"asc"},"results":[{"composite":false,"component_ids":[],"default":false,"force_puppet_environment":false,"version_count":0,"latest_version":null,"auto_publish":false,"solve_dependencies":false,"import_only":false,"repository_ids":[42],"id":12,"name":"Test
Content View","label":"Test_Content_View","description":null,"organization_id":7,"organization":{"name":"Test
Organization","label":"Test_Organization","id":7},"created_at":"2021-03-10
19:16:47 UTC","updated_at":"2021-03-10 19:16:47 UTC","environments":[],"repositories":[{"id":42,"name":"Test
Repository","label":"Test_Repository","content_type":"yum"}],"puppet_modules":[],"versions":[],"components":[],"content_view_components":[],"activation_keys":[],"next_version":"1.0","last_published":null,"permissions":{"view_content_views":true,"edit_content_views":true,"destroy_content_views":true,"publish_content_views":true,"promote_or_remove_content_views":true}}]}
'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
style-src ''unsafe-inline'' ''self'''
Content-Type:
- application/json; charset=utf-8
Foreman_api_version:
- '2'
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.5.0-develop
Keep-Alive:
- timeout=15, max=99
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- sameorigin
X-Permitted-Cross-Domain-Policies:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '1058'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json;version=2
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/katello/api/content_views/12
response:
body:
string: ' {"content_host_count":0,"composite":false,"component_ids":[],"default":false,"force_puppet_environment":false,"version_count":0,"latest_version":null,"auto_publish":false,"solve_dependencies":false,"import_only":false,"repository_ids":[42],"id":12,"name":"Test
Content View","label":"Test_Content_View","description":null,"organization_id":7,"organization":{"name":"Test
Organization","label":"Test_Organization","id":7},"created_at":"2021-03-10
19:16:47 UTC","updated_at":"2021-03-10 19:16:47 UTC","environments":[],"repositories":[{"id":42,"name":"Test
Repository","label":"Test_Repository","content_type":"yum"}],"puppet_modules":[],"versions":[],"components":[],"content_view_components":[],"activation_keys":[],"next_version":"1.0","last_published":null,"permissions":{"view_content_views":true,"edit_content_views":true,"destroy_content_views":true,"publish_content_views":true,"promote_or_remove_content_views":true},"duplicate_repositories_to_publish":[],"errors":null}
'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Connection:
- Keep-Alive
Content-Security-Policy:
- 'default-src ''self''; child-src ''self''; connect-src ''self'' ws: wss:;
img-src ''self'' data:; script-src ''unsafe-eval'' ''unsafe-inline'' ''self'';
style-src ''unsafe-inline'' ''self'''
Content-Type:
- application/json; charset=utf-8
Foreman_api_version:
- '2'
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.5.0-develop
Keep-Alive:
- timeout=15, max=98
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Download-Options:
- noopen
X-Frame-Options:
- sameorigin
X-Permitted-Cross-Domain-Policies:
- none
X-XSS-Protection:
- 1; mode=block
content-length:
- '980'
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit c9418f5

Please sign in to comment.