Module: Beaker::DSL::InstallUtils

Included in:
Beaker::DSL
Defined in:
lib/beaker/dsl/install_utils.rb

Overview

This module contains methods to help cloning, extracting git info, ordering of Puppet packages, and installing ruby projects that contain an ‘install.rb` script.

To mix this is into a class you need the following:

  • a method hosts that yields any hosts implementing Host‘s interface to act upon.

  • a method options that provides an options hash, see Options::OptionsHash

  • the module Roles that provides access to the various hosts implementing Host‘s interface to act upon

  • the module Wrappers the provides convenience methods for Command creation

Constant Summary collapse

SourcePath =

The default install path

"/opt/puppet-git-repos"
GitURI =

A regex to know if the uri passed is pointing to a git repo

%r{^(git|https?|file)://|^git@|^gitmirror@}
GitHubSig =

Github’s ssh signature for cloning via ssh

'github.com,207.97.227.239 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='
PUPPET_MODULE_INSTALL_IGNORE =

The directories in the module directory that will not be scp-ed to the test system when using ‘copy_module_to`

['.bundle', '.git', '.idea', '.vagrant', '.vendor', 'vendor', 'acceptance', 'bundle', 'spec', 'tests', 'log']

Instance Method Summary collapse

Instance Method Details

#add_system32_hosts_entry(host, opts = {}) ⇒ Object

Configure a host entry on the give host @example: will add a host entry for forge.puppetlabs.com

add_system32_hosts_entry(host, { :ip => '23.251.154.122', :name => 'forge.puppetlabs.com' })

Returns:

  • nil



724
725
726
727
728
729
730
731
732
# File 'lib/beaker/dsl/install_utils.rb', line 724

def add_system32_hosts_entry(host, opts = {})
  if host['platform'] =~ /windows/
    hosts_file = "C:\\Windows\\System32\\Drivers\\etc\\hosts"
    host_entry = "#{opts['ip']}`t`t#{opts['name']}"
    on host, powershell("\$text = \\\"#{host_entry}\\\"; Add-Content -path '#{hosts_file}' -value \$text")
  else
    raise "nothing to do for #{host.name} on #{host['platform']}"
  end
end

#build_ignore_list(opts = {}) ⇒ Object

Build an array list of files/directories to ignore when pushing to remote host Automatically adds ‘..’ and ‘.’ to array. If not opts of :ignore list is provided it will use the static variable PUPPET_MODULE_INSTALL_IGNORE

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :ignore_list (Array)

    A list of files/directories to ignore



1566
1567
1568
1569
1570
1571
1572
1573
1574
# File 'lib/beaker/dsl/install_utils.rb', line 1566

def build_ignore_list(opts = {})
  ignore_list = opts[:ignore_list] || PUPPET_MODULE_INSTALL_IGNORE
  if !ignore_list.kind_of?(Array) || ignore_list.nil?
    raise ArgumentError "Ignore list must be an Array"
  end
  ignore_list << '.' unless ignore_list.include? '.'
  ignore_list << '..' unless ignore_list.include? '..'
  ignore_list
end

#check_for_package(host, package_name) ⇒ Boolean

Check to see if a package is installed on a remote host

Parameters:

  • host (Host)

    A host object

  • package_name (String)

    Name of the package to check for.

Returns:

  • (Boolean)

    true/false if the package is found



1476
1477
1478
# File 'lib/beaker/dsl/install_utils.rb', line 1476

def check_for_package host, package_name
  host.check_for_package package_name
end

#configure_puppet(opts = {}) ⇒ Object

Configure puppet.conf for all hosts based upon a provided Hash

Parameters:

  • opts (Hash{Symbol=>String}) (defaults to: {})

Options Hash (opts):

  • :main (Hash{String=>String})

    configure the main section of puppet.conf

  • :agent (Hash{String=>String})

    configure the agent section of puppet.conf

Returns:

  • nil



741
742
743
744
745
# File 'lib/beaker/dsl/install_utils.rb', line 741

def configure_puppet(opts={})
  hosts.each do |host|
    configure_puppet_on(host,opts)
  end
end

#configure_puppet_on(host, opts = {}) ⇒ Object

Configure puppet.conf on the given host based upon a provided hash

Examples:

will configure /etc/puppet.conf on the puppet master.

config = {
  'main' => {
    'server'   => 'testbox.test.local',
    'certname' => 'testbox.test.local',
    'logdir'   => '/var/log/puppet',
    'vardir'   => '/var/lib/puppet',
    'ssldir'   => '/var/lib/puppet/ssl',
    'rundir'   => '/var/run/puppet'
  },
  'agent' => {
    'environment' => 'dev'
  }
}
configure_puppet(master, config)

Parameters:

  • host (Host)

    The host to configure puppet.conf on

  • opts (Hash{Symbol=>String}) (defaults to: {})

Options Hash (opts):

  • :main (Hash{String=>String})

    configure the main section of puppet.conf

  • :agent (Hash{String=>String})

    configure the agent section of puppet.conf

Returns:

  • nil



771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
# File 'lib/beaker/dsl/install_utils.rb', line 771

def configure_puppet_on(host, opts = {})
  if host['platform'] =~ /windows/
    puppet_conf = host.puppet['config']
    conf_data = ''
    opts.each do |section,options|
      conf_data << "[#{section}]`n"
      options.each do |option,value|
        conf_data << "#{option}=#{value}`n"
      end
      conf_data << "`n"
    end
    on host, powershell("\$text = \\\"#{conf_data}\\\"; Set-Content -path '#{puppet_conf}' -value \$text")
  else
    puppet_conf = host.puppet['config']
    conf_data = ''
    opts.each do |section,options|
      conf_data << "[#{section}]\n"
      options.each do |option,value|
        conf_data << "#{option}=#{value}\n"
      end
      conf_data << "\n"
    end
    on host, "echo \"#{conf_data}\" > #{puppet_conf}"
  end
end

#copy_module_to(one_or_more_hosts, opts = {}) ⇒ Object Also known as: copy_root_module_to

Install local module for acceptance testing should be used as a presuite to ensure local module is copied to the hosts you want, particularly masters

Parameters:

  • one_or_more_hosts (Host, Array<Host>, String, Symbol)

    One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :source (String) — default: './'

    The current directory where the module sits, otherwise will try

    and walk the tree to figure out
    
  • :module_name (String) — default: nil

    Name which the module should be installed under, please do not include author,

    if none is provided it will attempt to parse the metadata.json and then the Modulefile to determine
    the name of the module
    
  • :target_module_path (String) — default: host['distmoduledir']/modules

    Location where the module should be installed, will default

    to host['distmoduledir']/modules
    
  • :ignore_list (Array)
  • :protocol (String)

    Name of the underlying transfer method. Valid options are ‘scp’ or ‘rsync’.

Raises:

  • (ArgumentError)

    if not host is provided or module_name is not provided and can not be found in Modulefile



1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
# File 'lib/beaker/dsl/install_utils.rb', line 1422

def copy_module_to(one_or_more_hosts, opts = {})
  block_on one_or_more_hosts do |host|
    opts = {:source => './',
            :target_module_path => host['distmoduledir'],
            :ignore_list => PUPPET_MODULE_INSTALL_IGNORE}.merge(opts)
    ignore_list = build_ignore_list(opts)
    target_module_dir = on( host, "echo #{opts[:target_module_path]}" ).stdout.chomp
    source_path = File.expand_path( opts[:source] )
    source_dir = File.dirname(source_path)
    source_name = File.basename(source_path)
    if opts.has_key?(:module_name)
      module_name = opts[:module_name]
    else
      _, module_name = parse_for_modulename( source_path )
    end

    opts[:protocol] ||= 'scp'
    case opts[:protocol]
      when 'scp'
        #move to the host
        scp_to host, source_path, target_module_dir, {:ignore => ignore_list}
        #rename to the selected module name, if not correct
        cur_path = File.join(target_module_dir, source_name)
        new_path = File.join(target_module_dir, module_name)
        if cur_path != new_path
          # NOTE: this will need to be updated to handle powershell only windows SUTs
          on host, "mv #{cur_path} #{new_path}"
        end
      when 'rsync'
        rsync_to host, source, File.join(target_module_dir, module_name), {:ignore => ignore_list}
      else
        logger.debug "Unsupported transfer protocol, returning nil"
        nil
    end
  end
