[Fuego] [PATCH v3] logrotate: Add test cases for command logrotate.

Tim.Bird at sony.com Tim.Bird at sony.com
Thu Nov 7 14:08:34 UTC 2019


> -----Original Message-----
> From: Bird, Tim
> 
> > -----Original Message-----
> > From: Wang Mingyu
> >
...
> > +++ b/tests/Functional.logrotate/data/testlog.sh
> > @@ -0,0 +1,5 @@
> > +#!/bin/sh
> > +
> > +ddch=`date --date ' 1 days ago' '+%Y-%m-%d'`
> 
> Hmmm.  I'm not sure if we need an assert_has_program on 'date' or not.
> It's not in our required programs list, but maybe it should be.
> For now, I think it's OK to not add the 'assert_has_program date'.
> But there's a bigger problem.
> 
> The busybox date command does not support this '1 days ago' syntax, so this
> will be a problem on machines with only the busybox version of 'date'.
> I'm not sure what to do about that.  Coming up with the correct syntax
> for the logrotate.status file will be quite difficult if we can't use
> 'date' to calculate yesterday's date string.
> 
> Let me know what you think.
> 
> > +echo "logrotate state -- version 2" >> /var/lib/logrotate.status
> > +echo "\"/var/log/testlog\" $ddch" >> /var/lib/logrotate.status

OK.  I thought some more about this, and I think I've found something
that will work with busybox.  busybox date does not support "1 day ago",
but it does support working with the date in seconds format.  And posix
shells support arithmetic.  So the following should work:

today=$(date +%s)
# there are 86000 seconds in a day
yesterday=$(( $today - 86000 ))
ddch=$(date --date "@$yesterday" "+%Y-%m-%d"

Now, this code might have boundary issues.  That is, what happens
if you just happen to run the code when the target board thinks it is
1 second to midnight.  It's not clear to me that the original code, or the
rest of this test is free from this boundary issue either, so I think the code above
should suffice.  Besides, this will be a rare event, and really any test
that fails should be re-run to validate the status before turning the
result into a bug report.  The chance of the test failing twice due to this
boundary issue is, IMHO, acceptably small.

Please use this code for the calculation of '1 day ago' to put into
the logrotate.status file.

Also, please use modern shell command substitution syntax:
foo=$(cmd args ...)
rather than backticks
foo=`cmd args ...`

for grabbing command output into variables.  The backtick method
is deprecated.

Thanks,
 -- Tim



More information about the Fuego mailing list