Skip to content

Commit

Permalink
NightlyBase doesn't convert string in dayOfWeek param
Browse files Browse the repository at this point in the history
No conversion is made of the value in dayOfWeek if it's a string. The
value is directly passed to croniter without proper conversion.
This fix handles both single string values and multiple comma separated
values as well as abbreviation in the string. ("0" "5,6" "0,fri" et.c.)
  • Loading branch information
gangefors committed Dec 8, 2014
1 parent e09c7e1 commit 17f522c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions master/buildbot/schedulers/timed.py
Expand Up @@ -294,6 +294,17 @@ def _timeToCron(self, time, isDayOfWeek=False):
return time

if isinstance(time, basestring):
if isDayOfWeek:
time_array = str(time).split(',')
# string could be a comma separated list of values, e.g. "5,sun"
for i, t in enumerate(time_array):
try:
# try to convert value in place
time_array[i] = (int(t) + 1) % 7 # Conversion for croniter (see above)
except ValueError:
pass
return ','.join([str(s) for s in time_array]) # Convert the list to a string

return time

if isDayOfWeek:
Expand Down
18 changes: 18 additions & 0 deletions master/buildbot/test/unit/test_schedulers_timed_NightlyBase.py
Expand Up @@ -180,6 +180,24 @@ def test_getNextBuildTime_dayOfWeek_single(self):
((2011, 1, 4, 19, 19), (2011, 1, 4, 20, 0)), # still hourly!
)

def test_getNextBuildTime_dayOfWeek_single_as_string(self):
sched = self.makeScheduler(name='test', builderNames=['test'],
dayOfWeek="1") # Tuesday (2011-1-1 was a Saturday)
return self.do_getNextBuildTime_test(sched,
((2011, 1, 3, 22, 19), (2011, 1, 4, 0, 0)),
((2011, 1, 4, 19, 19), (2011, 1, 4, 20, 0)), # still hourly!
)

def test_getNextBuildTime_dayOfWeek_multiple_as_string(self):
sched = self.makeScheduler(name='test', builderNames=['test'],
dayOfWeek="tue,3") # Tuesday, Thursday (2011-1-1 was a Saturday)
return self.do_getNextBuildTime_test(sched,
((2011, 1, 3, 22, 19), (2011, 1, 4, 0, 0)),
((2011, 1, 4, 19, 19), (2011, 1, 4, 20, 0)), # still hourly!
((2011, 1, 5, 22, 19), (2011, 1, 6, 0, 0)),
((2011, 1, 6, 19, 19), (2011, 1, 6, 20, 0)), # still hourly!
)

def test_getNextBuildTime_dayOfWeek_multiple_hours(self):
sched = self.makeScheduler(name='test', builderNames=['test'],
dayOfWeek=[1, 3], hour=1) # Tuesday, Thursday (2011-1-1 was a Saturday)
Expand Down

0 comments on commit 17f522c

Please sign in to comment.