Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Review] Request from 'schubi2' @ 'yast/yast-packager/review_170928_disable_remote_installation' #287

Merged
merged 11 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package/yast2-packager.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Sep 28 16:32:30 CEST 2017 - schubi@suse.de

- Disable vpn, ssh,... and inform the user if the needed packages
are not available. (bnc#1055279, bnc#1058071)
- 4.0.9

-------------------------------------------------------------------
Mon Sep 25 14:10:51 UTC 2017 - igonzalezsosa@suse.com

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.8
Version: 4.0.9
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
3 changes: 3 additions & 0 deletions src/clients/inst_kickoff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def main
Mtab.clone_to_target
end

# Disabling VPN, SSH,.... if the packages are not available
Linuxrc.disable_remote(Packages.missing_remote_kind)

# Feature #301903, bugzilla #244937
if Mode.update
# "/" means updating the running system, bugzilla #246389
Expand Down
12 changes: 12 additions & 0 deletions src/lib/packager/clients/software_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ def make_proposal(flags)
"warning_level" => :blocker
)
end
remote_installation_error = Packages.check_remote_installation_packages
unless remote_installation_error.empty?
# The Default warning_level is "error". So the user can continue
# installation.
if @ret["warning"]
@ret["warning"] << "\n"
@ret["warning"] << remote_installation_error
else
@ret["warning"] = remote_installation_error
end
end

@ret
end

Expand Down
116 changes: 102 additions & 14 deletions src/modules/Packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class PackagesClass < Module
include Yast::Logger
include ERB::Util

attr_reader :missing_remote_packages, :missing_remote_kind

# All known types of resolvables
RESOLVABLE_TYPES = [:product, :patch, :package, :pattern, :language].freeze

Expand Down Expand Up @@ -151,6 +153,13 @@ def main
@base_source_id = nil

@old_packages_proposal = nil

# Remote kinds (vnc, ssh,...) which cannot be used in an
# installed system.
@missing_remote_kind = []
# Packages which are missed to enable remote handling in
# an installed system.
@missing_remote_packages = []
end

# summary functions
Expand Down Expand Up @@ -851,6 +860,59 @@ def InitializeAddOnProducts
nil
end

# Checking if all needed packages for remote installation
# will be installed on the target system.
# @return [String] empty string or error message if there are missing packages
def check_remote_installation_packages
@missing_remote_kind = []
@missing_remote_packages = []

if Linuxrc.braille
missing = braille_packages.reject { |tag| pkg_will_be_installed(tag) }
unless missing.empty?
@missing_remote_packages << missing
@missing_remote_kind << "BRAILLE"
end
end
if Linuxrc.usessh
missing = ssh_packages.reject { |tag| pkg_will_be_installed(tag) }
unless missing.empty?
@missing_remote_packages << missing
@missing_remote_kind << "SSH"
end
end
if Linuxrc.vnc
missing = vnc_packages.reject { |tag| pkg_will_be_installed(tag) }
unless missing.empty?
@missing_remote_packages << missing
@missing_remote_kind << "VNC"
end
end
if Linuxrc.display_ip
missing = remote_x11_packages.reject { |tag| pkg_will_be_installed(tag) }
unless missing.empty?
@missing_remote_packages << missing
@missing_remote_kind << "DISPLAY_IP"
end
end

missing_remote_packages.flatten!
unless missing_remote_packages.empty?
error_string = format(_("Cannot support %s remote access in the installed system" \
" due missing packages \n%s. \nIt will be disabled."),
@missing_remote_kind.join(", "), @missing_remote_packages.join(", "))
if Mode.auto
error_string << " \n"
error_string << _("But the AutoYaST installation will be still finished automatically " \
"without any user interaction.")
end
log.warn("Cannot support #{@missing_remote_kind} remote access in the " \
"installed system due missing packages #{@missing_remote_packages}")
return error_string
end
""
end

#-----------------------------------------------------------------------
# LOCALE FUNCTIONS
#-----------------------------------------------------------------------
Expand Down Expand Up @@ -930,20 +992,13 @@ def architecturePackages
# Compute special packages
# @return [Array](string)
def modePackages
tags = []
tags << "sbl" if Linuxrc.braille
# ssh installation
if Linuxrc.usessh
# "ip" tool is needed by the YaST2.ssh start script (bnc#920175)
tags.concat(["openssh", "iproute2"])
end

