mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 14:27:42 -02:30
Merge pull request #5015 from AlanCoding/awx_awx_cp1
tower_credential: Missing 'kind' attribute (#61324) Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -255,7 +255,7 @@ OLD_INPUT_NAMES = (
|
|||||||
|
|
||||||
def credential_type_for_kind(params):
|
def credential_type_for_kind(params):
|
||||||
credential_type_res = tower_cli.get_resource('credential_type')
|
credential_type_res = tower_cli.get_resource('credential_type')
|
||||||
kind = params.pop('kind')
|
kind = params.get('kind')
|
||||||
arguments = {'managed_by_tower': True}
|
arguments = {'managed_by_tower': True}
|
||||||
if kind == 'ssh':
|
if kind == 'ssh':
|
||||||
if params.get('vault_password'):
|
if params.get('vault_password'):
|
||||||
|
|||||||
@@ -7,20 +7,52 @@ from awx.main.models import Credential, CredentialType, Organization
|
|||||||
def test_create_machine_credential(run_module, admin_user):
|
def test_create_machine_credential(run_module, admin_user):
|
||||||
Organization.objects.create(name='test-org')
|
Organization.objects.create(name='test-org')
|
||||||
# create the ssh credential type
|
# create the ssh credential type
|
||||||
CredentialType.defaults['ssh']().save()
|
ct = CredentialType.defaults['ssh']()
|
||||||
|
ct.save()
|
||||||
# Example from docs
|
# Example from docs
|
||||||
result = run_module('tower_credential', dict(
|
result = run_module('tower_credential', dict(
|
||||||
name='Team Name',
|
name='Test Machine Credential',
|
||||||
description='Team Description',
|
|
||||||
organization='test-org',
|
organization='test-org',
|
||||||
kind='ssh',
|
kind='ssh',
|
||||||
state='present'
|
state='present'
|
||||||
), admin_user)
|
), admin_user)
|
||||||
|
assert result.get('changed'), result
|
||||||
|
|
||||||
cred = Credential.objects.get(name='Team Name')
|
cred = Credential.objects.get(name='Test Machine Credential')
|
||||||
|
assert cred.credential_type == ct
|
||||||
result.pop('invocation')
|
result.pop('invocation')
|
||||||
assert result == {
|
assert result == {
|
||||||
"credential": "Team Name",
|
"credential": "Test Machine Credential",
|
||||||
|
"state": "present",
|
||||||
|
"id": cred.pk,
|
||||||
|
"changed": True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_create_vault_credential(run_module, admin_user):
|
||||||
|
# https://github.com/ansible/ansible/issues/61324
|
||||||
|
Organization.objects.create(name='test-org')
|
||||||
|
ct = CredentialType.defaults['vault']()
|
||||||
|
ct.save()
|
||||||
|
|
||||||
|
result = run_module('tower_credential', dict(
|
||||||
|
name='Test Vault Credential',
|
||||||
|
organization='test-org',
|
||||||
|
kind='vault',
|
||||||
|
vault_id='bar',
|
||||||
|
vault_password='foobar',
|
||||||
|
state='present'
|
||||||
|
), admin_user)
|
||||||
|
assert result.get('changed'), result
|
||||||
|
|
||||||
|
cred = Credential.objects.get(name='Test Vault Credential')
|
||||||
|
assert cred.credential_type == ct
|
||||||
|
assert 'vault_id' in cred.inputs
|
||||||
|
assert 'vault_password' in cred.inputs
|
||||||
|
result.pop('invocation')
|
||||||
|
assert result == {
|
||||||
|
"credential": "Test Vault Credential",
|
||||||
"state": "present",
|
"state": "present",
|
||||||
"id": cred.pk,
|
"id": cred.pk,
|
||||||
"changed": True
|
"changed": True
|
||||||
@@ -39,6 +71,7 @@ def test_create_custom_credential_type(run_module, admin_user):
|
|||||||
state='present',
|
state='present',
|
||||||
validate_certs='false'
|
validate_certs='false'
|
||||||
), admin_user)
|
), admin_user)
|
||||||
|
assert result.get('changed'), result
|
||||||
|
|
||||||
ct = CredentialType.objects.get(name='Nexus')
|
ct = CredentialType.objects.get(name='Nexus')
|
||||||
result.pop('invocation')
|
result.pop('invocation')
|
||||||
|
|||||||
Reference in New Issue
Block a user