Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/SLE-12-SP4' into merge_sle12
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jul 18, 2018
2 parents 476ae43 + 81bb97f commit 10e73bc
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 6 deletions.
9 changes: 9 additions & 0 deletions package/yast2-packager.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Mon Jul 16 11:19:03 UTC 2018 - lslezak@suse.cz

- Do not display a false "not enough free space" warning popup if
the free space is bigger than 8EiB (2^63) (bsc#991090)
- Do not display the "not enough free space" warning for partitions
where nothing is going to be installed (bsc#926841)
- 4.0.69

-------------------------------------------------------------------
Tue Jun 26 17:19:48 CEST 2018 - schubi@suse.de

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


Name: yast2-packager
Version: 4.0.68
Version: 4.0.69
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
31 changes: 26 additions & 5 deletions src/modules/SlideShowCallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,23 @@ def DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, delet
if !pkgdu.nil?
# check each mount point
Builtins.foreach(pkgdu) do |part, data|
# disk sizes from libzypp, in KiB!
_disk_size, used_now, used_future, read_only = *data
# the size difference, how much the package needs on this partition
required_space = used_future - used_now

# skip read-only partitions, the package cannot be installed anyway
if Ops.get(data, 3, 0) == 1
if read_only == 1
Builtins.y2debug("Skipping read-only partition %1", part)
next
end

# nothing to install on this partition, skip it (bsc#926841)
if required_space <= 0
log.debug("Nothing to install at #{part}, skipping")
next
end

target_dir = File.join(Installation.destdir, part)

# handle missing directories (not existing yet or incorrect metadata),
Expand All @@ -310,13 +321,20 @@ def DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, delet
target_dir,
disk_available
)
if Ops.less_than(disk_available, Ops.get(data, 2, 0))

if disk_available < 0
log.debug("Data overflow, too much free space available, skipping the check")
next
end

# we need to convert the size to KiB to compare it with the libzypp size
if (disk_available / 1024) < required_space
Builtins.y2warning(
"Not enough free space in %1 (%2): available: %3, required: %4",
part,
target_dir,
disk_available,
Ops.get(data, 2, 0)
required_space
)

cont = YesNoAgainWarning(
Expand All @@ -338,7 +356,8 @@ def DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, delet
end
else
# disk usage for each partition is not known
# assume that all files will be installed into the root directory
# assume that all files will be installed into the root directory,
# this is the current free space (in bytes)
disk_available = Pkg.TargetAvailable(Installation.destdir)

Builtins.y2milestone(
Expand All @@ -347,7 +366,9 @@ def DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, delet
disk_available
)

if Ops.less_than(disk_available, pkg_size)
if disk_available < 0
log.debug("Data overflow, too much free space available, skipping the check")
elsif disk_available < pkg_size
Builtins.y2warning(
"Not enough free space in %1: available: %2, required: %3",
Installation.destdir,
Expand Down
114 changes: 114 additions & 0 deletions test/packages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1661,4 +1661,118 @@ def expect_source_urls(mapping)
expect(subject.sourceAccessPackages.sort).to eq(["cifs-mount", "nfs-client"])
end
end

# helper for the #repo_schemes tests to mock the repository configuration
def expect_source_urls(mapping)
expect(Yast::Pkg).to receive(:SourceGetCurrent).with(true).and_return(mapping.keys)

mapping.each do |id, url|
expect(Yast::Pkg).to receive(:SourceURL).with(id).and_return(url)
end
end

describe "#repo_schemes" do
it "returns empty list if no repository is defined" do
expect_source_urls({})
expect(subject.repo_schemes).to eq([])
end

it "returns all used schemes" do
expect_source_urls(
0 => "http://example.com",
1 => "https://example.com",
2 => "ftp://example.com",
3 => "dir:///packages",
4 => "dvd:///"
)
expect(subject.repo_schemes).to eq(["http", "https", "ftp", "dir", "dvd"])
end

it "returns unique list" do
expect_source_urls(
0 => "http://example.com",
1 => "http://example2.com",
7 => "ftp://example.com",
8 => "ftp://example2.com"
)
expect(subject.repo_schemes).to eq(["http", "ftp"])
end

it "returns the scheme of the base URL for ISO scheme" do
expect_source_urls(
# ISO over NFS, see "man zypper"
0 => "iso:/subdir?iso=DVD1.iso&url=nfs://server/dir&mnt=/nfs&filesystem=udf"
)
expect(subject.repo_schemes).to eq(["nfs"])
end

it "converts the scheme names to lower case" do
expect_source_urls(
0 => "HTTP://example.com",
8 => "FTP://example2.com"
)
expect(subject.repo_schemes).to eq(["http", "ftp"])
end

it "ignores invalid URL" do
expect_source_urls(0 => ":")
expect(subject.repo_schemes).to eq([])
end

it "ignores incomplete ISO URL (missing 'url' parameter)" do
expect_source_urls(0 => "iso:/subdir?iso=DVD1.iso&mnt=/nfs&filesystem=udf")
expect(subject.repo_schemes).to eq([])
end

it "ignores incomplete ISO URL (empty 'url' parameter)" do
expect_source_urls(0 => "iso:/subdir?iso=DVD1.iso&url=&mnt=/nfs&filesystem=udf")
expect(subject.repo_schemes).to eq([])
end

it "ignores invalid ISO URL (invalid 'url' parameter)" do
expect_source_urls(
0 => "iso:/subdir?iso=DVD1.iso&url=:&filesystem=udf"
)
expect(subject.repo_schemes).to eq([])
end
end

describe "#sourceAccessPackages" do
it "returns empty list if no repository is defined" do
expect(subject).to receive(:repo_schemes).and_return([])
expect(subject.sourceAccessPackages).to eq([])
end

# these do not need any extra package to access them
it "returns empty list for http(s), ftp, hd, cd, dvd and dir schemes" do
schemes = ["http", "https", "ftp", "hd", "cd", "dvd", "dir"]
expect(subject).to receive(:repo_schemes).and_return(schemes)
expect(subject.sourceAccessPackages).to eq([])
end

it "returns 'nfs-client' for nfs scheme" do
schemes = ["nfs"]
expect(subject).to receive(:repo_schemes).and_return(schemes)
expect(subject.sourceAccessPackages).to eq(["nfs-client"])
end

it "returns 'cifs-mount' for smb scheme" do
schemes = ["smb"]
expect(subject).to receive(:repo_schemes).and_return(schemes)
expect(subject.sourceAccessPackages).to eq(["cifs-mount"])
end

it "returns 'cifs-mount' for cifs scheme" do
schemes = ["cifs"]
expect(subject).to receive(:repo_schemes).and_return(schemes)
expect(subject.sourceAccessPackages).to eq(["cifs-mount"])
end

it "returns 'cifs-mount' and 'nfs-client' for smb and nfs schemes" do
schemes = ["cifs", "nfs"]
expect(subject).to receive(:repo_schemes).and_return(schemes)
# sort the result to make it order independent
expect(subject.sourceAccessPackages.sort).to eq(["cifs-mount", "nfs-client"])
end
end
end
73 changes: 73 additions & 0 deletions test/slide_show_callabacks_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env rspec

require_relative "test_helper"

Yast.import "SlideShowCallbacks"

describe Yast::SlideShowCallbacksClass do
subject { Yast::SlideShowCallbacksClass.new }

describe "#DisplayStartInstall" do
let(:pkg_name) { "libyui-ncurses-pkg-devel" }
let(:pkg_location) { "pkg_location" }
let(:pkg_description) { "pkg_description" }
let(:pkg_size) { 138510 }
let(:deleting) { false }

before do
allow(Yast::PackageSlideShow).to receive(:SlideDisplayStart)
allow(subject).to receive(:HandleInput)
allow(Yast::Installation).to receive(:destdir).and_return("/")
allow(File).to receive(:exist?).and_return(true)
allow(Yast::SlideShow).to receive(:SetUserAbort)

subject.instance_variable_set(:@ask_again, true)
subject.instance_variable_set(:@pkg_inprogress, pkg_name)
end

RSpec.shared_examples "free space check" do
it "does not display the space warning when free space is >8EiB" do
# sizes > 8EiB are returned as negative numbers (data overflow)
expect(Yast::Pkg).to receive(:TargetAvailable).and_return(-42)
expect(subject).to_not receive(:YesNoAgainWarning)

subject.DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, deleting)
end

it "does not display the space warning when free space is enough" do
# 1MiB free space
expect(Yast::Pkg).to receive(:TargetAvailable).and_return(1 << 20)
expect(subject).to_not receive(:YesNoAgainWarning)

subject.DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, deleting)
end

it "displays the space warning when free space is not enough" do
# 64KiB free space
expect(Yast::Pkg).to receive(:TargetAvailable).and_return(1 << 16)
expect(subject).to receive(:YesNoAgainWarning)

subject.DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, deleting)
end
end

context "package data usage is available" do
before do
expect(Yast::Pkg).to receive(:PkgDU).with(pkg_name).and_return(
# required space 230KiB
"/" => [6854656, 4483116, 4483346, 0]
)
end

include_examples "free space check"
end

context "package data usage is not available" do
before do
expect(Yast::Pkg).to receive(:PkgDU).with(pkg_name).and_return(nil)
end

include_examples "free space check"
end
end
end

0 comments on commit 10e73bc

Please sign in to comment.