end

#deploy_frictionless_to_master(host) ⇒ 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.

Classify the master so that it can deploy frictionless packages for a given host.

Parameters:

  • host (Host)

    The host to install pacakges for



435
436
437
438
439
440
441
442
# File 'lib/beaker/dsl/install_utils.rb', line 435

def deploy_frictionless_to_master(host)
  klass = host['platform'].gsub(/-/, '_').gsub(/\./,'')
  klass = "pe_repo::platform::#{klass}"
  on dashboard, "cd /opt/puppet/share/puppet-dashboard && /opt/puppet/bin/bundle exec /opt/puppet/bin/rake nodeclass:add[#{klass},skip]"
  on dashboard, "cd /opt/puppet/share/puppet-dashboard && /opt/puppet/bin/bundle exec /opt/puppet/bin/rake node:add[#{master},,,skip]"
  on dashboard, "cd /opt/puppet/share/puppet-dashboard && /opt/puppet/bin/bundle exec /opt/puppet/bin/rake node:addclass[#{master},#{klass}]"
  on master, puppet("agent -t"), :acceptable_exit_codes => [0,2]
end

#do_higgs_install(host, 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.

Perform a Puppet Enterprise Higgs install up until web browser interaction is required, runs on linux hosts only.

Examples:

do_higgs_install(master, {:pe_dir => path, :pe_ver => version})

Parameters:

  • host (Host)

    The host to install higgs on

  • opts (Hash{Symbol=>Symbol, String})

    The options

Options Hash (opts):

  • :pe_dir (String)

    Default directory or URL to pull PE package from (Otherwise uses individual hosts pe_dir)

  • :pe_ver (String)

    Default PE version to install (Otherwise uses individual hosts pe_ver)

Raises:

  • (StandardError)

    When installation times out



602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/beaker/dsl/install_utils.rb', line 602

def do_higgs_install host, opts
  use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true'
  platform = use_all_tar ? 'all' : host['platform']
  version = host['pe_ver'] || opts[:pe_ver]
  host['dist'] = "puppet-enterprise-#{version}-#{platform}"

  use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true'
  host['pe_installer'] ||= 'puppet-enterprise-installer'
  host['working_dir'] = host.tmpdir(Time.new.strftime("%Y-%m-%d_%H.%M.%S"))

  fetch_puppet([host], opts)

  host['higgs_file'] = "higgs_#{File.basename(host['working_dir'])}.log"
  on host, higgs_installer_cmd(host), opts

  #wait for output to host['higgs_file']
  #we're all done when we find this line in the PE installation log
  higgs_re = /Please\s+go\s+to\s+https:\/\/.*\s+in\s+your\s+browser\s+to\s+continue\s+installation/m
  res = Result.new(host, 'tmp cmd')
  tries = 10
  attempts = 0
  prev_sleep = 0
  cur_sleep = 1
  while (res.stdout !~ higgs_re) and (attempts < tries)
    res = on host, "cd #{host['working_dir']}/#{host['dist']} && cat #{host['higgs_file']}", :acceptable_exit_codes => (0..255)
    attempts += 1
    sleep( cur_sleep )
    prev_sleep = cur_sleep
    cur_sleep = cur_sleep + prev_sleep
  end

  if attempts >= tries
    raise "Failed to kick off PE (Higgs) web installation"
  end

end

#do_install(hosts, 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.

Perform a Puppet Enterprise upgrade or install

Examples:

do_install(hosts, {:type => :upgrade, :pe_dir => path, :pe_ver => version, :pe_ver_win =>  version_win})

Parameters:

  • hosts (Array<Host>)

    The hosts to install or upgrade PE on

  • opts (Hash{Symbol=>Symbol, String}) (defaults to: {})

    The options

Options Hash (opts):

  • :pe_dir (String)

    Default directory or URL to pull PE package from (Otherwise uses individual hosts pe_dir)

  • :pe_ver (String)

    Default PE version to install or upgrade to (Otherwise uses individual hosts pe_ver)

  • :pe_ver_win (String)

    Default PE version to install or upgrade to on Windows hosts (Otherwise uses individual Windows hosts pe_ver)

  • :type (Symbol) — default: :install

    One of :upgrade or :install

  • :set_console_password (Boolean)

    Should we set the PE console password in the answers file? Used during upgrade only.

  • :answers (Hash<String>)

    Pre-set answers based upon ENV vars and defaults (See Options::Presets.env_vars)



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/beaker/dsl/install_utils.rb', line 463

def do_install hosts, opts = {}
  masterless = (defined? options) ? options[:masterless] : false
  opts[:masterless] = masterless # has to pass masterless down for answer generation awareness
  opts[:type] = opts[:type] || :install
  unless masterless
    pre30database = version_is_less(opts[:pe_ver] || database['pe_ver'], '3.0')
    pre30master = version_is_less(opts[:pe_ver] || master['pe_ver'], '3.0')

    unless version_is_less(opts[:pe_ver] || master['pe_ver'], '3.4')
      master['puppetservice'] = 'pe-puppetserver'
    end
  end

  # Set PE distribution for all the hosts, create working dir
  use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true'
  hosts.each do |host|
    host['pe_installer'] ||= 'puppet-enterprise-installer'
    if host['platform'] !~ /windows|osx/
      platform = use_all_tar ? 'all' : host['platform']
      version = host['pe_ver'] || opts[:pe_ver]
      host['dist'] = "puppet-enterprise-#{version}-#{platform}"
    elsif host['platform'] =~ /osx/
      version = host['pe_ver'] || opts[:pe_ver]
      host['dist'] = "puppet-enterprise-#{version}-#{host['platform']}"
    elsif host['platform'] =~ /windows/
      version = host[:pe_ver] || opts['pe_ver_win']
      should_install_64bit = !(version_is_less(version, '3.4')) && host.is_x86_64? && !host['install_32'] && !opts['install_32']
      #only install 64bit builds if
      # - we are on pe version 3.4+
      # - we do not have install_32 set on host
      # - we do not have install_32 set globally
      if !(version_is_less(version, '4.0'))
        if should_install_64bit
          host['dist'] = "puppet-agent-#{version}-x64"
        else
          host['dist'] = "puppet-agent-#{version}-x86"
        end
      elsif should_install_64bit
        host['dist'] = "puppet-enterprise-#{version}-x64"
      else
        host['dist'] = "puppet-enterprise-#{version}"
      end
    end
    host['working_dir'] = host.tmpdir(Time.new.strftime("%Y-%m-%d_%H.%M.%S"))
  end

  fetch_puppet(hosts, opts)

  install_hosts = hosts.dup
  unless masterless
    # If we're installing a database version less than 3.0, ignore the database host
    install_hosts.delete(database) if pre30database and database != master and database != dashboard
  end

  install_hosts.each do |host|
    if host['platform'] =~ /windows/
      on host, installer_cmd(host, opts)
      if not host.is_cygwin?
        # HACK: for some reason, post install we need to refresh the connection to make puppet available for execution
        host.close
      end
    else
      # We only need answers if we're using the classic installer
      version = host['pe_ver'] || opts[:pe_ver]
      if host['roles'].include?('frictionless') &&  (! version_is_less(version, '3.2.0'))
        # If We're *not* running the classic installer, we want
        # to make sure the master has packages for us.
        deploy_frictionless_to_master(host)
        on host, installer_cmd(host, opts)
      elsif host['platform'] =~ /osx|eos/
        # If we're not frictionless, we need to run the OSX special-case
        on host, installer_cmd(host, opts)
        #set the certname and master
        on host, puppet("config set server #{master}")
        on host, puppet("config set certname #{host}")
        #run once to request cert
        acceptable_codes = host['platform'] =~ /osx/ ? [1] : [0, 1]
        on host, puppet_agent('-t'), :acceptable_exit_codes => acceptable_codes
      else
        answers = Beaker::Answers.create(opts[:pe_ver] || host['pe_ver'], hosts, opts)
        create_remote_file host, "#{host['working_dir']}/answers", answers.answer_string(host)
        on host, installer_cmd(host, opts)
      end
    end

    # On each agent, we ensure the certificate is signed then shut down the agent
    sign_certificate_for(host) unless masterless
    stop_agent_on(host)
  end

  unless masterless
    # Wait for PuppetDB to be totally up and running (post 3.0 version of pe only)
    sleep_until_puppetdb_started(database) unless pre30database

    # Run the agent once to ensure everything is in the dashboard
    install_hosts.each do |host|
      on host, puppet_agent('-t'), :acceptable_exit_codes => [0,2]

      # Workaround for PE-1105 when deploying 3.0.0
      # The installer did not respect our database host answers in 3.0.0,
      # and would cause puppetdb to be bounced by the agent run. By sleeping
      # again here, we ensure that if that bounce happens during an upgrade
      # test we won't fail early in the install process.
      if host['pe_ver'] == '3.0.0' and host == database
        sleep_until_puppetdb_started(database)
      end
    end

    install_hosts.each do |host|
      wait_for_host_in_dashboard(host)
    end

    if pre30master
      task = 'nodegroup:add_all_nodes group=default'
    else
      task = 'defaultgroup:ensure_default_group'
    end
    on dashboard, "/opt/puppet/bin/rake -sf /opt/puppet/share/puppet-dashboard/Rakefile #{task} RAILS_ENV=production"

    # Now that all hosts are in the dashbaord, run puppet one more
    # time to configure mcollective
    on install_hosts, puppet_agent('-t'), :acceptable_exit_codes => [0,2]
  end
