date.py 1.5 KB

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