Skip to content

Commit

Permalink
Merge pull request #937 from yast/fix_wireless
Browse files Browse the repository at this point in the history
Fix wireless
  • Loading branch information
jreidinger committed Sep 3, 2019
2 parents 8b8a905 + 70d488e commit 174d81c
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 40 deletions.
6 changes: 5 additions & 1 deletion src/lib/y2network/connection_config/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ class Base
attr_accessor :ip_aliases
# @return [Integer, nil]
attr_accessor :mtu
# @return [Startmode, nil]
# @return [Startmode]
attr_accessor :startmode
# @return [String] Connection's description (e.g., "Ethernet Card 0")
attr_accessor :description
# @return [String] Link layer address
attr_accessor :lladdress
# @return [String] configuration for ethtools when initializing
attr_accessor :ethtool_options

# Constructor
def initialize
@ip_aliases = []
@bootproto = BootProtocol::STATIC # TODO: maybe do test query if physical interface is attached?
@startmode = Startmode.create("manual")
@description = ""
@ethtool_options = ""
end

# Propose reasonable defaults for given config. Useful for newly created devices.
Expand Down
32 changes: 16 additions & 16 deletions src/lib/y2network/connection_config/wireless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ class Wireless < Base
attr_accessor :client_cert
# @return [String] client private key used to encrypt for TLS
attr_accessor :client_key
end

def initialize
super
def initialize
super

self.mode = "Managed"
self.essid = ""
self.nwid = ""
self.auth_mode = :open
self.wpa_psk = ""
self.key_length = 128
self.keys = []
self.default_key = 0
self.eap_mode = "PEAP"
self.eap_auth = "MSCHAPV2"
self.ap_scanmode = 1
# For WIFI DHCP makes more sense as majority of wifi routers act as dhcp servers
self.bootproto = BootProtocol::DHCP
self.mode = "Managed"
self.essid = ""
self.nwid = ""
self.auth_mode = :open
self.wpa_psk = ""
self.key_length = 128
self.keys = []
self.default_key = 0
self.eap_mode = "PEAP"
self.eap_auth = "MSCHAPV2"
self.ap_scanmode = 1
# For WIFI DHCP makes more sense as majority of wifi routers act as dhcp servers
self.bootproto = BootProtocol::DHCP
end
end
end
end
27 changes: 7 additions & 20 deletions src/lib/y2network/interface_config_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require "yast"
require "forwardable"

require "y2network/connection_config"
require "y2network/hwinfo"
Expand All @@ -36,6 +37,7 @@ module Y2Network
# {Yast::LanItemsClass#Commit Yast::LanItems.Commit(builder)} use it.
class InterfaceConfigBuilder
include Yast::Logger
extend Forwardable

# Load fresh instance of interface config builder for given type.
# It can be specialized type or generic, depending if specialized is needed.
Expand All @@ -56,14 +58,17 @@ def self.for(type, config: nil)
# @return [String] Device name (eth0, wlan0, etc.)
attr_reader :name
# @return [Y2Network::InterfaceType] type of @see Y2Network::Interface which is intended to be build
attr_accessor :type
attr_reader :type
# @return [Y2Network::ConnectionConfig] connection config on which builder operates
attr_reader :connection_config
# @return [Symbol] Mechanism to rename the interface (:none -no hardware based-, :mac or :bus_id)
attr_writer :renaming_mechanism
# @return [Y2Network::Interface,nil] Underlying interface if it exists
attr_reader :interface

def_delegators :@connection_config,
:startmode, :ethtool_options, :ethtool_options=

# Constructor
#
# Load with reasonable defaults
Expand Down Expand Up @@ -192,9 +197,7 @@ def firewall_zone
end

# sets assigned firewall zone
def firewall_zone=(value)
@firewall_zone = value
end
attr_writer :firewall_zone

# @return [Y2Network::BootProtocol]
def boot_protocol
Expand All @@ -207,11 +210,6 @@ def boot_protocol=(value)
@connection_config.bootproto = Y2Network::BootProtocol.from_name(value)
end

# @return [Startmode]
def startmode
@connection_config.startmode
end

# @param [String,Y2Network::Startmode] name startmode name used to create Startmode object
# or object itself
def startmode=(name)
Expand Down Expand Up @@ -285,17 +283,6 @@ def aliases=(value)
@aliases = value
end

# TODO: eth only?
# @return [String]
def ethtool_options
@config["ETHTOOL_OPTIONS"]
end

# @param [String] value
def ethtool_options=(value)
@config["ETHTOOL_OPTIONS"] = value
end

# @return [String]
def ip_address
default = @connection_config.ip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def connection_config
conn.lladdress = file.lladdr
conn.startmode = Startmode.create(file.startmode || "manual")
conn.startmode.priority = file.ifplugd_priority if conn.startmode.name == "ifplugd"
conn.ethtool_options = file.ethtool_options
update_connection_config(conn)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def write(conn)
file.lladdr = conn.lladdress
file.startmode = conn.startmode.to_s
file.ifplugd_priority = conn.startmode.priority if conn.startmode.name == "ifplugd"
file.ethtool_options = conn.ethtool_options unless conn.ethtool_options.empty?
add_ips(conn)
update_file(conn)
end
Expand Down
4 changes: 4 additions & 0 deletions src/lib/y2network/sysconfig/interface_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ def variable_name(param_name)
# @return [String] Link layer address
define_variable(:lladdr)

# !@attribute [r] ethtool_options
# @return [String] setting variables on device activation. See man ethtool
define_variable(:ethtool_options)

# !@attribute [r] wireless_key_length
# @return [Integer] Length in bits for all keys used
define_variable(:wireless_key_length, :integer)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2network/widgets/blink_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def contents
end

def handle
device = @settings["IFCFG"]
device = @settings.name
timeout = Yast::UI.QueryWidget(:blink_time, :Value)
log.info "blink, blink ... #{timeout} seconds on #{device} device"
cmd = "/usr/sbin/ethtool -p #{device.shellescape} #{timeout.to_i}"
Expand Down
2 changes: 2 additions & 0 deletions src/lib/y2network/widgets/wireless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def expert_settings_widget
class WirelessExpertSettings < CWM::PushButton
def initialize(settings)
@settings = settings

textdomain "network"
end

def label
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2network/widgets/wireless_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def store
def items
[
["ad-hoc", _("Ad-hoc")],
["managed", _("Managed")],
["Managed", _("Managed")],
["master", _("Master")]
]
end
Expand Down
3 changes: 3 additions & 0 deletions test/y2network/sysconfig/interfaces_writer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
allow(Yast::Execute).to receive(:on_target)
allow(eth0).to receive(:hardware).and_return(hardware)
allow(writer).to receive(:sleep)

# prevent collision with real hardware
allow(Y2Network::UdevRule).to receive(:all).and_return([])
end

around do |example|
Expand Down
6 changes: 5 additions & 1 deletion test/y2network/widgets/blink_button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
require "cwm/rspec"

require "y2network/widgets/blink_button"
require "y2network/interface_config_builder"

describe Y2Network::Widgets::BlinkButton do
subject { described_class.new("IFCFG" => "eth0") }
let(:builder) { Y2Network::InterfaceConfigBuilder.for("eth") }
subject { described_class.new(builder) }

before do
builder.name = "eth0"
# no real blinking
allow(Yast::SCR).to receive(:Execute)
end
Expand Down

0 comments on commit 174d81c

Please sign in to comment.