end

#extract_repo_info_from(uri) ⇒ Hash{Symbol=>String}

Returns a hash containing the project name, repository path, and revision (defaults to HEAD)

Examples:

Usage

project = extract_repo_info_from '[email protected]:puppetlabs/SuperSecretSauce#what_is_justin_doing'

puts project[:name]
#=> 'SuperSecretSauce'

puts project[:rev]
#=> 'what_is_justin_doing'

Parameters:

  • uri (String)

    A uri in the format of <git uri>#<revision> the ‘git://`, `http://`, `https://`, and ssh (if cloning as the remote git user) protocols are valid for <git uri>

Returns:

  • (Hash{Symbol=>String})

    Returns a hash containing the project name, repository path, and revision (defaults to HEAD)



50
51
52
53
54
55
56
57
# File 'lib/beaker/dsl/install_utils.rb', line 50

def extract_repo_info_from uri
  project = {}
  repo, rev = uri.split('#', 2)
  project[:name] = Pathname.new(repo).basename('.git').to_s
  project[:path] = repo
  project[:rev]  = rev || 'HEAD'
  return project
end

#fetch_puppet(hosts, 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.

Determine the PE package to download/upload per-host, download/upload that package onto the host and unpack it.

Parameters:

  • hosts (Array<Host>)

    The hosts to download/upload and unpack PE onto

  • opts (Hash{Symbol=>Symbol, String})

    The options

Options Hash (opts):

  • :pe_dir (String)

    Default directory or URL to pull PE package from (Otherwise uses individual hosts pe_dir)

  • :pe_ver (String)

    Default PE version to install or upgrade to (Otherwise uses individual hosts pe_ver)

  • :pe_ver_win (String)

    Default PE version to install or upgrade to on Windows hosts (Otherwise uses individual Windows hosts pe_ver)



417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/beaker/dsl/install_utils.rb', line 417

def fetch_puppet(hosts, opts)
  hosts.each do |host|
    # We install Puppet from the master for frictionless installs, so we don't need to *fetch* anything
    next if host['roles'].include?('frictionless') && (! version_is_less(opts[:pe_ver] || host['pe_ver'], '3.2.0'))

    if host['platform'] =~ /windows/
      fetch_puppet_on_windows(host, opts)
    elsif host['platform'] =~ /osx/
      fetch_puppet_on_mac(host, opts)
    else
      fetch_puppet_on_unix(host, opts)
    end
  end
end

#fetch_puppet_on_mac(host, 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.

Determine the PE package to download/upload on a mac host, download/upload that package onto the host. Assumed file name format: puppet-enterprise-3.3.0-rc1-559-g97f0833-osx-10.9-x86_64.dmg.

Parameters:

  • host (Host)

    The mac host to download/upload and unpack PE onto

  • opts (Hash{Symbol=>Symbol, String})

    The options

Options Hash (opts):

  • :pe_dir (String)

    Default directory or URL to pull PE package from (Otherwise uses individual hosts pe_dir)



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/beaker/dsl/install_utils.rb', line 311

def fetch_puppet_on_mac(host, opts)
  path = host['pe_dir'] || opts[:pe_dir]
  local = File.directory?(path)
  filename = "#{host['dist']}"
  extension = ".dmg"
  if local
    if not File.exists?("#{path}/#{filename}#{extension}")
      raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist"
    end
    scp_to host, "#{path}/#{filename}#{extension}", "#{host['working_dir']}/#{filename}#{extension}"
  else
    if not link_exists?("#{path}/#{filename}#{extension}")
      raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist"
    end
    on host, "cd #{host['working_dir']}; curl -O #{path}/#{filename}#{extension}"
  end
end

#fetch_puppet_on_unix(host, 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.

Determine the PE package to download/upload on a unix style host, download/upload that package onto the host and unpack it.

Parameters:

  • host (Host)

    The unix style host to download/upload and unpack PE onto

  • opts (Hash{Symbol=>Symbol, String})

    The options

Options Hash (opts):

  • :pe_dir (String)

    Default directory or URL to pull PE package from (Otherwise uses individual hosts pe_dir)



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/beaker/dsl/install_utils.rb', line 368

def fetch_puppet_on_unix(host, opts)
  path = host['pe_dir'] || opts[:pe_dir]
  local = File.directory?(path)
  filename = "#{host['dist']}"
  if local
    extension = File.exists?("#{path}/#{filename}.tar.gz") ? ".tar.gz" : ".tar"
    if not File.exists?("#{path}/#{filename}#{extension}")
      raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist"
    end
    scp_to host, "#{path}/#{filename}#{extension}", "#{host['working_dir']}/#{filename}#{extension}"
    if extension =~ /gz/
      on host, "cd #{host['working_dir']}; gunzip #{filename}#{extension}"
    end
    if extension =~ /tar/
      on host, "cd #{host['working_dir']}; tar -xvf #{filename}.tar"
    end
  else
    if host['platform'] =~ /eos/
      extension = '.swix'
    else
      extension = link_exists?("#{path}/#{filename}.tar.gz") ? ".tar.gz" : ".tar"
    end
    if not link_exists?("#{path}/#{filename}#{extension}")
      raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist"
    end

    if host['platform'] =~ /eos/
      commands = ['enable', "copy #{path}/#{filename}#{extension} extension:"]
      command = commands.join("\n")
      on host, "Cli -c '#{command}'"
    else
      unpack = 'tar -xvf -'
      unpack = extension =~ /gz/ ? 'gunzip | ' + unpack  : unpack
      on host, "cd #{host['working_dir']}; curl #{path}/#{filename}#{extension} | #{unpack}"
    end
  end
end

#fetch_puppet_on_windows(host, 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.

Determine the PE package to download/upload on a windows host, download/upload that package onto the host. Assumed file name format: puppet-enterprise-3.3.0-rc1-559-g97f0833.msi

Parameters:

  • host (Host)

    The windows host to download/upload and unpack PE onto

  • opts (Hash{Symbol=>Symbol, String})

    The options

Options Hash (opts):

  • :pe_dir (String)

    Default directory or URL to pull PE package from (Otherwise uses individual hosts pe_dir)

  • :pe_ver_win (String)

    Default PE version to install or upgrade to (Otherwise uses individual hosts pe_ver)



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/beaker/dsl/install_utils.rb', line 338

