Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Update docs and tests for credential fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Oct 25, 2019
1 parent 761bad1 commit fd05170
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ It is also what the Ansible `tower_*` modules use under the hood. Such as:

https://docs.ansible.com/ansible/latest/modules/tower_organization_module.html

These modules are now vendored as part of the AWX collection at:

https://galaxy.ansible.com/awx/awx

Supporting correct operation of the modules is the maintenance aim of this
package.

Expand Down
6 changes: 6 additions & 0 deletions docs/source/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release History
===============

3.3.7 (2019-10-25)
------------------

- Job template associate_credential now uses "credentials" endpoint
- Include related credentials to job templates in send and receive commands

3.3.6 (2019-07-19)
------------------

Expand Down
18 changes: 9 additions & 9 deletions tests/test_resources_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_create(self):
t.register_json(endpoint, {'changed': True, 'id': 42},
method='POST')
self.res.create(name='bar', job_type='run', inventory=1,
project=1, playbook='foobar.yml', credential=1)
project=1, playbook='foobar.yml')
self.assertEqual(t.requests[0].method, 'GET')
self.assertEqual(t.requests[1].method, 'POST')
self.assertEqual(len(t.requests), 2)
Expand All @@ -55,7 +55,7 @@ def test_create(self):
t.register_json(endpoint, {'changed': True, 'id': 42},
method='POST')
self.res.create(name='bar', inventory=1, project=1,
playbook='foobar.yml', credential=1)
playbook='foobar.yml')
req_body = json.loads(t.requests[1].body)
self.assertIn('job_type', req_body)
self.assertEqual(req_body['job_type'], 'run')
Expand All @@ -74,13 +74,13 @@ def test_job_template_create_with_echo(self):
'playbook': 'foobar.yml', 'credential': 1},
method='POST')
self.res.create(name='bar', job_type='run', inventory=1,
project=1, playbook='foobar.yml', credential=1)
project=1, playbook='foobar.yml')

f = ResSubcommand(self.res)._echo_method(self.res.create)
with mock.patch.object(click, 'secho'):
with settings.runtime_values(format='human'):
f(name='bar', job_type='run', inventory=1,
project=1, playbook='foobar.yml', credential=1)
project=1, playbook='foobar.yml')

def test_create_w_extra_vars(self):
"""Establish that a job template can be created
Expand All @@ -94,7 +94,7 @@ def test_create_w_extra_vars(self):
t.register_json(endpoint, {'changed': True, 'id': 42},
method='POST')
self.res.create(name='bar', job_type='run', inventory=1,
project=1, playbook='foobar.yml', credential=1,
project=1, playbook='foobar.yml',
extra_vars=['foo: bar'])
self.assertEqual(t.requests[0].method, 'GET')
self.assertEqual(t.requests[1].method, 'POST')
Expand Down Expand Up @@ -137,9 +137,9 @@ def test_associate_credential(self):
that we expect.
"""
with client.test_mode as t:
t.register_json('/job_templates/42/extra_credentials/?id=84',
t.register_json('/job_templates/42/credentials/?id=84',
{'count': 0, 'results': []})
t.register_json('/job_templates/42/extra_credentials/', {}, method='POST')
t.register_json('/job_templates/42/credentials/', {}, method='POST')
self.res.associate_credential(42, 84)
self.assertEqual(t.requests[1].body,
json.dumps({'associate': True, 'id': 84}))
Expand All @@ -149,10 +149,10 @@ def test_disassociate_credential(self):
that we expect.
"""
with client.test_mode as t:
t.register_json('/job_templates/42/extra_credentials/?id=84',
t.register_json('/job_templates/42/credentials/?id=84',
{'count': 1, 'results': [{'id': 84}],
'next': None, 'previous': None})
t.register_json('/job_templates/42/extra_credentials/', {}, method='POST')
t.register_json('/job_templates/42/credentials/', {}, method='POST')
self.res.disassociate_credential(42, 84)
self.assertEqual(t.requests[1].body,
json.dumps({'disassociate': True, 'id': 84}))
Expand Down
10 changes: 5 additions & 5 deletions tower_cli/cli/transfer/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,23 +957,23 @@ def import_credentials(self, existing_object, new_creds):
tower_cli.get_resource('job_template').disassociate_credential(
existing_object['id'], existing_name_to_id[cred]
)
self.log_change("Removed extra credential {}".format(cred))
self.log_change("Removed credential {}".format(cred))
except TowerCLIError as e:
self.log_error("Unable to remove extra credential {} : {}".format(cred, e))
self.log_error("Unable to remove credential {} : {}".format(cred, e))

# Creds to add is the difference between existing_creds and extra_creds
for cred in list(set(new_creds).difference(existing_creds)):
try:
new_credential = tower_cli.get_resource('credential').get(**{'name': cred})
except TowerCLIError as e:
self.log_error("Unable to resolve extra credential {} : {}".format(cred, e))
self.log_error("Unable to resolve credential {} : {}".format(cred, e))
continue

try:
tower_cli.get_resource('job_template').associate_credential(existing_object['id'], new_credential['id'])
self.log_change("Added extra credential {}".format(cred))
self.log_change("Added credential {}".format(cred))
except TowerCLIError as e:
self.log_error("Unable to add extra credential {} : ".format(cred, e))
self.log_error("Unable to add credential {} : ".format(cred, e))

def import_labels(self, existing_object, new_labels, asset_type):
existing_labels_data = common.extract_labels(existing_object)
Expand Down
2 changes: 1 addition & 1 deletion tower_cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


VERSION = '3.3.6'
VERSION = '3.3.7'
# This is the release number for the RPM builds
RELEASE = 1
CUR_API_VERSION = 'v2'
Expand Down

0 comments on commit fd05170

Please sign in to comment.