-
Notifications
You must be signed in to change notification settings - Fork 34
/
ctc_test.rb
140 lines (120 loc) · 4.49 KB
/
ctc_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env rspec
# 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 "y2network/s390_device_activators/ctc"
require "y2network/interface_config_builders/ctc"
describe Y2Network::S390DeviceActivators::Ctc do
let(:builder) do
res = Y2Network::InterfaceConfigBuilders::Ctc.new
res.name = "ctc0"
res
end
subject(:activator) { Y2Network::S390DeviceActivators::Ctc.new(builder) }
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.protocol = 0
end
describe "#configure" do
it "tries to activate the group device associated with the defined device id" do
expect(Yast::Execute).to receive(:on_target!)
.with("/sbin/chzdev", "ctc", subject.device_id, "-e",
"protocol=#{builder.protocol}", allowed_exitstatus: 0..255)
.and_return(0)
subject.configure
end
context "when activated succesfully" do
it "returns true" do
expect(Yast::Execute).to receive(:on_target!).and_return(0)
expect(subject.configure).to eq(true)
end
end
context "when failed the activation and returned a non zero return code" do
it "returns false" do
expect(Yast::Execute).to receive(:on_target!).and_return(34)
expect(subject.configure).to eq(false)
end
end
end
describe "#configured_interface" do
before do
allow(executor).to receive(:on_target!)
.with(["/sbin/lszdev", activator.device_id, "-c", "names", "-n"])
.and_return("ctc1")
end
it "obtains the network interface associated with builder device id" do
expect(subject.configured_interface).to eq("ctc1")
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" }
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", "ctc", "-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.0900:0.0.0901")
end
end
describe "#propose_channels" do
context "when the read and write channel have not been initialized" do
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)
end
it "initializes them from the given busid" do
expect { subject.propose_channels }.to change { subject.device_id }.from(nil).to(device_id)
end
end
end
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!
end
end
context "when the channel device ids have been set already" do
it "does not propose anything" do
expect(subject).to_not receive(:propose_channels)
subject.propose!
end
end
end
end