Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/SLE-15-SP1' into bsc1162545
Browse files Browse the repository at this point in the history
# Conflicts:
#	package/yast2-storage-ng.spec
#	src/lib/y2storage/callbacks/activate.rb
#	src/lib/y2storage/storage_env.rb
#	test/y2storage/callbacks/activate_test.rb
  • Loading branch information
aschnell committed Apr 6, 2020
2 parents 638cc81 + 4a558a7 commit 56972b1
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 10 deletions.
8 changes: 7 additions & 1 deletion package/yast2-storage-ng.changes
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
-------------------------------------------------------------------
Mon Apr 06 09:14:25 CEST 2020 - aschnell@suse.com

- allow to disable LUKS activation (bsc#1162545)
- 4.2.107

-------------------------------------------------------------------
Fri Apr 3 14:18:30 UTC 2020 - Ancor Gonzalez Sosa <ancor@suse.com>

- Partitioner: fixed a crash when some devices are modified both
before and after reprobing the hardware (bsc#1168325).
- 4.1.106
- 4.2.106

-------------------------------------------------------------------
Wed Apr 1 12:27:01 UTC 2020 - Ancor Gonzalez Sosa <ancor@suse.com>
Expand Down
2 changes: 1 addition & 1 deletion package/yast2-storage-ng.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-storage-ng
Version: 4.2.106
Version: 4.2.107
Release: 0
Summary: YaST2 - Storage Configuration
License: GPL-2.0-only OR GPL-3.0-only
Expand Down
5 changes: 4 additions & 1 deletion src/lib/y2storage/callbacks/activate.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) [2017-2019] SUSE LLC
# Copyright (c) [2017-2020] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -22,6 +22,7 @@

require "y2storage/dialogs/callbacks/activate_luks"
require "y2storage/callbacks/libstorage_callback"
require "y2storage/storage_env"

module Y2Storage
module Callbacks
Expand Down Expand Up @@ -69,6 +70,8 @@ def multipath(looks_like_real_multipath)
def luks(info, attempt)
log.info("Trying to open luks UUID: #{info.uuid} (#{attempt} attempts)")

return Storage::PairBoolString.new(false, "") if !StorageEnv.instance.activate_luks?

luks_error(attempt) if attempt > 1

dialog = Dialogs::Callbacks::ActivateLuks.new(info, attempt)
Expand Down
24 changes: 18 additions & 6 deletions src/lib/y2storage/storage_env.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) [2018] SUSE LLC
# Copyright (c) [2018-2020] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -30,7 +30,9 @@ class StorageEnv

ENV_BIOS_RAID = "LIBSTORAGE_MDPART".freeze

private_constant :ENV_MULTIPATH, :ENV_BIOS_RAID
ENV_ACTIVATE_LUKS = "YAST_ACTIVATE_LUKS".freeze

private_constant :ENV_MULTIPATH, :ENV_BIOS_RAID, :ENV_ACTIVATE_LUKS

def initialize
@active_cache = {}
Expand All @@ -57,13 +59,22 @@ def forced_bios_raid?
active?(ENV_BIOS_RAID)
end

# Whether LUKSes could be activated
#
# See bsc#1162545 for why this is needed and was added.
#
def activate_luks?
active?(ENV_ACTIVATE_LUKS, true)
end

private

# Whether the env variable is active
#
# @param variable [String]
# @param fallback [Boolean] Fallback value if env variable is not set
# @return [Boolean]
def active?(variable)
def active?(variable, fallback = false)
return @active_cache[variable] if @active_cache.key?(variable)

value = read(variable)
Expand All @@ -72,7 +83,7 @@ def active?(variable)
# variable is used with no value or with "1"
value.casecmp?("on") || value.empty? || value == "1"
else
false
fallback
end
@active_cache[variable] = result
end
Expand All @@ -88,8 +99,9 @@ def read(variable)
key = ENV.keys.sort.find { |k| k.match(/\A#{variable}\z/i) }
return nil unless key

log.debug "Found ENV variable: #{key.inspect}"
ENV[key]
value = ENV[key]
log.debug "Found ENV variable key: #{key.inspect} value: #{value.inspect}"
value
end
end
end
16 changes: 15 additions & 1 deletion test/y2storage/callbacks/activate_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env rspec

# Copyright (c) [2017-2019] SUSE LLC
# Copyright (c) [2017-2020] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -32,6 +32,8 @@
end

describe "#luks" do
before { mock_env(env_vars) }

let(:dialog) { instance_double(Y2Storage::Dialogs::Callbacks::ActivateLuks) }

before do
Expand All @@ -51,6 +53,7 @@
let(:attempts) { 1 }
let(:action) { nil }
let(:encryption_password) { "123456" }
let(:env_vars) { {} }

it "opens a dialog to request the password" do
expect(dialog).to receive(:run).once
Expand Down Expand Up @@ -96,6 +99,17 @@
subject.luks(info, attempts)
end
end

context "and YAST_ACTIVATE_LUKS was deactivated on boot" do
let(:env_vars) do
{ "YAST_ACTIVATE_LUKS" => "0" }
end

it "does not ask the user" do
expect(dialog).to_not receive(:run)
subject.luks(info, attempts)
end
end
end

describe "#multipath" do
Expand Down
71 changes: 71 additions & 0 deletions test/y2storage/storage_env_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env rspec
# Copyright (c) [2020] 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 LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require_relative "spec_helper"
require "y2storage"
require "y2storage/storage_env"

describe Y2Storage::StorageEnv do
before do
mock_env(env_vars)
end

describe "#activate_luks?" do
context "YAST_ACTIVATE_LUKS is not set" do
let(:env_vars) do
{}
end

it "returns true" do
expect(Y2Storage::StorageEnv.instance.activate_luks?).to be true
end
end

context "YAST_ACTIVATE_LUKS is empty" do
let(:env_vars) do
{ "YAST_ACTIVATE_LUKS" => "" }
end

it "returns true" do
expect(Y2Storage::StorageEnv.instance.activate_luks?).to be true
end
end

context "YAST_ACTIVATE_LUKS is set to '1'" do
let(:env_vars) do
{ "YAST_ACTIVATE_LUKS" => "1" }
end

it "returns true" do
expect(Y2Storage::StorageEnv.instance.activate_luks?).to be true
end
end

context "YAST_ACTIVATE_LUKS is set to '0'" do
let(:env_vars) do
{ "YAST_ACTIVATE_LUKS" => "0" }
end

it "returns false" do
expect(Y2Storage::StorageEnv.instance.activate_luks?).to be false
end
end
end
end

0 comments on commit 56972b1

Please sign in to comment.