Skip to content

Commit

Permalink
Merge pull request #65 from yast/repo_setup_bnc875839
Browse files Browse the repository at this point in the history
Activate repository setup from the SCC response (bnc#875839)
  • Loading branch information
lslezak committed May 5, 2014
2 parents 960753c + b227033 commit 11aa82f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 48 deletions.
8 changes: 8 additions & 0 deletions package/yast2-registration.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Mon May 5 13:33:21 UTC 2014 - lslezak@suse.cz

- Update "enabled" and "autorefresh" repository flags according to
the registration response, e.g. enable -Pool repositories
(bnc#875839)
- 3.1.43

-------------------------------------------------------------------
Fri May 2 12:01:45 UTC 2014 - lslezak@suse.cz

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-registration.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 3.1.42
Version: 3.1.43
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
43 changes: 43 additions & 0 deletions src/lib/registration/sw_mgmt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def self.add_services(product_services, credentials)
raise ::Registration::ServiceError.new(N_("Refreshing service '%s' failed."), source.name)
end
end

# activate the requested repository setup
repos_enable(product_services.map(&:enabled).flatten)
repos_disable_autorefresh(product_services.map(&:norefresh).flatten)
ensure
Pkg.SourceSaveAll
end
Expand Down Expand Up @@ -223,6 +227,45 @@ def self.set_repos_state(repos, enabled)
end
end

# Disable specified repositories
# @param repo_aliases [Array<String>] list of repository aliases
def self.repos_enable(repo_aliases)
each_repo(repo_aliases) do |repo_alias|
log.info "Enabling repository #{repo_alias}"
Pkg.SourceSetEnabled(repo_alias, true)
end
end

# Disable autorefresh for specified repositories
# @param repo_aliases [Array<String>] list of repository aliases
def self.repos_disable_autorefresh(repo_aliases)
each_repo(repo_aliases) do |repo_alias|
log.info "Disabling autorefresh for #{repo_alias} repository"
Pkg.SourceSetAutorefresh(repo_alias, false)
end
end

# a helper method for iterating over repositories
# @param repo_aliases [Array<String>] list of repository aliases
# @param block block evaluated for each found repository
def self.each_repo(repo_aliases, &block)
all_repos = Pkg.SourceGetCurrent(false)

repo_aliases.each do |repo_alias|
# find the repository with the alias
repo = all_repos.find do |repo|
Pkg.SourceGeneralData(repo)["alias"] == repo_alias
end

if repo
yield(repo)
else
log.warning "Repository '#{repo_alias}' was not found, skipping"
end
end
end

private_class_method :each_repo
end
end

106 changes: 59 additions & 47 deletions test/sw_mgmt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,48 @@
describe "Registration::SwMgmt" do
let(:yast_pkg) { double("Yast::Pkg") }

let(:service_name) { "SLES" }
let(:repos) do
{
# installation repository, not from registration
0 => {
"alias"=>"SLES12", "autorefresh"=>false,
"base_urls"=>["cd:///"],
"enabled"=>true, "is_update_repo"=>false, "keeppackages"=>false,
"mirror_list"=>"", "name"=>"SLES12", "priority"=>99, "product_dir"=>"",
"service"=>"", "type"=>"SUSE",
"url"=>"cd:///"
},
# pool repo from service
1 => {
"alias"=>"SLES:SLES12-Pool", "autorefresh"=>true,
"base_urls"=>["https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12-POOL"],
"enabled"=>true, "is_update_repo"=>false, "keeppackages"=>false,
"mirror_list"=>"", "name"=>"SLES12-Pool", "priority"=>99, "product_dir"=>"",
"service"=>service_name, "type"=>"YUM",
"url"=>"https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12-POOL"
},
# update repo from service
2 => {
"alias"=>"SLES:SLES12-Updates", "autorefresh"=>true,
"base_urls"=>["https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12"],
"enabled"=>true, "is_update_repo"=>true, "keeppackages"=>false,
"mirror_list"=>"", "name"=>"SLES12-Updates", "priority"=>99, "product_dir"=> "",
"service"=>service_name, "type"=>"YUM",
"url"=>"https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12"
},
# update repo from a different service
3 => {
"alias"=>"Another:SLES12-Updates", "autorefresh"=>true,
"base_urls"=>["https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12"],
"enabled"=>true, "is_update_repo"=>true, "keeppackages"=>false,
"mirror_list"=>"", "name"=>"SLES12-Updates", "priority"=>99, "product_dir"=> "",
"service"=> "Another", "type"=>"YUM",
"url"=>"https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12"
}
}
end

before do
stub_yast_require
require "registration/sw_mgmt"
Expand All @@ -17,47 +59,6 @@

describe ".service_repos" do
let(:services) { double }
let(:service_name) { "SLES" }
let(:repos) do
{
# installation repository, not from registration
0 => {
"alias"=>"SLES12", "autorefresh"=>false,
"base_urls"=>["cd:///"],
"enabled"=>true, "is_update_repo"=>false, "keeppackages"=>false,
"mirror_list"=>"", "name"=>"SLES12", "priority"=>99, "product_dir"=>"",
"service"=>"", "type"=>"SUSE",
"url"=>"cd:///"
},
# pool repo from service
1 => {
"alias"=>"SLES:SLES12-Pool", "autorefresh"=>true,
"base_urls"=>["https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12-POOL"],
"enabled"=>true, "is_update_repo"=>false, "keeppackages"=>false,
"mirror_list"=>"", "name"=>"SLES12-Pool", "priority"=>99, "product_dir"=>"",
"service"=>service_name, "type"=>"YUM",
"url"=>"https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12-POOL"
},
# update repo from service
2 => {
"alias"=>"SLES:SLES12-Updates", "autorefresh"=>true,
"base_urls"=>["https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12"],
"enabled"=>true, "is_update_repo"=>true, "keeppackages"=>false,
"mirror_list"=>"", "name"=>"SLES12-Updates", "priority"=>99, "product_dir"=> "",
"service"=>service_name, "type"=>"YUM",
"url"=>"https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12"
},
# update repo from a different service
3 => {
"alias"=>"Another:SLES12-Updates", "autorefresh"=>true,
"base_urls"=>["https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12"],
"enabled"=>true, "is_update_repo"=>true, "keeppackages"=>false,
"mirror_list"=>"", "name"=>"SLES12-Updates", "priority"=>99, "product_dir"=> "",
"service"=> "Another", "type"=>"YUM",
"url"=>"https://nu.novell.com/suse/x86_64/update/SLE-SERVER/12"
}
}
end

before do
service = double
Expand Down Expand Up @@ -93,25 +94,36 @@
let(:service_url) { "https://example.com/foo/bar?credentials=TEST_credentials" }
let(:credentials) { SUSE::Connect::Credentials.new("user", "password", "file") }
let(:product_services) do
SUSE::Connect::Service.new({"test" => service_url}, [], [])
SUSE::Connect::Service.new({service_name => service_url}, ["SLES:SLES12-Pool"],
["SLES:SLES12-Pool"])
end

before do
expect(yast_pkg).to receive(:SourceSaveAll).and_return(true).twice
expect(yast_pkg).to receive(:ServiceRefresh).with("test").and_return(true)
expect(yast_pkg).to receive(:ServiceSave).with("test").and_return(true)
expect(yast_pkg).to receive(:ServiceRefresh).with(service_name).and_return(true)
expect(yast_pkg).to receive(:ServiceSave).with(service_name).and_return(true)
SUSE::Connect::Credentials.any_instance.should_receive(:write)

# 1 -> "SLES:SLES12-Pool"
expect(yast_pkg).to receive(:SourceSetEnabled).with(1, true).and_return(true)
expect(yast_pkg).to receive(:SourceSetAutorefresh).with(1, false).and_return(true)

allow(yast_pkg).to receive(:SourceGetCurrent).with(false).and_return(repos.keys)
repos.each do |id, repo|
allow(yast_pkg).to receive(:SourceGeneralData).with(id).and_return(repo)
end
end

it "it creates a new service if the service does not exist yet" do
expect(yast_pkg).to receive(:ServiceAliases).and_return([])
expect(yast_pkg).to receive(:ServiceAdd).with("test", service_url).and_return(true)
expect(yast_pkg).to receive(:ServiceAdd).with(service_name, service_url).and_return(true)
expect { Registration::SwMgmt.add_services([product_services], credentials) }.to_not raise_error
end

it "updates the existing service if the service already exists" do
expect(yast_pkg).to receive(:ServiceAliases).and_return(["test"])
expect(yast_pkg).to receive(:ServiceSet).with("test", hash_including("url" => service_url)).and_return(true)
expect(yast_pkg).to receive(:ServiceAliases).and_return([service_name])
expect(yast_pkg).to receive(:ServiceSet).with(
service_name, hash_including("url" => service_url)).and_return(true)
expect { Registration::SwMgmt.add_services([product_services], credentials) }.to_not raise_error
end
end
Expand Down

0 comments on commit 11aa82f

Please sign in to comment.