Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restart YaST after upgrading the packages (bnc#942080)
to avoid using the old (removed) files
- Loading branch information
Showing
6 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
require "yast" | ||
|
||
require "singleton" | ||
|
||
module Migration | ||
# this class handles restarting the YaST module during online migration | ||
class Restarter | ||
include Singleton | ||
|
||
Yast.import "Installation" | ||
Yast.import "Directory" | ||
|
||
RESTART_FILE = Yast::Installation.restart_file | ||
# the generic restart file is removed by the yast script before starting | ||
# YaST again, we need an extra file to distinguish restart and full start | ||
MIGRATION_RESTART = Yast::Directory.vardir + "/migration_restarted" | ||
|
||
attr_reader :restarted | ||
|
||
# read the restart flag and remove it immediately to avoid | ||
# possible restart loop | ||
def initialize | ||
@restarted = File.exist?(MIGRATION_RESTART) | ||
|
||
clear_restart | ||
end | ||
|
||
# set the restart flag | ||
def restart_yast | ||
File.write(RESTART_FILE, "") | ||
File.write(MIGRATION_RESTART, "") | ||
end | ||
|
||
# clear the set restart flags | ||
def clear_restart | ||
File.unlink(RESTART_FILE) if File.exist?(RESTART_FILE) | ||
File.unlink(MIGRATION_RESTART) if File.exist?(MIGRATION_RESTART) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,5 @@ | |
expect(subject.run).to eq(:next) | ||
expect(subject.reboot).to eq(false) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# ------------------------------------------------------------------------------ | ||
# 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_relative "test_helper" | ||
|
||
require "migration/restarter" | ||
|
||
describe Migration::Restarter do | ||
# create a new anonymous instance for each test to avoid test dependencies | ||
# see http://stackoverflow.com/a/26172556/633234 | ||
subject { Class.new(Migration::Restarter).instance } | ||
|
||
describe "#restarted" do | ||
before do | ||
allow(File).to receive(:exist?).with(Migration::Restarter::RESTART_FILE) | ||
.and_return(false) | ||
end | ||
|
||
context "restart flag set" do | ||
before do | ||
expect(File).to receive(:exist?).with(Migration::Restarter::MIGRATION_RESTART) | ||
.twice.and_return(true) | ||
end | ||
|
||
it "removes the restart flag and returns true" do | ||
expect(File).to receive(:unlink).with(Migration::Restarter::MIGRATION_RESTART) | ||
expect(subject.restarted).to eq(true) | ||
end | ||
end | ||
|
||
context "restart flag not set" do | ||
before do | ||
expect(File).to receive(:exist?).with(Migration::Restarter::MIGRATION_RESTART) | ||
.twice.and_return(false) | ||
end | ||
|
||
it "returns false" do | ||
expect(File).to_not receive(:unlink).with(Migration::Restarter::MIGRATION_RESTART) | ||
expect(subject.restarted).to eq(false) | ||
end | ||
end | ||
end | ||
|
||
describe "#restart_yast" do | ||
before do | ||
allow(File).to receive(:exist?).with(Migration::Restarter::MIGRATION_RESTART) | ||
.and_return(false) | ||
allow(File).to receive(:exist?).with(Migration::Restarter::RESTART_FILE) | ||
.and_return(false) | ||
end | ||
|
||
it "set the restart flags" do | ||
expect(File).to receive(:write).with(Migration::Restarter::RESTART_FILE, "") | ||
expect(File).to receive(:write).with(Migration::Restarter::MIGRATION_RESTART, "") | ||
|
||
subject.restart_yast | ||
end | ||
end | ||
end |