Skip to content

Commit 27af75d

Browse files
Fix periodic task execution on templates without inventory.
1 parent da3af14 commit 27af75d

File tree

7 files changed

+42
-7
lines changed

7 files changed

+42
-7
lines changed

doc/api_schema.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ info:
6565
x-versions:
6666
application: 1.8.0
6767
library: 1.8.0
68-
vstutils: 3.5.0
69-
django: 2.2.12
70-
ansible: 2.9.9
68+
vstutils: 4.0.14
69+
django: 2.2.14
70+
ansible: 2.9.6
7171
version: v2
7272
x-user-id: 1
7373
host: localhost:8080
@@ -8119,6 +8119,7 @@ definitions:
81198119
MODULE: hidden
81208120
PLAYBOOK: hidden
81218121
TEMPLATE: autocomplete
8122+
x-nullable: true
81228123
enabled:
81238124
title: Enabled
81248125
type: boolean
@@ -8201,6 +8202,7 @@ definitions:
82018202
MODULE: hidden
82028203
PLAYBOOK: hidden
82038204
TEMPLATE: autocomplete
8205+
x-nullable: true
82048206
enabled:
82058207
title: Enabled
82068208
type: boolean

polemarch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
"VST_ROOT_URLCONF": os.getenv("VST_ROOT_URLCONF", 'vstutils.urls'),
3232
}
3333

34-
__version__ = "1.8.0"
34+
__version__ = "1.8.1"
3535

3636
prepare_environment(**default_settings)

polemarch/api/v2/serializers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,11 @@ class PeriodictaskSerializer(_WithVariablesSerializer):
553553
)
554554

555555
template_opt = vst_fields.DependEnumField(
556-
allow_blank=True, required=False, field='kind', types={
556+
allow_blank=True,
557+
required=False,
558+
allow_null=True,
559+
field='kind',
560+
types={
557561
'PLAYBOOK': 'hidden',
558562
'MODULE': 'hidden',
559563
'TEMPLATE': 'autocomplete',

polemarch/main/models/tasks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def get_data(self) -> Dict:
7777
@property
7878
def inventory_object(self) -> InvOrString:
7979
try:
80+
if 'inventory' not in self.data:
81+
return None
8082
return self.project.inventories.get(pk=int(self.data['inventory']))
8183
except (ValueError, Inventory.DoesNotExist):
8284
self.project.check_path(self.data['inventory'])

polemarch/main/tests/executions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,3 +1825,30 @@ def test_periodic_task_edit(self):
18251825
self.assertEqual(results[10]['data']['inventory'], '')
18261826
self.assertEqual(results[12]['data']['inventory'], './localhost, ')
18271827
self.assertEqual(results[-2]['data']['status'], 'OK')
1828+
1829+
def test_periodic_task_without_inventory(self):
1830+
template_data = self.template_playbook
1831+
del template_data['data']['inventory']
1832+
periodic_task = {
1833+
"name": "WithoutInventory",
1834+
"kind": "TEMPLATE",
1835+
"mode": "",
1836+
"inventory": "",
1837+
"save_result": True,
1838+
"template": "<<2[data][id]>>",
1839+
"template_opt": None,
1840+
"enabled": True,
1841+
"type": "CRONTAB",
1842+
"schedule": "56 9 * * 1-6",
1843+
"notes": ""
1844+
}
1845+
results = self.bulk([
1846+
{'method': 'post', 'path': ['project'], 'data': dict(name='test_pt_errors', repo_type='MANUAL')},
1847+
{'method': 'post', 'path': ['project', '<<0[data][id]>>', 'sync']},
1848+
{'method': 'post', 'path': ['project', '<<0[data][id]>>', 'template'], 'data': template_data},
1849+
{'method': 'post', 'path': ['project', '<<0[data][id]>>', 'periodic_task'], 'data': periodic_task},
1850+
{'method': 'post', 'path': ['project', '<<0[data][id]>>', 'periodic_task', '<<3[data][id]>>', 'execute']},
1851+
{'method': 'delete', 'path': ['project', '<<0[data][id]>>']},
1852+
])
1853+
self.assertEqual(len(tuple(filter(lambda x: x['status'] not in (201, 200, 204), results))), 0, results)
1854+
self.assertIn('history_id', results[4]['data'].keys())

requirements-doc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Docs
2-
vstutils[doc]~=4.0.0
2+
vstutils[doc]~=4.0.14

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Main
2-
vstutils[rpc,ldap,doc,prod]~=4.0.0
2+
vstutils[rpc,ldap,doc,prod]~=4.0.14
33
docutils~=0.16.0
44
markdown2==2.3.9
55

0 commit comments

Comments
 (0)