def fetch_puppet_on_windows(host, opts)
  path = host['pe_dir'] || opts[:pe_dir]
  local = File.directory?(path)
  version = host['pe_ver'] || opts[:pe_ver_win]
  filename = "#{host['dist']}"
  extension = ".msi"
  if local
    if not File.exists?("#{path}/#{filename}#{extension}")
      raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist"
    end
    scp_to host, "#{path}/#{filename}#{extension}", "#{host['working_dir']}/#{filename}#{extension}"
  else
    if not link_exists?("#{path}/#{filename}#{extension}")
      raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist"
    end
    if host.is_cygwin?
      on host, "cd #{host['working_dir']}; curl -O #{path}/#{filename}#{extension}"
    else
      on host, powershell("$webclient = New-Object System.Net.WebClient;  $webclient.DownloadFile('#{path}/#{filename}#{extension}','#{host['working_dir']}\\#{filename}#{extension}')")
    end
  end
end

#find_git_repo_versions(host, path, repository) ⇒ Hash

Note:

This requires the helper methods:

Returns Executes git describe on [host] and returns a Hash with the key of [repository] and value of the output from git describe.

Examples:

Getting multiple project versions

versions = [puppet_repo, facter_repo, hiera_repo].inject({}) do |vers, repo_info|
  vers.merge(find_git_repo_versions(host, '/opt/git-puppet-repos', repo_info) )
end

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface.

  • path (String)

    The path on the remote [host] to the repository

  • repository (Hash{Symbol=>String})

    A hash representing repo info like that emitted by #extract_repo_info_from

Returns:

  • (Hash)

    Executes git describe on [host] and returns a Hash with the key of [repository] and value of the output from git describe.



93
94
95
96
97
98
99
100
101
102
# File 'lib/beaker/dsl/install_utils.rb', line 93

def find_git_repo_versions host, path, repository
  version = {}
  step "Grab version for #{repository[:name]}" do
    on host, "cd #{path}/#{repository[:name]} && " +
              "git describe || true" do
      version[repository[:name]] = stdout.chomp
    end
  end
  version
end

#get_module_name(author_module_name) ⇒ String?

Parse modulename from the pattern ‘Auther-ModuleName’

Parameters:

  • author_module_name (String)

    <Author>-<ModuleName> pattern

Returns:

  • (String, nil)


1539
1540
1541
1542
1543
1544
# File 'lib/beaker/dsl/install_utils.rb', line 1539

def get_module_name(author_module_name)
  split_name = split_author_modulename(author_module_name)
  if split_name
    return split_name[:author], split_name[:module]
  end
end

#higgs_installer_cmd(host) ⇒ 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.

Create the Higgs install command string based upon the host and options settings. Installation command will be run as a background process. The output of the command will be stored in the provided host.

Parameters:

  • host (Host)

    The host that Higgs is to be installed on The host object must have the ‘working_dir’, ‘dist’ and ‘pe_installer’ field set correctly.



212
213
214
215
216
# File 'lib/beaker/dsl/install_utils.rb', line 212

def higgs_installer_cmd host

  "cd #{host['working_dir']}/#{host['dist']} ; nohup ./#{host['pe_installer']} <<<Y > #{host['higgs_file']} 2>&1 &"

end

#install_dev_puppet_module(opts) ⇒ Object Also known as: puppet_module_install

Install the desired module on all hosts using either the PMT or a

staging forge

