mirror of
https://github.com/ansible/awx.git
synced 2026-03-17 00:47:29 -02:30
Merge pull request #8043 from john-westcott-iv/instance_groups_module
Adding tower_instance_group module Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -53,8 +53,7 @@ no_api_parameter_ok = {
|
||||
# that needs to be developed. If the module is found on the file system it will auto-detect that the
|
||||
# work is being done and will bypass this check. At some point this module should be removed from this list.
|
||||
needs_development = [
|
||||
'tower_ad_hoc_command', 'tower_application', 'tower_instance_group', 'tower_inventory_script',
|
||||
'tower_workflow_approval'
|
||||
'tower_ad_hoc_command', 'tower_application', 'tower_inventory_script', 'tower_workflow_approval'
|
||||
]
|
||||
needs_param_development = {
|
||||
'tower_host': ['instance_id'],
|
||||
|
||||
71
awx_collection/test/awx/test_instance_group.py
Normal file
71
awx_collection/test/awx/test_instance_group.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from awx.main.models import InstanceGroup, Instance
|
||||
from awx.main.tests.functional.conftest import kube_credential, credentialtype_kube
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_instance_group_create(run_module, admin_user):
|
||||
result = run_module('tower_instance_group', {
|
||||
'name': 'foo-group',
|
||||
'policy_instance_percentage': 34,
|
||||
'policy_instance_minimum': 12,
|
||||
'state': 'present'
|
||||
}, admin_user)
|
||||
assert not result.get('failed', False), result
|
||||
assert result['changed']
|
||||
|
||||
ig = InstanceGroup.objects.get(name='foo-group')
|
||||
assert ig.policy_instance_percentage == 34
|
||||
assert ig.policy_instance_minimum == 12
|
||||
|
||||
# Create a new instance in the DB
|
||||
new_instance = Instance.objects.create(hostname='foo.example.com')
|
||||
|
||||
# Set the new instance group only to the one instnace
|
||||
result = run_module('tower_instance_group', {
|
||||
'name': 'foo-group',
|
||||
'instances': [new_instance.hostname],
|
||||
'state': 'present'
|
||||
}, admin_user)
|
||||
assert not result.get('failed', False), result
|
||||
assert result['changed']
|
||||
|
||||
ig = InstanceGroup.objects.get(name='foo-group')
|
||||
all_instance_names = []
|
||||
for instance in ig.instances.all():
|
||||
all_instance_names.append(instance.hostname)
|
||||
|
||||
assert new_instance.hostname in all_instance_names, 'Failed to add instance to group'
|
||||
assert len(all_instance_names) == 1, 'Too many instances in group {0}'.format(','.join(all_instance_names))
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_container_group_create(run_module, admin_user, kube_credential):
|
||||
pod_spec = "{ 'Nothing': True }"
|
||||
|
||||
result = run_module('tower_instance_group', {
|
||||
'name': 'foo-c-group',
|
||||
'credential': kube_credential.id,
|
||||
'state': 'present'
|
||||
}, admin_user)
|
||||
assert not result.get('failed', False), result['msg']
|
||||
assert result['changed']
|
||||
|
||||
ig = InstanceGroup.objects.get(name='foo-c-group')
|
||||
assert ig.pod_spec_override == ''
|
||||
|
||||
result = run_module('tower_instance_group', {
|
||||
'name': 'foo-c-group',
|
||||
'credential': kube_credential.id,
|
||||
'pod_spec_override': pod_spec,
|
||||
'state': 'present'
|
||||
}, admin_user)
|
||||
assert not result.get('failed', False), result['msg']
|
||||
assert result['changed']
|
||||
|
||||
ig = InstanceGroup.objects.get(name='foo-c-group')
|
||||
assert ig.pod_spec_override == pod_spec
|
||||
Reference in New Issue
Block a user