knife-lpar 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/CODEOWNERS +3 -0
- data/.github/ISSUE_TEMPLATE.md +21 -0
- data/.gitignore +27 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +26 -0
- data/LICENSE +201 -0
- data/README.md +97 -0
- data/Rakefile +35 -0
- data/knife-lpar.gemspec +22 -0
- data/lib/chef/knife/lpar_base.rb +57 -0
- data/lib/chef/knife/lpar_create.rb +247 -0
- data/lib/chef/knife/lpar_delete.rb +168 -0
- data/lib/chef/knife/lpar_list.rb +90 -0
- data/lib/knife-lpar/version.rb +5 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/lpar_base_spec.rb +58 -0
- data/spec/unit/lpar_create_spec.rb +197 -0
- data/spec/unit/lpar_delete_spec.rb +140 -0
- data/spec/unit/lpar_list_spec.rb +87 -0
- metadata +84 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Julian C. Dunn (<jdunn@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2014-2016 Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require "chef/knife"
|
20
|
+
require "chef/knife/lpar_base"
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class LparList < Knife
|
25
|
+
include Chef::Knife::LparBase
|
26
|
+
|
27
|
+
banner "knife lpar list HMC [options]"
|
28
|
+
|
29
|
+
option :virtual_server,
|
30
|
+
:short => "-v SERVER",
|
31
|
+
:long => "--virtual-server",
|
32
|
+
:description => "Virtual Server Name"
|
33
|
+
|
34
|
+
option :help,
|
35
|
+
:long => "--help",
|
36
|
+
:description => "Prints this menu"
|
37
|
+
|
38
|
+
#
|
39
|
+
# Run the plugin
|
40
|
+
#
|
41
|
+
def run
|
42
|
+
read_and_validate_params
|
43
|
+
@password = get_password
|
44
|
+
list_lpars
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
#
|
50
|
+
# Reads the input parameters and validates them.
|
51
|
+
# Will exit if it encounters an error
|
52
|
+
#
|
53
|
+
def read_and_validate_params
|
54
|
+
if @name_args.length < 1
|
55
|
+
show_usage
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
|
59
|
+
if config[:virtual_server].nil?
|
60
|
+
show_usage
|
61
|
+
exit 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def list_lpars
|
66
|
+
lpar_list = [
|
67
|
+
ui.color("LPAR ID", :bold),
|
68
|
+
ui.color("Type", :bold),
|
69
|
+
ui.color("Name", :bold),
|
70
|
+
ui.color("OS Version", :bold),
|
71
|
+
].flatten.compact
|
72
|
+
|
73
|
+
output_column_count = lpar_list.length
|
74
|
+
|
75
|
+
Net::SSH.start(@name_args[0], "hscroot", :password => @password) do |ssh|
|
76
|
+
|
77
|
+
command = "lssyscfg -m #{config[:virtual_server]} -F lpar_id,lpar_env,name,os_version -r lpar"
|
78
|
+
output = run_remote_command(ssh, command)
|
79
|
+
output.each_line do |lpar|
|
80
|
+
lpar.split(",").each do |field|
|
81
|
+
lpar_list << field.chomp
|
82
|
+
end
|
83
|
+
end
|
84
|
+
puts "\n"
|
85
|
+
puts ui.list(lpar_list, :uneven_columns_across, output_column_count)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014-2016 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
RSpec.configure do |c|
|
19
|
+
|
20
|
+
c.expect_with :rspec do |config|
|
21
|
+
config.syntax = [:should, :expect]
|
22
|
+
end
|
23
|
+
c.filter_run :focus => true
|
24
|
+
c.run_all_when_everything_filtered = true
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014-2016 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
require "chef/knife/lpar_base.rb"
|
20
|
+
|
21
|
+
describe Chef::Knife::LparBase do
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class DummyClass < Knife
|
25
|
+
include Knife::LparBase
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
subject(:dummy) do
|
31
|
+
Chef::Knife::DummyClass.new
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#print_with_output" do
|
35
|
+
it "should print the message when there is no extra output" do
|
36
|
+
expect(dummy.ui).to receive(:info).with("Message")
|
37
|
+
return_val = dummy.print_with_output("Message", nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should concatenate output to the message" do
|
41
|
+
expect(dummy.ui).to receive(:info).with("Message - with some output and whatnot")
|
42
|
+
return_val = dummy.print_with_output("Message", "with some output and whatnot")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#run_remote_command" do
|
47
|
+
before(:each) do
|
48
|
+
@session = double(Net::SSH)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Not sure how to do the stdout part
|
52
|
+
it "should return a value in :stdout" do
|
53
|
+
expect(dummy).to receive(:run_remote_command).and_call_original
|
54
|
+
expect(@session).to receive(:exec!).with("TestCommand")
|
55
|
+
dummy.run_remote_command(@session, "TestCommand")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014-2016 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
require "chef/knife/lpar_create.rb"
|
20
|
+
|
21
|
+
describe Chef::Knife::LparCreate do
|
22
|
+
|
23
|
+
subject(:knife) do
|
24
|
+
Chef::Knife::LparCreate.new(argv).tap do |c|
|
25
|
+
allow(c).to receive(:output).and_return(true)
|
26
|
+
c.parse_options(argv)
|
27
|
+
c.merge_configs
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#run" do
|
32
|
+
|
33
|
+
context "by default" do
|
34
|
+
let(:argv) { %w{ create serverurl -n fakename --vios fakevios --virtual-server fakevirt --disk fakedisk -p fakeprof } }
|
35
|
+
|
36
|
+
it "parses argv, gets password, and creates lpar" do
|
37
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
38
|
+
expect(knife).to receive(:get_password)
|
39
|
+
expect(knife).to receive(:create_lpar)
|
40
|
+
knife.run
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#read_and_validate_params" do
|
47
|
+
|
48
|
+
context "when argv is empty" do
|
49
|
+
let(:argv) { [] }
|
50
|
+
|
51
|
+
it "prints usage and exits" do
|
52
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
53
|
+
expect(knife).to receive(:show_usage)
|
54
|
+
expect { knife.run }.to raise_error(SystemExit)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the name parameter is missing" do
|
59
|
+
let(:argv) { %w{ create serverurl --vios fakevios --virtual-server fakevirt --disk fakedisk } }
|
60
|
+
|
61
|
+
it "prints usage and exits" do
|
62
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
63
|
+
expect(knife).to receive(:show_usage)
|
64
|
+
expect { knife.run }.to raise_error(SystemExit)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the vios parameter is missing" do
|
69
|
+
let(:argv) { %w{ create serverurl -n fakename --virtual-server fakevirt --disk fakedisk } }
|
70
|
+
|
71
|
+
it "prints usage and exits" do
|
72
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
73
|
+
expect(knife).to receive(:show_usage)
|
74
|
+
expect { knife.run }.to raise_error(SystemExit)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when the virtual-server parameter is missing" do
|
79
|
+
let(:argv) { %w{ create serverurl -n fakename --vios fakevios --disk fakedisk } }
|
80
|
+
|
81
|
+
it "prints usage and exits" do
|
82
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
83
|
+
expect(knife).to receive(:show_usage)
|
84
|
+
expect { knife.run }.to raise_error(SystemExit)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when the disk parameter is missing" do
|
89
|
+
let(:argv) { %w{ create serverurl -n fakename --vios fakevios --virtual-server fakevirt } }
|
90
|
+
|
91
|
+
it "prints usage and exits" do
|
92
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
93
|
+
expect(knife).to receive(:show_usage)
|
94
|
+
expect { knife.run }.to raise_error(SystemExit)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "by default" do
|
99
|
+
let(:argv) { %w{ create serverurl -n fakename --vios fakevios --virtual-server fakevirt --disk fakedisk -p fakeprof } }
|
100
|
+
|
101
|
+
it "sets defaults" do
|
102
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
103
|
+
expect(knife).to receive(:get_password)
|
104
|
+
expect(knife).to receive(:create_lpar)
|
105
|
+
knife.run
|
106
|
+
expect(knife.config[:profile]).to eq("fakeprof")
|
107
|
+
expect(knife.config[:min_mem]).to eq(1024)
|
108
|
+
expect(knife.config[:desired_mem]).to eq(4096)
|
109
|
+
expect(knife.config[:max_mem]).to eq(16384)
|
110
|
+
expect(knife.config[:min_procs]).to eq(1)
|
111
|
+
expect(knife.config[:desired_procs]).to eq(2)
|
112
|
+
expect(knife.config[:max_procs]).to eq(4)
|
113
|
+
expect(knife.config[:min_proc_units]).to eq(1)
|
114
|
+
expect(knife.config[:desired_proc_units]).to eq(2)
|
115
|
+
expect(knife.config[:max_proc_units]).to eq(4)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "without profile" do
|
120
|
+
let(:argv) { %w{ create serverurl -n fakename --vios fakevios --virtual-server fakevirt --disk fakedisk } }
|
121
|
+
|
122
|
+
it "defaults profile to name" do
|
123
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
124
|
+
expect(knife).to receive(:get_password)
|
125
|
+
expect(knife).to receive(:create_lpar)
|
126
|
+
knife.run
|
127
|
+
expect(knife.config[:profile]).to eq("fakename")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "#create_lpar" do
|
133
|
+
before(:each) do
|
134
|
+
Chef::Knife::LparCreate.load_deps
|
135
|
+
@session = double(Net::SSH)
|
136
|
+
allow(Net::SSH).to receive(:start).with("serverurl", "hscroot", :password => "testpass").and_yield(@session)
|
137
|
+
end
|
138
|
+
|
139
|
+
context "with an existing lpar name" do
|
140
|
+
let(:argv) { %w{ create serverurl -n fakename --vios fakevios --virtual-server fakevirt --disk fakedisk -p fakeprof} }
|
141
|
+
|
142
|
+
it "returns with an error since the lpar already exists" do
|
143
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
144
|
+
expect(knife).to receive(:get_password).and_return("testpass")
|
145
|
+
expect(knife).to receive(:create_lpar).and_call_original
|
146
|
+
|
147
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt -F name -r lpar | grep fakename").and_return("fakename")
|
148
|
+
expect(knife.ui).to receive(:fatal)
|
149
|
+
expect { knife.run }.to raise_error(SystemExit)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "with defaults" do
|
154
|
+
let(:argv) { %w{ create serverurl -n fakename --vios fakevios --virtual-server fakevirt --disk fakedisk -p fakeprof} }
|
155
|
+
|
156
|
+
it "does things" do
|
157
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
158
|
+
expect(knife).to receive(:get_password).and_return("testpass")
|
159
|
+
expect(knife).to receive(:create_lpar).and_call_original
|
160
|
+
|
161
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt -F name -r lpar | grep fakename").and_return(nil)
|
162
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"lsdev -type disk -virtual -field name\" | tail -1").and_return("fakevscsi1")
|
163
|
+
# this is real type of data it returns, deal with it :)
|
164
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"lsdev -dev fakevscsi1 -field physloc -fmt \\\":\\\"\"").and_return("U8231.E1D.06A398T-V2-C108-L1")
|
165
|
+
expect(knife).to receive(:run_remote_command).with(@session, "mksyscfg -m fakevirt -r lpar \
|
166
|
+
-i \"name=fakename, \
|
167
|
+
profile_name=fakeprof, \
|
168
|
+
lpar_env=aixlinux, \
|
169
|
+
min_mem=1024, \
|
170
|
+
desired_mem=4096, \
|
171
|
+
max_mem=16384, \
|
172
|
+
proc_mode=shared, \
|
173
|
+
min_procs=1, \
|
174
|
+
desired_procs=2, \
|
175
|
+
max_procs=4, \
|
176
|
+
min_proc_units=1, \
|
177
|
+
desired_proc_units=2, \
|
178
|
+
max_proc_units=4, \
|
179
|
+
sharing_mode=uncap, uncap_weight=128, \
|
180
|
+
boot_mode=norm, max_virtual_slots=10, \
|
181
|
+
\\\"virtual_eth_adapters=3/0/1//0/0\\\", \
|
182
|
+
\\\"virtual_scsi_adapters=2/client//fakevios/109/1\\\"\"")
|
183
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt --filter \"lpar_names=fakename\" -F lpar_id -r lpar").and_return("5")
|
184
|
+
expect(knife).to receive(:run_remote_command).with(@session, "chhwres -r virtualio -m fakevirt -o a -p fakevios --rsubtype scsi -s 109 -a \"adapter_type=server, remote_lpar_name=fakename, remote_slot_num=2\"")
|
185
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"mkvdev -fbo -vadapter vhost4\"").and_return("vadapter3")
|
186
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"loadopt -vtd vadapter3 -disk fakedisk\"")
|
187
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"mklv -lv fakename rootvg 50G\"")
|
188
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"mkvdev -vdev fakename -vadapter vhost4\"").and_return("fakevtopt3 Virtual Optical Device")
|
189
|
+
expect(knife).to receive(:run_remote_command).with(@session, "mksyscfg -r prof -m fakevirt -o save -p fakevios -n `lssyscfg -r lpar -m fakevirt --filter \"lpar_names=fakevios\" -F curr_profile` --force")
|
190
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"cfgdev\"")
|
191
|
+
expect(knife).to receive(:run_remote_command).with(@session, "chsysstate -r lpar -m fakevirt -o on -f fakeprof -b sms -n fakename")
|
192
|
+
|
193
|
+
knife.run
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014-2016 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "spec_helper"
|
19
|
+
require "chef/knife/lpar_delete.rb"
|
20
|
+
|
21
|
+
describe Chef::Knife::LparDelete do
|
22
|
+
|
23
|
+
subject(:knife) do
|
24
|
+
Chef::Knife::LparDelete.new(argv).tap do |c|
|
25
|
+
allow(c).to receive(:output).and_return(true)
|
26
|
+
c.parse_options(argv)
|
27
|
+
c.merge_configs
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#run" do
|
32
|
+
context "by default" do
|
33
|
+
let(:argv) { %w{ delete serverurl -n fakename --vios fakevios --virtual-server fakevirt } }
|
34
|
+
|
35
|
+
it "parses argv, gets password, and deletes lpar" do
|
36
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
37
|
+
expect(knife).to receive(:get_password)
|
38
|
+
expect(knife).to receive(:delete_lpar)
|
39
|
+
knife.run
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#read_and_validate_params" do
|
45
|
+
context "when argv is empty" do
|
46
|
+
let(:argv) { [] }
|
47
|
+
|
48
|
+
it "prints usage and exits" do
|
49
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
50
|
+
expect(knife).to receive(:show_usage)
|
51
|
+
expect { knife.run }.to raise_error(SystemExit)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when the name parameter is missing" do
|
56
|
+
let(:argv) { %w{ delete serverurl --vios fakevios --virtual-server fakevirt } }
|
57
|
+
|
58
|
+
it "prints usage and exits" do
|
59
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
60
|
+
expect(knife).to receive(:show_usage)
|
61
|
+
expect { knife.run }.to raise_error(SystemExit)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when the vios parameter is missing" do
|
66
|
+
let(:argv) { %w{ delete serverurl -n fakename --virtual-server fakevirt } }
|
67
|
+
|
68
|
+
it "prints usage and exits" do
|
69
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
70
|
+
expect(knife).to receive(:show_usage)
|
71
|
+
expect { knife.run }.to raise_error(SystemExit)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when the virtual-server parameter is missing" do
|
76
|
+
let(:argv) { %w{ delete serverurl -n fakename --vios fakevios } }
|
77
|
+
|
78
|
+
it "prints usage and exits" do
|
79
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
80
|
+
expect(knife).to receive(:show_usage)
|
81
|
+
expect { knife.run }.to raise_error(SystemExit)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#delete_lpar" do
|
87
|
+
before(:each) do
|
88
|
+
Chef::Knife::LparDelete.load_deps
|
89
|
+
@session = double(Net::SSH)
|
90
|
+
allow(Net::SSH).to receive(:start).with("serverurl", "hscroot", :password => "testpass").and_yield(@session)
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when lpar does not exist" do
|
94
|
+
let(:argv) { %w{ delete serverurl -n fakename --vios fakevios --virtual-server fakevirt } }
|
95
|
+
|
96
|
+
it "returns with an error since the lpar does not exist" do
|
97
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
98
|
+
expect(knife).to receive(:get_password).and_return("testpass")
|
99
|
+
expect(knife).to receive(:delete_lpar).and_call_original
|
100
|
+
|
101
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt -F name -r lpar --filter \"lpar_names=fakename\"").and_return(nil)
|
102
|
+
expect(knife.ui).to receive(:fatal)
|
103
|
+
expect { knife.run }.to raise_error(SystemExit)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns with an error since the lpar exists but is not activated/running" do
|
107
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
108
|
+
expect(knife).to receive(:get_password).and_return("testpass")
|
109
|
+
expect(knife).to receive(:delete_lpar).and_call_original
|
110
|
+
|
111
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt -F name -r lpar --filter \"lpar_names=fakename\"").and_return("fakename")
|
112
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt -F state -r lpar --filter \"lpar_names=fakename\"").and_return("Running")
|
113
|
+
expect(knife.ui).to receive(:fatal)
|
114
|
+
expect { knife.run }.to raise_error(SystemExit)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "does things" do
|
118
|
+
expect(knife).to receive(:read_and_validate_params).and_call_original
|
119
|
+
expect(knife).to receive(:get_password).and_return("testpass")
|
120
|
+
expect(knife).to receive(:delete_lpar).and_call_original
|
121
|
+
|
122
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt -F name -r lpar --filter \"lpar_names=fakename\"").and_return("fakename")
|
123
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt -F state -r lpar --filter \"lpar_names=fakename\"").and_return("Not Activated")
|
124
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt --filter \"lpar_names=fakename\" -F lpar_id -r lpar").and_return(8)
|
125
|
+
expect(knife).to receive(:run_remote_command).with(@session, "lssyscfg -m fakevirt -r prof --filter \"lpar_names=fakename\" -F virtual_scsi_adapters").and_return("2/client/2/fakevirt/106/1")
|
126
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"lsmap -vadapter vhost7 -type file_opt -field vtd -fmt \\\":\\\"\"").and_return("vtopt4")
|
127
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"lsmap -vadapter vhost7 -type lv -field vtd -fmt \\\":\\\"\"").and_return("vtscsi3")
|
128
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"lsmap -vadapter vhost7 -type lv -field backing -fmt \\\":\\\"\"").and_return("backingdevice")
|
129
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"rmvdev -vtd vtopt4\"")
|
130
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"rmvdev -vtd vtscsi3\"")
|
131
|
+
expect(knife).to receive(:run_remote_command).with(@session, "viosvrcmd -m fakevirt -p fakevios -c \"rmlv -f backingdevice\"")
|
132
|
+
expect(knife).to receive(:run_remote_command).with(@session, "chhwres -r virtualio -m fakevirt -o r -p fakevios --rsubtype scsi -s 106")
|
133
|
+
expect(knife).to receive(:run_remote_command).with(@session, "mksyscfg -r prof -m fakevirt -o save -p fakevios -n `lssyscfg -r lpar -m fakevirt --filter \"lpar_names=fakevios\" -F curr_profile` --force")
|
134
|
+
expect(knife).to receive(:run_remote_command).with(@session, "rmsyscfg -r lpar -m fakevirt -n fakename")
|
135
|
+
|
136
|
+
knife.run
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|