Skip to content

Commit

Permalink
Fix ProductFeatures#InitIfNeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Mar 12, 2019
1 parent 2c99f30 commit 14d10d3
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/control/src/modules/ProductFeatures.rb
Expand Up @@ -168,7 +168,8 @@ def Save
# Restore product features in running system
# @note This is a stable API function
def Restore
InitFeatures(true)
InitFeatures(false)

groups = SCR.Dir(path(".product.features.section"))
Builtins.foreach(groups) do |group|
Ops.set(@features, group, Ops.get(@features, group, {}))
Expand All @@ -191,7 +192,6 @@ def Restore
# @note This is a stable API function
# Either read from /etc/YaST2/ProductFeatures or set default values
def InitIfNeeded
return if !@features.nil?
if Stage.normal || Stage.firstboot
Restore()
else
Expand Down
92 changes: 92 additions & 0 deletions library/control/test/ProductFeatures_test.rb
Expand Up @@ -158,4 +158,96 @@
end
end
end

describe "#GetFeature" do
let(:scr_root_dir) { File.join(File.dirname(__FILE__), "data") }
let(:normal_stage) { false }
let(:firstboot_stage) { false }

before do
allow(Yast::Stage).to receive(:normal).and_return(normal_stage)
allow(Yast::Stage).to receive(:firstboot).and_return(firstboot_stage)
end

around do |example|
change_scr_root(scr_root_dir, &example)
end

context "when features are not initialized yet" do
it "initializes them" do
expect(subject.GetFeature("globals", "base_product_license_directory")).to_not be_nil
end
end

context "when features are already initialized" do
before do
subject.InitFeatures(true)
end

it "does not force to initialize them again" do
expect(subject).to receive(:InitFeatures).with(false)

subject.GetFeature("globals", "base_product_license_directory")
end


context "but it is in normal stage" do
let(:normal_stage) { true }

it "reads the value from the running system" do
# value readed from data/etc/YaST2/ProductFeatures file
expect(subject.GetFeature("globals", "base_product_license_directory"))
.to eq("/usr/share/licenses/product/base")
end
end

context "but it is in firstboot stage" do
let(:firstboot_stage) { true }

it "reads the value from the running system" do
# value readed from data/etc/YaST2/ProductFeatures file
expect(subject.GetFeature("globals", "base_product_license_directory"))
.to eq("/usr/share/licenses/product/base")
end
end
end
end

describe "#InitIfNeeded" do
let(:normal_stage) { false }
let(:firstboot_stage) { false }

before do
allow(Yast::Stage).to receive(:normal).and_return(normal_stage)
allow(Yast::Stage).to receive(:firstboot).and_return(firstboot_stage)
end

context "when features are not initialized yet" do
it "initializes the features" do
expect(subject).to receive(:InitFeatures).with(false)

subject.InitIfNeeded
end

context "and it is being executed in normal stage" do
let(:normal_stage) { true }

it "restores the available values in the running system" do
expect(subject).to receive(:Restore)

subject.InitIfNeeded
end
end

context "and it is being executed in firstboot stage" do
let(:firstboot_stage) { true }

it "restores the available values in the running system" do
expect(subject).to receive(:Restore)

subject.InitIfNeeded
end
end
end
end
end
59 changes: 59 additions & 0 deletions library/control/test/data/etc/YaST2/ProductFeatures
@@ -0,0 +1,59 @@
[globals]
additional_kernel_parameters = ""
addons_default = "no"
base_product_license_directory = "/usr/share/licenses/product/base"
debug_deploying = "no"
default_ntp_setup = "yes"
default_target = ""
disable_os_prober = "no"
disable_register_w3m = "yes"
display_register_forcereg = "yes"
enable_autologin = "yes"
enable_clone = "no"
enable_firewall = "yes"
enable_kdump = "yes"
enable_register_hwdata = "yes"
enable_register_optional = "yes"
enable_sshd = "no"
fam_local_only = "never"
firewall_enable_ssh = "no"
incomplete_translation_treshold = "95"
inform_about_suboptimal_distribution = "yes"
kexec_reboot = "yes"
keyboard = ""
language = ""
manual_online_update = "yes"
online_repositories_default = "yes"
register_monthly = "no"
relnotesurl = ""
rle_offer_rulevel_4 = "no"
root_password_as_first_user = "yes"
root_password_ca_check = "no"
run_init_scripts_in_parallel = "yes"
run_you = "yes"
show_addons = "yes"
show_drivers_info = "no"
show_online_repositories = "yes"
skip_language_dialog = "yes"
timezone = ""
ui_mode = "simple"
vendor_url = ""
write_hostname_to_hosts = "no"
[network]
force_static_ip = "no"
network_manager = "laptop"
startmode = "ifplugd"
[partitioning]
expert_partitioner_warning = "no"
use_flexible_partitioning = "no"
vm_keep_unpartitioned_region = "no"
[software]
base_selection = ""
default_desktop = "gnome"
delete_old_packages = "yes"
external_sources_link = "https://download.opensuse.org/YaST/Repos/openSUSE_Factory_Servers.xml"
inform_about_suboptimal_distribution = "no"
online_repos_preselected = "no"
only_update_installed = "no"
packages_transmogrify = ""
software_proposal = "selection"

0 comments on commit 14d10d3

Please sign in to comment.