Skip to content

Commit

Permalink
Fix periodic task execution on templates without inventory.
Browse files Browse the repository at this point in the history
  • Loading branch information
onegreyonewhite committed Oct 28, 2020
1 parent da3af14 commit 27af75d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
8 changes: 5 additions & 3 deletions doc/api_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ info:
x-versions:
application: 1.8.0
library: 1.8.0
vstutils: 3.5.0
django: 2.2.12
ansible: 2.9.9
vstutils: 4.0.14
django: 2.2.14
ansible: 2.9.6
version: v2
x-user-id: 1
host: localhost:8080
Expand Down Expand Up @@ -8119,6 +8119,7 @@ definitions:
MODULE: hidden
PLAYBOOK: hidden
TEMPLATE: autocomplete
x-nullable: true
enabled:
title: Enabled
type: boolean
Expand Down Expand Up @@ -8201,6 +8202,7 @@ definitions:
MODULE: hidden
PLAYBOOK: hidden
TEMPLATE: autocomplete
x-nullable: true
enabled:
title: Enabled
type: boolean
Expand Down
2 changes: 1 addition & 1 deletion polemarch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"VST_ROOT_URLCONF": os.getenv("VST_ROOT_URLCONF", 'vstutils.urls'),
}

__version__ = "1.8.0"
__version__ = "1.8.1"

prepare_environment(**default_settings)
6 changes: 5 additions & 1 deletion polemarch/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,11 @@ class PeriodictaskSerializer(_WithVariablesSerializer):
)

template_opt = vst_fields.DependEnumField(
allow_blank=True, required=False, field='kind', types={
allow_blank=True,
required=False,
allow_null=True,
field='kind',
types={
'PLAYBOOK': 'hidden',
'MODULE': 'hidden',
'TEMPLATE': 'autocomplete',
Expand Down
2 changes: 2 additions & 0 deletions polemarch/main/models/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def get_data(self) -> Dict:
@property
def inventory_object(self) -> InvOrString:
try:
if 'inventory' not in self.data:
return None
return self.project.inventories.get(pk=int(self.data['inventory']))
except (ValueError, Inventory.DoesNotExist):
self.project.check_path(self.data['inventory'])
Expand Down
27 changes: 27 additions & 0 deletions polemarch/main/tests/executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1825,3 +1825,30 @@ def test_periodic_task_edit(self):
self.assertEqual(results[10]['data']['inventory'], '')
self.assertEqual(results[12]['data']['inventory'], './localhost, ')
self.assertEqual(results[-2]['data']['status'], 'OK')

def test_periodic_task_without_inventory(self):
template_data = self.template_playbook
del template_data['data']['inventory']
periodic_task = {
"name": "WithoutInventory",
"kind": "TEMPLATE",
"mode": "",
"inventory": "",
"save_result": True,
"template": "<<2[data][id]>>",
"template_opt": None,
"enabled": True,
"type": "CRONTAB",
"schedule": "56 9 * * 1-6",
"notes": ""
}
results = self.bulk([
{'method': 'post', 'path': ['project'], 'data': dict(name='test_pt_errors', repo_type='MANUAL')},
{'method': 'post', 'path': ['project', '<<0[data][id]>>', 'sync']},
{'method': 'post', 'path': ['project', '<<0[data][id]>>', 'template'], 'data': template_data},
{'method': 'post', 'path': ['project', '<<0[data][id]>>', 'periodic_task'], 'data': periodic_task},
{'method': 'post', 'path': ['project', '<<0[data][id]>>', 'periodic_task', '<<3[data][id]>>', 'execute']},
{'method': 'delete', 'path': ['project', '<<0[data][id]>>']},
])
self.assertEqual(len(tuple(filter(lambda x: x['status'] not in (201, 200, 204), results))), 0, results)
self.assertIn('history_id', results[4]['data'].keys())
2 changes: 1 addition & 1 deletion requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Docs
vstutils[doc]~=4.0.0
vstutils[doc]~=4.0.14
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Main
vstutils[rpc,ldap,doc,prod]~=4.0.0
vstutils[rpc,ldap,doc,prod]~=4.0.14
docutils~=0.16.0
markdown2==2.3.9

Expand Down

0 comments on commit 27af75d

Please sign in to comment.