Skip to content

Commit

Permalink
sub_info: mark organization as required
Browse files Browse the repository at this point in the history
that's a change in 4.1
  • Loading branch information
evgeni committed Jun 23, 2021
1 parent 1247113 commit a06c19d
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 32 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/katello41-subscription-org-required.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- subscription_info - mark ``organization`` parameter as required, to match Katello
7 changes: 4 additions & 3 deletions plugins/modules/subscription_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- "Evgeni Golov (@evgeni)"
extends_documentation_fragment:
- theforeman.foreman.foreman
- theforeman.foreman.foreman.katelloinfomodule
- theforeman.foreman.foreman.infomodule
'''

Expand Down Expand Up @@ -62,16 +63,16 @@
'''

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


class ForemanSubscriptionInfo(ForemanInfoAnsibleModule):
class KatelloSubscriptionInfo(KatelloInfoAnsibleModule):
pass


def main():
module = ForemanSubscriptionInfo()
module = KatelloSubscriptionInfo()

with module.api_connection():
module.run()
Expand Down
97 changes: 79 additions & 18 deletions tests/test_playbooks/fixtures/subscription_info-0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interactions:
uri: https://foreman.example.org/api/status
response:
body:
string: '{"result":"ok","status":200,"version":"2.4.0","api_version":2}'
string: '{"result":"ok","status":200,"version":"2.5.0","api_version":2}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Expand All @@ -33,7 +33,7 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.4.0
- 2.5.0
Keep-Alive:
- timeout=15, max=100
Strict-Transport-Security:
Expand Down Expand Up @@ -67,13 +67,74 @@ interactions:
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/katello/api/subscriptions?search=name%3D%22Test+Product%22&per_page=4294967296
uri: https://foreman.example.org/katello/api/organizations?search=name%3D%22Test+Organization%22&per_page=4294967296
response:
body:
string: "{\n \"total\": 2,\n \"subtotal\": 1,\n \"page\": 1,\n \"per_page\"\
: 4294967296,\n \"search\": \"name=\\\"Test Organization\\\"\",\n \"sort\"\
: {\n \"by\": null,\n \"order\": null\n },\n \"results\": [{\"label\"\
:\"Test_Organization\",\"created_at\":\"2021-06-22 14:10:13 UTC\",\"updated_at\"\
:\"2021-06-22 14:10:15 UTC\",\"id\":3,\"name\":\"Test Organization\",\"title\"\
:\"Test Organization\",\"description\":\"A test organization\"}]\n}\n"
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
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:
- '388'
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/organizations/3/subscriptions?search=name%3D%22Test+Product%22&per_page=4294967296
response:
body:
string: '{"organization":{},"total":1,"subtotal":1,"page":1,"per_page":"4294967296","error":null,"search":"name=\"Test
Product\"","sort":{"by":"name","order":"asc"},"results":[{"id":3,"cp_id":"4028fae1795b4f4201795fa3db630035","subscription_id":3,"name":"Test
Product","start_date":"2021-05-12 08:14:04 UTC","end_date":"2049-12-01 00:00:00
UTC","available":-1,"quantity":-1,"consumed":0,"account_number":null,"contract_number":null,"support_level":null,"product_id":"677308081353","sockets":null,"cores":null,"ram":null,"instance_multiplier":1,"stacking_id":null,"multi_entitlement":false,"type":"NORMAL","product_name":"Test
Product\"","sort":{"by":"name","order":"asc"},"results":[{"id":1,"cp_id":"4028fa1f7a334db8017a340eba710015","subscription_id":1,"name":"Test
Product","start_date":"2021-06-22 14:10:18 UTC","end_date":"2049-12-01 00:00:00
UTC","available":-1,"quantity":-1,"consumed":0,"account_number":null,"contract_number":null,"support_level":null,"product_id":"173314738043","sockets":null,"cores":null,"ram":null,"instance_multiplier":1,"stacking_id":null,"multi_entitlement":false,"type":"NORMAL","product_name":"Test
Product","unmapped_guest":false,"virt_only":false,"virt_who":false,"upstream":false,"upstream_pool_id":null}]}
'
Expand All @@ -93,11 +154,11 @@ interactions:
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- ; ANY
- 3; Test Organization
Foreman_version:
- 2.4.0
- 2.5.0
Keep-Alive:
- timeout=15, max=99
- timeout=15, max=98
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
Expand Down Expand Up @@ -129,13 +190,13 @@ interactions:
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/katello/api/subscriptions/3
uri: https://foreman.example.org/katello/api/organizations/3/subscriptions/1
response:
body:
string: ' {"arch":"ALL","description":null,"support_type":null,"role":null,"usage":null,"addons":null,"id":3,"cp_id":"4028fae1795b4f4201795fa3db630035","subscription_id":3,"name":"Test
Product","start_date":"2021-05-12 08:14:04 UTC","end_date":"2049-12-01 00:00:00
UTC","available":-1,"quantity":-1,"consumed":0,"account_number":null,"contract_number":null,"support_level":null,"product_id":"677308081353","sockets":null,"cores":null,"ram":null,"instance_multiplier":1,"stacking_id":null,"multi_entitlement":false,"type":"NORMAL","product_name":"Test
Product","unmapped_guest":false,"virt_only":false,"virt_who":false,"upstream":false,"upstream_pool_id":null,"host_count":0,"provided_products":[{"id":3,"name":"Test
string: ' {"arch":"ALL","description":null,"support_type":null,"roles":null,"usage":null,"addons":null,"id":1,"cp_id":"4028fa1f7a334db8017a340eba710015","subscription_id":1,"name":"Test
Product","start_date":"2021-06-22 14:10:18 UTC","end_date":"2049-12-01 00:00:00
UTC","available":-1,"quantity":-1,"consumed":0,"account_number":null,"contract_number":null,"support_level":null,"product_id":"173314738043","sockets":null,"cores":null,"ram":null,"instance_multiplier":1,"stacking_id":null,"multi_entitlement":false,"type":"NORMAL","product_name":"Test
Product","unmapped_guest":false,"virt_only":false,"virt_who":false,"upstream":false,"upstream_pool_id":null,"host_count":0,"provided_products":[{"id":1,"name":"Test
Product"}],"activation_keys":[]}
'
Expand All @@ -155,11 +216,11 @@ interactions:
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- ; ANY
- 3; Test Organization
Foreman_version:
- 2.4.0
- 2.5.0
Keep-Alive:
- timeout=15, max=98
- timeout=15, max=97
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
Expand All @@ -175,7 +236,7 @@ interactions:
X-XSS-Protection:
- 1; mode=block
content-length:
- '741'
- '742'
status:
code: 200
message: OK
Expand Down
79 changes: 70 additions & 9 deletions tests/test_playbooks/fixtures/subscription_info-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interactions:
uri: https://foreman.example.org/api/status
response:
body:
string: '{"result":"ok","status":200,"version":"2.4.0","api_version":2}'
string: '{"result":"ok","status":200,"version":"2.5.0","api_version":2}'
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Expand All @@ -33,7 +33,7 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.4.0
- 2.5.0
Keep-Alive:
- timeout=15, max=100
Strict-Transport-Security:
Expand Down Expand Up @@ -67,13 +67,74 @@ interactions:
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/katello/api/subscriptions?search=name%3D%22Test+Product%22&per_page=4294967296
uri: https://foreman.example.org/katello/api/organizations?search=name%3D%22Test+Organization%22&per_page=4294967296
response:
body:
string: "{\n \"total\": 2,\n \"subtotal\": 1,\n \"page\": 1,\n \"per_page\"\
: 4294967296,\n \"search\": \"name=\\\"Test Organization\\\"\",\n \"sort\"\
: {\n \"by\": null,\n \"order\": null\n },\n \"results\": [{\"label\"\
:\"Test_Organization\",\"created_at\":\"2021-06-22 14:10:13 UTC\",\"updated_at\"\
:\"2021-06-22 14:10:15 UTC\",\"id\":3,\"name\":\"Test Organization\",\"title\"\
:\"Test Organization\",\"description\":\"A test organization\"}]\n}\n"
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
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:
- '388'
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/organizations/3/subscriptions?search=name%3D%22Test+Product%22&per_page=4294967296
response:
body:
string: '{"organization":{},"total":1,"subtotal":1,"page":1,"per_page":"4294967296","error":null,"search":"name=\"Test
Product\"","sort":{"by":"name","order":"asc"},"results":[{"id":3,"cp_id":"4028fae1795b4f4201795fa3db630035","subscription_id":3,"name":"Test
Product","start_date":"2021-05-12 08:14:04 UTC","end_date":"2049-12-01 00:00:00
UTC","available":-1,"quantity":-1,"consumed":0,"account_number":null,"contract_number":null,"support_level":null,"product_id":"677308081353","sockets":null,"cores":null,"ram":null,"instance_multiplier":1,"stacking_id":null,"multi_entitlement":false,"type":"NORMAL","product_name":"Test
Product\"","sort":{"by":"name","order":"asc"},"results":[{"id":1,"cp_id":"4028fa1f7a334db8017a340eba710015","subscription_id":1,"name":"Test
Product","start_date":"2021-06-22 14:10:18 UTC","end_date":"2049-12-01 00:00:00
UTC","available":-1,"quantity":-1,"consumed":0,"account_number":null,"contract_number":null,"support_level":null,"product_id":"173314738043","sockets":null,"cores":null,"ram":null,"instance_multiplier":1,"stacking_id":null,"multi_entitlement":false,"type":"NORMAL","product_name":"Test
Product","unmapped_guest":false,"virt_only":false,"virt_who":false,"upstream":false,"upstream_pool_id":null}]}
'
Expand All @@ -93,11 +154,11 @@ interactions:
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- ; ANY
- 3; Test Organization
Foreman_version:
- 2.4.0
- 2.5.0
Keep-Alive:
- timeout=15, max=99
- timeout=15, max=98
Strict-Transport-Security:
- max-age=631139040; includeSubdomains
Vary:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_playbooks/subscription_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
vars_files:
- vars/server.yml
tasks:
- name: Fetch Subscription info
- name: Fetch Subscription info via name
subscription_info:
username: "{{ foreman_username }}"
password: "{{ foreman_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
organization: "Test Organization"
name: "Test Product"
register: sub
- name: check results
Expand All @@ -34,12 +35,13 @@
- sub.subscription.name == 'Test Product'
- sub.subscription.product_name == 'Test Product'

- name: Fetch Subscription info
- name: Fetch Subscription info via search
subscription_info:
username: "{{ foreman_username }}"
password: "{{ foreman_password }}"
server_url: "{{ foreman_server_url }}"
validate_certs: "{{ foreman_validate_certs }}"
organization: "Test Organization"
search: name="Test Product"
register: sub
- name: check results
Expand Down

0 comments on commit a06c19d

Please sign in to comment.