Skip to content

Commit

Permalink
Update from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 20, 2020
1 parent b6140e6 commit a9814c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
13 changes: 4 additions & 9 deletions src/lib/installation/updates_manager.rb
Expand Up @@ -16,6 +16,7 @@
require "pathname"
require "installation/driver_update"
require "installation/update_repository"
require "yast2/execute"

module Installation
# This class takes care of managing installer updates
Expand Down Expand Up @@ -55,9 +56,6 @@ class CouldNotFetchUpdateFromRepo < RepoError; end
# Repo is unreachable (name solving issues, etc.).
class CouldNotProbeRepo < RepoError; end

# The control file was not updated due to some problem
class CouldNotUpdateControlFile < RepoError; end

DRIVER_UPDATES_PATHS = [Pathname("/update"), Pathname("/download")].freeze

# Constructor
Expand Down Expand Up @@ -128,15 +126,12 @@ def repositories?
private

NEW_CONTROL_FILE_PATH = "/usr/lib/skelcd/CD1/control.xml".freeze
APPLY_CMD = "/sbin/adddir %<source>s /".freeze

# Replaces the control file with the the updated one (if it exists)
# Replaces the control file with the updated one (if it exists)
def replace_control_file
return unless File.exist?(NEW_CONTROL_FILE_PATH)
cmd = format(APPLY_CMD, source: File.dirname(NEW_CONTROL_FILE_PATH))
out = Yast::SCR.Execute(Yast::Path.new(".target.bash_output"), cmd)
log.info("Updating control.xml file in inst-sys '#{cmd}': #{out}")
raise CouldNotUpdateControlFile unless out["exit"].zero?
log.info("Updating control.xml file in inst-sys")
Yast::Execute.locally!("/sbin/adddir", File.dirname(NEW_CONTROL_FILE_PATH), "/")
end
end
end
24 changes: 8 additions & 16 deletions test/updates_manager_test.rb
Expand Up @@ -131,26 +131,18 @@

context "when a new control file is available" do
let(:new_control_file?) { true }
let(:exit_code) { 0 }

before do
allow(Yast::SCR).to receive(:Execute).and_return("exit" => exit_code)
end

it "updates the control file if needed" do
expect(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash_output"), "/sbin/adddir /usr/lib/skelcd/CD1 /")
it "updates the control file" do
expect(Yast::Execute).to receive(:locally!)
.with("/sbin/adddir", "/usr/lib/skelcd/CD1", "/")
manager.apply_all
end
end

context "and updating the control file fails" do
let(:exit_code) { 1 }

it "raises an exception" do
expect { manager.apply_all }
.to raise_error(Installation::UpdatesManager::CouldNotUpdateControlFile)
end
end
it "does not replace the control file" do
expect(Yast::Execute).to_not receive(:locally!)
.with("/sbin/adddir", /skelcd/, "/")
manager.apply_all
end
end

Expand Down

0 comments on commit a9814c8

Please sign in to comment.