Skip to content

Commit

Permalink
- install into btrfs subvolume (fate#318392)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Feb 16, 2015
1 parent 04daba9 commit 841538f
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 91 deletions.
6 changes: 6 additions & 0 deletions package/yast2-storage.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon Feb 16 11:38:11 CET 2015 - aschnell@suse.de

- install into btrfs subvolume (fate#318392)
- version 3.1.53

-------------------------------------------------------------------
Fri Feb 13 10:46:05 CET 2015 - aschnell@suse.de

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


Name: yast2-storage
Version: 3.1.52
Version: 3.1.53
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module_DATA = \
modules/Partitions.rb \
modules/Region.rb \
modules/StorageClients.rb \
modules/StorageUtils.rb
modules/StorageSnapper.rb

client_DATA = \
clients/inst_disk_proposal.rb \
Expand Down
6 changes: 3 additions & 3 deletions src/clients/storage_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main
Yast.import "Storage"
Yast.import "StorageSettings"
Yast.import "StorageUpdate"
Yast.import "StorageUtils"
Yast.import "StorageSnapper"
Yast.import "Mode"
Yast.import "Installation"

Expand Down Expand Up @@ -91,8 +91,8 @@ def main
Storage.SaveUsedFs
StorageSettings.Save

if Mode.installation
StorageUtils.ConfigureSnapper()
if Mode.installation && StorageSnapper.ConfigureSnapper?
StorageSnapper.ConfigureSnapperStep4()
end

else
Expand Down
35 changes: 34 additions & 1 deletion src/modules/Storage.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding: utf-8

# Copyright (c) [2012-2014] Novell, Inc.
# Copyright (c) [2012-2015] Novell, Inc.
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -52,6 +52,7 @@ def main
Yast.import "StorageInit"
Yast.import "StorageDevices"
Yast.import "StorageClients"
Yast.import "StorageSnapper"
Yast.import "Stage"
Yast.import "String"
Yast.import "Hotplug"
Expand Down Expand Up @@ -367,6 +368,11 @@ def FinishLibstorage
end


def DefaultSubvolumeName()
return @sint.getDefaultSubvolName()
end


def ClassicStringToByte(str)
ret, bytes = ::Storage::humanStringToByte(str,true)
if( !ret )
Expand Down Expand Up @@ -4841,11 +4847,38 @@ def ReReadTargetMap
end


class MyCommitCallbacks < ::Storage::CommitCallbacks

def initialize()
super()
end

def post_root_filesystem_create()
StorageSnapper::ConfigureSnapperStep1()
end

def post_root_mount()
StorageSnapper::ConfigureSnapperStep2()
end

def post_root_fstab_add()
StorageSnapper::ConfigureSnapperStep3()
end

end


# Apply storage changes
#
# @return [Fixnum]
def CommitChanges
Builtins.y2milestone("CommitChanges")

if Mode.installation && StorageSnapper.ConfigureSnapper?
my_commit_callbacks = MyCommitCallbacks.new()
@sint.setCommitCallbacks(my_commit_callbacks)
end

ret = @sint.commit()
if ret<0
Builtins.y2error("CommitChanges sint ret:%1", ret)
Expand Down
150 changes: 150 additions & 0 deletions src/modules/StorageSnapper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# encoding: utf-8

# Copyright (c) [2012-2015] Novell, Inc.
#
# 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 Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may
# find current contact information at www.novell.com.


require "yast"


module Yast

class StorageSnapperClass < Module


include Yast::Logger


def main

textdomain "storage"

Yast.import "String"
Yast.import "Installation"
Yast.import "InstExtensionImage"
Yast.import "Storage"

end


def BashLogOutput(command)
tmp = SCR.Execute(path(".target.bash_output"), command)

log.info("exit: #{tmp.fetch("exit")}")
tmp.fetch("stdout").each_line { |line| log.info("stdout #{line}") }
tmp.fetch("stderr").each_line { |line| log.info("stderr #{line}") }

return tmp.fetch("exit")
end


def ConfigureSnapper?()

part = Storage.GetEntryForMountpoint("/")

if part.fetch("used_fs", :unknown) != :btrfs
return false
end

userdata = part.fetch("userdata", {})
if userdata.fetch("/", "") != "snapshots"
return false
end

return true

end


def ConfigureSnapperStep1()

log.info("configuring snapper for root fs - step 1")

if ENV["YAST2_STORAGE_SNAPPER_EXTEND"] != "no"
# TRANSLATORS: message in progress bar
InstExtensionImage.LoadExtension("snapper", _("Retrieving %s extension...") % "snapper")
end

part = Storage.GetEntryForMountpoint("/")

if BashLogOutput("/usr/lib/snapper/installation-helper --step 1 " <<
"--device '#{String.Quote(part["device"])}'") != 0
log.error("configuring snapper for root fs failed")
end

end


def ConfigureSnapperStep2()

log.info("configuring snapper for root fs - step 2")

part = Storage.GetEntryForMountpoint("/")

if BashLogOutput("/usr/lib/snapper/installation-helper --step 2 " <<
"--device '#{String.Quote(part["device"])}' " <<
"--root-prefix '#{String.Quote(Installation.destdir)}' " <<
"--default-subvolume-name '#{String.Quote(Storage.DefaultSubvolumeName())}'") != 0
log.error("configuring snapper for root fs failed")
end

end


def ConfigureSnapperStep3()

log.info("configuring snapper for root fs - step 3")

if BashLogOutput("/usr/lib/snapper/installation-helper --step 3 " <<
"--root-prefix '#{String.Quote(Installation.destdir)}' " <<
"--default-subvolume-name '#{String.Quote(Storage.DefaultSubvolumeName())}'") != 0
log.error("configuring snapper for root fs failed")
end

if ENV["YAST2_STORAGE_SNAPPER_EXTEND"] != "no"
# TRANSLATORS: message in progress bar
InstExtensionImage.UnLoadExtension("snapper", _("Releasing %s extension...") % "snapper")
end

end


def ConfigureSnapperStep4()

log.info("configuring snapper for root fs - step 4")

if BashLogOutput("/usr/lib/snapper/installation-helper --step 4") != 0
log.error("configuring snapper for root fs failed")
end

BashLogOutput("/usr/bin/snapper --no-dbus set-config " <<
"NUMBER_CLEANUP=yes NUMBER_LIMIT=10 NUMBER_LIMIT_IMPORTANT=10 " <<
"TIMELINE_CREATE=no")

SCR.Write(path(".sysconfig.yast2.USE_SNAPPER"), "yes")
SCR.Write(path(".sysconfig.yast2"), nil)

end

end

StorageSnapper = StorageSnapperClass.new
StorageSnapper.main

end
68 changes: 0 additions & 68 deletions src/modules/StorageUtils.rb

This file was deleted.

2 changes: 1 addition & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

TESTS = \
storage_utils_configure_snapper_test.rb \
storage_snapper_configure_snapper_test.rb \
storage_get_disk_partition.rb

TEST_EXTENSIONS = .rb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

require "yast"

Yast.import "StorageUtils"
Yast.import "StorageSnapper"
Yast.import "Storage"


describe "StorageUtils#ConfigureSnapper" do
describe "StorageSnapper#ConfigureSnapper?" do


it "configures snapper" do
Expand All @@ -22,13 +22,7 @@

Yast::Storage.stub(:GetEntryForMountpoint).with("/").once.and_return(data)

Yast::SCR.stub(:Execute).and_return(1)
Yast::SCR.should_receive(:Execute).exactly(2).times.and_return(0)

Yast::SCR.stub(:Write).and_return(1)
Yast::SCR.should_receive(:Write).exactly(2).times.and_return(0)

Yast::StorageUtils.ConfigureSnapper()
expect(Yast::StorageSnapper.ConfigureSnapper?).to be_true

end

Expand All @@ -43,13 +37,7 @@

Yast::Storage.stub(:GetEntryForMountpoint).with("/").once.and_return(data)

Yast::SCR.stub(:Execute).and_return(1)
Yast::SCR.should_receive(:Execute).exactly(0).times

Yast::SCR.stub(:Write).and_return(1)
Yast::SCR.should_receive(:Write).exactly(0).times

Yast::StorageUtils.ConfigureSnapper()
expect(Yast::StorageSnapper.ConfigureSnapper?).to be_false

end

Expand Down

0 comments on commit 841538f

Please sign in to comment.