Module: Beaker::DSL::InstallUtils::WindowsUtils

Included in:
FOSSUtils, PEUtils
Defined in:
lib/beaker/dsl/install_utils/windows_utils.rb

Overview

This module contains methods useful for Windows installs

Instance Method Summary collapse

Instance Method Details

#create_install_msi_batch_on(host, msi_path, msi_opts) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Given a host, path to MSI and MSI options, will create a batch file

on the host, returning the path to the randomized batch file and
the randomized log file

Parameters:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/beaker/dsl/install_utils/windows_utils.rb', line 49

def create_install_msi_batch_on(host, msi_path, msi_opts)
  timestamp = Time.new.strftime('%Y-%m-%d_%H.%M.%S')
  tmp_path = get_temp_path(host)

  batch_name = "install-puppet-msi-#{timestamp}.bat"
  batch_path = "#{tmp_path}\\#{batch_name}"

  log_path = "#{tmp_path}\\install-puppet-#{timestamp}.log"

  Tempfile.open(batch_name) do |tmp_file|
    batch_contents = msi_install_script(msi_path, msi_opts, log_path)

    File.open(tmp_file.path, 'w') { |file| file.puts(batch_contents) }
    host.do_scp_to(tmp_file.path, batch_path, {})
  end

  return batch_path, log_path
end

#get_temp_path(host) ⇒ Object

Given a host, returns it’s system TEMP path

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface.



11
12
13
14
15
# File 'lib/beaker/dsl/install_utils/windows_utils.rb', line 11

def get_temp_path(host)
  # under CYGWIN %TEMP% may not be set
  tmp_path = on(host, Command.new('ECHO %SYSTEMROOT%', [], { :cmdexe => true }))
  tmp_path.output.gsub(/\n/, '') + '\\TEMP'
end

#install_msi_on(hosts, msi_path, msi_opts = {}, opts = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Given hosts construct a PATH that includes puppetbindir, facterbindir and hierabindir

Examples:

install_msi_on(hosts, 'c:\puppet.msi', {:debug => true})

Parameters:

Options Hash (msi_opts):

  • INSTALLIDIR (String)

    Where Puppet and its dependencies should be installed. (Defaults vary based on operating system and intaller architecture) Requires Puppet 2.7.12 / PE 2.5.0

  • PUPPET_MASTER_SERVER (String)

    The hostname where the puppet master server can be reached. (Defaults to puppet) Requires Puppet 2.7.12 / PE 2.5.0

  • PUPPET_CA_SERVER (String)

    The hostname where the CA puppet master server can be reached, if you are using multiple masters and only one of them is acting as the CA. (Defaults the value of PUPPET_MASTER_SERVER) Requires Puppet 2.7.12 / PE 2.5.0

  • PUPPET_AGENT_CERTNAME (String)

    The node’s certificate name, and the name it uses when requesting catalogs. This will set a value for (Defaults to the node’s fqdn as discovered by facter fqdn) Requires Puppet 2.7.12 / PE 2.5.0

  • PUPPET_AGENT_ENVIRONMENT (String)

    The node’s environment. (Defaults to production) Requires Puppet 3.3.1 / PE 3.1.0

  • PUPPET_AGENT_STARTUP_MODE (String)

    Whether the puppet agent service should run (or be allowed to run) (Defaults to Manual - valid values are Automatic, Manual or Disabled) Requires Puppet 3.4.0 / PE 3.2.0

  • PUPPET_AGENT_ACCOUNT_USER (String)

    Whether the puppet agent service should run (or be allowed to run) (Defaults to LocalSystem) Requires Puppet 3.4.0 / PE 3.2.0

  • PUPPET_AGENT_ACCOUNT_PASSWORD (String)

    The password to use for puppet agent’s user account (No default) Requires Puppet 3.4.0 / PE 3.2.0

  • PUPPET_AGENT_ACCOUNT_DOMAIN (String)

    The domain of puppet agent’s user account. (Defaults to .) Requires Puppet 3.4.0 / PE 3.2.0

Options Hash (opts):

  • :debug (Boolean)

    output the MSI installation log when set to true otherwise do not output log (false; default behavior)



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/beaker/dsl/install_utils/windows_utils.rb', line 109

def install_msi_on(hosts, msi_path, msi_opts = {}, opts = {})
  block_on hosts do | host |
    msi_opts['PUPPET_AGENT_STARTUP_MODE'] ||= 'Manual'
    batch_path, log_file = create_install_msi_batch_on(host, msi_path, msi_opts)

    # begin / rescue here so that we can reuse existing error msg propagation
    begin
      # 1641 = ERROR_SUCCESS_REBOOT_INITIATED
      # 3010 = ERROR_SUCCESS_REBOOT_REQUIRED
      on host, Command.new("\"#{batch_path}\"", [], { :cmdexe => true }), :acceptable_exit_codes => [0, 1641, 3010]
    rescue
      on host, Command.new("type \"#{log_file}\"", [], { :cmdexe => true })
      raise
    end

    if opts[:debug]
      on host, Command.new("type \"#{log_file}\"", [], { :cmdexe => true })
    end

    if !host.is_cygwin?
      # HACK: for some reason, post install we need to refresh the connection to make puppet available for execution
      host.close
    end

    # verify service status post install
    # if puppet service exists, then pe-puppet is not queried
    # if puppet service does not exist, pe-puppet is queried and that exit code is used
    # therefore, this command will always exit 0 if either service is installed
    on host, Command.new("sc query puppet || sc query pe-puppet", [], { :cmdexe => true })
  end
end

#msi_install_script(msi_path, msi_opts, log_path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generates commands to be inserted into a Windows batch file to launch an MSI install

Parameters:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/beaker/dsl/install_utils/windows_utils.rb', line 25

def msi_install_script(msi_path, msi_opts, log_path)
  # msiexec requires backslashes in file paths launched under cmd.exe start /w
  url_pattern = /^(https?|file):\/\//
  msi_path = msi_path.gsub(/\//, "\\") if msi_path !~ url_pattern

  msi_params = msi_opts.map{|k, v| "#{k}=#{v}"}.join(' ')

  # msiexec requires quotes around paths with backslashes - c:\ or file://c:\
  # not strictly needed for http:// but it simplifies this code
  batch_contents = <<-BATCH
start /w msiexec.exe /i \"#{msi_path}\" /qn /L*V #{log_path} #{msi_params}
exit /B %errorlevel%
  BATCH
end