Passes options through to either ‘install_puppet_module_via_pmt_on`

or `copy_module_to`

Examples:

Installing a module from the local directory

install_dev_puppet_module( :source => './', :module_name => 'concat' )

Installing a module from a staging forge

options[:forge_host] = 'my-forge-api.example.com'
install_dev_puppet_module( :source => './', :module_name => 'concat' )

Parameters:

  • opts (Hash)

See Also:



1366
1367
1368
# File 'lib/beaker/dsl/install_utils.rb', line 1366

def install_dev_puppet_module( opts )
  block_on( hosts ) {|h| install_dev_puppet_module_on( h, opts ) }
end

#install_dev_puppet_module_on(host, opts) ⇒ Object Also known as: puppet_module_install_on

Install the desired module on all hosts using either the PMT or a

staging forge


1338
1339
1340
1341
1342
1343
1344
1345
1346
# File 'lib/beaker/dsl/install_utils.rb', line 1338

def install_dev_puppet_module_on( host, opts )
  if options[:forge_host]
    with_forge_stubbed_on( host ) do
      install_puppet_module_via_pmt_on( host, opts )
    end
  else
    copy_module_to( host, opts )
  end
end

#install_from_git(host, path, repository) ⇒ Object



106
107
108
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
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/beaker/dsl/install_utils.rb', line 106

def install_from_git host, path, repository
  name          = repository[:name]
  repo          = repository[:path]
  rev           = repository[:rev]
  depth         = repository[:depth]
  depth_branch  = repository[:depth_branch]
  target        = "#{path}/#{name}"

  if (depth_branch.nil?)
    depth_branch = rev
  end

  clone_cmd = "git clone #{repo} #{target}"
  if (depth)
    clone_cmd = "git clone --branch #{depth_branch} --depth #{depth} #{repo} #{target}"
  end

  step "Clone #{repo} if needed" do
    on host, "test -d #{path} || mkdir -p #{path}"
    on host, "test -d #{target} || #{clone_cmd}"
  end

  step "Update #{name} and check out revision #{rev}" do
    commands = ["cd #{target}",
                "remote rm origin",
                "remote add origin #{repo}",
                "fetch origin +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/*",
                "clean -fdx",
                "checkout -f #{rev}"]
    on host, commands.join(" && git ")
  end

  step "Install #{name} on the system" do
    # The solaris ruby IPS package has bindir set to /usr/ruby/1.8/bin.
    # However, this is not the path to which we want to deliver our
    # binaries. So if we are using solaris, we have to pass the bin and
    # sbin directories to the install.rb
    install_opts = ''
    install_opts = '--bindir=/usr/bin --sbindir=/usr/sbin' if
      host['platform'].include? 'solaris'

      on host,  "cd #{target} && " +
                "if [ -f install.rb ]; then " +
                "ruby ./install.rb #{install_opts}; " +
                "else true; fi"
  end
end

#install_higgs(higgs_host = master) ⇒ Object

Note:

Either pe_ver and pe_dir should be set in the ENV or each host should have pe_ver and pe_dir set individually. Install file names are assumed to be of the format puppet-enterprise-VERSION-PLATFORM.(tar)|(tar.gz).

Install Higgs up till the point where you need to continue installation in a web browser, defaults to execution on the master node.

Examples:

install_higgs

Parameters:

  • higgs_host (Host) (defaults to: master)

    The host to install Higgs on (supported on linux platform only)



1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
# File 'lib/beaker/dsl/install_utils.rb', line 1322

def install_higgs( higgs_host = master )
  #process the version files if necessary
  master['pe_dir'] ||= options[:pe_dir]
  master['pe_ver'] = master['pe_ver'] || options['pe_ver'] ||
    Beaker::Options::PEVersionScraper.load_pe_version(master[:pe_dir] || options[:pe_dir], options[:pe_version_file])
  if higgs_host['platform'] =~ /osx|windows/
    raise "Attempting higgs installation on host #{higgs_host.name} with unsupported platform #{higgs_host['platform']}"
  end
  #send in the global options hash
  do_higgs_install higgs_host, options
end

#install_package(host, package_name, package_version = nil) ⇒ Result

Install a package on a host

Parameters:

  • host (Host)

    A host object

  • package_name (String)

    Name of the package to install

Returns:

  • (Result)

    An object representing the outcome of *install command*.



1466
1467
1468
# File 'lib/beaker/dsl/install_utils.rb', line 1466

def install_package host, package_name, package_version = nil
  host.install_package package_name, '', package_version
end

#install_packages_from_local_dev_repo(host, package_name) ⇒ Object

Note:

This method only works on redhat-like and debian-like hosts.

Note:

This method is paired to be run directly after #install_puppetlabs_dev_repo

Installs packages from the local development repository on the given host

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface.

  • package_name (Regexp)

    The name of the package whose repository is being installed.



1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
# File 'lib/beaker/dsl/install_utils.rb', line 1245

def install_packages_from_local_dev_repo( host, package_name )
  if host['platform'] =~ /debian|ubuntu|cumulus/
    find_filename = '*.deb'
    find_command  = 'dpkg -i'
  elsif host['platform'] =~ /fedora|el|centos/
    find_filename = '*.rpm'
    find_command  = 'rpm -ivh'
  else
    raise "No repository installation step for #{host['platform']} yet..."
  end
  find_command = "find /root/#{package_name} -type f -name '#{find_filename}' -exec #{find_command} {} \\;"
  on host, find_command
end

#install_peObject

Note:

Either pe_ver and pe_dir should be set in the ENV or each host should have pe_ver and pe_dir set individually. Install file names are assumed to be of the format puppet-enterprise-VERSION-PLATFORM.(tar)|(tar.gz) for Unix like systems and puppet-enterprise-VERSION.msi for Windows systems.

Install PE based upon host configuration and options

Examples:

install_pe


1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
# File 'lib/beaker/dsl/install_utils.rb', line 1039

def install_pe
  #process the version files if necessary
  hosts.each do |host|
    host['pe_dir'] ||= options[:pe_dir]
    if host['platform'] =~ /windows/
      host['pe_ver'] = host['pe_ver'] || options['pe_ver'] ||
        Beaker::Options::PEVersionScraper.load_pe_version(host[:pe_dir] || options[:pe_dir], options[:pe_version_file_win])
    else
      host['pe_ver'] = host['pe_ver'] || options['pe_ver'] ||
        Beaker::Options::PEVersionScraper.load_pe_version(host[:pe_dir] || options[:pe_dir], options[:pe_version_file])
    end
  end
  #send in the global options hash
  do_install sorted_hosts, options
end

#install_puppet(opts = {}) ⇒ Object

Note:

This will attempt to add a repository for apt.puppetlabs.com on Debian, Ubuntu, or Cumulus machines, or yum.puppetlabs.com on EL or Fedora machines, then install the package ‘puppet’.

Install FOSS based upon host configuration and options

Examples:

will install puppet 3.6.1 from native puppetlabs provided packages wherever possible and will fail over to gem installation when impossible

install_puppet({
  :version          => '3.6.1',
  :facter_version   => '2.0.1',
  :hiera_version    => '1.3.3',
  :default_action   => 'gem_install',

 })

Will install latest packages on Enterprise Linux and Debian based distros and fail hard on all othere platforms.

install_puppet()

Parameters:

  • opts (Hash{Symbol=>String}) (defaults to: {})

Options Hash (opts):

  • :version (String)

    Version of puppet to download

  • :mac_download_url (String)

    Url to download msi pattern of %url%/puppet-%version%.msi

  • :win_download_url (String)

    Url to download dmg pattern of %url%/(puppet|hiera|facter)-%version%.msi

Returns:

  • nil

Raises:

  • (StandardError)

    When encountering an unsupported platform by default, or if gem cannot be found when default_action => ‘gem_install’

  • (FailTest)

    When error occurs during the actual installation process



685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/beaker/dsl/install_utils.rb', line 685

def install_puppet(opts = {})
  default_download_url = 'http://downloads.puppetlabs.com'
  opts = {:win_download_url => "#{default_download_url}/windows",
          :mac_download_url => "#{default_download_url}/mac"}.merge(opts)
  hosts.each do |host|
    if host['platform'] =~ /el-(5|6|7)/
      relver = $1
      install_puppet_from_rpm host, opts.merge(:release => relver, :family => 'el')
    elsif host['platform'] =~ /fedora-(\d+)/
      relver = $1
      install_puppet_from_rpm host, opts.merge(:release => relver, :family => 'fedora')
    elsif host['platform'] =~ /(ubuntu|debian|cumulus)/
      install_puppet_from_deb host, opts
    elsif host['platform'] =~ /windows/
      relver = opts[:version]
      install_puppet_from_msi host, opts
    elsif host['platform'] =~ /osx/
      install_puppet_from_dmg host, opts
    else
      if opts[:default_action] == 'gem_install'
        install_puppet_from_gem host, opts
      else
        raise "install_puppet() called for unsupported platform '#{host['platform']}' on '#{host.name}'"
      end
    end

    # Certain install paths may not create the config dirs/files needed
    on host, "mkdir -p #{host['puppetpath']}" unless host[:type] =~ /aio/
    on host, "echo '' >> #{host.puppet['hiera_config']}"
  end
  nil
end

#install_puppet_from_deb(host, 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.

Installs Puppet and dependencies from deb

Parameters:

  • host (Host)

    The host to install packages on

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install, if nil installs latest version

  • :facter_version (String)

    The version of Facter to install, if nil installs latest version

  • :hiera_version (String)

    The version of Hiera to install, if nil installs latest version

Returns:

  • nil



840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
# File 'lib/beaker/dsl/install_utils.rb', line 840

def install_puppet_from_deb( host, opts )
  if ! host.check_for_package 'lsb-release'
    host.install_package('lsb-release')
  end

  if ! host.check_for_command 'curl'
    on host, 'apt-get install -y curl'
  end

  on host, 'curl -O http://apt.puppetlabs.com/puppetlabs-release-$(lsb_release -c -s).deb'
  on host, 'dpkg -i puppetlabs-release-$(lsb_release -c -s).deb'
  on host, 'apt-get update'

  if opts[:facter_version]
    on host, "apt-get install -y facter=#{opts[:facter_version]}-1puppetlabs1"
  end

  if opts[:hiera_version]
    on host, "apt-get install -y hiera=#{opts[:hiera_version]}-1puppetlabs1"
  end

  if opts[:version]
    on host, "apt-get install -y puppet-common=#{opts[:version]}-1puppetlabs1"
    on host, "apt-get install -y puppet=#{opts[:version]}-1puppetlabs1"
  else
    on host, 'apt-get install -y puppet'
  end
end

#install_puppet_from_dmg(host, 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.

Installs Puppet and dependencies from dmg

Parameters:

  • host (Host)

    The host to install packages on

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install, required

  • :facter_version (String)

    The version of Facter to install, required

  • :hiera_version (String)

    The version of Hiera to install, required

  • :mac_download_url (String)

    Url to download msi pattern of %url%/puppet-%version%.msi

Returns:

  • nil



925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
# File 'lib/beaker/dsl/install_utils.rb', line 925

def install_puppet_from_dmg( host, opts )

  puppet_ver = opts[:version]
  facter_ver = opts[:facter_version]
  hiera_ver = opts[:hiera_version]

  if [puppet_ver, facter_ver, hiera_ver].include?(nil)
    raise "You need to specify versions for OSX host\n eg. install_puppet({:version => '3.6.2',:facter_version => '2.1.0',:hiera_version  => '1.3.4',})"
  end

  on host, "curl -O #{opts[:mac_download_url]}/puppet-#{puppet_ver}.dmg"
  on host, "curl -O #{opts[:mac_download_url]}/facter-#{facter_ver}.dmg"
  on host, "curl -O #{opts[:mac_download_url]}/hiera-#{hiera_ver}.dmg"

  on host, "hdiutil attach puppet-#{puppet_ver}.dmg"
  on host, "hdiutil attach facter-#{facter_ver}.dmg"
  on host, "hdiutil attach hiera-#{hiera_ver}.dmg"

  on host, "installer -pkg /Volumes/puppet-#{puppet_ver}/puppet-#{puppet_ver}.pkg -target /"
  on host, "installer -pkg /Volumes/facter-#{facter_ver}/facter-#{facter_ver}.pkg -target /"
  on host, "installer -pkg /Volumes/hiera-#{hiera_ver}/hiera-#{hiera_ver}.pkg -target /"
end

#install_puppet_from_gem(host, 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.

Installs Puppet and dependencies from gem

Parameters:

  • host (Host)

    The host to install packages on

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install, if nil installs latest

  • :facter_version (String)

    The version of Facter to install, if nil installs latest

  • :hiera_version (String)

    The version of Hiera to install, if nil installs latest

Returns:

  • nil

Raises:

  • (StandardError)

    if gem does not exist on target host



959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
# File 'lib/beaker/dsl/install_utils.rb', line 959

def install_puppet_from_gem( host, opts )
  # There are a lot of special things to do for Solaris and Solaris 10.
  # This is easier than checking host['platform'] every time.
  is_solaris10 = host['platform'] =~ /solaris-10/
  is_solaris = host['platform'] =~ /solaris/

  # Hosts may be provisioned with csw but pkgutil won't be in the
  # PATH by default to avoid changing the behavior for Puppet's tests
  if is_solaris10
    on host, 'ln -s /opt/csw/bin/pkgutil /usr/bin/pkgutil'
  end

  # Solaris doesn't necessarily have this, but gem needs it
  if is_solaris
    on host, 'mkdir -p /var/lib'
  end

  unless host.check_for_command( 'gem' )
    gempkg = case host['platform']
             when /solaris-11/                            then 'ruby-18'
             when /ubuntu-14/                             then 'ruby'
             when /solaris-10|ubuntu|debian|el-|cumulus/  then 'rubygems'
             else
               raise "install_puppet() called with default_action " +
                     "'gem_install' but program `gem' is " +
                     "not installed on #{host.name}"
             end

    host.install_package gempkg
  end

  # Link 'gem' to /usr/bin instead of adding /opt/csw/bin to PATH.
  if is_solaris10
    on host, 'ln -s /opt/csw/bin/gem /usr/bin/gem'
  end

  if host['platform'] =~ /debian|ubuntu|solaris|cumulus/
    gem_env = YAML.load( on( host, 'gem environment' ).stdout )
    gem_paths_array = gem_env['RubyGems Environment'].find {|h| h['GEM PATHS'] != nil }['GEM PATHS']
    path_with_gem = 'export PATH=' + gem_paths_array.join(':') + ':${PATH}'
    on host, "echo '#{path_with_gem}' >> ~/.bashrc"
  end

  if opts[:facter_version]
    on host, "gem install facter -v#{opts[:facter_version]} --no-ri --no-rdoc"
  end

  if opts[:hiera_version]
    on host, "gem install hiera -v#{opts[:hiera_version]} --no-ri --no-rdoc"
  end

  ver_cmd = opts[:version] ? "-v#{opts[:version]}" : ''
  on host, "gem install puppet #{ver_cmd} --no-ri --no-rdoc"

  # Similar to the treatment of 'gem' above.
  # This avoids adding /opt/csw/bin to PATH.
  if is_solaris
    gem_env = YAML.load( on( host, 'gem environment' ).stdout )
    # This is the section we want - this has the dir where gem executables go.
    env_sect = 'EXECUTABLE DIRECTORY'
    # Get the directory where 'gem' installs executables.
    # On Solaris 10 this is usually /opt/csw/bin
    gem_exec_dir = gem_env['RubyGems Environment'].find {|h| h[env_sect] != nil }[env_sect]

    on host, "ln -s #{gem_exec_dir}/hiera /usr/bin/hiera"
    on host, "ln -s #{gem_exec_dir}/facter /usr/bin/facter"
    on host, "ln -s #{gem_exec_dir}/puppet /usr/bin/puppet"
  end
