Skip to content

Commit

Permalink
initial support for handling $releasever
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Aug 26, 2015
1 parent 5a11a9a commit f669734
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 3 deletions.
81 changes: 81 additions & 0 deletions src/lib/registration/releasever.rb
@@ -0,0 +1,81 @@
# ------------------------------------------------------------------------------
# Copyright (c) 2015 SUSE LLC, All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------

require "yast"
require "registration/sw_mgmt"

require "uri"

module Registration
# this class handles activating the new releasever value in the package management
class Releasever
include Yast::Logger

# the placeholder used in the URL
RELEASEVER_ID = "$releasever"

Yast.import "Pkg"

attr_reader :version

# constructor
# @param [String] version the new release version value
def initialize(version)
@version = version
end

# activate the new releasever
def activate
log.info "Setting $releasever to: #{version}"
# export the settings
ENV["ZYPP_REPO_RELEASEVER"] = version

repos = releasever_repos
return if repos.empty?

refresh(repos)
# refresh the loaded packages
SwMgmt.sync_pool
end

private

# get the repositories which contain "$releasever" directory in the URL
# @return [Array<Fixnum>] the repository list
def releasever_repos
repos = Yast::Pkg.SourceGetCurrent(true)
repos.select do |repo|
data = Pkg.SourceGeneralData(repo)

url = URI(data["url"])
url.path.split("/").include?(RELEASEVER_ID)
end
end

# refresh the requested repositories
# @param [Array<Fixnum>] repos the repositories to refresh
def refresh(repos)
repos.each do |repo|
log.info "Refreshing repository #{repo}"
Yast::Pkg.SourceForceRefreshNow(repo)
end
end
end
end
8 changes: 8 additions & 0 deletions src/lib/registration/sw_mgmt.rb
Expand Up @@ -450,6 +450,14 @@ def self.products_from_repo(repo_id)
end
end

# synchronize the changes done by modifying the services or repositories,
# reinitialize the repositories and reload the available packages
def self.sync_pool
Yast::Pkg.SourceFinishAll
Yast::Pkg.SourceRestore
Yast::Pkg.SourceLoad
end

def self.get_release_type(product)
if product["product_line"]
oem_file = File.join(OEM_DIR, product["product_line"])
Expand Down
24 changes: 21 additions & 3 deletions src/lib/registration/ui/migration_repos_workflow.rb
Expand Up @@ -17,6 +17,7 @@
require "registration/registration"
require "registration/registration_ui"
require "registration/migration_repositories"
require "registration/releasever"
require "registration/sw_mgmt"
require "registration/ui/migration_selection_dialog"
require "registration/ui/migration_repos_selection_dialog"
Expand Down Expand Up @@ -111,6 +112,9 @@ def run
"select_migration_products" => {
abort: :abort,
cancel: :abort,
next: "update_releasever"
},
"update_releasever" => {
next: "register_migration_products"
},
"register_migration_products" => {
Expand Down Expand Up @@ -138,6 +142,7 @@ def run_sequence
"find_products" => [->() { find_products }, true],
"load_migration_products" => [->() { load_migration_products }, true],
"select_migration_products" => ->() { select_migration_products },
"update_releasever" => ->() { update_releasever },
"register_migration_products" => [->() { register_migration_products }, true],
"activate_migration_repos" => [->() { activate_migration_repos }, true],
"select_migration_repos" => ->() { select_migration_repos }
Expand Down Expand Up @@ -255,9 +260,7 @@ def register_migration_products

# synchronize the changes done by modifying the services,
# reinitialize the repositories and reload the available packages
Yast::Pkg.SourceFinishAll
Yast::Pkg.SourceRestore
Yast::Pkg.SourceLoad
SwMgmt.sync_pool

log.info "Registered services: #{registered_services}"
:next
Expand Down Expand Up @@ -309,6 +312,21 @@ def activate_migration_repos
def select_migration_repos
UI::MigrationReposSelectionDialog.run
end

# update the $releasever
def update_releasever
new_base = selected_migration.find(&:base)

if new_base
log.info "Activating new releasever for base product: #{new_base}"
releasever = Releasever.new(new_base.version)
releasever.activate
else
log.info "The base system is not updated, skipping releasever update"
end

:next
end
end
end
end

0 comments on commit f669734

Please sign in to comment.