Skip to content

Commit

Permalink
Check is network is running before trying self-update
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Mar 15, 2016
1 parent d819e20 commit 15470cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/lib/installation/clients/inst_update_installer.rb
Expand Up @@ -34,11 +34,12 @@ class InstUpdateInstaller
Yast.import "Linuxrc"
Yast.import "Popup"
Yast.import "Report"
Yast.import "NetworkService"

def main
textdomain "installation"

return :next if installer_updated? || !self_update_enabled?
return :next unless try_to_update?

log.info("Trying installer update")

Expand Down Expand Up @@ -180,6 +181,23 @@ def apply_update
true
end

# Check whether the update should be performed
#
# The update should be performed when these requeriments are met:
#
# * Installer is not updated yet.
# * Self-update feature is enabled.
# * Network is up.
#
# @return [Boolean] true if the update should be performed; false otherwise.
#
# @see #installer_updated?
# @see #self_update_enabled?
# @see NetworkService.isNetworkRunning
def try_to_update?
!installer_updated? && self_update_enabled? && NetworkService.isNetworkRunning
end

# Check whether the update is allowed to be applied
#
# It should be applied when one of these requirements is met:
Expand Down
8 changes: 8 additions & 0 deletions test/inst_update_installer_test.rb
Expand Up @@ -92,6 +92,14 @@
end
end
end

context "when network is not available" do
it "does not update the installer" do
expect(Yast::NetworkService).to receive(:isNetworkRunning).and_return(false)
expect(subject).to_not receive(:update_installer)
expect(subject.main).to eq(:next)
end
end
end

context "when update is disabled through Linuxrc" do
Expand Down

0 comments on commit 15470cd

Please sign in to comment.