Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions service/lib/agama/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ def collect_logs(path: nil)
# @param method [HALT, POWEROFF, STOP, REBOOT]
# @return [Boolean]
def finish_installation(method)
logs = collect_logs(path: "/tmp/var/logs/")

logger.info("Installation logs stored in #{logs}")

unless installation_phase.finish?
logger.error "The installer has not finished correctly. Please check logs"
return false
Expand Down
26 changes: 19 additions & 7 deletions service/lib/agama/storage/finisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
require "agama/helpers"
require "agama/http"
require "abstract_method"
require "fileutils"

Yast.import "Arch"
Yast.import "Installation"

module Agama
module Storage
Expand Down Expand Up @@ -217,21 +219,31 @@ def label
end

def run
wfm_write("copy_logs_finish")
copy_agama_scripts
FileUtils.mkdir_p(logs_dir, mode: 0o700)
collect_logs
copy_scripts
end

private

def copy_agama_scripts
def copy_scripts
return unless Dir.exist?(SCRIPTS_DIR)

Yast.import "Installation"
require "fileutils"
logs_dir = File.join(Yast::Installation.destdir, "var", "log", "agama-installation")
FileUtils.mkdir_p(logs_dir)
FileUtils.cp_r(SCRIPTS_DIR, logs_dir)
end

def collect_logs
path = File.join(logs_dir, "logs")
Yast::Execute.locally(
"agama", "logs", "store", "--destination", path
)
end

def logs_dir
@logs_dir ||= File.join(
Yast::Installation.destdir, "var", "log", "agama-installation"
)
end
end

# Executes post-installation scripts
Expand Down
7 changes: 7 additions & 0 deletions service/package/rubygem-agama-yast.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Mar 12 00:44:33 UTC 2025 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Copy Agama logs to the installed system (gh#agama/agama-project#2148).
- Set /var/log/agama-installation permissions to 0700
(gh#agama/agama-project#2140).

-------------------------------------------------------------------
Wed Mar 5 14:50:04 UTC 2025 - Ladislav Slezák <lslezak@suse.com>

Expand Down
6 changes: 0 additions & 6 deletions service/test/agama/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,11 @@
let(:method) { "reboot" }

before do
allow(subject).to receive(:collect_logs)
allow(subject).to receive(:iguana?).and_return(iguana)
allow(subject.installation_phase).to receive(:finish?).and_return(finished)
allow(logger).to receive(:error)
end

it "collects the logs" do
expect(subject).to receive(:collect_logs)
subject.finish_installation(method)
end

context "when it is not in finish the phase" do
it "logs the error and returns false" do
expect(logger).to receive(:error).with(/not finished/)
Expand Down
32 changes: 32 additions & 0 deletions service/test/agama/storage/finisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,35 @@

include_examples "progress"
end

describe Agama::Storage::Finisher::CopyLogsStep do
let(:logger) { Logger.new($stdout, level: :warn) }
let(:scripts_dir) { File.join(tmp_dir, "run", "agama", "scripts") }
let(:tmp_dir) { Dir.mktmpdir }

subject { Agama::Storage::Finisher::CopyLogsStep.new(logger) }

before do
allow(Yast::Installation).to receive(:destdir).and_return(File.join(tmp_dir, "mnt"))
allow(Yast::Execute).to receive(:locally)
stub_const("Agama::Storage::Finisher::CopyLogsStep::SCRIPTS_DIR",
File.join(tmp_dir, "run", "agama", "scripts"))
end

after do
FileUtils.remove_entry(tmp_dir)
end

context "when scripts artifacts exist" do
before do
FileUtils.mkdir_p(scripts_dir)
FileUtils.touch(File.join(scripts_dir, "test.sh"))
end

it "copies the artifacts to the installed system" do
subject.run
expect(File).to exist(File.join(tmp_dir, "mnt", "var", "log", "agama-installation",
"scripts"))
end
end
end
5 changes: 4 additions & 1 deletion service/test/agama/storage/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
allow(File).to receive(:directory?).with("/iguana").and_return iguana
allow(copy_files_class).to receive(:new).and_return(copy_files)
allow(Yast::Execute).to receive(:on_target!)
allow(Yast::Execute).to receive(:local)
end
let(:copy_files_class) { Agama::Storage::Finisher::CopyFilesStep }
let(:copy_files) { instance_double(copy_files_class, run?: true, run: true, label: "Copy") }
Expand All @@ -386,8 +387,10 @@
expect(scripts_client).to receive(:run).with("post")
expect(Yast::Execute).to receive(:on_target!)
.with("systemctl", "enable", "agama-scripts", allowed_exitstatus: [0, 1])
expect(Yast::WFM).to receive(:CallFunction).with("copy_logs_finish", ["Write"])
expect(Yast::WFM).to receive(:CallFunction).with("umount_finish", ["Write"])
expect(Yast::Execute).to receive(:locally).with(
"agama", "logs", "store", "--destination", /\/var\/log\/agama-installation\/logs/
)
storage.finish
end

Expand Down