Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly detect credentials for tower_project #43215

Merged
merged 1 commit into from Aug 2, 2018

Conversation

dmsimard
Copy link
Contributor

SUMMARY

It seemed like it was mostly the wrong variables been looked at, making
it so a git repository could not be created without a credential, for example.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

tower_project

ANSIBLE VERSION
ansible 2.6.1
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Jul 13 2018, 13:06:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
ADDITIONAL INFORMATION

Before:

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_Ovkg7T/ansible_module_tower_project.py", line 174, in <module>
    main()
  File "/tmp/ansible_Ovkg7T/ansible_module_tower_project.py", line 151, in main
    cred = cred_res.get(name=scm_credential)
  File "/usr/lib/python2.7/site-packages/tower_cli/models/base.py", line 486, in get
    response = self.read(pk=pk, fail_on_no_results=True, fail_on_multiple_results=True, **kwargs)
  File "/usr/lib/python2.7/site-packages/tower_cli/models/base.py", line 306, in read
    raise exc.NotFound('The requested object could not be found.')
tower_cli.exceptions.NotFound: The requested object could not be found.

failed: [localhost] (item={u'name': u'bastion-tower', u'scm_clean': True, u'scm_url': u'https://github.com/dmsimard/bastion-tower', u'scm_type': u'git', u'organization': u'default-organization', u'description': u'Repository for infrastructure management'}) => {
    "changed": false, 
    "item": {
        "description": "Repository for infrastructure management", 
        "name": "bastion-tower", 
        "organization": "default-organization", 
        "scm_clean": true, 
        "scm_type": "git", 
        "scm_url": "https://github.com/dmsimard/bastion-tower"
    }, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_Ovkg7T/ansible_module_tower_project.py\", line 174, in <module>\n    main()\n  File \"/tmp/ansible_Ovkg7T/ansible_module_tower_project.py\", line 151, in main\n    cred = cred_res.get(name=scm_credential)\n  File \"/usr/lib/python2.7/site-packages/tower_cli/models/base.py\", line 486, in get\n    response = self.read(pk=pk, fail_on_no_results=True, fail_on_multiple_results=True, **kwargs)\n  File \"/usr/lib/python2.7/site-packages/tower_cli/models/base.py\", line 306, in read\n    raise exc.NotFound('The requested object could not be found.')\ntower_cli.exceptions.NotFound: The requested object could not be found.\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 1
}

After:

TASK [tower-config : Configure Tower projects] ********************************
Tuesday 24 July 2018  15:18:34 +0000 (0:00:00.846)       0:00:03.225 ********** 
changed: [localhost] => (item={u'name': u'bastion-tower', u'scm_clean': True, u'scm_url': u'https://github.com/dmsimard/bastion-tower', u'scm_type': u'git', u'organization': u'default-organization', u'description': u'Repository for infrastructure management'})

@ansibot
Copy link
Contributor

ansibot commented Jul 24, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. small_patch support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. labels Jul 24, 2018
@ansibot ansibot added the test This PR relates to tests. label Jul 24, 2018
try:
cred_res = tower_cli.get_resource('credential')
cred = cred_res.get(name=scm_credential)
except (exc.NotFound) as excinfo:
module.fail_json(msg='Failed to update project, credential not found: {0}'.format(scm_credential), changed=False)
credential = cred['id']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not have a variable scm_credential and credential. You could just call this scm_credential, and supply that in the project.modify call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

name: git project
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks great 👍

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jul 24, 2018
@@ -104,7 +104,7 @@ def main():
scm_type=dict(choices=['manual', 'git', 'hg', 'svn'], default='manual'),
scm_url=dict(),
scm_branch=dict(),
scm_credential=dict(),
scm_credential=dict(default=None),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't None the default value already ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point, I somehow felt the need to make it explicity. Let me fix that.

@AlanCoding
Copy link
Member

shipit

It seemed like it was mostly the wrong variables been looked at, making
it so a git repository could not be created without a credential.
@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. small_patch stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jul 24, 2018
@pilou-
Copy link
Contributor

pilou- commented Jul 24, 2018

LGTM : test is executed and run without any error.

@ryanpetrello
Copy link
Contributor

shipit

@dmsimard
Copy link
Contributor Author

@AlanCoding I think your shipit doesn't count because I did a slight modification afterwards :/

@AlanCoding
Copy link
Member

shipit

@ansibot ansibot removed the community_review In order to be merged, this PR must follow the community review workflow. label Jul 25, 2018
@ansibot ansibot added the shipit This PR is ready to be merged by Core label Jul 25, 2018
@bcoca bcoca merged commit 934500f into ansible:devel Aug 2, 2018
@dagwieers dagwieers added the tower Tower community label Feb 8, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. module This issue/PR relates to a module. shipit This PR is ready to be merged by Core small_patch support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. tower Tower community traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants