diff --git a/package/yast2-country.changes b/package/yast2-country.changes index 7690ce73..cbb0ca36 100644 --- a/package/yast2-country.changes +++ b/package/yast2-country.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Tue Aug 3 16:38:40 UTC 2021 - José Iván López González + +- AutoYaST: allow empty /profile/timezone/timezone setting, + meaning to keep the UTC default (bsc#1188406). +- 4.2.22 + ------------------------------------------------------------------- Tue Jun 15 09:17:24 UTC 2021 - Imobach Gonzalez Sosa @@ -3448,4 +3455,3 @@ Fri Jun 28 14:38:44 CEST 2002 - fehr@suse.de Mon Jun 24 10:38:11 CEST 2002 - kkaempf@suse.de - Initial version, merge console, keyboard, language, and timezone. - diff --git a/package/yast2-country.spec b/package/yast2-country.spec index 1f8a8c93..b1cb865f 100644 --- a/package/yast2-country.spec +++ b/package/yast2-country.spec @@ -17,7 +17,7 @@ Name: yast2-country -Version: 4.2.21 +Version: 4.2.22 Release: 0 Summary: YaST2 - Country Settings (Language, Keyboard, and Timezone) License: GPL-2.0-only diff --git a/timezone/src/modules/Timezone.rb b/timezone/src/modules/Timezone.rb index 25ebde68..4c151475 100644 --- a/timezone/src/modules/Timezone.rb +++ b/timezone/src/modules/Timezone.rb @@ -837,27 +837,7 @@ def Save return end - cmd = if Stage.initial - # do use --root option, running in chroot does not work - "/usr/bin/systemd-firstboot --root '#{Installation.destdir}' --timezone '#{@timezone}'" - else - # this sets both the locale (see "man localectl") - "/usr/bin/timedatectl set-timezone #{@timezone}" - end - log.info "Making timezone setting persistent: #{cmd}" - result = if Stage.initial - WFM.Execute(path(".local.bash_output"), cmd) - else - SCR.Execute(path(".target.bash_output"), cmd) - end - if result["exit"] != 0 - log.error "Timezone configuration not written. Failed to execute '#{cmd}'" - log.error "output: #{result.inspect}" - # TRANSLATORS: the "%s" is replaced by the executed command - Report.Error(_("Could not save the timezone setting, the command\n%s\nfailed.") % cmd) - else - log.info "output: #{result.inspect}" - end + write_timezone SCR.Write(path(".sysconfig.clock.DEFAULT_TIMEZONE"), @default_timezone) @@ -1125,6 +1105,40 @@ def windows_architecture? def disk_analyzer Y2Storage::StorageManager.instance.probed_disk_analyzer end + + # Writes the timezone configuration + def write_timezone + if @timezone.nil? || @timezone.strip.empty? + log.warn("Timezone configuration not written. No value was given.") + return + end + + cmd = if Stage.initial + # do use --root option, running in chroot does not work + "/usr/bin/systemd-firstboot --root '#{Installation.destdir}' --timezone '#{@timezone}'" + else + # this sets both the locale (see "man localectl") + "/usr/bin/timedatectl set-timezone #{@timezone}" + end + + log.info "Making timezone setting persistent: #{cmd}" + + result = if Stage.initial + WFM.Execute(path(".local.bash_output"), cmd) + else + SCR.Execute(path(".target.bash_output"), cmd) + end + + if result["exit"] != 0 + log.error "Timezone configuration not written. Failed to execute '#{cmd}'" + log.error "output: #{result.inspect}" + + # TRANSLATORS: the "%s" is replaced by the executed command + Report.Error(_("Could not save the timezone setting, the command\n%s\nfailed.") % cmd) + else + log.info "output: #{result.inspect}" + end + end end Timezone = TimezoneClass.new diff --git a/timezone/test/Timezone_test.rb b/timezone/test/Timezone_test.rb index d6698475..5008b24b 100755 --- a/timezone/test/Timezone_test.rb +++ b/timezone/test/Timezone_test.rb @@ -541,4 +541,75 @@ expect(subject.UpdateTimezone("US/Pacific")).to eq "America/Los_Angeles" end end + + describe "#Save" do + before do + allow(Yast::SCR).to receive(:Write) + + allow(Yast::Mode).to receive(:mode).and_return(mode) + end + + context "when the system is being updated" do + let(:mode) { "update" } + + it "does not write the timezone" do + expect(Yast::WFM).to_not receive(:Execute) + expect(Yast::SCR).to_not receive(:Execute) + + subject.Save + end + end + + context "when the system is not being updated" do + let(:mode) { "autoinstallation" } + + before do + allow(Yast::SCR).to receive(:Write) + + allow(subject).to receive(:ReadAdjTime).and_return(nil) + + allow(subject).to receive(:CallMkinitrd) + + subject.Import(settings) + end + + + context "and no timezone value is given" do + let(:settings) { { "hwclock" => "UTC", "timezone" => "" } } + + it "does not write the timezone" do + expect(Yast::WFM).to_not receive(:Execute) + expect(Yast::SCR).to_not receive(:Execute) + + subject.Save + end + end + + context "and a timezone value is given" do + let(:settings) { {"hwclock" => "UTC", "timezone" => "US/Pacific"} } + + context "and it is running in the initial stage" do + let(:initial) { true } + + it "uses systemd-firstboot command to set the timezone" do + expect(Yast::WFM).to receive(:Execute).with(anything, /systemd-firstboot/) + .and_return("exit" => 0) + + subject.Save + end + end + + context "and it is not running in the initial stage" do + let(:initial) { false } + + it "uses timedatectl command to set the timezone" do + expect(Yast::SCR).to receive(:Execute).with(anything, /timedatectl/) + .and_return("exit" => 0) + + subject.Save + end + end + end + end + end end