packages = find_providers(tags)
packages.concat(vnc_packages) if Linuxrc.vnc
# this means we have a remote X server
packages.concat(remote_x11_packages) if Linuxrc.display_ip

Builtins.y2milestone("Installation mode packages: %1", packages)
packages = []
packages << braille_packages if Linuxrc.braille
packages << ssh_packages if Linuxrc.usessh
packages << vnc_packages if Linuxrc.vnc
packages << remote_x11_packages if Linuxrc.display_ip
packages.flatten!
log.info("Installation mode packages: #{packages}")
packages
end

Expand Down Expand Up @@ -2373,6 +2428,25 @@ def log_software_selection
nil
end

# List of packages expected to be installed in order to enable
# ssh.
#
# @return [Array<String>] package list
def ssh_packages
# "ip" tool is needed by the YaST2.ssh start script (bnc#920175)
tags = ["openssh", "iproute2"]
find_providers(tags)
end

# List of packages expected to be installed in order to enable
# braille
#
# @return [Array<String>] package list
def braille_packages
tags = ["sbl"]
find_providers(tags)
end

# List of packages expected to be installed in order to enable
# remote administration (VNC)
#
Expand Down Expand Up @@ -2439,6 +2513,7 @@ def remote_x11_packages
publish function: :vnc_packages, type: "list <string> ()"
publish function: :remote_x11_packages, type: "list <string> ()"
publish variable: :init_called, type: "boolean"
publish function: :check_remote_installation_packages, type: "void (string)"

private

Expand Down Expand Up @@ -2688,6 +2763,19 @@ def create_baseproduct_symlink
log.info("Creating #{BASE_PRODUCT_FILE} symlink pointing to #{product_file}")
::FileUtils.ln_s(product_file, BASE_PRODUCT_FILE)
end

# Checking if a package will be installed or is already installed
# on a system and will not be deleted.
# @param [String] package name
# @return [Boolean] true if the package will be on the installed system
def pkg_will_be_installed(tag)
provides = Pkg.PkgQueryProvides(tag)
# e.g.: [["kernel-bigsmp", :CAND, :NONE], ["kernel-default", :CAND, :CAND],
# ["kernel-default", `BOTH, :INST]]
ret = provides.any? { |p| p[2] != :NONE }
log.info("#{tag} will #{ret ? "" : "not "}be installed")
ret
end
end

Packages = PackagesClass.new
Expand Down
162 changes: 162 additions & 0 deletions test/packages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,168 @@ def product(properties = {})
end
end

describe "#check_remote_installation_packages" do
before do
allow(Yast::Linuxrc).to receive(:vnc).and_return vnc
allow(Yast::Linuxrc).to receive(:display_ip).and_return display_ip
allow(Yast::Linuxrc).to receive(:braille).and_return braille
allow(Yast::Linuxrc).to receive(:usessh).and_return usessh
allow(Yast::Packages).to receive(:vnc_packages).and_return(vnc_packages)
allow(Yast::Packages).to receive(:remote_x11_packages).and_return(remote_x11_packages)
allow(Yast::Packages).to receive(:ssh_packages).and_return(ssh_packages)
allow(Yast::Packages).to receive(:braille_packages).and_return(braille_packages)
end

let(:vnc_packages) { %w(some-vnc-packages) }
let(:remote_x11_packages) { %w(some-x11-packages) }
let(:ssh_packages) { %w(openssh iproute2) }
let(:braille_packages) { %w(sbl) }

context "on a boring local regular installation" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do a lot of boring installations during testing... 😝

let(:vnc) { false }
let(:display_ip) { false }
let(:braille) { false }
let(:usessh) { false }

it "reports no error" do
expect(Yast::Packages.check_remote_installation_packages).to be_empty
expect(Yast::Packages.missing_remote_packages).to be_empty
expect(Yast::Packages.missing_remote_kind).to be_empty
end
end

context "on a installation with braille enabled" do
let(:vnc) { false }
let(:display_ip) { false }
let(:braille) { true }
let(:usessh) { false }

