3 # Time constants in seconds
8 # Retrieve CA Certificate from the given host
10 # @param [Host] host single Beaker::Host
12 # @return [OpenSSL::X509::Certificate] Certificate object
13 def get_ca_cert_on(host)
14 if host[:roles].include? 'master' then
15 dir = on(host, puppet('config', 'print', 'cadir')).stdout.chomp
16 ca_path = "#{dir}/ca_crt.pem"
18 dir = on(host, puppet('config', 'print', 'certdir')).stdout.chomp
19 ca_path = "#{dir}/ca.pem"
21 on(host, "cat #{ca_path}") do |result|
22 cert = OpenSSL::X509::Certificate.new(result.stdout)
27 # Execute `date` command on host with optional arguments
28 # and get back a Ruby Time object
30 # @param [Host] host single Beaker::Host to run the command on
31 # @param [Array<String>] args Array of arguments to be appended to the
33 # @return [Time] Ruby Time object
34 def get_time_on(host, args = [])
35 arg_string = args.join(' ')
36 date = on(host, "date #{arg_string}").stdout.chomp
37 return Time.parse(date)
40 # Retrieve the CA enddate on a given host as a Ruby time object
42 # @param [Host] host single Beaker::Host to get CA enddate from
44 # @return [Time] Ruby Time object, or nil if error
45 def get_ca_enddate_time_on(host)
46 cert = get_ca_cert_on(host)
47 return cert.not_after if cert
51 # Retrieve the current ca_serial value for `puppet certgen ca` on a given host
53 # @param [Host] host single Beaker::Host to get ca_serial from
55 # @return [String] ca_serial in hexadecimal, or nil if error
56 def get_ca_serial_id_on(host)
57 cert = get_ca_cert_on(host)
58 return cert.serial.to_s(16) if cert
62 # Patch puppet to get around the date check validation.
64 # This method is used to patch puppet in order to prevent it from failing to
65 # create a CA if the system clock is turned back in time by years. The same
66 # method is used to reverse the patch with the `reverse` parameter.
68 # @param [Host] host single Beaker::Host to run the command on
69 # @param [String] reverse causes the patch to be reversed
70 def patch_puppet_date_check_on(host, reverse=nil)
71 reverse = '--reverse' if reverse
72 apply_manifest_on(host, 'package { "patch": ensure => present}')
73 interface_documentation_file = "/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/interface/documentation.rb"
76 < raise ArgumentError, "copyright with a year \#{fault} is very strange; did you accidentally add or subtract two years?"
78 > #raise ArgumentError, "copyright with a year \#{fault} is very strange; did you accidentally add or subtract two years?"
80 patch_file = host.tmpfile('iface_doc_patch')
81 create_remote_file(host, patch_file, patch)
82 on(host, "patch #{reverse} #{interface_documentation_file} < #{patch_file}", :acceptable_exit_codes => [0,1])