Project

Profile

Help

Issue #4910

closed

AnsibleDistribution allows setting repo and repo_version together in a PUT request

Added by rochacbruno almost 5 years ago. Updated over 3 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Platform Release:
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 56
Quarter:

Description

As stated in https://pulp.plan.io/issues/4846


4. Update the AnsibleDistribution to set both 'repository' and 'repository_version' and verify it rejects it. These options cannot be used together

It is true for a POST request, however when using a PUT to update existing distribution it allows both fields to exist together.

How to reproduce it: (Using pulp-smash shell)

Having `pulp-smash` installed do

$ cd pulp_ansible
$ export PULP_SMASH_CONFIG_FILE=path/to/settings.json
$ pulp-smash shell

Now inside pulp-smash shell run the following script (if ipython is installed you must be able to copy-paste the whole script)

from pulp_ansible.tests.functional import constants as ct

# create a repo
repo = api.client.post(pulp3.constants.REPO_PATH, pulp3.utils.gen_repo())

# create ansible galaxy role remote
_url = 'https://galaxy.ansible.com/api/v1/roles/?namespace__name=elastic'
_body = pulp3.utils.gen_remote(url=_url)
remote = api.client.post(ct.ANSIBLE_REMOTE_PATH, _body)

# sync it
pulp3.utils.sync(cfg, remote, repo)
repo = api.client.get(repo['_href'])

# create ansible distribution
_body = pulp3.utils.gen_distribution(repository=repo['_href'])
dist = api.client.post(ct.ANSIBLE_DISTRIBUTION_PATH, _body)

# Assert distribution has repository but not repository_version
assert dist['repository'] is not None
assert dist['repository_version'] is None

# Patch dist removing repository and setting repository version
api.client.patch(dist['_href'], {'repository': None})
api.client.patch(dist['_href'], {'repository_version': repo['_latest_version_href']})
# re-read the dist
dist =  api.client.get(dist['_href'])

# Assert distribution now has repository_version but not repository
assert dist['repository'] is None
assert dist['repository_version'] is not None

# Now We try to use a `PUT` to replace the whole distribution
# the new object will have only repository but not repository_version
new_dist = dist.copy()
new_dist['repository'] = repo['_href']
del new_dist['repository_version']

assert 'repository_version' not in new_dist
assert new_dist['repository'] == repo['_href']

# Perform the PUT replacing the whole distribution
api.client.put(dist['_href'], new_dist)

# Re-read the distribution
dist = api.client.get(dist['_href'])

# Notice that the distribution now has repository and repository_version together

assert dist['repository'] == repo['_href']  # passes
assert dist['repository_version'] is None  # fails

Actual results:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
~/Projects/pulp/pulp-smash/pulp_smash/pulp_smash_cli.py in <module>
     51
     52 assert dist['repository'] == repo['_href']  # passes
---> 53 assert dist['repository_version'] is None  # fails

AssertionError:

Expected results:

No error since the PUT replaced the whole object.


Related issues

Related to Pulp - Test #4846: CRUD RepositoryVersionDistributionCLOSED - COMPLETErochacbrunoActions

Also available in: Atom PDF