ctdb-scripts: Improve update and listing code
[samba4-gss.git] / python / samba / tests / samba_tool / timecmd.py
blob8e286f67f3788d7458804e503d3e6e008ebf3b68
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Sean Dague <sdague@linux.vnet.ibm.com> 2011
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import os
19 from time import localtime, strptime, mktime
20 from samba.tests.samba_tool.base import SambaToolCmdTest
23 class TimeCmdTestCase(SambaToolCmdTest):
24 """Tests for samba-tool time subcommands"""
26 def test_timeget(self):
27 """Run time against the server and make sure it looks accurate"""
28 (result, out, err) = self.runcmd("time", os.environ["SERVER"])
29 self.assertCmdSuccess(result, out, err, "Ensuring time ran successfully")
31 timefmt = strptime(out, "%a %b %d %H:%M:%S %Y %Z\n")
32 servertime = int(mktime(timefmt))
33 now = int(mktime(localtime()))
35 # because there is a race here, allow up to 5 seconds difference in times
36 delta = 5
37 self.assertTrue((servertime > (now - delta) and (servertime < (now + delta)), "Time is now"))
39 def test_timefail(self):
40 """Run time against a non-existent server, and make sure it fails"""
41 (result, out, err) = self.runcmd("time", "notaserver")
42 self.assertEqual(result, -1, "check for result code")
43 self.assertNotEqual(err.strip().find("NT_STATUS_OBJECT_NAME_NOT_FOUND"), -1, "ensure right error string")
44 self.assertEqual(out, "", "ensure no output returned")