Skip to content

Commit bb3a603

Browse files
committed
feat(ruby): collect Agama logs after the installation
* Save the logs into the installed system. * Set the proper permissions (700) to the /var/log/agama-installation folder.
1 parent 5b8933e commit bb3a603

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

service/lib/agama/storage/finisher.rb

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
require "agama/helpers"
2929
require "agama/http"
3030
require "abstract_method"
31+
require "fileutils"
3132

3233
Yast.import "Arch"
34+
Yast.import "Installation"
3335

3436
module Agama
3537
module Storage
@@ -217,21 +219,31 @@ def label
217219
end
218220

219221
def run
220-
wfm_write("copy_logs_finish")
221-
copy_agama_scripts
222+
FileUtils.mkdir_p(logs_dir, mode: 0o700)
223+
collect_logs
224+
copy_scripts
222225
end
223226

224227
private
225228

226-
def copy_agama_scripts
229+
def copy_scripts
227230
return unless Dir.exist?(SCRIPTS_DIR)
228231

229-
Yast.import "Installation"
230-
require "fileutils"
231-
logs_dir = File.join(Yast::Installation.destdir, "var", "log", "agama-installation")
232-
FileUtils.mkdir_p(logs_dir)
233232
FileUtils.cp_r(SCRIPTS_DIR, logs_dir)
234233
end
234+
235+
def collect_logs
236+
path = File.join(logs_dir, "logs")
237+
Yast::Execute.locally(
238+
"agama", "logs", "store", "--destination", path
239+
)
240+
end
241+
242+
def logs_dir
243+
@logs_dir ||= File.join(
244+
Yast::Installation.destdir, "var", "log", "agama-installation"
245+
)
246+
end
235247
end
236248

237249
# Executes post-installation scripts

service/test/agama/storage/finisher_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,35 @@
141141

142142
include_examples "progress"
143143
end
144+
145+
describe Agama::Storage::Finisher::CopyLogsStep do
146+
let(:logger) { Logger.new($stdout, level: :warn) }
147+
let(:scripts_dir) { File.join(tmp_dir, "run", "agama", "scripts") }
148+
let(:tmp_dir) { Dir.mktmpdir }
149+
150+
subject { Agama::Storage::Finisher::CopyLogsStep.new(logger) }
151+
152+
before do
153+
allow(Yast::Installation).to receive(:destdir).and_return(File.join(tmp_dir, "mnt"))
154+
allow(Yast::Execute).to receive(:locally)
155+
stub_const("Agama::Storage::Finisher::CopyLogsStep::SCRIPTS_DIR",
156+
File.join(tmp_dir, "run", "agama", "scripts"))
157+
end
158+
159+
after do
160+
FileUtils.remove_entry(tmp_dir)
161+
end
162+
163+
context "when scripts artifacts exist" do
164+
before do
165+
FileUtils.mkdir_p(scripts_dir)
166+
FileUtils.touch(File.join(scripts_dir, "test.sh"))
167+
end
168+
169+
it "copies the artifacts to the installed system" do
170+
subject.run
171+
expect(File).to exist(File.join(tmp_dir, "mnt", "var", "log", "agama-installation",
172+
"scripts"))
173+
end
174+
end
175+
end

service/test/agama/storage/manager_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@
361361
allow(File).to receive(:directory?).with("/iguana").and_return iguana
362362
allow(copy_files_class).to receive(:new).and_return(copy_files)
363363
allow(Yast::Execute).to receive(:on_target!)
364+
allow(Yast::Execute).to receive(:local)
364365
end
365366
let(:copy_files_class) { Agama::Storage::Finisher::CopyFilesStep }
366367
let(:copy_files) { instance_double(copy_files_class, run?: true, run: true, label: "Copy") }
@@ -378,8 +379,10 @@
378379
expect(scripts_client).to receive(:run).with("post")
379380
expect(Yast::Execute).to receive(:on_target!)
380381
.with("systemctl", "enable", "agama-scripts", allowed_exitstatus: [0, 1])
381-
expect(Yast::WFM).to receive(:CallFunction).with("copy_logs_finish", ["Write"])
382382
expect(Yast::WFM).to receive(:CallFunction).with("umount_finish", ["Write"])
383+
expect(Yast::Execute).to receive(:locally).with(
384+
"agama", "logs", "store", "--destination", /\/var\/log\/agama-installation\/logs/
385+
)
383386
storage.finish
384387
end
385388

0 commit comments

Comments
 (0)