Skip to content

Commit

Permalink
unscope repositories by org
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Nov 19, 2020
1 parent 1c1f8b9 commit e2b421f
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 106 deletions.
7 changes: 7 additions & 0 deletions plugins/modules/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ def main():
entity_opts={'scope': ['product']},
)

# KatelloEntityAnsibleModule automatically adds organization to the entity scope
# but repositories are scoped by product (and these are org scoped)
module.foreman_spec['entity']['scope'].remove('organization')

if module.foreman_params['content_type'] != 'docker':
invalid_list = [key for key in ['docker_upstream_name', 'docker_tags_whitelist'] if key in module.foreman_params]
if invalid_list:
Expand All @@ -318,6 +322,9 @@ def main():
module.foreman_params['http_proxy_policy'] = 'none' if module.foreman_params['ignore_global_proxy'] else 'global_default_http_proxy'

with module.api_connection():
if not module.desired_absent:
module.auto_lookup_entities()
module.foreman_params.pop('organization')
module.run()


Expand Down
41 changes: 21 additions & 20 deletions tests/test_playbooks/fixtures/repository_deb-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-develop","api_version":2}'
string: '{"result":"ok","status":200,"version":"2.2.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-develop
- 2.2.0
Keep-Alive:
- timeout=15, max=100
Strict-Transport-Security:
Expand All @@ -51,7 +51,7 @@ interactions:
X-XSS-Protection:
- 1; mode=block
content-length:
- '70'
- '62'
status:
code: 200
message: OK
Expand All @@ -70,11 +70,12 @@ interactions:
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\":\"2020-11-10
13:26:32 UTC\",\"updated_at\":\"2020-11-10 13:26:32 UTC\",\"id\":3,\"name\":\"Test
Organization\",\"title\":\"Test Organization\",\"description\":\"A test organization\"}]\n}\n"
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\":\"2020-11-17 14:59:16 UTC\",\"updated_at\"\
:\"2020-11-17 14:59:16 UTC\",\"id\":3,\"name\":\"Test Organization\",\"title\"\
:\"Test Organization\",\"description\":\"A test organization\"}]\n}\n"
headers:
Cache-Control:
- max-age=0, private, must-revalidate
Expand All @@ -93,7 +94,7 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.4.0-develop
- 2.2.0
Keep-Alive:
- timeout=15, max=99
Strict-Transport-Security:
Expand Down Expand Up @@ -131,7 +132,7 @@ interactions:
response:
body:
string: '{"total":1,"subtotal":1,"page":1,"per_page":"4294967296","error":null,"search":"name=\"Test
Product\"","sort":{"by":"name","order":"asc"},"results":[{"id":1,"cp_id":"183366231652","name":"Test
Product\"","sort":{"by":"name","order":"asc"},"results":[{"id":1,"cp_id":"518635537281","name":"Test
Product","label":"Test_Product","description":"A happy little test product","provider_id":3,"sync_plan_id":null,"sync_summary":{},"gpg_key_id":null,"ssl_ca_cert_id":null,"ssl_client_cert_id":null,"ssl_client_key_id":null,"sync_state":null,"last_sync":null,"last_sync_words":null,"organization_id":3,"organization":{"name":"Test
Organization","label":"Test_Organization","id":3},"sync_plan":null,"repository_count":0}]}
Expand All @@ -154,7 +155,7 @@ interactions:
Foreman_current_organization:
- 3; Test Organization
Foreman_version:
- 2.4.0-develop
- 2.2.0
Keep-Alive:
- timeout=15, max=98
Strict-Transport-Security:
Expand Down Expand Up @@ -188,7 +189,7 @@ interactions:
User-Agent:
- apypie (https://github.com/Apipie/apypie)
method: GET
uri: https://foreman.example.org/katello/api/organizations/3/repositories?product_id=1&search=name%3D%22Test+Debian+Repository%22&per_page=4294967296
uri: https://foreman.example.org/katello/api/products/1/repositories?search=name%3D%22Test+Debian+Repository%22&per_page=4294967296
response:
body:
string: '{"total":0,"subtotal":0,"page":1,"per_page":"4294967296","error":null,"search":"name=\"Test
Expand All @@ -211,9 +212,9 @@ interactions:
Foreman_current_location:
- ; ANY
Foreman_current_organization:
- 3; Test Organization
- ; ANY
Foreman_version:
- 2.4.0-develop
- 2.2.0
Keep-Alive:
- timeout=15, max=97
Strict-Transport-Security:
Expand Down Expand Up @@ -257,12 +258,12 @@ interactions:
response:
body:
string: ' {"ostree_branches":[],"relative_path":"Test_Organization/Library/custom/Test_Product/just_a_test_repo3","promoted":false,"content_view_version_id":2,"library_instance_id":null,"organization_id":3,"organization":{"name":"Test
Organization","label":"Test_Organization","id":3},"created_at":"2020-11-10
13:26:44 UTC","updated_at":"2020-11-10 13:26:45 UTC","backend_identifier":"8e2c9db4-255c-4ee7-a61c-c377d1ec8296","container_repository_name":null,"full_path":"http://foreman.example.com/pulp/deb/Test_Organization/Library/custom/Test_Product/just_a_test_repo3/","version_href":null,"remote_href":null,"publication_href":null,"id":1,"name":"Test
Debian Repository","label":"just_a_test_repo3","description":null,"last_sync":null,"content_view":{"id":2,"name":"Default
Organization","label":"Test_Organization","id":3},"created_at":"2020-11-17
14:59:26 UTC","updated_at":"2020-11-17 14:59:28 UTC","backend_identifier":"c101c775-9b4f-44e1-89dd-55980ea6bb98","container_repository_name":null,"full_path":"http://centos7-katello-3-17.yatsu.example.com/pulp/deb/Test_Organization/Library/custom/Test_Product/just_a_test_repo3/","version_href":null,"remote_href":null,"publication_href":null,"id":1,"name":"Test
Debian Repository","label":"just_a_test_repo3","description":null,"last_sync":null,"content_view":{"id":4,"name":"Default
Organization View"},"content_view_version":{"id":2,"name":"Default Organization
View 1.0","content_view_id":2},"kt_environment":{"id":2,"name":"Library"},"content_type":"deb","url":"https://ftp.debian.org","arch":"noarch","os_versions":null,"content_id":"1605014804842","major":null,"minor":null,"product":{"id":1,"cp_id":"183366231652","name":"Test
Product","orphaned":false,"redhat":false,"sync_plan":null},"content_label":"Test_Organization_Test_Product_just_a_test_repo3","content_counts":{"ostree_branch":0,"docker_manifest":0,"docker_manifest_list":0,"docker_tag":0,"rpm":0,"srpm":0,"package":0,"package_group":0,"erratum":0,"puppet_module":0,"file":0,"deb":0,"module_stream":0,"ansible_collection":0},"last_sync_words":null,"environment":{"id":2,"registry_unauthenticated_pull":false},"docker_upstream_name":null,"docker_tags_whitelist":null,"mirror_on_sync":true,"verify_ssl_on_sync":true,"unprotected":true,"checksum_type":null,"download_policy":null,"ansible_collection_requirements":null,"gpg_key_id":null,"ssl_ca_cert_id":null,"ssl_client_cert_id":null,"ssl_client_key_id":null,"upstream_username":null,"ostree_upstream_sync_policy":null,"ostree_upstream_sync_depth":null,"computed_ostree_upstream_sync_depth":0,"deb_releases":"buster","deb_components":null,"deb_architectures":"i386","http_proxy_policy":"global_default_http_proxy","http_proxy_id":null,"http_proxy_name":"env-proxy-02.infra.sat.rdu2.redhat.com","ignorable_content":null,"gpg_key":null,"http_proxy":{"id":1,"name":"env-proxy-02.infra.sat.rdu2.redhat.com","policy":"global_default_http_proxy"},"ssl_ca_cert":{"id":null,"name":null},"ssl_client_cert":{"id":null,"name":null},"ssl_client_key":{"id":null,"name":null},"permissions":{"deletable":true},"upstream_password_exists":false,"upstream_auth_exists":false,"content_view_environments":[]}
View 1.0","content_view_id":4},"kt_environment":{"id":2,"name":"Library"},"content_type":"deb","url":"https://ftp.debian.org","arch":"noarch","content_id":"1605625167528","major":null,"minor":null,"product":{"id":1,"cp_id":"518635537281","name":"Test
Product","orphaned":false,"redhat":false,"sync_plan":null},"content_label":"Test_Organization_Test_Product_just_a_test_repo3","content_counts":{"ostree_branch":0,"docker_manifest":0,"docker_manifest_list":0,"docker_tag":0,"rpm":0,"srpm":0,"package":0,"package_group":0,"erratum":0,"puppet_module":0,"file":0,"deb":0,"module_stream":0,"ansible_collection":0},"last_sync_words":null,"environment":{"id":2,"registry_unauthenticated_pull":false},"docker_upstream_name":null,"docker_tags_whitelist":null,"mirror_on_sync":true,"verify_ssl_on_sync":true,"unprotected":true,"checksum_type":null,"download_policy":null,"ansible_collection_requirements":null,"gpg_key_id":null,"ssl_ca_cert_id":null,"ssl_client_cert_id":null,"ssl_client_key_id":null,"upstream_username":null,"ostree_upstream_sync_policy":null,"ostree_upstream_sync_depth":null,"computed_ostree_upstream_sync_depth":0,"deb_releases":"buster","deb_components":null,"deb_architectures":"i386","http_proxy_policy":"global_default_http_proxy","http_proxy_id":null,"http_proxy_name":null,"ignorable_content":null,"gpg_key":null,"http_proxy":{"id":null,"name":null,"policy":"global_default_http_proxy"},"ssl_ca_cert":{"id":null,"name":null},"ssl_client_cert":{"id":null,"name":null},"ssl_client_key":{"id":null,"name":null},"permissions":{"deletable":true},"upstream_password_exists":false,"upstream_auth_exists":false,"content_view_environments":[]}
'
headers:
Expand All @@ -283,7 +284,7 @@ interactions:
Foreman_current_organization:
- ; ANY
Foreman_version:
- 2.4.0-develop
- 2.2.0
Keep-Alive:
- timeout=15, max=96
Strict-Transport-Security:
Expand Down
Loading

0 comments on commit e2b421f

Please sign in to comment.