Skip to content

Commit

Permalink
Fixed tests and added device activation details to the Popup
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jan 29, 2020
1 parent ea5d8fd commit 2583f22
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/lib/y2network/connection_config/ctc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def device_id
#
# @param id [String] s390 group device id
def device_id=(id)
@read_channel, @write_channel = id.split(":")
@read_channel, @write_channel = id.to_s.split(":")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/lib/y2network/connection_config/lcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def device_id
#
# @param id [String] s390 group device id
def device_id=(id)
@read_channel, @write_channel = id.split(":")
@read_channel, @write_channel = id.to_s.split(":")
end
end
end
Expand Down
26 changes: 15 additions & 11 deletions src/lib/y2network/dialogs/s390_device_activation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require "y2network/widgets/s390_common"
require "y2network/widgets/s390_channels"
require "y2network/sysconfig/interfaces_reader"
require "yast2/popup"

Yast.import "Lan"

Expand Down Expand Up @@ -81,24 +82,17 @@ def contents
def run
ret = super
if ret == :next
configured = activator.configure
_stdout, stderr, status = activator.configure
configured = status.zero?

if configured
interface_name = activator.configured_interface
builder.name = interface_name
add_interface(interface_name)
end

# TODO: Refresh the list of interfaces in yast_config. Take into
# account that the interface in yast_config does not have a name so
# the builder.interface is probably nil and should be obtained
# through the busid.
if !configured || builder.name.empty?
Yast::Popup.Error(
_(
"An error occurred while creating device.\nSee YaST log for details."
)
)

show_activation_error(stderr)
ret = nil
end
end
Expand All @@ -112,6 +106,16 @@ def abort_handler

private

def show_activation_error(message)
Yast2::Popup.show(
# TRANSLATORS: s390 group device activation error report. %s are the
# details of the error
_("An error occurred while activating the device.<br/><br/>" \
"<b>Details:<b/><br/>%s") % message,
richtext: true, headline: :error
)
end

def reader
@reader ||= Y2Network::Sysconfig::InterfacesReader.new
end
Expand Down
4 changes: 1 addition & 3 deletions src/lib/y2network/presenters/s390_group_device_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ def initialize(name, config)

def text
device = @config.s390_devices.by_id(@name)
busid = device.id.split(":").first

hardware = device.hardware
descr = hardware ? hardware.description : ""

rich = Yast::HTML.Bold(descr) + "<br><br>"
rich = Yast::HTML.Bold(descr) + "<br>"
rich << "<b>ID: </b>" << device.id << "<br>"
rich << "<b>Type: </b>" << device.type.short_name << "<br><br>"

Expand Down
5 changes: 1 addition & 4 deletions src/lib/y2network/s390_device_activators/ctc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ def configure_attributes

# Modifies the read and write channel from the the device id
def propose_channels
id = builder.name
return unless id

self.read_channel, self.write_channel = id.split(":")
builder.device_id = builder.name
end

def propose!
Expand Down
6 changes: 6 additions & 0 deletions test/y2network/dialogs/s390_device_activation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
before do
allow(activator).to receive(:configure).and_return(configured)
allow(activator).to receive(:configured_interface).and_return("eth4")
allow(subject).to receive(:add_interface)
allow(subject).to receive(:cwm_show).and_return(dialog_action)
end

Expand All @@ -60,6 +61,11 @@
expect(builder.name).to eql("eth4")
end

it "adds the new interface to the config" do
expect(subject).to receive(:add_interface).with("eth4")
subject.run
end

it "returns :next" do
expect(subject.run).to eql(:next)
end
Expand Down
9 changes: 5 additions & 4 deletions test/y2network/s390_device_activators/ctc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@

let(:executor) { double("Yast::Execute", on_target!: "") }
let(:initialize_channels) { true }

