Skip to content

Commit

Permalink
Merge pull request #276 from joseivanlopez/no-timezone
Browse files Browse the repository at this point in the history
Do not write empty timezone
  • Loading branch information
joseivanlopez committed Aug 4, 2021
2 parents 204bc3e + 2643a70 commit 17c3b82
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 23 deletions.
8 changes: 7 additions & 1 deletion package/yast2-country.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Aug 3 16:38:40 UTC 2021 - José Iván López González <jlopez@suse.com>

- 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 <igonzalezsosa@suse.com>

Expand Down Expand Up @@ -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.

2 changes: 1 addition & 1 deletion package/yast2-country.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 35 additions & 21 deletions timezone/src/modules/Timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
71 changes: 71 additions & 0 deletions timezone/test/Timezone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 17c3b82

Please sign in to comment.