context "needed packages are available" do
before do
braille_packages.each do |pkg|
allow(Yast::Pkg).to receive(:PkgQueryProvides).with(pkg)
.and_return([[pkg, :CAND, :CAND]])
end
end

it "reports no error" do
expect(Yast::Packages.check_remote_installation_packages).to be_empty
expect(Yast::Packages.missing_remote_packages).to be_empty
expect(Yast::Packages.missing_remote_kind).to be_empty
end
end

context "needed packages are not available" do
before do
braille_packages.each do |pkg|
allow(Yast::Pkg).to receive(:PkgQueryProvides).with(pkg)
.and_return([[pkg, :CAND, :NONE]])
end
end

it "reports error" do
expect(Yast::Packages.check_remote_installation_packages).to_not be_empty
expect(Yast::Packages.missing_remote_packages).to eq(braille_packages)
expect(Yast::Packages.missing_remote_kind).to eq(["BRAILLE"])
end
end
end

context "over ssh with a remote X server" do
let(:vnc) { false }
let(:display_ip) { true }
let(:braille) { false }
let(:usessh) { true }

context "needed packages are available" do
before do
(remote_x11_packages + ssh_packages).each do |pkg|
allow(Yast::Pkg).to receive(:PkgQueryProvides).with(pkg)
.and_return([[pkg, :CAND, :CAND]])
end
end

it "reports no error" do
expect(Yast::Packages.check_remote_installation_packages).to be_empty
expect(Yast::Packages.missing_remote_packages).to be_empty
expect(Yast::Packages.missing_remote_kind).to be_empty
end
end

context "only ssh packages are available" do
before do
ssh_packages.each do |pkg|
allow(Yast::Pkg).to receive(:PkgQueryProvides).with(pkg)
.and_return([[pkg, :CAND, :NONE]])
end
remote_x11_packages.each do |pkg|
allow(Yast::Pkg).to receive(:PkgQueryProvides).with(pkg)
.and_return([[pkg, :CAND, :CAND]])
end
end

it "reports error for X11 packages" do
expect(Yast::Packages.check_remote_installation_packages).to_not be_empty
expect(Yast::Packages.missing_remote_packages).to eq(ssh_packages)
expect(Yast::Packages.missing_remote_kind).to eq(["SSH"])
end
end

context "no package is available" do
before do
(remote_x11_packages + ssh_packages).each do |pkg|
allow(Yast::Pkg).to receive(:PkgQueryProvides).with(pkg)
.and_return([[pkg, :CAND, :NONE]])
end
end

it "reports error for X11 and ssh packages" do
expect(Yast::Packages.check_remote_installation_packages).to_not be_empty
expect(Yast::Packages.missing_remote_packages.sort)
.to eq((ssh_packages + remote_x11_packages).sort)
expect(Yast::Packages.missing_remote_kind).to eq(["SSH", "DISPLAY_IP"])
end
end
end

context "on vnc installation" do
let(:vnc) { true }
let(:display_ip) { false }
let(:braille) { false }
let(:usessh) { false }

context "needed packages are available" do
before do
vnc_packages.each do |pkg|
allow(Yast::Pkg).to receive(:PkgQueryProvides).with(pkg)
.and_return([[pkg, :CAND, :CAND]])
end
end

it "reports no error" do
expect(Yast::Packages.check_remote_installation_packages).to be_empty
expect(Yast::Packages.missing_remote_packages).to be_empty
expect(Yast::Packages.missing_remote_kind).to be_empty
end
end

context "needed packages are not available" do
before do
vnc_packages.each do |pkg|
allow(Yast::Pkg).to receive(:PkgQueryProvides).with(pkg)
.and_return([[pkg, :CAND, :NONE]])
end
end

it "reports error" do
expect(Yast::Packages.check_remote_installation_packages).to_not be_empty
expect(Yast::Packages.missing_remote_packages).to eq(vnc_packages)
expect(Yast::Packages.missing_remote_kind).to eq(["VNC"])
end
end
end
end

describe "#Reset" do
# Reset all package changes done by YaST then re-select only the products
# which previously were selected. (see bsc#963036).
Expand Down