end

#install_puppet_from_msi(host, opts) ⇒ Object

Installs Puppet and dependencies from msi

Parameters:

  • host (Host)

    The host to install packages on

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install, required

  • :win_download_url (String)

    The url to download puppet from



875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
# File 'lib/beaker/dsl/install_utils.rb', line 875

def install_puppet_from_msi( host, opts )
  #only install 64bit builds if
  # - we are on puppet version 3.7+
  # - we do not have install_32 set on host
  # - we do not have install_32 set globally
  version = opts[:version]
  if !(version_is_less(version, '3.7')) and host.is_x86_64? and not host['install_32'] and not opts['install_32']
    host['dist'] = "puppet-#{version}-x64"
  else
    host['dist'] = "puppet-#{version}"
  end
  link = "#{opts[:win_download_url]}/#{host['dist']}.msi"
  if not link_exists?( link )
    raise "Puppet #{version} at #{link} does not exist!"
  end

  if host.is_cygwin?
    dest = "#{host['dist']}.msi"
    on host, "curl -O #{link}"

    #Because the msi installer doesn't add Puppet to the environment path
    #Add both potential paths for simplicity
    #NOTE - this is unnecessary if the host has been correctly identified as 'foss' during set up
    puppetbin_path = "\"/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin\":\"/cygdrive/c/Program Files/Puppet Labs/Puppet/bin\""
    on host, %Q{ echo 'export PATH=$PATH:#{puppetbin_path}' > /etc/bash.bashrc }
  else
    dest = "C:\\Windows\\Temp\\#{host['dist']}.msi"

    on host, "set PATH=\"%PATH%;#{host['puppetbindir']}\""
    on host, "setx PATH \"%PATH%;#{host['puppetbindir']}\""

    on host, powershell("$webclient = New-Object System.Net.WebClient;  $webclient.DownloadFile('#{link}','#{dest}')")

    on host, "if not exist #{host['distmoduledir']} (md #{host['distmoduledir']})"
  end

  on host, "cmd /C 'start /w msiexec.exe /qn /i #{dest}'"
end

#install_puppet_from_rpm(host, 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.

Installs Puppet and dependencies using rpm

Parameters:

  • host (Host)

    The host to install packages on

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install, if nil installs latest version

  • :facter_version (String)

    The version of Facter to install, if nil installs latest version

  • :hiera_version (String)

    The version of Hiera to install, if nil installs latest version

  • :default_action (String)

    What to do if we don’t know how to install native packages on host. Valid value is ‘gem_install’ or nil. If nil raises an exception when on an unsupported platform. When ‘gem_install’ attempts to install Puppet via gem.

  • :release (String)

    The major release of the OS

  • :family (String)

    The OS family (one of ‘el’ or ‘fedora’)

Returns:

  • nil



813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# File 'lib/beaker/dsl/install_utils.rb', line 813

def install_puppet_from_rpm( host, opts )
  release_package_string = "http://yum.puppetlabs.com/puppetlabs-release-#{opts[:family]}-#{opts[:release]}.noarch.rpm"

  on host, "rpm -q --quiet puppetlabs-release || rpm -ivh #{release_package_string}"

  if opts[:facter_version]
    on host, "yum install -y facter-#{opts[:facter_version]}"
  end

  if opts[:hiera_version]
    on host, "yum install -y hiera-#{opts[:hiera_version]}"
  end

  puppet_pkg = opts[:version] ? "puppet-#{opts[:version]}" : 'puppet'
  on host, "yum install -y #{puppet_pkg}"
end

#install_puppet_module_via_pmt(opts = {}) ⇒ Object

Install the desired module with the PMT on all known hosts



1397
1398
1399
# File 'lib/beaker/dsl/install_utils.rb', line 1397

def install_puppet_module_via_pmt( opts = {} )
  install_puppet_module_via_pmt_on(hosts, opts)
end

#install_puppet_module_via_pmt_on(host, opts = {}) ⇒ Object

Install the desired module with the PMT on a given host

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :module_name (String)

    The short name of the module to be installed

  • :version (String)

    The version of the module to be installed



1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
# File 'lib/beaker/dsl/install_utils.rb', line 1376

def install_puppet_module_via_pmt_on( host, opts = {} )
  block_on host do |h|
    version_info = opts[:version] ? "-v #{opts[:version]}" : ""
    if opts[:source]
      author_name, module_name = parse_for_modulename( opts[:source] )
      modname = "#{author_name}-#{module_name}"
    else
      modname = opts[:module_name]
    end

    puppet_opts = {}
    if host[:default_module_install_opts].respond_to? :merge
      puppet_opts = host[:default_module_install_opts].merge( puppet_opts )
    end

    on h, puppet("module install #{modname} #{version_info}", puppet_opts)
  end
end

#install_puppetagent_dev_repo(host, opts) ⇒ Object

Install development repo of the puppet-agent on the given host

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of puppet-agent to install

  • :copy_base_local (String)

    Directory where puppet-agent artifact will be stored locally (default: ‘tmp/repo_configs’)

  • :copy_dir_external (String)

    Directory where puppet-agent artifact will be pushed to on the external machine (default: ‘/root’)

Returns:

  • nil



1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
# File 'lib/beaker/dsl/install_utils.rb', line 1271

