fission 0.3.0 → 0.4.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/fission.rb +5 -6
- data/lib/fission/cli.rb +77 -7
- data/lib/fission/command.rb +43 -1
- data/lib/fission/command/clone.rb +19 -20
- data/lib/fission/command/delete.rb +29 -25
- data/lib/fission/command/snapshot_create.rb +11 -26
- data/lib/fission/command/snapshot_list.rb +13 -19
- data/lib/fission/command/snapshot_revert.rb +11 -26
- data/lib/fission/command/start.rb +11 -25
- data/lib/fission/command/status.rb +26 -10
- data/lib/fission/command/stop.rb +10 -21
- data/lib/fission/command/suspend.rb +21 -21
- data/lib/fission/command_helpers.rb +21 -0
- data/lib/fission/config.rb +35 -0
- data/lib/fission/fusion.rb +11 -3
- data/lib/fission/lease.rb +148 -0
- data/lib/fission/metadata.rb +55 -2
- data/lib/fission/response.rb +76 -0
- data/lib/fission/ui.rb +49 -0
- data/lib/fission/version.rb +1 -1
- data/lib/fission/vm.rb +653 -75
- data/spec/contexts/command.rb +12 -0
- data/spec/fission/cli_spec.rb +4 -11
- data/spec/fission/command/clone_spec.rb +45 -45
- data/spec/fission/command/delete_spec.rb +56 -43
- data/spec/fission/command/snapshot_create_spec.rb +29 -51
- data/spec/fission/command/snapshot_list_spec.rb +25 -26
- data/spec/fission/command/snapshot_revert_spec.rb +27 -53
- data/spec/fission/command/start_spec.rb +25 -69
- data/spec/fission/command/status_spec.rb +48 -13
- data/spec/fission/command/stop_spec.rb +25 -42
- data/spec/fission/command/suspend_spec.rb +54 -49
- data/spec/fission/command_helpers_spec.rb +30 -0
- data/spec/fission/command_spec.rb +19 -0
- data/spec/fission/config_spec.rb +24 -0
- data/spec/fission/fusion_spec.rb +6 -6
- data/spec/fission/lease_spec.rb +176 -0
- data/spec/fission/metadata_spec.rb +8 -8
- data/spec/fission/response_spec.rb +81 -0
- data/spec/fission/vm_spec.rb +869 -193
- data/spec/fission_spec.rb +0 -6
- data/spec/helpers/command_helpers.rb +12 -0
- data/spec/helpers/response_helpers.rb +21 -0
- data/spec/matchers/be_a_successful_response.rb +7 -0
- data/spec/matchers/be_an_unsuccessful_response.rb +10 -0
- data/spec/spec_helper.rb +7 -0
- metadata +24 -5
@@ -0,0 +1,12 @@
|
|
1
|
+
shared_context 'command_setup' do
|
2
|
+
before do
|
3
|
+
@string_io = StringIO.new
|
4
|
+
ui_stub = Fission::UI.new(@string_io)
|
5
|
+
Fission::UI.stub!(:new).and_return(ui_stub)
|
6
|
+
|
7
|
+
@all_running_response_mock = mock('all_running_response')
|
8
|
+
@state_response_mock = mock('state_response')
|
9
|
+
@vm_mock = mock('vm_mock')
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
data/spec/fission/cli_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../../spec_helper.rb', __FILE__)
|
|
3
3
|
describe Fission::CLI do
|
4
4
|
before do
|
5
5
|
@string_io = StringIO.new
|
6
|
-
Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
|
6
|
+
Fission::CLI.stub!(:ui).and_return(Fission::UI.new(@string_io))
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'self.commands' do
|
@@ -17,9 +17,7 @@ describe Fission::CLI do
|
|
17
17
|
describe 'execute' do
|
18
18
|
describe 'with no arguments' do
|
19
19
|
it 'should output the usage info' do
|
20
|
-
lambda {
|
21
|
-
Fission::CLI.execute []
|
22
|
-
}.should raise_error SystemExit
|
20
|
+
lambda { Fission::CLI.execute [] }.should raise_error SystemExit
|
23
21
|
|
24
22
|
@string_io.string.should match /Usage/
|
25
23
|
end
|
@@ -28,12 +26,9 @@ describe Fission::CLI do
|
|
28
26
|
describe '-v or --version' do
|
29
27
|
['-v', '--version'].each do |arg|
|
30
28
|
it "should output the version with #{arg}" do
|
31
|
-
lambda {
|
32
|
-
Fission::CLI.execute [arg]
|
33
|
-
}.should raise_error SystemExit
|
29
|
+
lambda { Fission::CLI.execute [arg] }.should raise_error SystemExit
|
34
30
|
|
35
31
|
@string_io.string.should match /#{Fission::VERSION}/
|
36
|
-
|
37
32
|
end
|
38
33
|
end
|
39
34
|
end
|
@@ -41,9 +36,7 @@ describe Fission::CLI do
|
|
41
36
|
describe '-h or --help' do
|
42
37
|
['-h', '--help'].each do |arg|
|
43
38
|
it "should output the usage info with #{arg}" do
|
44
|
-
lambda {
|
45
|
-
Fission::CLI.execute [arg]
|
46
|
-
}.should raise_error SystemExit
|
39
|
+
lambda { Fission::CLI.execute [arg] }.should raise_error SystemExit
|
47
40
|
|
48
41
|
@string_io.string.should match /Usage/
|
49
42
|
end
|
@@ -1,76 +1,76 @@
|
|
1
1
|
require File.expand_path('../../../spec_helper.rb', __FILE__)
|
2
2
|
|
3
3
|
describe Fission::Command::Clone do
|
4
|
+
include_context 'command_setup'
|
5
|
+
|
4
6
|
before do
|
5
7
|
@vm_info = ['foo', 'bar']
|
6
|
-
@
|
7
|
-
|
8
|
-
end
|
8
|
+
@source_vm_mock = mock('source_vm')
|
9
|
+
@target_vm_mock = mock('target_vm')
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
it "should output an error and the help when #{args.count} arguments are passed in" do
|
13
|
-
Fission::Command::Clone.should_receive(:help)
|
11
|
+
@clone_response_mock = mock('clone_reponse')
|
12
|
+
@start_response_mock = mock('start_reponse')
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
command.execute
|
18
|
-
}.should raise_error SystemExit
|
19
|
-
|
20
|
-
@string_io.string.should match /Incorrect arguments for clone command/
|
21
|
-
end
|
22
|
-
end
|
14
|
+
@source_vm_mock.stub(:name).and_return('foo')
|
15
|
+
@target_vm_mock.stub(:name).and_return('bar')
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
Fission::VM.stub(:new).with('foo').and_return(@source_vm_mock)
|
18
|
+
Fission::VM.stub(:new).with('bar').and_return(@target_vm_mock)
|
19
|
+
Fission::VM.stub(:clone).with(@vm_info.first, @vm_info[1]).
|
20
|
+
and_return(@clone_response_mock)
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
command.execute
|
31
|
-
}.should raise_error SystemExit
|
23
|
+
describe 'execute' do
|
24
|
+
subject { Fission::Command::Clone }
|
32
25
|
|
33
|
-
|
26
|
+
[ [], ['foo'] ].each do |args|
|
27
|
+
it_should_not_accept_arguments_of args, 'clone'
|
34
28
|
end
|
35
29
|
|
36
|
-
it
|
37
|
-
@
|
38
|
-
Fission::VM.should_receive(:exists?).with(vm).and_return(true)
|
39
|
-
end
|
30
|
+
it 'should clone the vm' do
|
31
|
+
@clone_response_mock.stub_as_successful
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
command.execute
|
44
|
-
}.should raise_error SystemExit
|
33
|
+
command = Fission::Command::Clone.new @vm_info
|
34
|
+
command.execute
|
45
35
|
|
46
|
-
@string_io.string.should match /
|
36
|
+
@string_io.string.should match /Clone complete/
|
47
37
|
end
|
48
38
|
|
49
|
-
it 'should
|
50
|
-
|
51
|
-
|
52
|
-
Fission::VM.should_receive(:clone).with(@vm_info.first, @vm_info[1])
|
39
|
+
it 'should output an error and exit if there is an error cloning' do
|
40
|
+
@clone_response_mock.stub_as_unsuccessful
|
41
|
+
|
53
42
|
command = Fission::Command::Clone.new @vm_info
|
54
|
-
command.execute
|
43
|
+
lambda { command.execute }.should raise_error SystemExit
|
55
44
|
|
56
|
-
@string_io.string.should match /
|
45
|
+
@string_io.string.should match /There was an error cloning the VM.+it blew up/m
|
57
46
|
end
|
58
47
|
|
59
48
|
describe 'with --start' do
|
60
|
-
|
61
|
-
@
|
62
|
-
|
63
|
-
|
64
|
-
Fission::VM.should_receive(:clone).with(@vm_info.first, @vm_info[1])
|
49
|
+
before do
|
50
|
+
@clone_response_mock.stub_as_successful true
|
51
|
+
@target_vm_mock.should_receive(:start).and_return(@start_response_mock)
|
52
|
+
end
|
65
53
|
|
66
|
-
|
67
|
-
|
54
|
+
it 'should clone the vm and start it' do
|
55
|
+
@start_response_mock.stub_as_successful
|
68
56
|
|
69
57
|
command = Fission::Command::Clone.new @vm_info << '--start'
|
70
58
|
command.execute
|
71
59
|
|
72
60
|
@string_io.string.should match /Clone complete/
|
73
61
|
@string_io.string.should match /Starting '#{@vm_info[1]}'/
|
62
|
+
@string_io.string.should match /VM '#{@vm_info[1]}' started/
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should output an error and exit if there is an error starting the VM after cloning it' do
|
66
|
+
@start_response_mock.stub_as_unsuccessful
|
67
|
+
|
68
|
+
command = Fission::Command::Clone.new @vm_info << '--start'
|
69
|
+
lambda { command.execute }.should raise_error SystemExit
|
70
|
+
|
71
|
+
@string_io.string.should match /Clone complete/
|
72
|
+
@string_io.string.should match /Starting '#{@vm_info[1]}'/
|
73
|
+
@string_io.string.should match /There was an error starting the VM.+it blew up/m
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -1,65 +1,74 @@
|
|
1
1
|
require File.expand_path('../../../spec_helper.rb', __FILE__)
|
2
2
|
|
3
3
|
describe Fission::Command::Delete do
|
4
|
+
include_context 'command_setup'
|
5
|
+
|
4
6
|
before do
|
5
7
|
@target_vm = ['foo']
|
6
|
-
|
7
|
-
|
8
|
+
Fission::VM.stub(:new).and_return(@vm_mock)
|
9
|
+
|
10
|
+
@delete_response_mock = mock('delete_response')
|
11
|
+
@running_response_mock = mock('running?')
|
12
|
+
|
13
|
+
@vm_mock.stub(:name).and_return(@target_vm.first)
|
14
|
+
@vm_mock.stub(:running?).and_return(@running_response_mock)
|
15
|
+
@running_response_mock.stub_as_successful false
|
16
|
+
Fission::Fusion.stub(:running?).and_return(false)
|
8
17
|
end
|
9
18
|
|
10
19
|
describe "execute" do
|
11
|
-
|
12
|
-
Fission::Command::Delete.should_receive(:help)
|
20
|
+
subject { Fission::Command::Delete }
|
13
21
|
|
14
|
-
|
15
|
-
command = Fission::Command::Delete.new
|
16
|
-
command.execute
|
17
|
-
}.should raise_error SystemExit
|
22
|
+
it_should_not_accept_arguments_of [], 'delete'
|
18
23
|
|
19
|
-
|
24
|
+
it "should try to delete the vm" do
|
25
|
+
@delete_response_mock.stub_as_successful
|
26
|
+
|
27
|
+
@vm_mock.should_receive(:delete).and_return(@delete_response_mock)
|
28
|
+
|
29
|
+
Fission::Fusion.should_receive(:running?).and_return(false)
|
30
|
+
|
31
|
+
command = Fission::Command::Delete.new @target_vm
|
32
|
+
command.execute
|
33
|
+
|
34
|
+
@string_io.string.should match /Deletion complete/
|
20
35
|
end
|
21
36
|
|
22
|
-
it "should output an error and exit if
|
23
|
-
|
37
|
+
it "should output an error and exit if unable to determine if it's running" do
|
38
|
+
@running_response_mock.stub_as_unsuccessful
|
24
39
|
|
25
|
-
|
26
|
-
|
27
|
-
command.execute
|
28
|
-
}.should raise_error SystemExit
|
40
|
+
command = Fission::Command::Delete.new @target_vm
|
41
|
+
lambda { command.execute }.should raise_error SystemExit
|
29
42
|
|
30
|
-
@string_io.string.should match /
|
43
|
+
@string_io.string.should match /There was an error determining if the VM is running.+it blew up.+/m
|
31
44
|
end
|
32
45
|
|
33
|
-
it
|
34
|
-
|
35
|
-
|
36
|
-
|
46
|
+
it 'should output an error and exit if there was an error deleting the VM' do
|
47
|
+
@delete_response_mock.stub_as_unsuccessful
|
48
|
+
|
49
|
+
@vm_mock.should_receive(:delete).and_return(@delete_response_mock)
|
50
|
+
|
37
51
|
command = Fission::Command::Delete.new @target_vm
|
38
|
-
command.execute
|
39
|
-
|
52
|
+
lambda { command.execute }.should raise_error SystemExit
|
53
|
+
|
54
|
+
@string_io.string.should match /There was an error deleting the VM.+it blew up/m
|
40
55
|
end
|
41
56
|
|
42
57
|
it 'should output an error and exit if the VM is running' do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
command.execute
|
48
|
-
}.should raise_error SystemExit
|
58
|
+
@running_response_mock.stub_as_successful true
|
59
|
+
|
60
|
+
command = Fission::Command::Delete.new @target_vm
|
61
|
+
lambda { command.execute }.should raise_error SystemExit
|
49
62
|
|
50
63
|
@string_io.string.should match /VM is currently running/
|
51
64
|
@string_io.string.should match /Either stop\/suspend the VM or use '--force' and try again/
|
52
65
|
end
|
53
66
|
|
54
67
|
it 'should output an error and exit if the fusion app is running' do
|
55
|
-
Fission::
|
56
|
-
Fission::VM.should_receive(:all_running).and_return(['bar'])
|
57
|
-
Fission::Fusion.should_receive(:is_running?).and_return(true)
|
68
|
+
Fission::Fusion.stub(:running?).and_return(true)
|
58
69
|
|
59
|
-
|
60
|
-
|
61
|
-
command.execute
|
62
|
-
}.should raise_error SystemExit
|
70
|
+
command = Fission::Command::Delete.new @target_vm
|
71
|
+
lambda { command.execute }.should raise_error SystemExit
|
63
72
|
|
64
73
|
@string_io.string.should match /Fusion GUI is currently running/
|
65
74
|
@string_io.string.should match /Either exit the Fusion GUI or use '--force' and try again/
|
@@ -68,41 +77,45 @@ describe Fission::Command::Delete do
|
|
68
77
|
|
69
78
|
describe 'with --force' do
|
70
79
|
before do
|
71
|
-
|
80
|
+
@vm_mock.should_receive(:delete).and_return(@delete_response_mock)
|
81
|
+
@delete_response_mock.stub_as_successful true
|
72
82
|
end
|
73
83
|
|
74
84
|
it "should stop the VM if it's running and then delete it" do
|
75
85
|
@stop_cmd_mock = mock('stop_cmd')
|
86
|
+
|
76
87
|
@stop_cmd_mock.should_receive(:execute)
|
77
|
-
|
78
|
-
|
88
|
+
@running_response_mock.stub_as_successful true
|
89
|
+
|
79
90
|
Fission::Command::Stop.should_receive(:new).with(@target_vm).
|
80
|
-
|
91
|
+
and_return(@stop_cmd_mock)
|
81
92
|
command = Fission::Command::Delete.new @target_vm << '--force'
|
82
93
|
command.execute
|
94
|
+
|
83
95
|
@string_io.string.should match /VM is currently running/
|
84
96
|
@string_io.string.should match /Going to stop it/
|
85
97
|
@string_io.string.should match /Deletion complete/
|
86
98
|
end
|
87
99
|
|
88
100
|
it 'should output a warning about fusion metadata issue and then delete the VM' do
|
89
|
-
|
90
|
-
Fission::Fusion.should_receive(:
|
101
|
+
|
102
|
+
Fission::Fusion.should_receive(:running?).and_return(true)
|
91
103
|
command = Fission::Command::Delete.new @target_vm << '--force'
|
92
104
|
command.execute
|
105
|
+
|
93
106
|
@string_io.string.should match /Fusion GUI is currently running/
|
94
107
|
@string_io.string.should match /metadata for the VM may not be removed completely/
|
95
108
|
@string_io.string.should match /Deletion complete/
|
96
109
|
end
|
97
|
-
|
98
110
|
end
|
111
|
+
|
99
112
|
end
|
100
113
|
|
101
114
|
describe 'help' do
|
102
115
|
it 'should output info for this command' do
|
103
116
|
output = Fission::Command::Delete.help
|
104
117
|
|
105
|
-
output.should match /delete
|
118
|
+
output.should match /delete vm_name \[--force\]/
|
106
119
|
output.should match /--force/
|
107
120
|
end
|
108
121
|
end
|
@@ -1,88 +1,66 @@
|
|
1
1
|
require File.expand_path('../../../spec_helper.rb', __FILE__)
|
2
2
|
|
3
3
|
describe Fission::Command::SnapshotCreate do
|
4
|
+
include_context 'command_setup'
|
5
|
+
|
4
6
|
before do
|
5
7
|
@target_vm = ['foo']
|
6
|
-
@vm_mock = mock('vm_mock')
|
7
8
|
Fission::VM.stub!(:new).and_return(@vm_mock)
|
8
|
-
|
9
|
-
|
9
|
+
|
10
|
+
@snap_create_response_mock = mock('snap_create_response')
|
11
|
+
|
12
|
+
@vm_mock.stub(:name).and_return(@target_vm.first)
|
10
13
|
end
|
11
14
|
|
12
15
|
describe 'execute' do
|
13
|
-
|
14
|
-
Fission::Command::SnapshotCreate.should_receive(:help)
|
16
|
+
subject { Fission::Command::SnapshotCreate }
|
15
17
|
|
16
|
-
|
17
|
-
command = Fission::Command::SnapshotCreate.new
|
18
|
-
command.execute
|
19
|
-
}.should raise_error SystemExit
|
20
|
-
|
21
|
-
@string_io.string.should match /Incorrect arguments for snapshot create command/
|
22
|
-
end
|
18
|
+
it_should_not_accept_arguments_of [], 'snapshot create'
|
23
19
|
|
24
20
|
it "should output an error and the help when no snapshot name is passed in" do
|
25
21
|
Fission::Command::SnapshotCreate.should_receive(:help)
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
command.execute
|
30
|
-
}.should raise_error SystemExit
|
23
|
+
command = Fission::Command::SnapshotCreate.new @target_vm
|
24
|
+
lambda { command.execute }.should raise_error SystemExit
|
31
25
|
|
32
26
|
@string_io.string.should match /Incorrect arguments for snapshot create command/
|
33
27
|
end
|
34
28
|
|
35
|
-
it
|
36
|
-
|
37
|
-
|
38
|
-
lambda {
|
39
|
-
command = Fission::Command::SnapshotCreate.new @target_vm << 'snap_1'
|
40
|
-
command.execute
|
41
|
-
}.should raise_error SystemExit
|
29
|
+
it 'should create a new snapshot with the provided name' do
|
30
|
+
@snap_create_response_mock.stub_as_successful []
|
42
31
|
|
43
|
-
@
|
44
|
-
|
32
|
+
@vm_mock.should_receive(:create_snapshot).
|
33
|
+
with('snap_1').
|
34
|
+
and_return(@snap_create_response_mock)
|
45
35
|
|
46
|
-
|
47
|
-
|
48
|
-
Fission::VM.should_receive(:all_running).and_return([])
|
49
|
-
lambda {
|
50
|
-
command = Fission::Command::SnapshotCreate.new @target_vm << 'snap_1'
|
51
|
-
command.execute
|
52
|
-
}.should raise_error SystemExit
|
36
|
+
command = Fission::Command::SnapshotCreate.new @target_vm << 'snap_1'
|
37
|
+
command.execute
|
53
38
|
|
54
|
-
@string_io.string.should match /
|
55
|
-
@string_io.string.should match /
|
39
|
+
@string_io.string.should match /Creating snapshot/
|
40
|
+
@string_io.string.should match /Snapshot 'snap_1' created/
|
56
41
|
end
|
57
42
|
|
58
|
-
it
|
59
|
-
|
60
|
-
Fission::VM.should_receive(:all_running).and_return(['foo'])
|
61
|
-
@vm_mock.should_receive(:snapshots).and_return(['snap_1'])
|
62
|
-
lambda {
|
63
|
-
command = Fission::Command::SnapshotCreate.new @target_vm << 'snap_1'
|
64
|
-
command.execute
|
65
|
-
}.should raise_error SystemExit
|
43
|
+
it 'should output an error and exit if there was an error creating the snapshot' do
|
44
|
+
@snap_create_response_mock.stub_as_unsuccessful
|
66
45
|
|
67
|
-
@
|
68
|
-
|
46
|
+
@vm_mock.should_receive(:create_snapshot).
|
47
|
+
with('snap_1').
|
48
|
+
and_return(@snap_create_response_mock)
|
69
49
|
|
70
|
-
it 'should create a new snapshot with the provided name' do
|
71
|
-
Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
|
72
|
-
Fission::VM.should_receive(:all_running).and_return(['foo'])
|
73
|
-
@vm_mock.should_receive(:snapshots).and_return([])
|
74
|
-
@vm_mock.should_receive(:create_snapshot).with('snap_1')
|
75
50
|
command = Fission::Command::SnapshotCreate.new @target_vm << 'snap_1'
|
76
|
-
command.execute
|
51
|
+
lambda { command.execute }.should raise_error SystemExit
|
52
|
+
|
77
53
|
@string_io.string.should match /Creating snapshot/
|
54
|
+
@string_io.string.should match /There was an error creating the snapshot.+it blew up.+/m
|
78
55
|
end
|
56
|
+
|
79
57
|
end
|
80
58
|
|
81
59
|
describe 'help' do
|
82
60
|
it 'should output info for this command' do
|
83
61
|
output = Fission::Command::SnapshotCreate.help
|
84
62
|
|
85
|
-
output.should match /snapshot create
|
63
|
+
output.should match /snapshot create vm_name snapshot_1/
|
86
64
|
end
|
87
65
|
end
|
88
66
|
end
|