before do
allow(Yast::Execute).to receive(:stdout).and_return(executor)
builder.read_channel = "0.0.0900" if initialize_channels
builder.write_channel = "0.0.0901" if initialize_channels
builder.device_id = builder.name = "0.0.0900:0.0.0901" if initialize_channels
builder.protocol = 0
end

Expand Down Expand Up @@ -89,11 +89,12 @@
let(:initialize_channels) { false }
let(:device_id) { "0.0.0800:0.0.0801" }
let(:write_channel) { "0.0.0801" }

let(:hwinfo) { Y2Network::Hwinfo.new("busid" => write_channel) }

before do
allow(subject).to receive(:device_id_from).with(write_channel).and_return(device_id)
allow(builder).to receive(:hwinfo).and_return(hwinfo)
builder.name = device_id
end

it "initializes them from the given busid" do
Expand All @@ -105,6 +106,7 @@
describe "#propose!" do
context "when no device id has been initialized" do
let(:initialize_channels) { false }

it "proposes the channel device ids to be used" do
expect(subject).to receive(:propose_channels)
subject.propose!
Expand All @@ -118,5 +120,4 @@
end
end
end

end
20 changes: 1 addition & 19 deletions test/y2network/s390_device_activators/qeth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,6 @@
end
end

describe "#device_id_from" do
context "given the read or write device id" do
let(:device_id) { "0.0.0800:0.0.0801:0.0.0802" }
let(:write_channel) { "0.0.0801" }
let(:hwinfo) { Y2Network::Hwinfo.new("busid" => write_channel) }
before do
allow(builder).to receive(:hwinfo).and_return(hwinfo)
allow(executor).to receive(:on_target!)
.with(["/sbin/lszdev", "qeth", "-c", "id", "-n"])
.and_return(device_id)
end

it "obtains the triplet device ids listed by lszdev" do
expect(subject.device_id_from(hwinfo.busid)).to eq(device_id)
end
end
end

describe "#device_id" do
it "returns the read and write channel device ids joined by ':'" do
expect(subject.device_id).to eql("0.0.0700:0.0.0701:0.0.0702")
Expand All @@ -112,8 +94,8 @@
let(:hwinfo) { Y2Network::Hwinfo.new("busid" => write_channel) }

before do
allow(subject).to receive(:device_id_from).with(write_channel).and_return(device_id)
allow(builder).to receive(:hwinfo).and_return(hwinfo)
builder.name = device_id
end

it "initializes them from the given busid" do
Expand Down
8 changes: 5 additions & 3 deletions test/y2network/sysconfig/config_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@
let(:interfaces) { [eth0, wlan0] }
let(:eth0_config) { instance_double(Y2Network::ConnectionConfig::Ethernet) }
let(:connections) { [eth0_config] }
let(:s390_devices) { [] }
let(:drivers) { Y2Network::Driver.new("virtio_net", "") }
let(:routes_file) { instance_double(Y2Network::Sysconfig::RoutesFile, load: nil, routes: []) }
let(:dns_reader) { instance_double(Y2Network::Sysconfig::DNSReader, config: dns) }
let(:hostname_reader) { instance_double(Y2Network::Sysconfig::HostnameReader, config: hostname) }
let(:interfaces_reader) do
instance_double(
Y2Network::Sysconfig::InterfacesReader,
interfaces: Y2Network::InterfacesCollection.new(interfaces),
connections: connections,
drivers: drivers
interfaces: Y2Network::InterfacesCollection.new(interfaces),
connections: connections,
s390_devices: s390_devices,
drivers: drivers
)
end

Expand Down
2 changes: 1 addition & 1 deletion test/y2network/widgets/interfaces_table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

before do
allow(Yast::Lan).to receive(:yast_config)
.and_return(double(interfaces: interfaces, connections: connections))
.and_return(double(interfaces: interfaces, connections: connections, s390_devices: []))
allow(Yast::UI).to receive(:QueryWidget).and_return([])
allow(subject).to receive(:value).and_return("eth0")
end
Expand Down

0 comments on commit 2583f22

Please sign in to comment.