Server IP : 85.214.239.14 / Your IP : 3.142.130.127 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/task/2/cwd/usr/lib/python3/dist-packages/ansible_collections/awx/awx/test/awx/ |
Upload File : |
from __future__ import absolute_import, division, print_function __metaclass__ = type import pytest from awx.main.models import Organization, Inventory, Group, Host @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) variables = {"ansible_network_os": "iosxr"} result = run_module('group', dict(name='Test Group', inventory='test-inv', variables=variables, 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, 'name': 'Test Group', 'changed': True, } @pytest.mark.django_db def test_associate_hosts_and_children(run_module, admin_user, organization): inv = Inventory.objects.create(name='test-inv', organization=organization) group = Group.objects.create(name='Test Group', inventory=inv) inv_hosts = [Host.objects.create(inventory=inv, name='foo{0}'.format(i)) for i in range(3)] group.hosts.add(inv_hosts[0], inv_hosts[1]) child = Group.objects.create(inventory=inv, name='child_group') result = run_module( 'group', dict(name='Test Group', inventory='test-inv', hosts=[inv_hosts[1].name, inv_hosts[2].name], children=[child.name], state='present'), admin_user, ) assert not result.get('failed', False), result.get('msg', result) assert result['changed'] is True assert set(group.hosts.all()) == set([inv_hosts[1], inv_hosts[2]]) assert set(group.children.all()) == set([child]) @pytest.mark.django_db def test_associate_on_create(run_module, admin_user, organization): inv = Inventory.objects.create(name='test-inv', organization=organization) child = Group.objects.create(name='test-child', inventory=inv) host = Host.objects.create(name='test-host', inventory=inv) result = run_module('group', dict(name='Test Group', inventory='test-inv', hosts=[host.name], groups=[child.name], state='present'), admin_user) assert not result.get('failed', False), result.get('msg', result) assert result['changed'] is True group = Group.objects.get(pk=result['id']) assert set(group.hosts.all()) == set([host]) assert set(group.children.all()) == set([child]) @pytest.mark.django_db def test_children_alias_of_groups(run_module, admin_user, organization): inv = Inventory.objects.create(name='test-inv', organization=organization) group = Group.objects.create(name='Test Group', inventory=inv) child = Group.objects.create(inventory=inv, name='child_group') result = run_module('group', dict(name='Test Group', inventory='test-inv', groups=[child.name], state='present'), admin_user) assert not result.get('failed', False), result.get('msg', result) assert result['changed'] is True assert set(group.children.all()) == set([child]) @pytest.mark.django_db def test_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, ) result = run_module('group', dict(name='Test Group', inventory='test-inv', state='present'), admin_user) result.pop('invocation') assert result == { 'id': group.id, 'changed': False, # idempotency assertion }