def install_puppetagent_dev_repo( host, opts )
  opts[:copy_base_local]    ||= File.join('tmp', 'repo_configs')
  opts[:copy_dir_external]  ||= File.join('/', 'root')
  variant, version, arch, codename = host['platform'].to_array
  release_path = "#{options[:dev_builds_url]}/puppet-agent/#{opts[:version]}/artifacts/"
  copy_dir_local = File.join(opts[:copy_base_local], variant)
  onhost_copy_base = opts[:copy_dir_external]

  case variant
  when /^(fedora|el|centos)$/
    release_path << "el/#{version}/products/#{arch}"
    release_file = "puppet-agent-#{opts[:version]}-1.#{arch}.rpm"
  when /^(debian|ubuntu|cumulus)$/
    release_path << "deb/#{codename}"
    release_file = "puppet-agent_#{opts[:version]}-1_#{arch}.deb"
  when /^windows$/
    release_path << 'windows'
    onhost_copy_base = '`cygpath -smF 35`/'
    arch_suffix = arch =~ /64/ ? '64' : '86'
    release_file = "puppet-agent-x#{arch_suffix}.msi"
  else
    raise "No repository installation step for #{variant} yet..."
  end

  onhost_copied_file = File.join(onhost_copy_base, release_file)
  fetch_http_file( release_path, release_file, copy_dir_local)
  scp_to host, File.join(copy_dir_local, release_file), onhost_copy_base

  case variant
  when /^(fedora|el|centos)$/
    on host, "rpm -ivh #{onhost_copied_file}"
  when /^(debian|ubuntu|cumulus)$/
    on host, "dpkg -i --force-all #{onhost_copied_file}"
    on host, "apt-get update"
  when /^windows$/
    result = on host, "echo #{onhost_copied_file}"
    onhost_copied_file = result.raw_output.chomp
    on host, Command.new("start /w #{onhost_copied_file}", [], { :cmdexe => true })
  end
end

#install_puppetlabs_dev_repo(host, package_name, build_version, repo_configs_dir = 'tmp/repo_configs') ⇒ Object

Note:

This method only works on redhat-like and debian-like hosts.

Install development repository on the given host. This method pushes all repository information including package files for the specified package_name to the host and modifies the repository configuration file to point at the new repository. This is particularly useful for installing development packages on hosts that can’t access the builds server.

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface.

  • package_name (String)

    The name of the package whose repository is being installed.

  • build_version (String)

    A string identifying the output of a packaging job for use in looking up repository directory information

  • repo_configs_dir (String) (defaults to: 'tmp/repo_configs')

    A local directory where repository files will be stored as an intermediate step before pushing them to the given host.



1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
# File 'lib/beaker/dsl/install_utils.rb', line 1141

def install_puppetlabs_dev_repo ( host, package_name, build_version,
                          repo_configs_dir = 'tmp/repo_configs' )
  variant, version, arch, codename = host['platform'].to_array
  platform_configs_dir = File.join(repo_configs_dir, variant)

  # some of the uses of dev_builds_url below can't include protocol info,
  # pluse this opens up possibility of switching the behavior on provided
  # url type
  _, protocol, hostname = options[:dev_builds_url].partition /.*:\/\//
  dev_builds_url = protocol + hostname

  on host, "mkdir -p /root/#{package_name}"

  case variant
  when /^(fedora|el|centos)$/
    variant = (($1 == 'centos') ? 'el' : $1)
    fedora_prefix = ((variant == 'fedora') ? 'f' : '')

    if host.is_pe?
      pattern = "pl-%s-%s-repos-pe-%s-%s%s-%s.repo"
    else
      pattern = "pl-%s-%s-%s-%s%s-%s.repo"
    end

    repo_filename = pattern % [
      package_name,
      build_version,
      variant,
      fedora_prefix,
      version,
      arch
    ]

    repo = fetch_http_file( "%s/%s/%s/repo_configs/rpm/" %
                 [ dev_builds_url, package_name, build_version ],
                  repo_filename,
                  platform_configs_dir)

    link = "%s/%s/%s/repos/%s/%s%s/products/%s/" %
      [ dev_builds_url, package_name, build_version, variant,
        fedora_prefix, version, arch ]

    if not link_exists?( link )
      link = "%s/%s/%s/repos/%s/%s%s/devel/%s/" %
        [ dev_builds_url, package_name, build_version, variant,
          fedora_prefix, version, arch ]
    end

    if not link_exists?( link )
      raise "Unable to reach a repo directory at #{link}"
    end

    repo_dir = fetch_http_dir( link, platform_configs_dir )

    config_dir = '/etc/yum.repos.d/'
    scp_to host, repo, config_dir
    scp_to host, repo_dir, "/root/#{package_name}"

    search = "baseurl\\s*=\\s*http:\\/\\/#{hostname}.*$"
    replace = "baseurl=file:\\/\\/\\/root\\/#{package_name}\\/#{arch}"
    sed_command = "sed -i 's/#{search}/#{replace}/'"
    find_and_sed = "find #{config_dir} -name \"*.repo\" -exec #{sed_command} {} \\;"

    on host, find_and_sed

  when /^(debian|ubuntu|cumulus)$/
    list = fetch_http_file( "%s/%s/%s/repo_configs/deb/" %
                   [ dev_builds_url, package_name, build_version ],
                  "pl-%s-%s-%s.list" %
                   [ package_name, build_version, codename ],
                  platform_configs_dir )

    repo_dir = fetch_http_dir( "%s/%s/%s/repos/apt/%s" %
                                [ dev_builds_url, package_name,
                                  build_version, codename ],
                                 platform_configs_dir )

    config_dir = '/etc/apt/sources.list.d'
    scp_to host, list, config_dir
    scp_to host, repo_dir, "/root/#{package_name}"

    search = "deb\\s\\+http:\\/\\/#{hostname}.*$"
    replace = "deb file:\\/\\/\\/root\\/#{package_name}\\/#{codename} #{codename} main"
    sed_command = "sed -i 's/#{search}/#{replace}/'"
    find_and_sed = "find #{config_dir} -name \"*.list\" -exec #{sed_command} {} \\;"

    on host, find_and_sed
    on host, "apt-get update"

  else
    raise "No repository installation step for #{variant} yet..."
  end
end

#install_puppetlabs_release_repo(host) ⇒ Object

Note:

This method only works on redhat-like and debian-like hosts.

Install official puppetlabs release repository configuration on host.

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface.



1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
# File 'lib/beaker/dsl/install_utils.rb', line 1098

def install_puppetlabs_release_repo ( host )
  variant, version, arch, codename = host['platform'].to_array

  case variant
  when /^(fedora|el|centos)$/
    variant = (($1 == 'centos') ? 'el' : $1)

    rpm = options[:release_yum_repo_url] +
      "/puppetlabs-release-%s-%s.noarch.rpm" % [variant, version]

    on host, "rpm -ivh #{rpm}"

  when /^(debian|ubuntu|cumulus)$/
    deb = URI.join(options[:release_apt_repo_url],  "puppetlabs-release-%s.deb" % codename)

    on host, "wget -O /tmp/puppet.deb #{deb}"
    on host, "dpkg -i --force-all /tmp/puppet.deb"
    on host, "apt-get update"
  else
    raise "No repository installation step for #{variant} yet..."
  end
end

#installer_cmd(host, 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.

Create the PE install command string based upon the host and options settings

Examples:

on host, "#{installer_cmd(host, opts)} -a #{host['working_dir']}/answers"

Parameters:

  • host (Host)

    The host that PE is to be installed on For UNIX machines using the full PE installer, the host object must have the ‘pe_installer’ field set correctly.

  • opts (Hash{Symbol=>String})

    The options

Options Hash (opts):

  • :pe_ver_win (String)

    Default PE version to install or upgrade to on Windows hosts (Othersie uses individual Windows hosts pe_ver)

  • :pe_ver (String)

    Default PE version to install or upgrade to (Otherwise uses individual hosts pe_ver)

  • :pe_debug (Boolean) — default: false

    Should we run the installer in debug mode?



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/beaker/dsl/install_utils.rb', line 166

