brocadesan 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +113 -0
- data/Rakefile +46 -0
- data/brocadesan.gemspec +14 -0
- data/lib/brocadesan.rb +8 -0
- data/lib/brocadesan/alias.rb +64 -0
- data/lib/brocadesan/config/brocade/san/switch_cmd_mapping.yml +116 -0
- data/lib/brocadesan/config/parser_mapping.yml +21 -0
- data/lib/brocadesan/device.rb +296 -0
- data/lib/brocadesan/monkey/string.rb +11 -0
- data/lib/brocadesan/provisioning.rb +894 -0
- data/lib/brocadesan/switch.rb +882 -0
- data/lib/brocadesan/wwn.rb +63 -0
- data/lib/brocadesan/zone.rb +60 -0
- data/lib/brocadesan/zone_configuration.rb +38 -0
- data/lib/meta_methods.rb +263 -0
- data/test/alias_test.rb +68 -0
- data/test/device_test.rb +203 -0
- data/test/output_helpers.rb +308 -0
- data/test/outputs/agshow_1.txt +7 -0
- data/test/outputs/agshow_1.yml +31 -0
- data/test/outputs/agshow_2.txt +4 -0
- data/test/outputs/agshow_2.yml +3 -0
- data/test/outputs/apt_policy_1.txt +6 -0
- data/test/outputs/apt_policy_1.yml +3 -0
- data/test/outputs/cfgshow_1.txt +5 -0
- data/test/outputs/cfgshow_1.yml +7 -0
- data/test/outputs/cfgshow_2.txt +31 -0
- data/test/outputs/cfgshow_2.yml +32 -0
- data/test/outputs/cfgshow_3.txt +9 -0
- data/test/outputs/cfgshow_3.yml +12 -0
- data/test/outputs/cfgtransshow_1.txt +2 -0
- data/test/outputs/cfgtransshow_1.yml +5 -0
- data/test/outputs/cfgtransshow_2.txt +3 -0
- data/test/outputs/cfgtransshow_2.yml +4 -0
- data/test/outputs/cfgtransshow_3.txt +3 -0
- data/test/outputs/cfgtransshow_3.yml +4 -0
- data/test/outputs/chassisname_1.txt +2 -0
- data/test/outputs/chassisname_1.yml +3 -0
- data/test/outputs/dlsshow_1.txt +4 -0
- data/test/outputs/dlsshow_1.yml +4 -0
- data/test/outputs/dlsshow_2.txt +4 -0
- data/test/outputs/dlsshow_2.yml +4 -0
- data/test/outputs/fabricshow_1.txt +10 -0
- data/test/outputs/fabricshow_1.yml +34 -0
- data/test/outputs/iodshow_1.txt +4 -0
- data/test/outputs/iodshow_1.yml +4 -0
- data/test/outputs/islshow_1.txt +6 -0
- data/test/outputs/islshow_1.yml +62 -0
- data/test/outputs/islshow_2.txt +2 -0
- data/test/outputs/islshow_2.yml +2 -0
- data/test/outputs/lscfg_show_1.txt +71 -0
- data/test/outputs/lscfg_show_1.yml +5 -0
- data/test/outputs/ns_1.txt +80 -0
- data/test/outputs/ns_1.yml +39 -0
- data/test/outputs/ns_2.txt +37 -0
- data/test/outputs/ns_2.yml +21 -0
- data/test/outputs/putty.log +1867 -0
- data/test/outputs/switch_1.txt +25 -0
- data/test/outputs/switch_1.yml +73 -0
- data/test/outputs/switch_2.txt +18 -0
- data/test/outputs/switch_2.yml +42 -0
- data/test/outputs/switch_3.txt +14 -0
- data/test/outputs/switch_3.yml +46 -0
- data/test/outputs/switchstatusshow_1.txt +21 -0
- data/test/outputs/switchstatusshow_1.yml +19 -0
- data/test/outputs/trunkshow_1.txt +8 -0
- data/test/outputs/trunkshow_1.yml +44 -0
- data/test/outputs/trunkshow_2.txt +2 -0
- data/test/outputs/trunkshow_2.yml +2 -0
- data/test/outputs/version_1.txt +6 -0
- data/test/outputs/version_1.yml +8 -0
- data/test/outputs/vf_switch_1.txt +25 -0
- data/test/outputs/vf_switch_1.yml +73 -0
- data/test/provisioning_test.rb +1043 -0
- data/test/switch_test.rb +476 -0
- data/test/wwn_test.rb +41 -0
- data/test/zone_configuration_test.rb +65 -0
- data/test/zone_test.rb +73 -0
- metadata +170 -0
data/test/switch_test.rb
ADDED
@@ -0,0 +1,476 @@
|
|
1
|
+
require 'brocadesan'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'output_helpers'
|
4
|
+
|
5
|
+
module Brocade module SAN
|
6
|
+
|
7
|
+
class SwitchTest < MiniTest::Test
|
8
|
+
include OutputReader
|
9
|
+
include Mock::Net::SSH
|
10
|
+
patch_set
|
11
|
+
|
12
|
+
def setup
|
13
|
+
init_dev
|
14
|
+
end
|
15
|
+
|
16
|
+
def init_dev
|
17
|
+
@device = Switch.new("test","test","test")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_query
|
21
|
+
response=@device.query("test")
|
22
|
+
assert_instance_of Switch::Response, response
|
23
|
+
assert_equal @device.prompt+"test\n"+Mock::Net::SSH::get_data+"\n", response.data
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_device_setup
|
27
|
+
assert_instance_of Switch, @device
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_set_context
|
31
|
+
@device.set_context(3)
|
32
|
+
assert_equal 3, @device.fid
|
33
|
+
assert_empty @device.instance_variable_get(:@loaded)
|
34
|
+
assert_equal 3, @device.fid
|
35
|
+
@device.set_context("A3")
|
36
|
+
assert_equal 128, @device.fid
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_get
|
40
|
+
@output_dir=File.join(Dir.pwd,"test","outputs")
|
41
|
+
read_all_starting_with "switch_" do |file,output|
|
42
|
+
init_dev
|
43
|
+
response=new_mock_response
|
44
|
+
response.data=output
|
45
|
+
yaml=read_yaml_for(file)
|
46
|
+
|
47
|
+
@device.stub :query, response do
|
48
|
+
assert_equal yaml[:switch_name], @device.get(:name)
|
49
|
+
# clear configuration
|
50
|
+
@device.instance_variable_set(:@configuration,{})
|
51
|
+
assert_nil @device.get(:name) #nil if not reloaded
|
52
|
+
assert_equal yaml[:switch_name], @device.get(:name,true) # ok if reloaded
|
53
|
+
|
54
|
+
#raise error if unknow parameter is requested
|
55
|
+
assert_raises Switch::Error do
|
56
|
+
@device.get(:dummy,true)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_vf
|
63
|
+
response=new_mock_response
|
64
|
+
response.data="> switchshow |grep \"^LS Attributes\"\n"
|
65
|
+
@device.stub :query, response do
|
66
|
+
assert_equal "disabled", @device.vf(true)
|
67
|
+
end
|
68
|
+
|
69
|
+
response.data="> switchshow |grep \"^LS Attributes\"\nLS Attributes: [FID: 128, Base Switch: No, Default Switch: Yes, Address Mode 0]\n"
|
70
|
+
|
71
|
+
@device.stub :query, response do
|
72
|
+
# running it without force should still show the same
|
73
|
+
assert_equal "disabled", @device.vf
|
74
|
+
|
75
|
+
assert_equal "enabled", @device.vf(true)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_get_with_vf
|
80
|
+
@output_dir=File.join(Dir.pwd,"test","outputs")
|
81
|
+
read_all_starting_with "vf_switch" do |file,output|
|
82
|
+
init_dev
|
83
|
+
response=new_mock_response
|
84
|
+
response.data=output
|
85
|
+
@device.configuration[:vf]="enabled"
|
86
|
+
@device.set_context 99
|
87
|
+
|
88
|
+
@device.stub :query, response do
|
89
|
+
assert_equal read_yaml_for(file)[:switch_name], @device.get(:name)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_refresh
|
95
|
+
#returns true and runs query if not loaded or forced, runs query
|
96
|
+
@device.instance_variable_set(:@configuration,{:name=>"test", :parsing_position=>"test"})
|
97
|
+
@device.send(:refresh, "switchshow")
|
98
|
+
assert_equal a = {:name=>"test", :parsing_position=>"end"}, @device.configuration
|
99
|
+
assert_equal true, @device.instance_variable_get(:@loaded)[:switchshow]
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_dynamic_methods
|
103
|
+
@output_dir=File.join(Dir.pwd,"test","outputs")
|
104
|
+
read_all_starting_with "" do |file,output|
|
105
|
+
response=new_mock_response
|
106
|
+
response.data=output
|
107
|
+
init_dev
|
108
|
+
yaml=read_yaml_for(file)
|
109
|
+
@device.stub :query, response do
|
110
|
+
Switch::CMD_MAPPING.each do |k,v|
|
111
|
+
#puts "#{v[:attr].to_sym}: #{read_yaml_for(file)[v[:attr].to_sym]} = #{@device.method(k).call}"
|
112
|
+
assert_equal yaml[v[:attr].to_sym], @device.method(k).call
|
113
|
+
# clear configuration
|
114
|
+
@device.instance_variable_set(:@configuration,{})
|
115
|
+
assert_nil @device.method(k).call #nil if not reloaded
|
116
|
+
assert_equal yaml[v[:attr].to_sym], @device.method(k).call(true) # ok if reloaded
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_fullcmd
|
123
|
+
assert_equal "test", @device.send(:fullcmd,"test")
|
124
|
+
|
125
|
+
#vf enabled but no fid
|
126
|
+
@device.configuration[:vf]="enabled"
|
127
|
+
assert_equal "test", @device.send(:fullcmd,"test")
|
128
|
+
|
129
|
+
#vf enabled and fid given
|
130
|
+
@device.set_context 99
|
131
|
+
assert_equal "fosexec --fid 99 \'test\'", @device.send(:fullcmd,"test")
|
132
|
+
|
133
|
+
#vf enabled and fid given and piped commnad
|
134
|
+
@device.set_context 99
|
135
|
+
assert_equal "fosexec --fid 99 \'test\' |grep shit", @device.send(:fullcmd,"test|grep shit")
|
136
|
+
|
137
|
+
#vf enabled and fid given and piped commnad
|
138
|
+
@device.set_context 99
|
139
|
+
assert_equal "fosexec --fid 99 \'test\' | grep shit| grep shit2", @device.send(:fullcmd,"test| grep shit| grep shit2")
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_zone_cfgs_and_effective_cfg_and_zones
|
143
|
+
@output_dir=File.join(Dir.pwd,"test","outputs")
|
144
|
+
read_all_starting_with "cfgshow_" do |file,output|
|
145
|
+
response=new_mock_response
|
146
|
+
response.data=output
|
147
|
+
init_dev
|
148
|
+
yaml=read_yaml_for(file)
|
149
|
+
@device.stub :query, response do
|
150
|
+
cfgs=@device.zone_configurations.map {|c| c.name }
|
151
|
+
yaml[:defined_configuration][:cfg].each do |config, members|
|
152
|
+
assert cfgs.include?(config)
|
153
|
+
end
|
154
|
+
ef_cfg=@device.zone_configurations.map {|c| c.name if c.effective }.delete_if {|c| c==nil}
|
155
|
+
assert_equal yaml[:defined_configuration][:cfg].keys[0], ef_cfg.first
|
156
|
+
|
157
|
+
#test if effective_configuration method
|
158
|
+
assert_equal yaml[:defined_configuration][:cfg].keys[0], @device.effective_configuration.name
|
159
|
+
|
160
|
+
# test zones
|
161
|
+
if yaml[:defined_configuration][:zone]
|
162
|
+
zones=@device.zones.map {|z| z.name }
|
163
|
+
yaml[:defined_configuration][:zone].each do |zone, members|
|
164
|
+
assert zones.include?(zone)
|
165
|
+
end
|
166
|
+
|
167
|
+
# testig active zones
|
168
|
+
zones_1=@device.effective_configuration(true).members
|
169
|
+
zones_2=@device.zones
|
170
|
+
|
171
|
+
zones_2.each do |zone|
|
172
|
+
if zones_1.include? zone.name
|
173
|
+
assert zone.active, "Zone should be active"
|
174
|
+
else
|
175
|
+
refute zone.active, "Zone should not be active"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# test aliases
|
181
|
+
if yaml[:defined_configuration][:alias]
|
182
|
+
aliases=@device.aliases.map {|a| a.name }
|
183
|
+
yaml[:defined_configuration][:alias].each do |al, members|
|
184
|
+
assert aliases.include?(al)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_find_zone_alias
|
192
|
+
|
193
|
+
response=new_mock_response
|
194
|
+
response.data="> configshow |grep -i -E zone.VAL_lis9swep01_m1p1_IEVA16:\nzone.VAL_lis9swep01_m1p1_IEVA16:ieva16_A1_ho;ieva16_B1_ho;ida16R24c7_bay12_m1p1"
|
195
|
+
init_dev
|
196
|
+
|
197
|
+
@device.stub :query, response do
|
198
|
+
z=@device.find_zone("VAL_lis9swep01_m1p1_IEVA16")
|
199
|
+
assert_equal "VAL_lis9swep01_m1p1_IEVA16", z[0].name
|
200
|
+
assert_equal ["ieva16_A1_ho","ieva16_B1_ho","ida16R24c7_bay12_m1p1"], z[0].members
|
201
|
+
end
|
202
|
+
|
203
|
+
response.data="> configshow |grep -i -E zone.unknown:"
|
204
|
+
|
205
|
+
@device.stub :query, response do
|
206
|
+
z=@device.find_zone("unknown")
|
207
|
+
assert_equal [], z
|
208
|
+
end
|
209
|
+
|
210
|
+
# test find aliases
|
211
|
+
|
212
|
+
response.data="> configshow |grep -i -E ^alias.ivls01n0_1:\nalias.ivls01n0_1:50:02:26:40:8F:DC:20:00"
|
213
|
+
|
214
|
+
@device.stub :query, response do
|
215
|
+
a=@device.find_alias("ivls01n0_1")
|
216
|
+
assert_equal "ivls01n0_1", a[0].name
|
217
|
+
assert_equal ["50:02:26:40:8F:DC:20:00"], a[0].members
|
218
|
+
end
|
219
|
+
|
220
|
+
response.data="> configshow |grep -i -E ^alias.unknown:"
|
221
|
+
|
222
|
+
@device.stub :query, response do
|
223
|
+
a=@device.find_alias("unknown")
|
224
|
+
assert_equal [], a
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
def test_find_zones_aliases
|
230
|
+
|
231
|
+
response=new_mock_response
|
232
|
+
response.data="> configshow |grep -i -E ^zone.VAL_lis9swep01_m1p1\nzone.VAL_lis9swep01_m1p1_IEVA16:ieva16_A1_ho;ieva16_B1_ho;ida16R24c7_bay12_m1p1\nzone.VAL_lis9swep01_m1p1_IVLS01:ivls01n2_1;ivls01n3_1;ida16R24c7_bay12_m1p1"
|
233
|
+
init_dev
|
234
|
+
|
235
|
+
@device.stub :query, response do
|
236
|
+
z=@device.find_zones("VAL_lis9swep01_m1p1")
|
237
|
+
assert_equal ["VAL_lis9swep01_m1p1_IEVA16","VAL_lis9swep01_m1p1_IVLS01"], z.map {|zone| zone.name }
|
238
|
+
assert_equal [["ieva16_A1_ho","ieva16_B1_ho","ida16R24c7_bay12_m1p1"],["ivls01n2_1","ivls01n3_1","ida16R24c7_bay12_m1p1"]], z.map {|zone| zone.members }
|
239
|
+
end
|
240
|
+
|
241
|
+
response.data="> configshow |grep -i -E zone.unknown:"
|
242
|
+
|
243
|
+
@device.stub :query, response do
|
244
|
+
z=@device.find_zones("unknown")
|
245
|
+
assert_equal [], z
|
246
|
+
end
|
247
|
+
|
248
|
+
response.data="> configshow |grep -i -E ^alias.ivls01n\nalias.ivls01n0_1:50:02:26:40:8F:DC:20:00\nalias.ivls01n1_1:50:02:26:40:8F:DC:20:01\nalias.ivls01n2_1:50:02:26:40:8F:DC:20:02\nalias.ivls01n3_1:50:02:26:40:8F:DC:20:03\nalias.ivls01n4_1:50:02:26:40:8F:DC:20:04\nalias.ivls01n5_1:50:02:26:40:8F:DC:20:05"
|
249
|
+
|
250
|
+
@device.stub :query, response do
|
251
|
+
a=@device.find_aliases("ivls01n")
|
252
|
+
assert_equal ["ivls01n0_1","ivls01n1_1","ivls01n2_1","ivls01n3_1","ivls01n4_1","ivls01n5_1"], a.map {|al| al.name }
|
253
|
+
assert_equal [["50:02:26:40:8F:DC:20:00"],["50:02:26:40:8F:DC:20:01"],["50:02:26:40:8F:DC:20:02"],["50:02:26:40:8F:DC:20:03"],["50:02:26:40:8F:DC:20:04"],["50:02:26:40:8F:DC:20:05"]], a.map {|al| al.members }
|
254
|
+
end
|
255
|
+
|
256
|
+
response.data="> configshow |grep -i -E alias.unknown:"
|
257
|
+
|
258
|
+
@device.stub :query, response do
|
259
|
+
a=@device.find_aliases("unknown")
|
260
|
+
assert_equal [], a
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_find_by_member
|
265
|
+
response=new_mock_response
|
266
|
+
|
267
|
+
# find owners of zone
|
268
|
+
response.data="> configshow |grep -i -E \"^zone|alias|cfg\.\" | grep -i -E \"(:|;)zone_a(;|$)\""
|
269
|
+
response.data<<"\n"
|
270
|
+
response.data<<"cfg.ecs_a:zone_a;zone_b;zone_c\n"
|
271
|
+
|
272
|
+
|
273
|
+
@device.stub :query, response do
|
274
|
+
owners=@device.find_by_member("zone_a")
|
275
|
+
assert_equal "ecs_a", owners[0].name
|
276
|
+
owners=@device.find_by_member("zone_b")
|
277
|
+
assert_equal "ecs_a", owners[0].name
|
278
|
+
owners=@device.find_by_member("zone_c")
|
279
|
+
assert_equal "ecs_a", owners[0].name
|
280
|
+
owners=@device.find_by_member("zone_d")
|
281
|
+
end
|
282
|
+
|
283
|
+
# cannot find anything
|
284
|
+
response.data="> configshow |grep -i -E \"^zone|alias|cfg\.\" | grep -i -E \"(:|;)zone_a(;|$)\""
|
285
|
+
response.data<<"\n"
|
286
|
+
response.data<<"\n"
|
287
|
+
|
288
|
+
@device.stub :query, response do
|
289
|
+
owners=@device.find_by_member("zone_a")
|
290
|
+
assert_empty owners
|
291
|
+
end
|
292
|
+
|
293
|
+
# find owners of wwn
|
294
|
+
response.data="> configshow |grep -i -E \"^zone|alias|cfg\.\" | grep -i -E \"(:|;)50:00:01:02:03:04:05:06(;|$)\""
|
295
|
+
response.data<<"\n"
|
296
|
+
response.data<<"zone.zone_a:50:00:01:02:03:04:05:06;50:00:01:02:03:04:06:06;50:00:01:02:03:04:06:07\n"
|
297
|
+
response.data<<"alias.alias_a:50:00:01:02:03:04:06:05;50:00:01:02:03:04:06:06;50:00:01:02:03:04:06:07\n"
|
298
|
+
|
299
|
+
@device.stub :query, response do
|
300
|
+
owners=@device.find_by_member("50:00:01:02:03:04:05:06")
|
301
|
+
assert_equal 2, owners.size
|
302
|
+
assert_instance_of Zone, owners[0]
|
303
|
+
assert_instance_of Alias, owners[1]
|
304
|
+
end
|
305
|
+
|
306
|
+
# test transaction => true
|
307
|
+
@output_dir=File.join(Dir.pwd,"test","outputs")
|
308
|
+
read_all_starting_with "cfgshow_2" do |file,output|
|
309
|
+
z1 = Zone.new("zone1")
|
310
|
+
z1.add_member "alias1"
|
311
|
+
z1.add_member "alias2"
|
312
|
+
|
313
|
+
z2 = Zone.new("zone2")
|
314
|
+
z2.add_member "alias1"
|
315
|
+
z2.add_member "alias3"
|
316
|
+
|
317
|
+
z3 = Zone.new("zone3")
|
318
|
+
z3.add_member "alias3"
|
319
|
+
z3.add_member "alias4"
|
320
|
+
|
321
|
+
z5 = Zone.new("zone5")
|
322
|
+
z5.add_member "alias1"
|
323
|
+
z5.add_member "alias4"
|
324
|
+
|
325
|
+
response.data=output.dup
|
326
|
+
@device.stub :query, response do
|
327
|
+
zones = @device.find_by_member("alias2",:object=>:all, :transaction => true)
|
328
|
+
assert_equal z1.name, zones[0].name
|
329
|
+
assert_equal z1.members, zones[0].members
|
330
|
+
end
|
331
|
+
response.data=output.dup
|
332
|
+
@device.stub :query, response do
|
333
|
+
zones = @device.find_by_member("alias1",:object=>:all, :transaction => true)
|
334
|
+
assert_equal 3, zones.size
|
335
|
+
assert_equal z1.name, zones[0].name
|
336
|
+
assert_equal z1.members, zones[0].members
|
337
|
+
assert_equal z2.name, zones[1].name
|
338
|
+
assert_equal z2.members, zones[1].members
|
339
|
+
assert_equal z5.name, zones[2].name
|
340
|
+
assert_equal z5.members, zones[2].members
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
@device.query_stub do
|
345
|
+
@device.stub :old_query, response do
|
346
|
+
# no parameters -> :exact and :all
|
347
|
+
@device.find_by_member("test")
|
348
|
+
assert_equal "configshow | grep -i -E \"^zone|alias|cfg.\" | grep -i -E \"(:|;)test(;|$)\"",@device.instance_variable_get(:@query_string)
|
349
|
+
@device.instance_variable_set(:@query_string,"")
|
350
|
+
# find zone
|
351
|
+
@device.find_by_member("test", :object => :zone)
|
352
|
+
assert_equal "configshow | grep -i -E \"^zone.\" | grep -i -E \"(:|;)test(;|$)\"",@device.instance_variable_get(:@query_string)
|
353
|
+
@device.instance_variable_set(:@query_string,"")
|
354
|
+
# find alias
|
355
|
+
@device.find_by_member("test", :object => :alias)
|
356
|
+
assert_equal "configshow | grep -i -E \"^alias.\" | grep -i -E \"(:|;)test(;|$)\"",@device.instance_variable_get(:@query_string)
|
357
|
+
@device.instance_variable_set(:@query_string,"")
|
358
|
+
#find partial
|
359
|
+
@device.find_by_member("test", :find_mode => :partial)
|
360
|
+
assert_equal "configshow | grep -i -E \"^zone|alias|cfg.\" | grep -i -E \":.*test\"",@device.instance_variable_get(:@query_string)
|
361
|
+
@device.instance_variable_set(:@query_string,"")
|
362
|
+
#find by partial and zone
|
363
|
+
@device.find_by_member("test", :find_mode => :partial, :object=>:zone)
|
364
|
+
assert_equal "configshow | grep -i -E \"^zone.\" | grep -i -E \":.*test\"",@device.instance_variable_get(:@query_string)
|
365
|
+
@device.instance_variable_set(:@query_string,"")
|
366
|
+
@device.find_by_member("test", :transaction => true)
|
367
|
+
assert_equal "cfgshow",@device.instance_variable_get(:@query_string)
|
368
|
+
@device.instance_variable_set(:@query_string,"")
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_wwns
|
374
|
+
@output_dir=File.join(Dir.pwd,"test","outputs")
|
375
|
+
read_all_starting_with "ns_" do |file,output|
|
376
|
+
response=new_mock_response
|
377
|
+
response.data=output
|
378
|
+
init_dev
|
379
|
+
yaml=read_yaml_for(file)
|
380
|
+
@device.stub :query, response do
|
381
|
+
wwns=@device.wwns.map {|w| w.value}
|
382
|
+
yaml[:wwn_local].each do |wwn|
|
383
|
+
assert wwns.include?(wwn[:value]), "WWN #{wwn} is not included in #{wwns.inspect}"
|
384
|
+
end
|
385
|
+
wwns=@device.wwns(false,:cached).map {|w| w.value}
|
386
|
+
yaml[:wwn_remote].each do |wwn|
|
387
|
+
assert wwns.include?(wwn[:value]), "WWN #{wwn} is not included in #{wwns.inspect}"
|
388
|
+
end
|
389
|
+
wwns=@device.wwns(false,:all).map {|w| w.value}
|
390
|
+
yaml[:wwn_local].each do |wwn|
|
391
|
+
assert wwns.include?(wwn[:value]), "WWN #{wwn} is not included in #{wwns.inspect}"
|
392
|
+
end
|
393
|
+
yaml[:wwn_remote].each do |wwn|
|
394
|
+
assert wwns.include?(wwn[:value]), "WWN #{wwn} is not included in #{wwns.inspect}"
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
def test_find_wwn
|
401
|
+
@output_dir=File.join(Dir.pwd,"test","outputs")
|
402
|
+
read_all_starting_with "ns_1" do |file,output|
|
403
|
+
response=new_mock_response
|
404
|
+
response.data=output
|
405
|
+
init_dev
|
406
|
+
yaml=read_yaml_for(file)
|
407
|
+
@device.stub :query, response do
|
408
|
+
|
409
|
+
# test find wwn
|
410
|
+
yaml[:wwn_local].each do |wwn|
|
411
|
+
w=@device.find_wwn(wwn[:value])
|
412
|
+
assert_equal wwn[:value], w.value
|
413
|
+
|
414
|
+
# test insensitive
|
415
|
+
w=@device.find_wwn(wwn[:value].upcase)
|
416
|
+
assert_equal wwn[:value], w.value
|
417
|
+
end
|
418
|
+
|
419
|
+
yaml[:wwn_remote].each do |wwn|
|
420
|
+
w=@device.find_wwn(wwn[:value],true,:fabric_wide=>true)
|
421
|
+
assert_equal wwn[:value], w.value
|
422
|
+
|
423
|
+
# test insensitive
|
424
|
+
w=@device.find_wwn(wwn[:value].upcase,true,:fabric_wide=>true)
|
425
|
+
assert_equal wwn[:value], w.value
|
426
|
+
end
|
427
|
+
|
428
|
+
assert_nil @device.find_wwn("unknown")
|
429
|
+
end
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_fabric
|
434
|
+
@output_dir=File.join(Dir.pwd,"test","outputs")
|
435
|
+
read_all_starting_with "fabricshow_" do |file,output|
|
436
|
+
response=new_mock_response
|
437
|
+
response.data=output
|
438
|
+
init_dev
|
439
|
+
yaml=read_yaml_for(file)
|
440
|
+
@device.stub :query, response do
|
441
|
+
|
442
|
+
assert_equal yaml[:fabric], @device.fabric
|
443
|
+
# clear configuration
|
444
|
+
@device.instance_variable_set(:@configuration,{})
|
445
|
+
assert_nil @device.fabric #nil if not reloaded
|
446
|
+
assert_equal yaml[:fabric], @device.fabric(true) # ok if reloaded
|
447
|
+
|
448
|
+
assert @device.instance_variable_get(:@loaded)[:fabricshow], "Should be true"
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
end
|
454
|
+
|
455
|
+
class SwitchResponseTest < MiniTest::Test
|
456
|
+
include OutputReader
|
457
|
+
|
458
|
+
def test_parse
|
459
|
+
@output_dir=File.join(Dir.pwd,"test","outputs")
|
460
|
+
read_all_starting_with "" do |file, output|
|
461
|
+
response=new_mock_response
|
462
|
+
response.data=output
|
463
|
+
response.parse
|
464
|
+
assert_equal read_yaml_for(file), response.parsed
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
def test_after_before_parse
|
469
|
+
response=new_mock_response
|
470
|
+
response.parsed[:ports]=["A","B","A"]
|
471
|
+
response.parse
|
472
|
+
assert_equal nil, response.parsed[:ports]
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
end; end
|