fission 0.4.0 → 0.5.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +12 -3
- data/README.md +45 -19
- data/bin/fission +1 -1
- data/fission.gemspec +3 -2
- data/lib/fission.rb +15 -0
- data/lib/fission/action/shell_executor.rb +37 -0
- data/lib/fission/action/snapshot/creator.rb +81 -0
- data/lib/fission/action/snapshot/deleter.rb +85 -0
- data/lib/fission/action/snapshot/lister.rb +90 -0
- data/lib/fission/action/snapshot/reverter.rb +81 -0
- data/lib/fission/action/vm/cloner.rb +191 -0
- data/lib/fission/action/vm/deleter.rb +73 -0
- data/lib/fission/action/vm/lister.rb +138 -0
- data/lib/fission/action/vm/starter.rb +88 -0
- data/lib/fission/action/vm/stopper.rb +79 -0
- data/lib/fission/action/vm/suspender.rb +68 -0
- data/lib/fission/cli.rb +21 -117
- data/lib/fission/command.rb +39 -0
- data/lib/fission/command/clone.rb +11 -6
- data/lib/fission/command/delete.rb +11 -6
- data/lib/fission/command/info.rb +62 -0
- data/lib/fission/command/snapshot_create.rb +9 -3
- data/lib/fission/command/snapshot_delete.rb +38 -0
- data/lib/fission/command/snapshot_list.rb +9 -3
- data/lib/fission/command/snapshot_revert.rb +9 -3
- data/lib/fission/command/start.rb +11 -6
- data/lib/fission/command/status.rb +9 -1
- data/lib/fission/command/stop.rb +9 -3
- data/lib/fission/command/suspend.rb +11 -6
- data/lib/fission/command_helpers.rb +18 -4
- data/lib/fission/command_line_parser.rb +189 -0
- data/lib/fission/config.rb +1 -1
- data/lib/fission/fusion.rb +3 -4
- data/lib/fission/lease.rb +2 -1
- data/lib/fission/metadata.rb +6 -1
- data/lib/fission/response.rb +17 -9
- data/lib/fission/version.rb +1 -1
- data/lib/fission/vm.rb +142 -382
- data/lib/fission/vm_configuration.rb +79 -0
- data/spec/fission/action/execute_shell_command_spec.rb +25 -0
- data/spec/fission/action/snapshot/creator_spec.rb +77 -0
- data/spec/fission/action/snapshot/deleter_spec.rb +84 -0
- data/spec/fission/action/snapshot/lister_spec.rb +67 -0
- data/spec/fission/action/snapshot/reverter_spec.rb +76 -0
- data/spec/fission/action/vm/cloner_spec.rb +198 -0
- data/spec/fission/action/vm/deleter_spec.rb +79 -0
- data/spec/fission/action/vm/lister_spec.rb +164 -0
- data/spec/fission/action/vm/starter_spec.rb +88 -0
- data/spec/fission/action/vm/stopper_spec.rb +71 -0
- data/spec/fission/action/vm/suspender_spec.rb +59 -0
- data/spec/fission/cli_spec.rb +32 -157
- data/spec/fission/command/clone_spec.rb +9 -3
- data/spec/fission/command/delete_spec.rb +11 -3
- data/spec/fission/command/info_spec.rb +130 -0
- data/spec/fission/command/snapshot_create_spec.rb +11 -3
- data/spec/fission/command/snapshot_delete_spec.rb +74 -0
- data/spec/fission/command/snapshot_list_spec.rb +11 -3
- data/spec/fission/command/snapshot_revert_spec.rb +11 -3
- data/spec/fission/command/start_spec.rb +11 -3
- data/spec/fission/command/status_spec.rb +16 -5
- data/spec/fission/command/stop_spec.rb +11 -3
- data/spec/fission/command/suspend_spec.rb +11 -3
- data/spec/fission/command_helpers_spec.rb +27 -5
- data/spec/fission/command_line_parser_spec.rb +267 -0
- data/spec/fission/command_spec.rb +16 -1
- data/spec/fission/config_spec.rb +3 -3
- data/spec/fission/fusion_spec.rb +11 -6
- data/spec/fission/lease_spec.rb +81 -45
- data/spec/fission/metadata_spec.rb +29 -6
- data/spec/fission/response_spec.rb +20 -9
- data/spec/fission/ui_spec.rb +1 -1
- data/spec/fission/vm_configuration_spec.rb +132 -0
- data/spec/fission/vm_spec.rb +393 -750
- data/spec/helpers/command_helpers.rb +1 -1
- metadata +93 -15
- data/.rvmrc +0 -1
data/spec/fission/cli_spec.rb
CHANGED
@@ -1,175 +1,50 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Fission::CLI do
|
4
4
|
before do
|
5
5
|
@string_io = StringIO.new
|
6
|
-
Fission::CLI.stub
|
6
|
+
Fission::CLI.any_instance.stub(:ui).and_return(Fission::UI.new(@string_io))
|
7
|
+
@parser = mock 'parser'
|
8
|
+
@parser.stub :parse
|
9
|
+
@parser.stub :command
|
7
10
|
end
|
8
11
|
|
9
|
-
describe '
|
10
|
-
it 'should
|
11
|
-
Fission::
|
12
|
-
|
13
|
-
'start', 'status', 'stop', 'suspend']
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'execute' do
|
18
|
-
describe 'with no arguments' do
|
19
|
-
it 'should output the usage info' do
|
20
|
-
lambda { Fission::CLI.execute [] }.should raise_error SystemExit
|
12
|
+
describe 'initialize' do
|
13
|
+
it 'should create a parse object using ARGV' do
|
14
|
+
Fission::CommandLineParser.should_receive(:new).with(ARGV).
|
15
|
+
and_return(@parser)
|
21
16
|
|
22
|
-
|
23
|
-
end
|
17
|
+
Fission::CLI.new
|
24
18
|
end
|
25
19
|
|
26
|
-
|
27
|
-
['
|
28
|
-
|
29
|
-
lambda { Fission::CLI.execute [arg] }.should raise_error SystemExit
|
30
|
-
|
31
|
-
@string_io.string.should match /#{Fission::VERSION}/
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
20
|
+
it 'should create a parse object with the provided args' do
|
21
|
+
Fission::CommandLineParser.should_receive(:new).with(['foo']).
|
22
|
+
and_return(@parser)
|
35
23
|
|
36
|
-
|
37
|
-
['-h', '--help'].each do |arg|
|
38
|
-
it "should output the usage info with #{arg}" do
|
39
|
-
lambda { Fission::CLI.execute [arg] }.should raise_error SystemExit
|
24
|
+
Fission::CLI.new ['foo']
|
40
25
|
|
41
|
-
@string_io.string.should match /Usage/
|
42
|
-
end
|
43
|
-
end
|
44
26
|
end
|
45
27
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
describe 'clone' do
|
53
|
-
it "should try to clone the vm" do
|
54
|
-
Fission::Command::Clone.stub!(:help).and_return('')
|
55
|
-
Fission::Command::Clone.should_receive(:new).with(['foo', 'bar']).
|
56
|
-
and_return(@cmd_mock)
|
57
|
-
Fission::CLI.execute ['clone', 'foo', 'bar']
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should try to clone the vm and start it' do
|
61
|
-
Fission::Command::Clone.stub!(:help).and_return('')
|
62
|
-
Fission::Command::Clone.should_receive(:new).with(['foo', 'bar', '--start']).
|
63
|
-
and_return(@cmd_mock)
|
64
|
-
Fission::CLI.execute ['clone', 'foo', 'bar', '--start']
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'snapshot create' do
|
69
|
-
it "should create a snapshot" do
|
70
|
-
Fission::Command::SnapshotCreate.stub!(:help).and_return('')
|
71
|
-
Fission::Command::SnapshotCreate.should_receive(:new).
|
72
|
-
with(['foo', 'snap1']).
|
73
|
-
and_return(@cmd_mock)
|
74
|
-
Fission::CLI.execute ['snapshot', 'create', 'foo', 'snap1']
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe 'snapshot list' do
|
79
|
-
it "should list the snapshots" do
|
80
|
-
Fission::Command::SnapshotList.stub!(:help).and_return('')
|
81
|
-
Fission::Command::SnapshotList.should_receive(:new).
|
82
|
-
with([]).
|
83
|
-
and_return(@cmd_mock)
|
84
|
-
Fission::CLI.execute ['snapshot', 'list']
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe 'snapshot revert' do
|
89
|
-
it "should revert to the snapshots" do
|
90
|
-
Fission::Command::SnapshotRevert.stub!(:help).and_return('')
|
91
|
-
Fission::Command::SnapshotRevert.should_receive(:new).
|
92
|
-
with(['foo', 'snap1']).
|
93
|
-
and_return(@cmd_mock)
|
94
|
-
Fission::CLI.execute ['snapshot', 'revert', 'foo', 'snap1']
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe 'start' do
|
99
|
-
it "should try to start the vm" do
|
100
|
-
Fission::Command::Start.stub!(:help).and_return('')
|
101
|
-
Fission::Command::Start.should_receive(:new).
|
102
|
-
with(['foo']).
|
103
|
-
and_return(@cmd_mock)
|
104
|
-
Fission::CLI.execute ['start', 'foo']
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'should try to start the vm headless' do
|
108
|
-
Fission::Command::Start.stub!(:help).and_return('')
|
109
|
-
Fission::Command::Start.should_receive(:new).
|
110
|
-
with(['foo', '--headless']).
|
111
|
-
and_return(@cmd_mock)
|
112
|
-
Fission::CLI.execute ['start', 'foo', '--headless']
|
113
|
-
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe 'status' do
|
118
|
-
it "should try to get the status for all VMs" do
|
119
|
-
Fission::Command::Status.stub!(:help).and_return('')
|
120
|
-
Fission::Command::Status.should_receive(:new).
|
121
|
-
with([]).
|
122
|
-
and_return(@cmd_mock)
|
123
|
-
Fission::CLI.execute ['status']
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe 'stop' do
|
128
|
-
it "should try to stop the vm" do
|
129
|
-
Fission::Command::Stop.stub!(:help).and_return('')
|
130
|
-
Fission::Command::Stop.should_receive(:new).
|
131
|
-
with(['foo']).
|
132
|
-
and_return(@cmd_mock)
|
133
|
-
Fission::CLI.execute ['stop', 'foo']
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe 'suspend' do
|
138
|
-
it "should try to suspend the vm" do
|
139
|
-
Fission::Command::Suspend.stub!(:help).and_return('')
|
140
|
-
Fission::Command::Suspend.should_receive(:new).
|
141
|
-
with(['foo']).
|
142
|
-
and_return(@cmd_mock)
|
143
|
-
Fission::CLI.execute ['suspend', 'foo']
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'should try to suspend all of vms' do
|
147
|
-
Fission::Command::Suspend.stub!(:help).and_return('')
|
148
|
-
Fission::Command::Suspend.should_receive(:new).
|
149
|
-
with(['--all']).
|
150
|
-
and_return(@cmd_mock)
|
151
|
-
Fission::CLI.execute ['suspend', '--all']
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe 'delete' do
|
156
|
-
it "should try to delete the vm" do
|
157
|
-
Fission::Command::Delete.stub!(:help).and_return('')
|
158
|
-
Fission::Command::Delete.should_receive(:new).
|
159
|
-
with(['foo']).
|
160
|
-
and_return(@cmd_mock)
|
161
|
-
Fission::CLI.execute ['delete', 'foo']
|
162
|
-
end
|
28
|
+
it 'should create a parse object using our parser' do
|
29
|
+
@parser.should_receive(:new).with(ARGV).and_return(@parser)
|
30
|
+
Fission::CLI.new nil, @parser
|
31
|
+
end
|
163
32
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
and_return(@cmd_mock)
|
169
|
-
Fission::CLI.execute ['delete', 'foo', '--force']
|
170
|
-
end
|
171
|
-
end
|
33
|
+
it 'should parse the arguments using the parser' do
|
34
|
+
@parser.should_receive(:new).with(ARGV).and_return(@parser)
|
35
|
+
@parser.should_receive :parse
|
36
|
+
Fission::CLI.new nil, @parser
|
172
37
|
end
|
38
|
+
end
|
173
39
|
|
40
|
+
describe 'execute' do
|
41
|
+
it 'should execute the parsed command' do
|
42
|
+
@cmd_mock = mock ('cmd')
|
43
|
+
@cmd_mock.should_receive :execute
|
44
|
+
@parser.stub(:new).and_return(@parser)
|
45
|
+
@parser.stub(:command).and_return(@cmd_mock)
|
46
|
+
Fission::CLI.new(nil, @parser).execute
|
47
|
+
end
|
174
48
|
end
|
49
|
+
|
175
50
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Fission::Command::Clone do
|
4
4
|
include_context 'command_setup'
|
@@ -20,10 +20,16 @@ describe Fission::Command::Clone do
|
|
20
20
|
and_return(@clone_response_mock)
|
21
21
|
end
|
22
22
|
|
23
|
+
describe 'command_name' do
|
24
|
+
it 'should return the pretty command name' do
|
25
|
+
Fission::Command::Clone.new.command_name.should == 'clone'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
23
29
|
describe 'execute' do
|
24
30
|
subject { Fission::Command::Clone }
|
25
31
|
|
26
|
-
[ [], ['foo'] ].each do |args|
|
32
|
+
[ [], ['foo'], ['--bar'] ].each do |args|
|
27
33
|
it_should_not_accept_arguments_of args, 'clone'
|
28
34
|
end
|
29
35
|
|
@@ -80,7 +86,7 @@ describe Fission::Command::Clone do
|
|
80
86
|
it 'should output info for this command' do
|
81
87
|
output = Fission::Command::Clone.help
|
82
88
|
|
83
|
-
output.should match /clone
|
89
|
+
output.should match /fission clone SOURCE_VM TARGET_VM.+OPTIONS/m
|
84
90
|
end
|
85
91
|
end
|
86
92
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Fission::Command::Delete do
|
4
4
|
include_context 'command_setup'
|
@@ -16,10 +16,18 @@ describe Fission::Command::Delete do
|
|
16
16
|
Fission::Fusion.stub(:running?).and_return(false)
|
17
17
|
end
|
18
18
|
|
19
|
+
describe 'command_name' do
|
20
|
+
it 'should return the pretty command name' do
|
21
|
+
Fission::Command::Delete.new.command_name.should == 'delete'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
19
25
|
describe "execute" do
|
20
26
|
subject { Fission::Command::Delete }
|
21
27
|
|
22
|
-
|
28
|
+
[ [], ['--bar'] ].each do |args|
|
29
|
+
it_should_not_accept_arguments_of args, 'delete'
|
30
|
+
end
|
23
31
|
|
24
32
|
it "should try to delete the vm" do
|
25
33
|
@delete_response_mock.stub_as_successful
|
@@ -115,7 +123,7 @@ describe Fission::Command::Delete do
|
|
115
123
|
it 'should output info for this command' do
|
116
124
|
output = Fission::Command::Delete.help
|
117
125
|
|
118
|
-
output.should match /delete
|
126
|
+
output.should match /fission delete TARGET_VM \[OPTIONS\]/
|
119
127
|
output.should match /--force/
|
120
128
|
end
|
121
129
|
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fission::Command::Info do
|
4
|
+
include_context 'command_setup'
|
5
|
+
|
6
|
+
before do
|
7
|
+
@target_vm = ['foo']
|
8
|
+
Fission::VM.stub!(:new).and_return(@vm_mock)
|
9
|
+
|
10
|
+
@network_info_response_mock = mock('network_info_response')
|
11
|
+
@hardware_info_response_mock = mock('hardware_info_response')
|
12
|
+
@guest_os_response_mock = mock('guest_os_response')
|
13
|
+
|
14
|
+
@vm_mock.stub(:name).and_return(@target_vm.first)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'command_name' do
|
18
|
+
it 'should return the pretty command name' do
|
19
|
+
Fission::Command::Info.new.command_name.should == 'info'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'execute' do
|
24
|
+
before do
|
25
|
+
@vm_mock.stub(:network_info).and_return(@network_info_response_mock)
|
26
|
+
@vm_mock.stub(:hardware_info).and_return(@hardware_info_response_mock)
|
27
|
+
@vm_mock.stub(:guestos).and_return(@guest_os_response_mock)
|
28
|
+
@network_info = { 'ethernet0' => { 'mac_address' => '00:11:22:33:AA:BB',
|
29
|
+
'ip_address' => '192.168.1.10' },
|
30
|
+
'ethernet1' => { 'mac_address' => '00:11:22:33:AA:BB',
|
31
|
+
'ip_address' => '192.168.1.10' } }
|
32
|
+
@hardware_info_response_mock.stub_as_successful Hash.new
|
33
|
+
@network_info_response_mock.stub_as_successful Hash.new
|
34
|
+
@guest_os_response_mock.stub_as_successful 'debian5'
|
35
|
+
end
|
36
|
+
|
37
|
+
subject { Fission::Command::Info }
|
38
|
+
|
39
|
+
[ [], ['--bar'] ].each do |args|
|
40
|
+
it_should_not_accept_arguments_of args, 'info'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should output the vm name' do
|
44
|
+
command = Fission::Command::Info.new @target_vm
|
45
|
+
command.execute
|
46
|
+
|
47
|
+
@string_io.string.should match /foo/
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should output the os' do
|
51
|
+
command = Fission::Command::Info.new @target_vm
|
52
|
+
command.execute
|
53
|
+
|
54
|
+
@string_io.string.should match /os: debian5/
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should output that the os is unknown if applicable' do
|
58
|
+
@guest_os_response_mock.stub_as_successful ''
|
59
|
+
command = Fission::Command::Info.new @target_vm
|
60
|
+
command.execute
|
61
|
+
|
62
|
+
@string_io.string.should match /os: unknown/
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should output an error and exit if there was an error getting the os info' do
|
66
|
+
@guest_os_response_mock.stub_as_unsuccessful
|
67
|
+
|
68
|
+
command = Fission::Command::Info.new @target_vm
|
69
|
+
lambda { command.execute }.should raise_error SystemExit
|
70
|
+
|
71
|
+
@string_io.string.should match /There was an error getting the OS info.+it blew up.+/m
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should output the number of cpus' do
|
75
|
+
hardware_info = { 'cpus' => 2}
|
76
|
+
@hardware_info_response_mock.stub_as_successful hardware_info
|
77
|
+
|
78
|
+
command = Fission::Command::Info.new @target_vm
|
79
|
+
command.execute
|
80
|
+
|
81
|
+
@string_io.string.should match /cpus\: 2/
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should output the amount of memory' do
|
85
|
+
hardware_info = { 'memory' => 2048}
|
86
|
+
@hardware_info_response_mock.stub_as_successful hardware_info
|
87
|
+
|
88
|
+
command = Fission::Command::Info.new @target_vm
|
89
|
+
command.execute
|
90
|
+
|
91
|
+
@string_io.string.should match /memory\: 2048/
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should output an error and exit if there was an error getting the hardware info' do
|
95
|
+
@hardware_info_response_mock.stub_as_unsuccessful
|
96
|
+
|
97
|
+
command = Fission::Command::Info.new @target_vm
|
98
|
+
lambda { command.execute }.should raise_error SystemExit
|
99
|
+
|
100
|
+
@string_io.string.should match /There was an error getting the hardware info.+it blew up.+/m
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should output the network info' do
|
104
|
+
@network_info_response_mock.stub_as_successful @network_info
|
105
|
+
|
106
|
+
command = Fission::Command::Info.new @target_vm
|
107
|
+
command.execute
|
108
|
+
|
109
|
+
@string_io.string.should match /ethernet0 mac address: 00:11:22:33:AA:BB/
|
110
|
+
@string_io.string.should match /ethernet0 ip address: 192\.168\.1\.10/
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should output an error and exit if there was an error getting the network info' do
|
114
|
+
@network_info_response_mock.stub_as_unsuccessful
|
115
|
+
|
116
|
+
command = Fission::Command::Info.new @target_vm
|
117
|
+
lambda { command.execute }.should raise_error SystemExit
|
118
|
+
|
119
|
+
@string_io.string.should match /There was an error getting the network info.+it blew up.+/m
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'help' do
|
124
|
+
it 'should output info for this command' do
|
125
|
+
output = Fission::Command::Info.help
|
126
|
+
|
127
|
+
output.should match /fission info TARGET_VM/
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Fission::Command::SnapshotCreate do
|
4
4
|
include_context 'command_setup'
|
@@ -12,10 +12,18 @@ describe Fission::Command::SnapshotCreate do
|
|
12
12
|
@vm_mock.stub(:name).and_return(@target_vm.first)
|
13
13
|
end
|
14
14
|
|
15
|
+
describe 'command_name' do
|
16
|
+
it 'should return the pretty command name' do
|
17
|
+
Fission::Command::SnapshotCreate.new.command_name.should == 'snapshot create'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
15
21
|
describe 'execute' do
|
16
22
|
subject { Fission::Command::SnapshotCreate }
|
17
23
|
|
18
|
-
|
24
|
+
[ [], ['foo'], ['--bar'] ].each do |args|
|
25
|
+
it_should_not_accept_arguments_of args, 'snapshot create'
|
26
|
+
end
|
19
27
|
|
20
28
|
it "should output an error and the help when no snapshot name is passed in" do
|
21
29
|
Fission::Command::SnapshotCreate.should_receive(:help)
|
@@ -60,7 +68,7 @@ describe Fission::Command::SnapshotCreate do
|
|
60
68
|
it 'should output info for this command' do
|
61
69
|
output = Fission::Command::SnapshotCreate.help
|
62
70
|
|
63
|
-
output.should match /snapshot create
|
71
|
+
output.should match /fission snapshot create TARGET_VM SNAPSHOT_NAME/
|
64
72
|
end
|
65
73
|
end
|
66
74
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fission::Command::SnapshotDelete do
|
4
|
+
include_context 'command_setup'
|
5
|
+
|
6
|
+
before do
|
7
|
+
@target_vm = ['foo']
|
8
|
+
Fission::VM.stub!(:new).and_return(@vm_mock)
|
9
|
+
|
10
|
+
@snap_delete_response_mock = mock('snap_delete_response')
|
11
|
+
|
12
|
+
@vm_mock.stub(:name).and_return(@target_vm.first)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'command_name' do
|
16
|
+
it 'should return the pretty command name' do
|
17
|
+
Fission::Command::SnapshotDelete.new.command_name.should == 'snapshot delete'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'execute' do
|
22
|
+
subject { Fission::Command::SnapshotDelete }
|
23
|
+
|
24
|
+
[ [], ['foo'], ['--bar'] ].each do |args|
|
25
|
+
it_should_not_accept_arguments_of args, 'snapshot delete'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should output an error and the help when no snapshot name is passed in" do
|
29
|
+
Fission::Command::SnapshotDelete.should_receive(:help)
|
30
|
+
|
31
|
+
command = Fission::Command::SnapshotDelete.new @target_vm
|
32
|
+
lambda { command.execute }.should raise_error SystemExit
|
33
|
+
|
34
|
+
@string_io.string.should match /Incorrect arguments for snapshot delete command/
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should delete a new snapshot with the provided name' do
|
38
|
+
@snap_delete_response_mock.stub_as_successful []
|
39
|
+
|
40
|
+
@vm_mock.should_receive(:delete_snapshot).
|
41
|
+
with('snap_1').
|
42
|
+
and_return(@snap_delete_response_mock)
|
43
|
+
|
44
|
+
command = Fission::Command::SnapshotDelete.new @target_vm << 'snap_1'
|
45
|
+
command.execute
|
46
|
+
|
47
|
+
@string_io.string.should match /Deleting snapshot/
|
48
|
+
@string_io.string.should match /Snapshot 'snap_1' deleted/
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should output an error and exit if there was an error creating the snapshot' do
|
52
|
+
@snap_delete_response_mock.stub_as_unsuccessful
|
53
|
+
|
54
|
+
@vm_mock.should_receive(:delete_snapshot).
|
55
|
+
with('snap_1').
|
56
|
+
and_return(@snap_delete_response_mock)
|
57
|
+
|
58
|
+
command = Fission::Command::SnapshotDelete.new @target_vm << 'snap_1'
|
59
|
+
lambda { command.execute }.should raise_error SystemExit
|
60
|
+
|
61
|
+
@string_io.string.should match /Deleting snapshot/
|
62
|
+
@string_io.string.should match /There was an error deleting the snapshot.+it blew up.+/m
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'help' do
|
68
|
+
it 'should output info for this command' do
|
69
|
+
output = Fission::Command::SnapshotDelete.help
|
70
|
+
|
71
|
+
output.should match /fission snapshot delete TARGET_VM SNAPSHOT_NAME/
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|