mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Fix misc whitespace and formatting issues
This commit is contained in:
parent
ea9ffb94c8
commit
0ea317ce5f
@ -4,12 +4,16 @@ Support for reboot, shutdown, etc
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import python libs
|
||||
from datetime import datetime
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
|
||||
__virtualname__ = 'system'
|
||||
|
||||
@ -112,7 +116,7 @@ def shutdown(at_time=None):
|
||||
return ret
|
||||
|
||||
|
||||
def _linux_set_datetime(new_time,utc=None):
|
||||
def _linux_set_datetime(new_time, utc=None):
|
||||
'''set the system date/time on linux'''
|
||||
# Modified version of: http://stackoverflow.com/a/12292874
|
||||
import ctypes
|
||||
@ -153,6 +157,7 @@ def _linux_set_datetime(new_time,utc=None):
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def _posix_set_datetime(new_date, utc=None):
|
||||
'''
|
||||
set the system date/time using the date command
|
||||
@ -174,6 +179,7 @@ def _posix_set_datetime(new_date, utc=None):
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _try_parse_datetime(time_str, fmts):
|
||||
'''
|
||||
Attempts to parse the input time_str as a date.
|
||||
@ -189,7 +195,7 @@ def _try_parse_datetime(time_str, fmts):
|
||||
try:
|
||||
result = datetime.strptime(time_str, fmt)
|
||||
break
|
||||
except ValueError,e:
|
||||
except ValueError, e:
|
||||
pass
|
||||
return result
|
||||
|
||||
@ -214,6 +220,7 @@ def get_system_time(utc=None):
|
||||
t = datetime.now()
|
||||
return datetime.strftime(t, "%I:%M %p")
|
||||
|
||||
|
||||
def set_system_time(newtime, utc=None, posix=None):
|
||||
'''
|
||||
Set the system time.
|
||||
@ -248,6 +255,7 @@ def set_system_time(newtime, utc=None, posix=None):
|
||||
return set_system_date_time(hours=dt_obj.hour, minutes=dt_obj.minute,
|
||||
seconds=dt_obj.second, utc=utc, posix=posix)
|
||||
|
||||
|
||||
def get_system_date_time(utc=None):
|
||||
'''
|
||||
Get the system date/time.
|
||||
|
@ -2,24 +2,20 @@
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import datetime
|
||||
import os
|
||||
import hashlib
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting import skipIf
|
||||
from salttesting.helpers import (
|
||||
destructiveTest,
|
||||
ensure_in_syspath,
|
||||
requires_system_grains
|
||||
ensure_in_syspath
|
||||
)
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import salt libs
|
||||
import integration
|
||||
import salt.utils
|
||||
import time
|
||||
import datetime
|
||||
|
||||
class SystemModuleTest(integration.ModuleCase):
|
||||
'''
|
||||
@ -54,9 +50,9 @@ class SystemModuleTest(integration.ModuleCase):
|
||||
t1 = datetime.datetime.now()
|
||||
res = self.run_function('system.get_system_date_time')
|
||||
t2 = datetime.datetime.strptime(res, self.fmt_str)
|
||||
msg = ("Difference in times is too large. Now: {} Fake: {}"
|
||||
msg = ("Difference in times is too large. Now: {0} Fake: {1}"
|
||||
.format(t1, t2))
|
||||
self.assertTrue(self._same_times(t1, t2),msg=msg)
|
||||
self.assertTrue(self._same_times(t1, t2), msg=msg)
|
||||
|
||||
def test_get_system_date_time_utc(self):
|
||||
'''
|
||||
@ -65,7 +61,7 @@ class SystemModuleTest(integration.ModuleCase):
|
||||
t1 = datetime.datetime.utcnow()
|
||||
res = self.run_function('system.get_system_date_time', utc=True)
|
||||
t2 = datetime.datetime.strptime(res, self.fmt_str)
|
||||
msg = ("Difference in times is too large. Now: {} Fake: {}"
|
||||
msg = ("Difference in times is too large. Now: {0} Fake: {1}"
|
||||
.format(t1, t2))
|
||||
self.assertTrue(self._same_times(t1, t2), msg=msg)
|
||||
|
||||
@ -83,7 +79,7 @@ class SystemModuleTest(integration.ModuleCase):
|
||||
self._set_time(self._fake_time)
|
||||
|
||||
time_now = datetime.datetime.now()
|
||||
msg = ("Difference in times is too large. Now: {} Fake: {}"
|
||||
msg = ("Difference in times is too large. Now: {0} Fake: {1}"
|
||||
.format(time_now, self._fake_time))
|
||||
self.assertTrue(self._same_times(time_now, self._fake_time), msg=msg)
|
||||
|
||||
@ -103,9 +99,9 @@ class SystemModuleTest(integration.ModuleCase):
|
||||
result = self._set_time(self._fake_time, utc=True)
|
||||
|
||||
time_now = datetime.datetime.utcnow()
|
||||
msg = ("Difference in times is too large. Now: {} Fake: {}"
|
||||
msg = ("Difference in times is too large. Now: {0} Fake: {1}"
|
||||
.format(time_now, self._fake_time))
|
||||
self.assertTrue(result and self._same_times(time_now,self._fake_time),
|
||||
self.assertTrue(result and self._same_times(time_now, self._fake_time),
|
||||
msg=msg)
|
||||
|
||||
self._restore_time(utc=True)
|
||||
@ -124,7 +120,7 @@ class SystemModuleTest(integration.ModuleCase):
|
||||
result = self._set_time(self._fake_time, posix=True)
|
||||
|
||||
time_now = datetime.datetime.now()
|
||||
msg = ("Difference in times is too large. Now: {} Fake: {}"
|
||||
msg = ("Difference in times is too large. Now: {0} Fake: {1}"
|
||||
.format(time_now, self._fake_time))
|
||||
self.assertTrue(result and self._same_times(time_now, self._fake_time,
|
||||
seconds_diff=60), msg=msg) # posix only enables setting to minute
|
||||
@ -145,7 +141,7 @@ class SystemModuleTest(integration.ModuleCase):
|
||||
result = self._set_time(self._fake_time, posix=True, utc=True)
|
||||
|
||||
time_now = datetime.datetime.utcnow()
|
||||
msg = ("Difference in times is too large. Now: {} Fake: {}"
|
||||
msg = ("Difference in times is too large. Now: {0} Fake: {1}"
|
||||
.format(time_now, self._fake_time))
|
||||
self.assertTrue(result and self._same_times(time_now, self._fake_time,
|
||||
seconds_diff=60), msg=msg) # posix only enables setting to minute
|
||||
@ -159,14 +155,14 @@ class SystemModuleTest(integration.ModuleCase):
|
||||
Test setting the system time without adjusting the date.
|
||||
'''
|
||||
self._fake_time = datetime.datetime.combine(datetime.date.today(),
|
||||
datetime.time(4,5,0))
|
||||
datetime.time(4, 5, 0))
|
||||
|
||||
self._save_time()
|
||||
|
||||
result = self.run_function('system.set_system_time', ["04:05:00"])
|
||||
|
||||
time_now = datetime.datetime.now()
|
||||
msg = ("Difference in times is too large. Now: {} Fake: {}"
|
||||
msg = ("Difference in times is too large. Now: {0} Fake: {1}"
|
||||
.format(time_now, self._fake_time))
|
||||
|
||||
self.assertTrue(result)
|
||||
@ -190,7 +186,7 @@ class SystemModuleTest(integration.ModuleCase):
|
||||
result = self.run_function('system.set_system_date', ["2000-12-25"])
|
||||
|
||||
time_now = datetime.datetime.now()
|
||||
msg = ("Difference in times is too large. Now: {} Fake: {}"
|
||||
msg = ("Difference in times is too large. Now: {0} Fake: {1}"
|
||||
.format(time_now, self._fake_time))
|
||||
|
||||
self.assertTrue(result)
|
||||
|
Loading…
Reference in New Issue
Block a user