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
19 changes: 19 additions & 0 deletions service/lib/agama/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def unlink_resolv
# @return [Logger]
attr_reader :logger

HOSTNAME = "/etc/hostname"
RESOLV = "/etc/resolv.conf"
RESOLV_FLAG = "/run/agama/manage_resolv"
ETC_NM_DIR = "/etc/NetworkManager"
Expand All @@ -89,6 +90,8 @@ def enable_service

# Copies NetworkManager configuration files
def copy_files
copy(HOSTNAME)

return unless Dir.exist?(ETC_NM_DIR)

# runtime configuration is copied first, so in case of later modification
Expand Down Expand Up @@ -117,5 +120,21 @@ def copy_directory(source, target)
FileUtils.mkdir_p(target)
FileUtils.cp(Dir.glob(File.join(source, "*")), target)
end

# Copies a file
#
# This method checks whether the source file exists. It copies the file to the target system if
# it exists
#
# @param source [String] source file
# @param target [String,nil] target directory, only needed in case it is different to the
# original source path in the target system.
def copy(source, target = nil)
return unless File.exist?(source)

path = target || File.join(Yast::Installation.destdir, source)
FileUtils.mkdir_p(File.dirname(path))
FileUtils.copy_entry(source, path)
end
end
end
6 changes: 6 additions & 0 deletions service/package/rubygem-agama-yast.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Mar 28 19:22:51 UTC 2025 - Knut Anderssen <kanderssen@suse.com>

- Copy the hostname to the installed system if it exists
(gh#agama-project/agama#2226).

-------------------------------------------------------------------
Fri Mar 28 11:13:48 UTC 2025 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
20 changes: 18 additions & 2 deletions service/test/agama/network_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@

let(:logger) { Logger.new($stdout, level: :warn) }
let(:targetdir) { File.join(rootdir, "mnt") }
let(:fixtures) { File.join(FIXTURES_PATH, "root_dir") }
let(:hostname_path) { File.join(fixtures, "etc", "hostname") }

before do
allow(Yast::Installation).to receive(:destdir).and_return(targetdir)
stub_const("Agama::Network::HOSTNAME", hostname_path)
stub_const("Agama::Network::RUN_NM_DIR", File.join(rootdir, "run", "NetworkManager"))
end

after do
Expand Down Expand Up @@ -84,6 +88,20 @@
)
end
end
context "when an static hostname is present" do
let(:test_path) { File.join(fixtures, "etc", "hostname.test") }

around do |block|
FileUtils.mv test_path, hostname_path
block.call
FileUtils.mv hostname_path, test_path
end

it "copies it to the target system" do
network.install
expect(File.exist?(File.join(targetdir, Agama::Network::HOSTNAME))).to eql(true)
end
end

it "enables the NetworkManager service" do
expect(service).to receive(:enable)
Expand All @@ -103,14 +121,12 @@
describe "#link_resolv" do
let(:rootdir) { Dir.mktmpdir }

let(:fixtures) { File.join(FIXTURES_PATH, "root_dir") }
let(:resolv_fixture) { File.join(FIXTURES_PATH, "etc", "resolv.conf") }
let(:resolv_flag) { File.join(rootdir, "run", "agama", "manage_resolv") }
let(:resolv) { File.join(targetdir, "etc", "resolv.conf") }

before do
stub_const("Agama::Network::RESOLV_FLAG", resolv_flag)
stub_const("Agama::Network::RUN_NM_DIR", File.join(rootdir, "run", "NetworkManager"))
FileUtils.mkdir_p targetdir
FileUtils.cp_r(Dir["#{fixtures}/*"], rootdir)
FileUtils.cp_r(Dir["#{fixtures}/*"], targetdir)
Expand Down
1 change: 1 addition & 0 deletions service/test/fixtures/root_dir/etc/hostname.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
agama
Loading