Module: ForemanMaintain::Concerns::Upstream

Includes:
ForemanAndKatelloVersionMap
Defined in:
lib/foreman_maintain/concerns/upstream.rb

Constant Summary

Constants included from ForemanAndKatelloVersionMap

ForemanAndKatelloVersionMap::FOREMAN_AND_KATELLO_VERSION_MAP

Instance Method Summary collapse

Methods included from ForemanAndKatelloVersionMap

#foreman_version_by_katello, #katello_version_by_foreman

Instance Method Details

#foreman_release_pkg_url(version) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/foreman_maintain/concerns/upstream.rb', line 16

def foreman_release_pkg_url(version)
  if el?
    "#{server_url}releases/#{version}/#{el_short_name}/x86_64/foreman-release.rpm"
  elsif debian_or_ubuntu?
    "#{server_url}pool/#{os_version_codename}/#{version}"\
    '/f/foreman-release/foreman-release.deb'
  else
    raise 'Unknown operating system detected!'
  end
end

#katello_pkgs_url(katello_version) ⇒ Object



27
28
29
# File 'lib/foreman_maintain/concerns/upstream.rb', line 27

def katello_pkgs_url(katello_version)
  "#{server_url}katello/#{katello_version}/katello/#{el_short_name}/x86_64/"
end

#katello_release_pkg(version) ⇒ Object



31
32
33
# File 'lib/foreman_maintain/concerns/upstream.rb', line 31

def katello_release_pkg(version)
  "#{katello_pkgs_url(katello_version_by_foreman(version))}katello-repos-latest.rpm"
end

#repoids_and_urlsObject



85
86
87
88
89
90
91
92
93
# File 'lib/foreman_maintain/concerns/upstream.rb', line 85

def repoids_and_urls
  repoids_and_urls = {}
  repository_manager.enabled_repos.each do |repo, url|
    repo_urls.each do |regex|
      repoids_and_urls[repo] = url if url&.match?(regex)
    end
  end
  repoids_and_urls
end

#server_urlObject



6
7
8
9
10
11
12
13
14
# File 'lib/foreman_maintain/concerns/upstream.rb', line 6

def server_url
  if el?
    'https://yum.theforeman.org/'
  elsif debian_or_ubuntu?
    'https://deb.theforeman.org/'
  else
    raise 'Unknown operating system detected!'
  end
end

#setup_repositories(version) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/foreman_maintain/concerns/upstream.rb', line 73

def setup_repositories(version)
  # Documentation needs update with respect to new env vars
  activation_key = ENV['ACTIVATION_KEY']
  org = ENV['FOREMAN_ORG']
  if activation_key
    use_activation_key(activation_key, org)
  else
    update_foreman_release_pkg(version)
    update_katello_release_pkg(version)
  end
end

#update_foreman_release_pkg(version) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/foreman_maintain/concerns/upstream.rb', line 57

def update_foreman_release_pkg(version)
  pkg_url = foreman_release_pkg_url(version)
  if el?
    update_release_pkg_el(pkg_url)
  elsif debian_or_ubuntu?
    update_release_pkg_deb(pkg_url)
  end
end

#update_katello_release_pkg(version) ⇒ Object



66
67
68
69
70
71
# File 'lib/foreman_maintain/concerns/upstream.rb', line 66

def update_katello_release_pkg(version)
  if feature(:katello)
    pkg_url = katello_release_pkg(version)
    update_release_pkg_el(pkg_url)
  end
end

#update_release_pkg_deb(pkg_url) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/foreman_maintain/concerns/upstream.rb', line 39

def update_release_pkg_deb(pkg_url)
  Dir.mktmpdir do |dir|
    release_file_path = "#{dir}/foreman-release.deb"
    exit_status, = execute_with_status("wget -q -O #{release_file_path} #{pkg_url}")
    if exit_status == 0
      package_manager.install(release_file_path, assumeyes: true)
    else
      warn! "Couldn't install Foreman release package: #{pkg_url}"
    end
  end
end

#update_release_pkg_el(pkg_url) ⇒ Object



35
36
37
# File 'lib/foreman_maintain/concerns/upstream.rb', line 35

def update_release_pkg_el(pkg_url)
  package_manager.install(pkg_url, assumeyes: true)
end

#use_activation_key(activation_key, org) ⇒ Object



51
52
53
54
55
# File 'lib/foreman_maintain/concerns/upstream.rb', line 51

def use_activation_key(activation_key, org)
  org_options = org ? %(--org #{shellescape(org)}) : ''
  execute!(%(subscription-manager register #{org_options}\
              --activationkey #{shellescape(activation_key)} --force))
end