Skip to content

Commit

Permalink
Do not propose a hostname during AY
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Mar 19, 2020
1 parent ff4947b commit 9616c09
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/lib/y2network/autoinst/hostname_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ def initialize(section)
def config
Y2Network::Hostname.new(
dhcp_hostname: section.dhcp_hostname,
static: section.hostname || default_hostname,
static: static_hostname,
installer: section.hostname
)
end

private

# Returns a default hostname proposal for installer
# Returns the current static_hostname
#
# @return [String]
def default_hostname
Y2Network::Sysconfig::HostnameReader.new.hostname
def static_hostname
Y2Network::Sysconfig::HostnameReader.new.static_hostname
end
end
end
Expand Down
9 changes: 8 additions & 1 deletion src/lib/y2network/sysconfig/hostname_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,19 @@ def hostname_from_resolver
nil
end

# Reads the system (local) hostname
# Reads the transient hostname or system (local) hostname
#
# @return [String, nil] Hostname
def hostname_from_system
Yast::Execute.on_target!("/usr/bin/hostname", stdout: :capture).strip
rescue Cheetah::ExecutionFailed
static_hostname
end

# Reads the static hostname from /etc/hostname
#
# @return [String, nil]
def static_hostname
name = Yast::SCR.Read(Yast::Path.new(".target.string"), "/etc/hostname").to_s.strip
name.empty? ? nil : name
end
Expand Down
57 changes: 57 additions & 0 deletions test/y2network/autoinst/hostname_reader_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env rspec

# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require_relative "../../test_helper"
require "y2network/autoinst/hostname_reader"

describe Y2Network::Autoinst::HostnameReader do
let(:subject) { described_class.new(dns_section) }

let(:dns_section) do
Y2Network::AutoinstProfile::DNSSection.new_from_hashes(profile["dns"])
end

let(:current_static_hostname) { "test" }

before do
allow_any_instance_of(Y2Network::Sysconfig::HostnameReader)
.to receive(:static_hostname).and_return(current_static_hostname)
end

let(:profile) do
{
"dns" => {
"hostname" => "host",
"dhcp_hostname" => true, "write_hostname" => true
}
}
end

describe "#config" do
it "builds a new Y2Network::Hostname config from the profile dns section" do
config = subject.config
expect(config).to be_a Y2Network::Hostname
expect(config.installer).to eq("host")
expect(config.dhcp_hostname).to eq(true)
expect(config.static).to eq(current_static_hostname)
end
end
end

0 comments on commit 9616c09

Please sign in to comment.