def installer_cmd(host, opts)
  version = host['pe_ver'] || opts[:pe_ver]
  if host['platform'] =~ /windows/
    log_file = "#{File.basename(host['working_dir'])}.log"
    pe_debug = host[:pe_debug] || opts[:pe_debug] ? " && cat #{log_file}" : ''
    if host.is_cygwin?
      "cd #{host['working_dir']} && cmd /C 'start /w msiexec.exe /qn /L*V #{log_file} /i #{host['dist']}.msi PUPPET_MASTER_SERVER=#{master} PUPPET_AGENT_CERTNAME=#{host}'#{pe_debug}"
    else
      "cd #{host['working_dir']} &&  msiexec.exe /qn /L*V #{log_file} /i #{host['dist']}.msi PUPPET_MASTER_SERVER=#{master} PUPPET_AGENT_CERTNAME=#{host}#{pe_debug}"
    end
  # Frictionless install didn't exist pre-3.2.0, so in that case we fall
  # through and do a regular install.
  elsif host['roles'].include? 'frictionless' and ! version_is_less(version, '3.2.0')
    # PE 3.4 introduced the ability to pass in config options to the bash script in the form
    # of <section>:<key>=<value>
    frictionless_install_opts = []
    if host.has_key?('frictionless_options') and !  version_is_less(version, '3.4.0')
      # since we have options to pass in, we need to tell the bash script
      host['frictionless_options'].each do |section, settings|
        settings.each do |key, value|
          frictionless_install_opts << "#{section}:#{key}=#{value}"
        end
      end
    end

    pe_debug = host[:pe_debug] || opts[:pe_debug] ? ' -x' : ''
    "cd #{host['working_dir']} && curl --tlsv1 -kO https://#{master}:8140/packages/#{version}/install.bash && bash#{pe_debug} install.bash #{frictionless_install_opts.join(' ')}".strip
  elsif host['platform'] =~ /osx/
    version = host['pe_ver'] || opts[:pe_ver]
    pe_debug = host[:pe_debug] || opts[:pe_debug] ? ' -verboseR' : ''
    "cd #{host['working_dir']} && hdiutil attach #{host['dist']}.dmg && installer#{pe_debug} -pkg /Volumes/puppet-enterprise-#{version}/puppet-enterprise-installer-#{version}.pkg -target /"
  elsif host['platform'] =~ /eos/
    commands = ['enable', "extension puppet-enterprise-#{version}-#{host['platform']}.swix"]
    command = commands.join("\n")
    "Cli -c '#{command}'"
  else
    pe_debug = host[:pe_debug] || opts[:pe_debug]  ? ' -D' : ''
    "cd #{host['working_dir']}/#{host['dist']} && ./#{host['pe_installer']}#{pe_debug} -a #{host['working_dir']}/answers"
  end
end

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.

Determine is a given URL is accessible

Examples:

extension = link_exists?("#{URL}.tar.gz") ? ".tar.gz" : ".tar"

Parameters:

  • link (String)

    The URL to examine

Returns:

  • (Boolean)

    true if the URL has a ‘200’ HTTP response code, false otherwise



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/beaker/dsl/install_utils.rb', line 224

def link_exists?(link)
  require "net/http"
  require "net/https"
  require "open-uri"
  url = URI.parse(link)
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = (url.scheme == 'https')
  http.start do |http|
    return http.head(url.request_uri).code == "200"
  end
end

#parse_for_modulename(root_module_dir) ⇒ String

Parse root directory of a module for module name Searches for metadata.json and then if none found, Modulefile and parses for the Name attribute

Parameters:

  • root_module_dir (String)

Returns:

  • (String)

    module name



1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
# File 'lib/beaker/dsl/install_utils.rb', line 1512

def parse_for_modulename(root_module_dir)
  author_name, module_name = nil, nil
  if File.exists?("#{root_module_dir}/metadata.json")
    logger.debug "Attempting to parse Modulename from metadata.json"
    module_json = JSON.parse(File.read "#{root_module_dir}/metadata.json")
    if(module_json.has_key?('name'))
      author_name, module_name = get_module_name(module_json['name'])
    end
  end
  if !module_name && File.exists?("#{root_module_dir}/Modulefile")
    logger.debug "Attempting to parse Modulename from Modulefile"
    if /^name\s+'?(\w+-\w+)'?\s*$/i.match(File.read("#{root_module_dir}/Modulefile"))
      author_name, module_name = get_module_name(Regexp.last_match[1])
    end
  end
  if !module_name && !author_name
    logger.debug "Unable to determine name, returning null"
  end
  return author_name, module_name
end

#parse_for_moduleroot(possible_module_directory) ⇒ String?

Recursive method for finding the module root Assumes that a Modulefile exists

Parameters:

  • possible_module_directory (String)

    will look for Modulefile and if none found go up one level and try again until root is reached

Returns:

  • (String, nil)


1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
# File 'lib/beaker/dsl/install_utils.rb', line 1496

def parse_for_moduleroot(possible_module_directory)
  if File.exists?("#{possible_module_directory}/Modulefile") || File.exists?("#{possible_module_directory}/metadata.json")
    possible_module_directory
  elsif possible_module_directory === '/'
    logger.error "At root, can't parse for another directory"
    nil
  else
    logger.debug "No Modulefile or metadata.json found at #{possible_module_directory}, moving up"
    parse_for_moduleroot File.expand_path(File.join(possible_module_directory,'..'))
  end
end

#split_author_modulename(author_module_attr) ⇒ Hash<Symbol,String>?

Split the Author-Name into a hash

Parameters:

  • author_module_attr (String)

Returns:

  • (Hash<Symbol,String>, nil)

    :author and :module symbols will be returned



1551
1552
1553
1554
1555
1556
1557
1558
# File 'lib/beaker/dsl/install_utils.rb', line 1551

def split_author_modulename(author_module_attr)
  result = /(\w+)-(\w+)/.match(author_module_attr)
  if result
    {:author => result[1], :module => result[2]}
  else
    nil
  end
end

#upgrade_package(host, package_name) ⇒ Result

Upgrade a package on a host. The package must already be installed

Parameters:

  • host (Host)

    A host object

  • package_name (String)

    Name of the package to install

Returns:

  • (Result)

    An object representing the outcome of *upgrade command*.



1486
1487
1488
# File 'lib/beaker/dsl/install_utils.rb', line 1486

def upgrade_package host, package_name
  host.upgrade_package package_name
end

#upgrade_pe(path = nil) ⇒ Object

Note:

Install file names are assumed to be of the format puppet-enterprise-VERSION-PLATFORM.(tar)|(tar.gz) for Unix like systems and puppet-enterprise-VERSION.msi for Windows systems.

Upgrade PE based upon host configuration and options

Examples:

upgrade_pe("http://neptune.puppetlabs.lan/3.0/ci-ready/")

Parameters:

  • path (String) (defaults to: nil)

    A path (either local directory or a URL to a listing of PE builds). Will contain a LATEST file indicating the latest build to install. This is ignored if a pe_upgrade_ver and pe_upgrade_dir are specified in the host configuration file.



1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
# File 'lib/beaker/dsl/install_utils.rb', line 1066

def upgrade_pe path=nil
  set_console_password = false
  # if we are upgrading from something lower than 3.4 then we need to set the pe console password
  if (dashboard[:pe_ver] ? version_is_less(dashboard[:pe_ver], "3.4.0") : true)
    set_console_password = true
  end
  # get new version information
  hosts.each do |host|
    host['pe_dir'] = host['pe_upgrade_dir'] || path
    if host['platform'] =~ /windows/
      host['pe_ver'] = host['pe_upgrade_ver'] || options['pe_upgrade_ver'] ||
        Options::PEVersionScraper.load_pe_version(host['pe_dir'], options[:pe_version_file_win])
    else
      host['pe_ver'] = host['pe_upgrade_ver'] || options['pe_upgrade_ver'] ||
        Options::PEVersionScraper.load_pe_version(host['pe_dir'], options[:pe_version_file])
    end
    if version_is_less(host['pe_ver'], '3.0')
      host['pe_installer'] ||= 'puppet-enterprise-upgrader'
    end
  end
  # send in the global options hash
  do_install(sorted_hosts, options.merge({:type => :upgrade, :set_console_password => set_console_password}))
  options['upgrade'] = true
end