-
Notifications
You must be signed in to change notification settings - Fork 9
/
finish_client_test.rb
executable file
·182 lines (144 loc) · 5.92 KB
/
finish_client_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env rspec
require_relative "../test_helper"
require "y2iscsi_client/finish_client"
describe Y2IscsiClient::FinishClient do
describe "#write" do
before do
Yast::Installation.destdir = "/mnt"
allow(Yast::IscsiClientLib).to receive(:sessions).and_return sessions
allow(File).to receive(:directory?).with("/etc/iscsi").and_return etc_exists
allow(File).to receive(:directory?).with("/var/lib/iscsi").and_return var_exists
end
let(:sessions) { [] }
let(:etc_exists) { false }
let(:var_exists) { false }
context "if there is an /etc/iscsi directory in the int-sys" do
let(:etc_exists) { true }
context "and there is also a /var/lib/iscsi directory" do
let(:var_exists) { true }
it "copies the content of both directories to the target system" do
expect(Yast::Execute).to receive(:locally!) do |*args|
expect(args.join(" "))
.to eq "mkdir -p /mnt/etc/iscsi && cp -a /etc/iscsi/* /mnt/etc/iscsi/"
end
expect(Yast::Execute).to receive(:locally!) do |*args|
expect(args.join(" "))
.to eq "mkdir -p /mnt/var/lib/iscsi && cp -a /var/lib/iscsi/* /mnt/var/lib/iscsi/"
end
subject.write
end
end
context "but there is no /var/lib/iscsi directory" do
let(:var_exists) { false }
it "copies the content of /etc/iscsi to the target system" do
expect(Yast::Execute).to receive(:locally!) do |*args|
expect(args.join(" "))
.to eq "mkdir -p /mnt/etc/iscsi && cp -a /etc/iscsi/* /mnt/etc/iscsi/"
end
subject.write
end
it "does not copy /var/lib/iscsi" do
allow(Yast::Execute).to receive(:locally!) do |*args|
expect(args).to_not include "/mnt/var/lib/iscsi"
expect(args).to_not include "/var/lib/iscsi/*"
end
subject.write
end
end
end
context "if there is no /etc/iscsi directory in the int-sys" do
let(:etc_exists) { false }
context "but there is a /var/lib/iscsi directory" do
let(:var_exists) { true }
it "copies the content of /var/lib/iscsi to the target system" do
expect(Yast::Execute).to receive(:locally!) do |*args|
expect(args.join(" "))
.to eq "mkdir -p /mnt/var/lib/iscsi && cp -a /var/lib/iscsi/* /mnt/var/lib/iscsi/"
end
subject.write
end
it "does not copy /etc/iscsi" do
allow(Yast::Execute).to receive(:locally!) do |*args|
expect(args).to_not include "/mnt/etc/iscsi"
expect(args).to_not include "/etc/iscsi/*"
end
subject.write
end
end
context "and there is no /var/lib/iscsi directory either" do
let(:var_exists) { false }
it "does not copy any file" do
expect(Yast::Execute).to_not receive(:locally!)
subject.write
end
end
end
context "if there are directories to be copied to the target system" do
let(:etc_exists) { true }
let(:var_exists) { true }
it "fails gracefully (no exception or crash) if copying fails" do
allow(Yast::Execute).to receive(:locally!).with(any_args, "cp", "-a", anything, anything)
.and_raise Cheetah::ExecutionFailed.new("cmd", 1, "", "Something went wrong")
expect { subject.write }.to_not raise_error
end
end
context "if there are no active iSCSI sessions" do
let(:sessions) { [] }
it "does not modify any socket or service" do
expect(Yast::Service).to_not receive(:Enable)
expect(Yast2::Systemd::Socket).to_not receive(:find)
subject.write
end
end
context "if there are active iSCSI sessions" do
let(:sessions) { ["1.1.1.1:2222 iqn.something default"] }
before do
allow(Yast2::Systemd::Socket).to receive(:find).and_return nil
allow(Yast::Service).to receive(:Enable)
allow(Yast::IscsiClientLib).to receive(:iscsiuio_relevant?).and_return uio
end
context "and the iscsiuio service is not needed" do
let(:uio) { false }
it "enables the iscsid and iscsi services" do
expect(Yast::Service).to receive(:Enable).with("iscsid")
expect(Yast::Service).to receive(:Enable).with("iscsi")
subject.write
end
it "it does not enable the iscsiuio service nor socket" do
expect(Yast2::Systemd::Socket).to_not receive(:find).with("iscsiuio")
expect(Yast::Service).to_not receive(:Enable).with("iscsiuio")
subject.write
end
end
context "and the iscsiuio service is needed" do
let(:uio) { true }
before do
allow(Yast2::Systemd::Socket).to receive(:find).with("iscsiuio").and_return(uio_socket)
end
context "and there is an iscsiuio socket" do
let(:uio_socket) { instance_double(Yast2::Systemd::Socket) }
it "enables the iscsid and iscsi services and the iscsiuio socket" do
expect(Yast::Service).to receive(:Enable).with("iscsid")
expect(Yast::Service).to receive(:Enable).with("iscsi")
expect(uio_socket).to receive(:enable)
subject.write
end
it "it does not enable the iscsiuio service" do
allow(uio_socket).to receive(:enable)
expect(Yast::Service).to_not receive(:Enable).with("iscsiuio")
subject.write
end
end
context "and there is no iscsiuio socket" do
let(:uio_socket) { nil }
it "enables the iscsid, iscsi and iscsiuio services" do
expect(Yast::Service).to receive(:Enable).with("iscsid")
expect(Yast::Service).to receive(:Enable).with("iscsi")
expect(Yast::Service).to receive(:Enable).with("iscsiuio")
subject.write
end
end
end
end
end
end