Skip to content

Commit

Permalink
Added physical_port_id routines and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed May 13, 2016
1 parent de8dc4e commit dd77c36
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/include/network/routines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,17 @@ def has_carrier?(dev_name)
).to_i != 0
end

def has_physical_port_id?(dev_name)
!physical_port_id(dev_name).empty?
end

def physical_port_id(dev_name)
SCR.Read(
path(".target.string"),
"/sys/class/net/#{dev_name}/phys_port_id"
).to_s.strip
end

# Checks if device is physically connected to a network
#
# It does neccessary steps which might be needed for proper initialization
Expand Down
35 changes: 35 additions & 0 deletions test/routines_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,38 @@ def initialize
.to match_array([Item(Id(0), "x", false), Item(Id(1), "y", true)])
end
end

describe "physical_port_id" do
subject(:routines) { RoutinesTestClass.new }
let(:phys_port_id) { "physical_port_id" }

before do
allow(Yast::SCR).to receive(:Read)
.with(Yast::Path.new(".target.string"), "/sys/class/net/eth0/phys_port_id")
.and_return(phys_port_id)
end

context "when the module driver support it" do
it "returns ethernet physical port id" do
expect(routines.physical_port_id("eth0")).to eql("physical_port_id")
end
end

context "when the module driver doesn't support it" do
let(:phys_port_id) { nil }

it "returns an empty string" do
expect(routines.physical_port_id("eth0")).to be_empty
end
end
end

describe "#has_physical_port_id?" do
subject(:routines) { RoutinesTestClass.new }

it "returns true if physical port id is not empty" do
allow(routines).to receive(:physical_port_id).with("eth0") { "physical_port_id" }

expect(routines.has_physical_port_id?("eth0")).to eql(true)
end
end

0 comments on commit dd77c36

Please sign in to comment.