Skip to content

Commit

Permalink
cdn_repo: make packages parameter optional
Browse files Browse the repository at this point in the history
CDN repositories that are not "content_type: Docker" should not have
packages set.
  • Loading branch information
ktdreyer committed May 8, 2020
1 parent 9bdfc25 commit b3dfe71
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
20 changes: 18 additions & 2 deletions library/errata_tool_cdn_repo.py
Expand Up @@ -56,13 +56,29 @@
Errata Tool will apply this package's tag to all variants. If the tag
is a dict, the Errata Tool will apply the package's tag to the single
variant that you specify in the dict.
required: true
- If you omit this parameter, Ansible will remove all the existing
packages from this repository. You should omit this parameter for
repositories that are not content_type: Docker.
required: false
default: {} (no packages)
'''

EXAMPLES = '''
- name: create cdn repositories
hosts: localhost
tasks:
- name: Add rhceph-4-tools-for-rhel-8-x86_64-rpms cdn repo
errata_tool_cdn_repo:
name: redhat-rhceph-rhceph-4-rhel8
release_type: Primary
content_type: Binary
use_for_tps: True
arch: x86_64
variants:
- 8Base-RHCEPH-4.0-Tools
- 8Base-RHCEPH-4.1-Tools
- name: Add redhat-rhceph-rhceph-4-rhel8 cdn repo
errata_tool_cdn_repo:
name: redhat-rhceph-rhceph-4-rhel8
Expand Down Expand Up @@ -525,7 +541,7 @@ def run_module():
arch=dict(),
use_for_tps=dict(type='bool', default=False),
variants=dict(type='list', required=True),
packages=dict(type='dict', required=True),
packages=dict(type='dict', default={}),
)
module = AnsibleModule(
argument_spec=module_args,
Expand Down
37 changes: 37 additions & 0 deletions tests/test_errata_tool_cdn_repo.py
Expand Up @@ -745,6 +745,28 @@ def test_edit(self, client, params):
assert result['changed'] is True
assert set(result['stdout_lines']) == set(expected_stdout_lines)

def test_no_packages(self, client):
params = {
'name': 'rhceph-4-tools-for-rhel-8-x86_64-rpms',
'release_type': 'Primary',
'content_type': 'Binary',
'use_for_tps': True,
'arch': 'x86_64',
'variants': ['8Base-RHCEPH-4.0-Tools', '8Base-RHCEPH-4.1-Tools'],
'packages': {},
}
client.adapter.register_uri(
'GET',
PROD + '/api/v1/cdn_repos',
json={'data': []})
check_mode = True
result = ensure_cdn_repo(client, check_mode, params)
expected = {
'changed': True,
'stdout_lines': ['created rhceph-4-tools-for-rhel-8-x86_64-rpms'],
}
assert result == expected


class TestMain(object):

Expand Down Expand Up @@ -787,6 +809,21 @@ def container_module_args(self):
]},
}

def test_simple_rpms(self):
module_args = {
'name': 'rhceph-4-tools-for-rhel-8-x86_64-rpms',
'release_type': 'Primary',
'content_type': 'Binary',
'use_for_tps': True,
'arch': 'x86_64',
'variants': ['8Base-RHCEPH-4.0-Tools', '8Base-RHCEPH-4.1-Tools'],
}
set_module_args(module_args)
with pytest.raises(AnsibleExitJson) as exit:
main()
result = exit.value.args[0]
assert result['changed'] is True

def test_simple_container(self, container_module_args):
set_module_args(container_module_args)
with pytest.raises(AnsibleExitJson) as exit:
Expand Down

0 comments on commit b3dfe71

Please sign in to comment.