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
Actions #1

Updated by rochacbruno almost 5 years ago

  • Related to Test #4846: CRUD RepositoryVersionDistribution added
Actions #2

Updated by daviddavis almost 5 years ago

  • Triaged changed from No to Yes
  • Sprint set to Sprint 54
Actions #3

Updated by ttereshc almost 5 years ago

  • Sprint changed from Sprint 54 to Sprint 55
Actions #4

Updated by dkliban@redhat.com almost 5 years ago

  • Sprint changed from Sprint 55 to Sprint 56
Actions #5

Updated by daviddavis over 4 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to fao89
Actions #6

Updated by fao89 over 4 years ago

  • Status changed from ASSIGNED to CLOSED - WORKSFORME
(pulp) [vagrant@pulp3-source-fedora28 hello]$ http POST $BASE_ADDR/pulp/api/v3/distributions/ansible/ansible/ \
>   name='baz10' \
>   base_path='foo10' \
>   repository=${REPO_HREF} \
>   repository_version=${REPO_HREF}versions/1/ 
HTTP/1.1 400 Bad Request
Allow: GET, POST, HEAD, OPTIONS
Connection: close
Content-Length: 102
Content-Type: application/json
Date: Fri, 26 Jul 2019 17:40:55 GMT
Server: gunicorn/19.9.0
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

{
    "non_field_errors": [
        "The attributes 'repository' and 'repository_version' must be usedexclusively."
    ]
}

(pulp) [vagrant@pulp3-source-fedora28 devel]$ http PUT $BASE_ADDR/pulp/api/v3/distributions/ansible/ansible/4262ed83-e86c-4a13-baff-fc543c46a391/ \
>   name='baz10' \
>   base_path='foo10' \
>   repository=${REPO_HREF} \
>   repository_version=${REPO_HREF}versions/1/ 
HTTP/1.1 400 Bad Request
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Connection: close
Content-Length: 102
Content-Type: application/json
Date: Fri, 26 Jul 2019 17:49:01 GMT
Server: gunicorn/19.9.0
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

{
    "non_field_errors": [
        "The attributes 'repository' and 'repository_version' must be usedexclusively."
    ]
}
Actions #7

Updated by fao89 over 4 years ago

  • Status changed from CLOSED - WORKSFORME to ASSIGNED
=================================== FAILURES ===================================
 RepositoryVersionDistributionTestCase.test_05_positive_full_update_distribution_to_use_repo 
self = <pulp_ansible.tests.functional.api.role.test_crd_distribution.RepositoryVersionDistributionTestCase testMethod=test_05_positive_full_update_distribution_to_use_repo>
    @skip_if(bool, "distribution", False)
    @skip_if(bool, "repo", False)
    def test_05_positive_full_update_distribution_to_use_repo(self):
        """Put a distribution with 'repository' field set."""
        if not selectors.bug_is_fixed(4910, self.cfg.pulp_version):
            raise unittest.SkipTest("Issue 4910 is not resolved")

        new_dist = self.distribution.copy()
        new_dist["repository"] = self.repo["_href"]
        del new_dist["repository_version"]
        del self.distribution["repository_version"]

        self.distribution.update(self.client.put(self.distribution["_href"], new_dist))

        self.assertEqual(self.distribution["repository"], self.repo["_href"])

>       self.assertIsNone(self.distribution["repository_version"])
E       AssertionError: '/pulp/api/v3/repositories/c8047abd-eb82-4718-9f35-80beb674755b/versions/1/' is not None
pulp_ansible/tests/functional/api/role/test_crd_distribution.py:132: AssertionError

Added by Fabricio Aguiar over 4 years ago

Revision ce2a9647 | View on GitHub

assure exclusively on repository serializer

closes #4910

Actions #9

Updated by Anonymous over 4 years ago

  • Status changed from POST to MODIFIED
Actions #10

Updated by daviddavis over 4 years ago

  • Status changed from MODIFIED to POST
Actions #11

Updated by daviddavis over 4 years ago

  • Status changed from POST to MODIFIED

Added by Fabricio Aguiar over 4 years ago

Revision 43357cf9 | View on GitHub

update test for 4910

ref #4910

Actions #12

Updated by bmbouter over 3 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF