-
Notifications
You must be signed in to change notification settings - Fork 43
/
cronjob_schemas.py
140 lines (105 loc) · 4.63 KB
/
cronjob_schemas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from typing import List, Tuple
from acto.input.testcase import K8sTestCase, TestCase
from acto.schema import ObjectSchema
from . import (K8sBooleanSchema, K8sIntegerSchema, K8sObjectSchema,
K8sStringSchema)
class ConcurrencyPolicySchema(K8sStringSchema):
def concurrency_policy_change_precondition(prev):
return prev is not None
def concurrency_policy_change(prev):
if prev == 'Forbid':
return 'Replace'
else:
return 'Forbid'
def concurrency_policy_change_setup(prev):
return 'Forbid'
def invalid_concurrency_policy_change(prev):
return 'InvalidConcurrencyPolicy'
ConcurrencyPolicyChangeTestcase = K8sTestCase(concurrency_policy_change_precondition,
concurrency_policy_change,
concurrency_policy_change_setup)
InvalidConcurrencyPolicyChangeTestcase = K8sTestCase(concurrency_policy_change_precondition,
invalid_concurrency_policy_change,
concurrency_policy_change_setup)
def gen(self, exclude_value=None, minimum: bool = False, **kwargs):
if exclude_value == 'Replace':
return 'Forbid'
else:
return 'Replace'
def test_cases(self) -> Tuple[List[TestCase], List[TestCase]]:
base_testcases = super().test_cases()
base_testcases[1].extend([
ConcurrencyPolicySchema.ConcurrencyPolicyChangeTestcase,
ConcurrencyPolicySchema.InvalidConcurrencyPolicyChangeTestcase
])
return base_testcases
def Match(schema: ObjectSchema) -> bool:
return K8sStringSchema.Match(schema)
def __str__(self) -> str:
return "ConcurrencyPolicy"
class CronJobScheduleSchema(K8sStringSchema):
def cronjob_schedule_change_precondition(prev):
return prev is not None
def cronjob_schedule_change(prev):
if prev == '0 0 * * *':
return '0 0 * * *1'
else:
return '0 0 * * *'
def cronjob_schedule_change_setup(prev):
return '0 0 * * *'
def invalid_cronjob_schedule_change(prev):
return 'InvalidCronJobSchedule'
CronJobScheduleChangeTestcase = K8sTestCase(cronjob_schedule_change_precondition,
cronjob_schedule_change,
cronjob_schedule_change_setup)
InvalidCronJobScheduleChangeTestcase = K8sTestCase(cronjob_schedule_change_precondition,
invalid_cronjob_schedule_change,
cronjob_schedule_change_setup)
def gen(self, exclude_value=None, minimum: bool = False, **kwargs):
return "0 0 * * *"
def test_cases(self) -> Tuple[List[TestCase], List[TestCase]]:
base_testcases = super().test_cases()
base_testcases[1].extend([
CronJobScheduleSchema.CronJobScheduleChangeTestcase,
CronJobScheduleSchema.InvalidCronJobScheduleChangeTestcase
])
return base_testcases
def Match(schema: ObjectSchema) -> bool:
return K8sStringSchema.Match(schema)
def __str__(self) -> str:
return "CronJobSchedule"
class CronJobSpecSchema(K8sObjectSchema):
fields = {
'concurrencyPolicy': ConcurrencyPolicySchema,
"schedule": CronJobScheduleSchema,
"startingDeadlineSeconds": K8sIntegerSchema,
"successfulJobsHistoryLimit": K8sIntegerSchema,
"suspend": K8sBooleanSchema,
"failedJobsHistoryLimit": K8sIntegerSchema,
"jobTemplate": K8sObjectSchema,
}
def Match(schema: ObjectSchema) -> bool:
if not K8sObjectSchema.Match(schema):
return False
for field, field_schema in CronJobSpecSchema.fields.items():
if field not in schema.properties:
return False
elif not field_schema.Match(schema.properties[field]):
return False
return True
class CronJobSchema(K8sObjectSchema):
fields = {
'metadata': K8sObjectSchema,
'spec': CronJobSpecSchema,
}
def Match(schema: ObjectSchema) -> bool:
if not K8sObjectSchema.Match(schema):
return False
for field, field_schema in CronJobSchema.fields.items():
if field not in schema.properties:
return False
elif not field_schema.Match(schema.properties[field]):
return False
return True
def __str__(self) -> str:
return "CronJob"