Skip to content

Commit

Permalink
Do not crash with an exception when editing hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Feb 20, 2020
1 parent b36d267 commit fe9490c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/y2network/interface_config_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,16 @@ def save
end
end

yast_config.rename_interface(@old_name, name, renaming_mechanism) if renamed_interface?
yast_config.add_or_update_connection_config(@connection_config)
# Assign the new added interface in case of a new connection for an
# unplugged one (bsc#1162679)
self.interface = find_interface unless interface

if interface.respond_to?(:custom_driver)
interface.custom_driver = driver_auto? ? nil : driver.name
yast_config.add_or_update_driver(driver) unless driver_auto?
end
yast_config.rename_interface(@old_name, name, renaming_mechanism) if renamed_interface?
yast_config.add_or_update_connection_config(@connection_config)

nil
end
Expand Down Expand Up @@ -245,7 +249,7 @@ def ifplugd_priority
def driver
return @driver if @driver

if @interface.custom_driver
if @interface&.custom_driver
@driver = yast_config.drivers.find { |d| d.name == @interface.custom_driver }
end
@driver ||= :auto
Expand Down
13 changes: 13 additions & 0 deletions test/y2network/interface_config_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@
subject.save
end

context "when the new connection config is for an unplugged interface" do
subject(:config_builder) do
res = Y2Network::InterfaceConfigBuilder.for("eth")
res.name = "eth1"
res
end

it "assigns the added interface to the builder" do
subject.save
expect(subject.interface.name).to eq("eth1")
end
end

context "when interface was renamed" do
before do
subject.rename_interface("eth2")
Expand Down

0 comments on commit fe9490c

Please sign in to comment.