Skip to content

Commit

Permalink
Improve documentation regarding driver updates
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Mar 11, 2016
1 parent cc2b95d commit e958cbe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/lib/installation/clients/inst_update_installer.rb
Expand Up @@ -40,7 +40,7 @@ def update_installer

# Check if installer was updated
#
# It checks if a fle UPDATED_FILENAME exists in Directory.vardir
# It checks if a file UPDATED_FILENAME exists in Directory.vardir
#
# @return [Boolean] true if it exists; false otherwise.
def installer_updated?
Expand Down
35 changes: 15 additions & 20 deletions src/lib/installation/driver_update.rb
@@ -1,17 +1,17 @@
require "yast"
require "tempfile"
require "open-uri"
require "pathname"

module Installation
# Represents a driver update disk (DUD)
#
# The DUD will be fetched from a remote URL. At this time, only HTTP/HTTPS
# are supported.
# The DUD will be fetched from a given URL. At this time, HTTP, HTTPS, FTP
# and file:/ are supported.
class DriverUpdate
class NotFound < StandardError; end

EXTRACT_CMD = "gzip -dc %<source>s | cpio --quiet --sparse -dimu --no-absolute-filenames"
APPLY_CMD = "/etc/adddir %<source>s/inst-sys /"
APPLY_CMD = "/etc/adddir %<source>s/inst-sys /" # openSUSE/installation-images
FETCH_CMD = "/usr/bin/curl --location --verbose --fail --max-time 300 --connect-timeout 15 " \
"%<uri>s --output '%<output>s'"
TEMP_FILENAME = "remote.dud"
Expand All @@ -20,20 +20,16 @@ class NotFound < StandardError; end

# Constructor
#
# @param uri [URI] DUD's URI
# @param uri [URI] Driver Update URI
def initialize(uri)
Yast.import "Linuxrc"
@uri = uri
@local_path = nil
end

# Fetch the DUD and stores it in the given directory
#
# Retrieves and extract the DUD to the given directory.
# Fetch the DUD and store it in the given directory
#
# @param target [Pathname] Directory to extract the DUD to.
#
# FIXME: should it be called by the constructor?
def fetch(target)
@local_path = target
Dir.mktmpdir do |dir|
Expand All @@ -46,13 +42,8 @@ def fetch(target)
end

# Apply the DUD to the running system
#
# @return [Boolean] true if the DUD was applied; false otherwise.
#
# FIXME: remove the ! sign
# FIXME: handle update.{pre,post} scripts
def apply!
raise "Not fetched yet!" if local_path.nil?
def apply
raise "Driver updated not fetched yet!" if local_path.nil?
adddir
run_update_pre
end
Expand All @@ -74,7 +65,7 @@ def extract(source, target)

# Set up the target directory
#
# Refresh the target directory (re-creates it)
# Refresh the target directory (dir will be re-created).
#
# @param dir [Pathname] Directory to re-create
def setup_target(dir)
Expand All @@ -84,7 +75,9 @@ def setup_target(dir)

# Download the DUD to a file
#
# @return [True] True if download was successful
# If the file is not downloaded, DriverUpdate::NotFound exception is risen.
#
# @return [True] true if download was successful
def download_file_to(path)
cmd = format(FETCH_CMD, uri: uri, output: path)
Yast::SCR.Execute(Yast::Path.new(".target.bash_output"), cmd)
Expand All @@ -100,6 +93,9 @@ def update_dir
path.relative_path_from(Pathname.new("/"))
end

# Add files/directories to the inst-sys
#
# @see APPLY_CMD
def adddir
cmd = format(APPLY_CMD, source: local_path)
out = Yast::SCR.Execute(Yast::Path.new(".target.bash_output"), cmd)
Expand All @@ -117,6 +113,5 @@ def run_update_pre
out = Yast::SCR.Execute(Yast::Path.new(".target.bash_output"), update_pre_path.to_s)
out["exit"].zero?
end

end
end
2 changes: 1 addition & 1 deletion src/lib/installation/updates_manager.rb
Expand Up @@ -57,7 +57,7 @@ def fetch_all

# Applies all updates in the pool
def apply_all
updates.each(&:apply!)
updates.each(&:apply)
end

private
Expand Down
10 changes: 3 additions & 7 deletions test/driver_update_test.rb
Expand Up @@ -3,10 +3,6 @@
require_relative "./test_helper"

require "installation/driver_update"
require "pathname"
require "uri"
require "fileutils"
require "net/http"
require "open-uri"

Yast.import "Linuxrc"
Expand Down Expand Up @@ -52,7 +48,7 @@
end
end

describe "#apply!" do
describe "#apply" do
let(:local_path) { TEMP_DIR.join("000") }

context "when the remote file was fetched" do
Expand All @@ -64,15 +60,15 @@
expect(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash_output"), "/etc/adddir #{local_path}/inst-sys /")
.and_return("exit" => 0)
subject.apply!
subject.apply
end
end

context "when the remote file was not fetched" do
let(:local_path) { nil }

it "raises an exception" do
expect { subject.apply! }.to raise_error(RuntimeError)
expect { subject.apply }.to raise_error(RuntimeError)
end
end
end
Expand Down

0 comments on commit e958cbe

Please sign in to comment.