JT param everything (#12646)

* Making almost all fields promptable on job templates and config models
* Adding EE, IG and label access checks
* Changing jobs preferred instance group function to handle the new IG cache field
* Adding new ask fields to job template modules
* Address unit/functional tests
* Adding migration file
This commit is contained in:
John Westcott IV
2022-08-16 12:24:02 -04:00
committed by Alan Rominger
parent 04d0e3915c
commit 33c0fb79d6
20 changed files with 781 additions and 38 deletions

View File

@@ -64,3 +64,18 @@ class TestSlicingModels:
inventory2 = Inventory.objects.create(organization=organization, name='fooinv')
[inventory2.hosts.create(name='foo{}'.format(i)) for i in range(3)]
assert job_template.get_effective_slice_ct({'inventory': inventory2})
def test_effective_slice_count_prompt(self, job_template, inventory, organization):
job_template.inventory = inventory
# Add our prompt fields to the JT to allow overrides
job_template.ask_job_slice_count_on_launch = True
job_template.ask_inventory_on_launch = True
# Set a default value of the slice count to something low
job_template.job_slice_count = 2
# Create an inventory with 4 nodes
inventory2 = Inventory.objects.create(organization=organization, name='fooinv')
[inventory2.hosts.create(name='foo{}'.format(i)) for i in range(4)]
# The inventory slice count will be the min of the number of nodes (4) or the job slice (2)
assert job_template.get_effective_slice_ct({'inventory': inventory2}) == 2
# Now we are going to pass in an override (like the prompt would) and as long as that is < host count we expect that back
assert job_template.get_effective_slice_ct({'inventory': inventory2, 'slice_count': 3}) == 3

View File

@@ -1,7 +1,7 @@
import pytest
# AWX
from awx.main.models import JobTemplate, JobLaunchConfig
from awx.main.models import JobTemplate, JobLaunchConfig, ExecutionEnvironment
@pytest.fixture
@@ -61,7 +61,17 @@ class TestConfigReversibility:
config = config_factory({'limit': 'foobar'})
assert config.prompts_dict() == {'limit': 'foobar'}
def test_related_objects(self, config_factory, inventory, credential):
prompts = {'limit': 'foobar', 'inventory': inventory, 'credentials': set([credential])}
def test_related_objects(self, config_factory, inventory, credential, label, default_instance_group):
ee = ExecutionEnvironment.objects.create(name='test-ee', image='quay.io/foo/bar')
prompts = {
'limit': 'foobar',
'inventory': inventory,
'credentials': [credential],
'execution_environment': ee,
'labels': [label],
'instance_groups': [default_instance_group],
}
config = config_factory(prompts)
print(prompts)
print(config.prompts_dict())
assert config.prompts_dict() == prompts