Merge pull request #5191 from AlanCoding/tower_group_id

Make tower_group idempotent

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2019-11-21 04:26:16 +00:00
committed by GitHub
2 changed files with 60 additions and 5 deletions

View File

@@ -0,0 +1,56 @@
import pytest
from awx.main.models import Organization, Inventory, Group
@pytest.mark.django_db
def test_create_group(run_module, admin_user):
org = Organization.objects.create(name='test-org')
inv = Inventory.objects.create(name='test-inv', organization=org)
result = run_module('tower_group', dict(
name='Test Group',
inventory='test-inv',
variables='ansible_network_os: iosxr',
state='present'
), admin_user)
assert result.get('changed'), result
group = Group.objects.get(name='Test Group')
assert group.inventory == inv
assert group.variables == 'ansible_network_os: iosxr'
result.pop('invocation')
assert result == {
'id': group.id,
'group': 'Test Group',
'changed': True,
'state': 'present'
}
@pytest.mark.django_db
def test_tower_group_idempotent(run_module, admin_user):
# https://github.com/ansible/ansible/issues/46803
org = Organization.objects.create(name='test-org')
inv = Inventory.objects.create(name='test-inv', organization=org)
group = Group.objects.create(
name='Test Group',
inventory=inv,
variables='ansible_network_os: iosxr'
)
result = run_module('tower_group', dict(
name='Test Group',
inventory='test-inv',
variables='ansible_network_os: iosxr',
state='present'
), admin_user)
result.pop('invocation')
assert result == {
'id': group.id,
'group': 'Test Group',
'changed': False, # idempotency assertion
'state': 'present'
}