Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | import re |
| 2 | |
| 3 | from oeqa.runtime.case import OERuntimeTestCase |
| 4 | from oeqa.core.decorator.depends import OETestDepends |
| 5 | from oeqa.core.decorator.oeid import OETestID |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 6 | from oeqa.runtime.decorator.package import OEHasPackage |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7 | |
| 8 | class DateTest(OERuntimeTestCase): |
| 9 | |
| 10 | def setUp(self): |
| 11 | if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd': |
| 12 | self.logger.debug('Stopping systemd-timesyncd daemon') |
| 13 | self.target.run('systemctl stop systemd-timesyncd') |
| 14 | |
| 15 | def tearDown(self): |
| 16 | if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd': |
| 17 | self.logger.debug('Starting systemd-timesyncd daemon') |
| 18 | self.target.run('systemctl start systemd-timesyncd') |
| 19 | |
| 20 | @OETestID(211) |
| 21 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 22 | @OEHasPackage(['coreutils', 'busybox']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 23 | def test_date(self): |
| 24 | (status, output) = self.target.run('date +"%Y-%m-%d %T"') |
| 25 | msg = 'Failed to get initial date, output: %s' % output |
| 26 | self.assertEqual(status, 0, msg=msg) |
| 27 | oldDate = output |
| 28 | |
| 29 | sampleDate = '"2016-08-09 10:00:00"' |
| 30 | (status, output) = self.target.run("date -s %s" % sampleDate) |
| 31 | self.assertEqual(status, 0, msg='Date set failed, output: %s' % output) |
| 32 | |
| 33 | (status, output) = self.target.run("date -R") |
| 34 | p = re.match('Tue, 09 Aug 2016 10:00:.. \+0000', output) |
| 35 | msg = 'The date was not set correctly, output: %s' % output |
| 36 | self.assertTrue(p, msg=msg) |
| 37 | |
| 38 | (status, output) = self.target.run('date -s "%s"' % oldDate) |
| 39 | msg = 'Failed to reset date, output: %s' % output |
| 40 | self.assertEqual(status, 0, msg=msg) |