Skip to content

Commit

Permalink
Add an InterfaceNaming widget to hide the renaming details
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Aug 29, 2019
1 parent b1d3241 commit dd5726e
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 17 deletions.
6 changes: 2 additions & 4 deletions src/lib/y2network/widgets/general_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
require "cwm/tabs"

# used widgets
require "y2network/widgets/interface_name"
require "y2network/widgets/udev_rules"
require "y2network/widgets/interface_naming"
require "y2network/widgets/startmode"
require "y2network/widgets/ifplugd_priority"
require "y2network/widgets/firewall_zone"
Expand Down Expand Up @@ -52,8 +51,7 @@ def contents
1,
0,
VBox(
# FIXME: udev rules for anything without hwinfo is wrong
@settings.newly_added? ? InterfaceName.new(@settings) : UdevRules.new(@settings),
InterfaceNaming.new(@settings),
Frame(
_("Device Activation"),
HBox(Startmode.new(@settings, ifplugd_widget), ifplugd_widget, HStretch())
Expand Down
3 changes: 2 additions & 1 deletion src/lib/y2network/widgets/interface_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def validate
end

def store
@settings.name = value
return if @settings.name == value
@settings.rename_interface(value)
end
end
end
Expand Down
57 changes: 57 additions & 0 deletions src/lib/y2network/widgets/interface_naming.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) [2019] 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 "cwm/custom_widget"
require "y2network/widgets/udev_rules"
require "y2network/widgets/interface_name"

module Y2Network
module Widgets
# Widget to handle interface naming, including udev based renames.
class InterfaceNaming < ::CWM::CustomWidget
# Constructor
#
# @param [Y2Network::InterfaceConfigBuilder] Interface configuration builder object
def initialize(builder)
@builder = builder
end

# @see CWM::CustomWidget#contents
def contents
VBox(widget)
end

private

def udev_based_rename?
hardware = @builder.interface.hardware
return false unless hardware
!!(hardware.mac || hardware.busid)
end

# Internal widget
#
# It uses an internal widget to handle the rename depending on whether
# udev based renames are needed or not.
def widget
@widget ||= udev_based_rename? ? UdevRules.new(@builder) : InterfaceName.new(@builder)
end
end
end
end
17 changes: 5 additions & 12 deletions src/lib/y2network/widgets/udev_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def contents
_("Udev Rules"),
HBox(
InputField(Id(:udev_rules_name), Opt(:hstretch, :disabled), _("Device Name"), ""),
@settings.interface.can_be_renamed? ? change_button : Empty()
PushButton(Id(:udev_rules_change), _("Change"))
)
)
end
Expand All @@ -46,15 +46,14 @@ def init
end

def handle
self.value = Y2Network::Dialogs::RenameInterface.new(@settings).run
dialog = Y2Network::Dialogs::RenameInterface.new(@settings)
ret = dialog.run
return unless ret == :ok
self.value = @settings.name

nil
end

def store
# TODO: nothing to do as done in RenameInterface which looks wrong
end

def value=(name)
Yast::UI.ChangeWidget(Id(:udev_rules_name), :Value, name)
end
Expand All @@ -70,12 +69,6 @@ def help
"example, eth1, wlan0 ) and assures a persistent device name upon reboot.\n"
)
end

private

def change_button
PushButton(Id(:udev_rules_change), _("Change"))
end
end
end
end
42 changes: 42 additions & 0 deletions test/y2network/widgets/interface_naming_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) [2019] 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 "cwm/rspec"

require "y2network/widgets/interface_naming"
require "y2network/interface_config_builder"
require "y2network/physical_interface"

describe Y2Network::Widgets::InterfaceNaming do
subject(:widget) { described_class.new(builder) }

let(:builder) do
instance_double(
Y2Network::InterfaceConfigBuilder,
interface: interface
)
end

let(:interface) { instance_double(Y2Network::PhysicalInterface, hardware: nil) }

include_examples "CWM::CustomWidget"
describe "#contents"
describe "#store"
end

0 comments on commit dd5726e

Please sign in to comment.