Fix tempest unittests

The new version of croniter introduces year fields, and that breaks the
unittest for tempest charm. In tempest charm, we only support vixie
cron, and that means exactly 5 fields are required.

Change-Id: I0da988c820ac0b691c8b51a56cfa756c90783499
This commit is contained in:
Chi Wai Chan 2024-07-25 11:47:37 +08:00
parent 2266f650f9
commit a064acd183
No known key found for this signature in database
2 changed files with 14 additions and 6 deletions

View File

@ -54,12 +54,12 @@ def validated_schedule(schedule: str) -> Schedule:
if not schedule:
return Schedule(value=schedule, valid=True, err="")
# croniter supports second repeats, but vixie cron does not.
if len(schedule.split()) == 6:
# croniter supports more fields, but vixie cron does not.
if len(schedule.split()) != 5:
return Schedule(
value=schedule,
valid=False,
err="This cron does not support seconds in schedule (6 fields). "
err="This cron only support Vixie cron in schedule (5 fields). "
"Exactly 5 columns must be specified for iterator expression.",
)
@ -70,9 +70,9 @@ def validated_schedule(schedule: str) -> Schedule:
cron = croniter(schedule, base, max_years_between_matches=1)
except ValueError as e:
msg = str(e)
# croniter supports second repeats, but vixie cron does not,
# croniter supports more fields, but vixie cron does not,
# so update the error message here to suit.
if "Exactly 5 or 6 columns" in msg:
if croniter.bad_length in msg:
msg = (
"Exactly 5 columns must be specified for iterator expression."
)

View File

@ -70,7 +70,15 @@ class TempestCharmValidatorTests(unittest.TestCase):
exp = "*/30 * * * * 6"
schedule = validated_schedule(exp)
self.assertFalse(schedule.valid)
self.assertIn("not support seconds", schedule.err)
self.assertIn("Exactly 5 columns", schedule.err)
self.assertEqual(schedule.value, exp)
def test_expression_seven_fields(self):
"""Verify an expression with seven fields is caught."""
exp = "*/30 * * * * 6 2024/2"
schedule = validated_schedule(exp)
self.assertFalse(schedule.valid)
self.assertIn("Exactly 5 columns", schedule.err)
self.assertEqual(schedule.value, exp)
def test_expression_missing_column(self):