Class: Beaker::Utils::RepoControl

Inherits:
Object
  • Object
show all
Defined in:
lib/beaker/utils/repo_control.rb

Constant Summary collapse

APT_CFG =
%q{ Acquire::http::Proxy "http://proxy.puppetlabs.net:3128/"; }
IPS_PKG_REPO =
"http://solaris-11-internal-repo.delivery.puppetlabs.net"

Instance Method Summary collapse

Constructor Details

#initialize(options, hosts) ⇒ RepoControl

Returns a new instance of RepoControl.



8
9
10
11
12
13
# File 'lib/beaker/utils/repo_control.rb', line 8

def initialize(options, hosts)
  @options = options.dup
  @hosts = hosts
  @logger = options[:logger]
  @debug_opt = options[:debug] ? 'vh' : ''
end

Instance Method Details

#add_el_extrasObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/beaker/utils/repo_control.rb', line 68

def add_el_extras
  #add_el_extras
  #only supports el-* platforms
  @hosts.each do |host|
    case
    when host['platform'] =~ /el-(5|6)/
      result = host.exec(Command.new('rpm -qa | grep epel-release'), :acceptable_exit_codes => [0,1])
      if result.exit_code == 1
        url = epel_info_for! host
        host.exec(Command.new("rpm -i#{@debug_opt} #{url}"))
        host.exec(Command.new('yum clean all && yum makecache'))
      end
    else
      @logger.debug "#{host}: package repo configuration not modified"
    end
  end
rescue => e
  report_and_raise(@logger, e, "add_repos")
end

#apt_get_update(host) ⇒ Object



29
30
31
32
33
# File 'lib/beaker/utils/repo_control.rb', line 29

def apt_get_update host
  if host[:platform] =~ /(ubuntu)|(debian)/ 
    host.exec(Command.new("apt-get -y -f -m update"))
  end
end

#copy_file_to_remote(host, file_path, file_content) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/beaker/utils/repo_control.rb', line 35

def copy_file_to_remote(host, file_path, file_content)
  Tempfile.open 'beaker' do |tempfile|
    File.open(tempfile.path, 'w') {|file| file.puts file_content }

    host.do_scp_to(tempfile.path, file_path, @options)
  end

end

#epel_info_for!(host) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/beaker/utils/repo_control.rb', line 15

def epel_info_for! host
  version = host['platform'].match(/el-(\d+)/)[1]
  if version == '6'
    pkg = 'epel-release-6-8.noarch.rpm'
    url = "http://mirror.itc.virginia.edu/fedora-epel/6/i386/#{pkg}"
  elsif version == '5'
    pkg = 'epel-release-5-4.noarch.rpm'
    url = "http://archive.linux.duke.edu/pub/epel/5/i386/#{pkg}"
  else
    raise "I don't understand your platform description!"
  end
  return url
end

#proxy_configObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/beaker/utils/repo_control.rb', line 44

def proxy_config
  # repo_proxy
  # supports ubuntu, debian and solaris platforms
  @hosts.each do |host|
    case
    when host['platform'] =~ /ubuntu/
      host.exec(Command.new("if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi"))
      copy_file_to_remote(host, '/etc/apt/apt.conf', APT_CFG)
      apt_get_update(host)
    when host['platform'] =~ /debian/
      host.exec(Command.new("if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi"))
      copy_file_to_remote(host, '/etc/apt/apt.conf', APT_CFG)
      apt_get_update(host)
    when host['platform'] =~ /solaris-11/
      host.exec(Command.new("/usr/bin/pkg unset-publisher solaris || :"))
      host.exec(Command.new("/usr/bin/pkg set-publisher -g %s solaris" % IPS_PKG_REPO))
    else
      @logger.debug "#{host}: repo proxy configuration not modified"
    end
  end
rescue => e
  report_and_raise(@logger, e, "proxy_config")
end