Class: Beaker::Utils::NTPControl
- Inherits:
-
Object
- Object
- Beaker::Utils::NTPControl
- Defined in:
- lib/beaker/utils/ntp_control.rb
Constant Summary collapse
- NTPSERVER =
'pool.ntp.org'
Instance Method Summary collapse
-
#initialize(options, hosts) ⇒ NTPControl
constructor
A new instance of NTPControl.
- #timesync ⇒ Object
Constructor Details
#initialize(options, hosts) ⇒ NTPControl
Returns a new instance of NTPControl.
5 6 7 8 9 |
# File 'lib/beaker/utils/ntp_control.rb', line 5 def initialize(, hosts) @options = .dup @hosts = hosts @logger = [:logger] end |
Instance Method Details
#timesync ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/beaker/utils/ntp_control.rb', line 11 def timesync @logger.notify "Update system time sync" @logger.notify "run ntpdate against NTP pool systems" @hosts.each do |host| success=FALSE if host['platform'].include? 'solaris-10' host.exec(Command.new("sleep 10 && ntpdate -w #{NTPSERVER}")) elsif host['platform'].include? 'windows' # The exit code of 5 is for Windows 2008 systems where the w32tm /register command # is not actually necessary. host.exec(Command.new("w32tm /register"), :acceptable_exit_codes => [0,5]) host.exec(Command.new("net start w32time"), :acceptable_exit_codes => [0,2]) host.exec(Command.new("w32tm /config /manualpeerlist:#{NTPSERVER} /syncfromflags:manual /update")) host.exec(Command.new("w32tm /resync")) else count=0 until success do count+=1 raise "ntp time sync failed after #{count} tries" and break if count > 3 if host.exec(Command.new("ntpdate -t 20 #{NTPSERVER}")).exit_code == 0 success=TRUE end end @logger.notify "NTP date succeeded after #{count} tries" end end rescue => e report_and_raise(@logger, e, "timesync (--ntp)") end |