Merge pull request #180 from chrismeyersfsu/fix-7383

fix single update_on_project_update per-inventory
This commit is contained in:
Chris Meyers
2017-08-07 10:57:01 -04:00
committed by GitHub
4 changed files with 26 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ from django.utils.translation import ugettext_lazy as _
from django.db import transaction from django.db import transaction
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.timezone import now from django.utils.timezone import now
from django.db.models import Q
# AWX # AWX
from awx.api.versioning import reverse from awx.api.versioning import reverse
@@ -1396,11 +1397,19 @@ class InventorySource(UnifiedJobTemplate, InventorySourceOptions):
if self.update_on_project_update is True and \ if self.update_on_project_update is True and \
self.source == 'scm' and \ self.source == 'scm' and \
InventorySource.objects.filter( InventorySource.objects.filter(
inventory=self.inventory, Q(inventory=self.inventory,
update_on_project_update=True, source='scm').exists(): update_on_project_update=True, source='scm') &
~Q(id=self.id)).exists():
raise ValidationError(_("More than one SCM-based inventory source with update on project update on per-inventory not allowed."))
return self.update_on_project_update
def clean_update_on_launch(self):
if self.update_on_project_update is True and \
self.source == 'scm' and \
self.update_on_launch is True:
raise ValidationError(_("Cannot update SCM-based inventory source on launch if set to update on project update. " raise ValidationError(_("Cannot update SCM-based inventory source on launch if set to update on project update. "
"Instead, configure the corresponding source project to update on launch.")) "Instead, configure the corresponding source project to update on launch."))
return self.update_on_project_update return self.update_on_launch
def clean_overwrite_vars(self): def clean_overwrite_vars(self):
if self.source == 'scm' and not self.overwrite_vars: if self.source == 'scm' and not self.overwrite_vars:

View File

@@ -404,9 +404,8 @@ class TestControlledBySCM:
{'update_on_project_update': True,}, {'update_on_project_update': True,},
admin_user, expect=400) admin_user, expect=400)
content = json.loads(res.content) content = json.loads(res.content)
assert content['update_on_project_update'] == ["Cannot update SCM-based inventory source on launch if set to update on " assert content['update_on_project_update'] == ["More than one SCM-based inventory source with update on project update "
"project update. Instead, configure the corresponding source project to " "on per-inventory not allowed."]
"update on launch."]
def test_adding_inv_src_without_proj_access_prohibited(self, post, project, inventory, rando): def test_adding_inv_src_without_proj_access_prohibited(self, post, project, inventory, rando):
inventory.admin_role.members.add(rando) inventory.admin_role.members.add(rando)

View File

@@ -58,6 +58,9 @@ class TestSCMClean:
inv_src1.clean_update_on_project_update() inv_src1.clean_update_on_project_update()
inv_src1.save() inv_src1.save()
inv_src1.source_vars = '---\nhello: world'
inv_src1.clean_update_on_project_update()
inv_src2 = InventorySource(inventory=inventory, inv_src2 = InventorySource(inventory=inventory,
update_on_project_update=True, update_on_project_update=True,
source='scm') source='scm')

View File

@@ -108,3 +108,11 @@ class TestControlledBySCM():
with pytest.raises(ValidationError): with pytest.raises(ValidationError):
inv_src.clean_source_path() inv_src.clean_source_path()
def test_clean_update_on_launch_update_on_project_update(self):
inv_src = InventorySource(update_on_project_update=True,
update_on_launch=True,
source='scm')
with pytest.raises(ValidationError):
inv_src.clean_update_on_launch()