mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 11:27:36 -02:30
Fix typo, modify can_update to prevent inventory update from even starting when source script is missing.
This commit is contained in:
@@ -1472,7 +1472,7 @@ class CustomInventoryScriptAccess(BaseAccess):
|
|||||||
if self.user.is_superuser:
|
if self.user.is_superuser:
|
||||||
return True
|
return True
|
||||||
if not self.active:
|
if not self.active:
|
||||||
return Flase
|
return False
|
||||||
return bool(obj.organization in self.user.organizations.all() or obj.organization in self.user.admin_of_organizations.all())
|
return bool(obj.organization in self.user.organizations.all() or obj.organization in self.user.admin_of_organizations.all())
|
||||||
|
|
||||||
def can_add(self, data):
|
def can_add(self, data):
|
||||||
|
|||||||
@@ -1140,7 +1140,10 @@ class InventorySource(UnifiedJobTemplate, InventorySourceOptions):
|
|||||||
return reverse('api:inventory_source_detail', args=(self.pk,))
|
return reverse('api:inventory_source_detail', args=(self.pk,))
|
||||||
|
|
||||||
def _can_update(self):
|
def _can_update(self):
|
||||||
return bool(self.source in CLOUD_INVENTORY_SOURCES)
|
if self.source == 'custom':
|
||||||
|
return bool(self.source_script and self.source_script.active)
|
||||||
|
else:
|
||||||
|
return bool(self.source in CLOUD_INVENTORY_SOURCES)
|
||||||
|
|
||||||
def create_inventory_update(self, **kwargs):
|
def create_inventory_update(self, **kwargs):
|
||||||
return self.create_unified_job(**kwargs)
|
return self.create_unified_job(**kwargs)
|
||||||
|
|||||||
@@ -1116,7 +1116,10 @@ class InventoryUpdatesTest(BaseTransactionTest):
|
|||||||
should_error = kwargs.pop('should_error', False)
|
should_error = kwargs.pop('should_error', False)
|
||||||
if not inventory_update:
|
if not inventory_update:
|
||||||
inventory_update = inventory_source.update(**kwargs)
|
inventory_update = inventory_source.update(**kwargs)
|
||||||
self.assertTrue(inventory_update)
|
if not should_fail and not should_error:
|
||||||
|
self.assertTrue(inventory_update)
|
||||||
|
elif not inventory_update:
|
||||||
|
return None
|
||||||
inventory_update = InventoryUpdate.objects.get(pk=inventory_update.pk)
|
inventory_update = InventoryUpdate.objects.get(pk=inventory_update.pk)
|
||||||
#print inventory_update.result_stdout
|
#print inventory_update.result_stdout
|
||||||
if should_error:
|
if should_error:
|
||||||
@@ -1746,7 +1749,7 @@ class InventoryUpdatesTest(BaseTransactionTest):
|
|||||||
# Create the inventory script
|
# Create the inventory script
|
||||||
self.create_test_license_file()
|
self.create_test_license_file()
|
||||||
inventory_scripts = reverse('api:inventory_script_list')
|
inventory_scripts = reverse('api:inventory_script_list')
|
||||||
new_script = dict(name="Test", description="Test Script", script=TEST_SIMPLE_INVENTORY_SCRIPT)
|
new_script = dict(name="Test", description="Test Script", script=TEST_SIMPLE_INVENTORY_SCRIPT, organization=self.organization.id)
|
||||||
script_data = self.post(inventory_scripts, data=new_script, expect=201, auth=self.get_super_credentials())
|
script_data = self.post(inventory_scripts, data=new_script, expect=201, auth=self.get_super_credentials())
|
||||||
|
|
||||||
custom_inv = self.organization.inventories.create(name='Custom Script Inventory')
|
custom_inv = self.organization.inventories.create(name='Custom Script Inventory')
|
||||||
@@ -1762,3 +1765,11 @@ class InventoryUpdatesTest(BaseTransactionTest):
|
|||||||
with self.current_user(self.super_django_user):
|
with self.current_user(self.super_django_user):
|
||||||
response = self.put(custom_inv_src, inv_src_opts, expect=200)
|
response = self.put(custom_inv_src, inv_src_opts, expect=200)
|
||||||
self.check_inventory_source(custom_group.inventory_source)
|
self.check_inventory_source(custom_group.inventory_source)
|
||||||
|
|
||||||
|
# Delete script, verify that update fails.
|
||||||
|
inventory_source = InventorySource.objects.get(pk=custom_group.inventory_source.pk)
|
||||||
|
self.assertTrue(inventory_source.can_update)
|
||||||
|
self.delete(script_data['url'], expect=204, auth=self.get_super_credentials())
|
||||||
|
inventory_source = InventorySource.objects.get(pk=inventory_source.pk)
|
||||||
|
self.assertFalse(inventory_source.can_update)
|
||||||
|
self.check_inventory_update(inventory_source, should_fail=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user