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.
Files changed (50) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +3 -0
  3. data/README.md +1 -1
  4. data/lib/fission.rb +5 -6
  5. data/lib/fission/cli.rb +77 -7
  6. data/lib/fission/command.rb +43 -1
  7. data/lib/fission/command/clone.rb +19 -20
  8. data/lib/fission/command/delete.rb +29 -25
  9. data/lib/fission/command/snapshot_create.rb +11 -26
  10. data/lib/fission/command/snapshot_list.rb +13 -19
  11. data/lib/fission/command/snapshot_revert.rb +11 -26
  12. data/lib/fission/command/start.rb +11 -25
  13. data/lib/fission/command/status.rb +26 -10
  14. data/lib/fission/command/stop.rb +10 -21
  15. data/lib/fission/command/suspend.rb +21 -21
  16. data/lib/fission/command_helpers.rb +21 -0
  17. data/lib/fission/config.rb +35 -0
  18. data/lib/fission/fusion.rb +11 -3
  19. data/lib/fission/lease.rb +148 -0
  20. data/lib/fission/metadata.rb +55 -2
  21. data/lib/fission/response.rb +76 -0
  22. data/lib/fission/ui.rb +49 -0
  23. data/lib/fission/version.rb +1 -1
  24. data/lib/fission/vm.rb +653 -75
  25. data/spec/contexts/command.rb +12 -0
  26. data/spec/fission/cli_spec.rb +4 -11
  27. data/spec/fission/command/clone_spec.rb +45 -45
  28. data/spec/fission/command/delete_spec.rb +56 -43
  29. data/spec/fission/command/snapshot_create_spec.rb +29 -51
  30. data/spec/fission/command/snapshot_list_spec.rb +25 -26
  31. data/spec/fission/command/snapshot_revert_spec.rb +27 -53
  32. data/spec/fission/command/start_spec.rb +25 -69
  33. data/spec/fission/command/status_spec.rb +48 -13
  34. data/spec/fission/command/stop_spec.rb +25 -42
  35. data/spec/fission/command/suspend_spec.rb +54 -49
  36. data/spec/fission/command_helpers_spec.rb +30 -0
  37. data/spec/fission/command_spec.rb +19 -0
  38. data/spec/fission/config_spec.rb +24 -0
  39. data/spec/fission/fusion_spec.rb +6 -6
  40. data/spec/fission/lease_spec.rb +176 -0
  41. data/spec/fission/metadata_spec.rb +8 -8
  42. data/spec/fission/response_spec.rb +81 -0
  43. data/spec/fission/vm_spec.rb +869 -193
  44. data/spec/fission_spec.rb +0 -6
  45. data/spec/helpers/command_helpers.rb +12 -0
  46. data/spec/helpers/response_helpers.rb +21 -0
  47. data/spec/matchers/be_a_successful_response.rb +7 -0
  48. data/spec/matchers/be_an_unsuccessful_response.rb +10 -0
  49. data/spec/spec_helper.rb +7 -0
  50. metadata +24 -5
@@ -1,40 +1,29 @@
1
1
  require File.expand_path('../../../spec_helper.rb', __FILE__)
2
2
 
3
3
  describe Fission::Command::SnapshotList 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
- @string_io = StringIO.new
9
- Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
10
- end
11
9
 
12
- describe 'execute' do
13
- it "should output an error and the help when no VM argument is passed in" do
14
- Fission::Command::SnapshotList.should_receive(:help)
10
+ @snap_list_response_mock = mock('snap_list_response')
15
11
 
16
- lambda {
17
- command = Fission::Command::SnapshotList.new
18
- command.execute
19
- }.should raise_error SystemExit
12
+ @vm_mock.stub(:name).and_return(@target_vm.first)
13
+ end
20
14
 
21
- @string_io.string.should match /Incorrect arguments for snapshot list command/
15
+ describe 'execute' do
16
+ before do
17
+ @vm_mock.stub(:snapshots).and_return(@snap_list_response_mock)
22
18
  end
23
19
 
24
- it "should output an error and exit if it can't find the target vm" do
25
- Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(false)
26
-
27
- lambda {
28
- command = Fission::Command::SnapshotList.new @target_vm
29
- command.execute
30
- }.should raise_error SystemExit
20
+ subject { Fission::Command::SnapshotList }
31
21
 
32
- @string_io.string.should match /Unable to find the VM #{@target_vm.first}/
33
- end
22
+ it_should_not_accept_arguments_of [], 'snapshot list'
34
23
 
35
24
  it 'should output the list of snapshots if any exist' do
36
- Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
37
- @vm_mock.should_receive(:snapshots).and_return(['snap 1', 'snap 2', 'snap 3'])
25
+ @snap_list_response_mock.stub_as_successful ['snap 1', 'snap 2', 'snap 3']
26
+
38
27
  command = Fission::Command::SnapshotList.new @target_vm
39
28
  command.execute
40
29
 
@@ -42,20 +31,30 @@ describe Fission::Command::SnapshotList do
42
31
  end
43
32
 
44
33
  it 'should output that it could not find any snapshots if none exist' do
45
- Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
46
- @vm_mock.should_receive(:snapshots).and_return([])
34
+ @snap_list_response_mock.stub_as_successful []
35
+
47
36
  command = Fission::Command::SnapshotList.new @target_vm
48
37
  command.execute
49
38
 
50
39
  @string_io.string.should match /No snapshots found for VM '#{@target_vm.first}'/
51
40
  end
41
+
42
+ it 'should output an error and exit if there was an error getting the list of snapshots' do
43
+ @snap_list_response_mock.stub_as_unsuccessful
44
+
45
+ command = Fission::Command::SnapshotList.new @target_vm
46
+ lambda { command.execute }.should raise_error SystemExit
47
+
48
+ @string_io.string.should match /There was an error listing the snapshots.+it blew up.+/m
49
+ end
50
+
52
51
  end
53
52
 
54
53
  describe 'help' do
55
54
  it 'should output info for this command' do
56
55
  output = Fission::Command::SnapshotList.help
57
56
 
58
- output.should match /snapshot list/
57
+ output.should match /snapshot list vm_name/
59
58
  end
60
59
  end
61
60
  end
@@ -1,90 +1,64 @@
1
1
  require File.expand_path('../../../spec_helper.rb', __FILE__)
2
2
 
3
3
  describe Fission::Command::SnapshotRevert 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
- @string_io = StringIO.new
9
- Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
9
+
10
+ @snap_revert_response_mock = mock('snap_revert_response')
11
+
12
+ @vm_mock.stub(:name).and_return(@target_vm.first)
10
13
  end
11
14
 
12
15
  describe 'execute' do
13
- it "should output an error and the help when no vm name is passed in" do
14
- Fission::Command::SnapshotRevert.should_receive(:help)
15
-
16
- lambda {
17
- command = Fission::Command::SnapshotRevert.new
18
- command.execute
19
- }.should raise_error SystemExit
16
+ subject { Fission::Command::SnapshotRevert }
20
17
 
21
- @string_io.string.should match /Incorrect arguments for snapshot revert command/
22
- end
18
+ it_should_not_accept_arguments_of [], 'snapshot revert'
23
19
 
24
20
  it "should output an error and the help when no snapshot name is passed in" do
25
21
  Fission::Command::SnapshotRevert.should_receive(:help)
26
22
 
27
- lambda {
28
- command = Fission::Command::SnapshotRevert.new @target_vm
29
- command.execute
30
- }.should raise_error SystemExit
23
+ command = Fission::Command::SnapshotRevert.new @target_vm
24
+ lambda { command.execute }.should raise_error SystemExit
31
25
 
32
26
  @string_io.string.should match /Incorrect arguments for snapshot revert command/
33
27
  end
34
28
 
35
- it "should output an error and exit if it can't find the target vm" do
36
- Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(false)
37
-
38
- lambda {
39
- command = Fission::Command::SnapshotRevert.new @target_vm << 'snap_1'
40
- command.execute
41
- }.should raise_error SystemExit
42
-
43
- @string_io.string.should match /Unable to find the VM #{@target_vm.first}/
44
- end
29
+ it 'should revert to the snapshot with the provided name' do
30
+ @snap_revert_response_mock.stub_as_successful
45
31
 
46
- it "should output an error and exit if it can't find the snapshot" do
47
- Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
48
- Fission::Fusion.should_receive(:is_running?).and_return(false)
49
- @vm_mock.should_receive(:snapshots).and_return([])
32
+ @vm_mock.should_receive(:revert_to_snapshot).with('snap_1').
33
+ and_return(@snap_revert_response_mock)
50
34
 
51
- lambda {
52
- command = Fission::Command::SnapshotRevert.new @target_vm << 'snap_1'
53
- command.execute
54
- }.should raise_error SystemExit
35
+ command = Fission::Command::SnapshotRevert.new @target_vm << 'snap_1'
36
+ command.execute
55
37
 
56
- @string_io.string.should match /Unable to find the snapshot 'snap_1'/
38
+ @string_io.string.should match /Reverting to snapshot 'snap_1'/
39
+ @string_io.string.should match /Reverted to snapshot 'snap_1'/
57
40
  end
58
41
 
59
- it 'should output an error and exit if the fusion app is running' do
60
- Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
61
- Fission::Fusion.should_receive(:is_running?).and_return(true)
62
-
63
- lambda {
64
- command = Fission::Command::SnapshotRevert.new @target_vm << 'snap_1'
65
- command.execute
66
- }.should raise_error SystemExit
42
+ it 'should output an error and exit if there was an error reverting to the snapshot' do
43
+ @snap_revert_response_mock.stub_as_unsuccessful
67
44
 
68
- @string_io.string.should match /Fusion GUI is currently running/
69
- @string_io.string.should match /Please exit the Fusion GUI and try again/
70
- end
45
+ @vm_mock.should_receive(:revert_to_snapshot).with('snap_1').
46
+ and_return(@snap_revert_response_mock)
71
47
 
72
- it 'should revert to the snapshot with the provided name' do
73
- Fission::VM.should_receive(:exists?).with(@target_vm.first).and_return(true)
74
- Fission::Fusion.should_receive(:is_running?).and_return(false)
75
- @vm_mock.should_receive(:snapshots).and_return(['snap_1', 'snap_2'])
76
- @vm_mock.should_receive(:revert_to_snapshot).with('snap_1')
77
48
  command = Fission::Command::SnapshotRevert.new @target_vm << 'snap_1'
78
- command.execute
49
+ lambda { command.execute }.should raise_error SystemExit
50
+
79
51
  @string_io.string.should match /Reverting to snapshot 'snap_1'/
52
+ @string_io.string.should match /There was an error reverting to the snapshot.+it blew up.+/m
80
53
  end
54
+
81
55
  end
82
56
 
83
57
  describe 'help' do
84
58
  it 'should output info for this command' do
85
59
  output = Fission::Command::SnapshotRevert.help
86
60
 
87
- output.should match /snapshot revert my_vm snapshot_1/
61
+ output.should match /snapshot revert vm_name snapshot_1/
88
62
  end
89
63
  end
90
64
  end
@@ -1,99 +1,55 @@
1
1
  require File.expand_path('../../../spec_helper.rb', __FILE__)
2
2
 
3
3
  describe Fission::Command::Start do
4
- before do
5
- @vm_info = ['foo']
6
- @string_io = StringIO.new
7
- Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
8
- @vm_mock = mock('vm_mock')
9
- end
10
-
11
- describe 'execute' do
12
- it "should output an error and the help when no VM argument is passed in" do
13
- Fission::Command::Start.should_receive(:help)
14
-
15
- lambda {
16
- command = Fission::Command::Start.new
17
- command.execute
18
- }.should raise_error SystemExit
19
-
20
- @string_io.string.should match /Incorrect arguments for start command/
21
- end
4
+ include_context 'command_setup'
22
5
 
23
- it "should output an error and exit if it can't find the vm" do
24
- Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(false)
25
-
26
- lambda {
27
- command = Fission::Command::Start.new @vm_info
28
- command.execute
29
- }.should raise_error SystemExit
6
+ before do
7
+ @target_vm = ['foo']
8
+ Fission::VM.stub(:new).and_return(@vm_mock)
30
9
 
31
- @string_io.string.should match /Unable to find the VM #{@vm_info.first}/
32
- end
10
+ @start_response_mock = mock('start_response')
33
11
 
12
+ @vm_mock.stub(:name).and_return(@target_vm.first)
13
+ end
34
14
 
35
- it "should output and exit if the vm is already running" do
36
- Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(true)
37
- Fission::VM.should_receive(:all_running).and_return(@vm_info)
15
+ describe 'execute' do
16
+ subject { Fission::Command::Start }
38
17
 
39
- lambda {
40
- command = Fission::Command::Start.new @vm_info
41
- command.execute
42
- }.should raise_error SystemExit
18
+ it_should_not_accept_arguments_of [], 'start'
43
19
 
44
- @string_io.string.should match /VM '#{@vm_info.first}' is already running/
45
- end
20
+ it 'should output an error and exit if there was an error starting the vm' do
21
+ @start_response_mock.stub_as_unsuccessful
46
22
 
47
- it 'should try to start the vm if it is not running' do
48
- Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(true)
49
- Fission::VM.should_receive(:all_running).and_return([])
50
- Fission::VM.should_receive(:new).with(@vm_info.first).and_return(@vm_mock)
51
- @vm_mock.should_receive(:start)
23
+ @vm_mock.should_receive(:start).and_return(@start_response_mock)
52
24
 
53
- command = Fission::Command::Start.new @vm_info
54
- command.execute
25
+ command = Fission::Command::Start.new @target_vm
26
+ lambda { command.execute }.should raise_error SystemExit
55
27
 
56
- @string_io.string.should match /Starting '#{@vm_info.first}'/
28
+ @string_io.string.should match /Starting '#{@target_vm.first}'/
29
+ @string_io.string.should match /There was a problem starting the VM.+it blew up.+/m
57
30
  end
58
31
 
59
32
  describe 'with --headless' do
60
33
  it 'should start the vm headless' do
61
- Fission::Fusion.should_receive(:is_running?).and_return(false)
62
- Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(true)
63
- Fission::VM.should_receive(:all_running).and_return([])
64
- Fission::VM.should_receive(:new).with(@vm_info.first).and_return(@vm_mock)
65
- @vm_mock.should_receive(:start).with(:headless => true)
34
+ @start_response_mock.stub_as_successful
66
35
 
67
- command = Fission::Command::Start.new @vm_info << '--headless'
68
- command.execute
36
+ @vm_mock.should_receive(:start).and_return(@start_response_mock)
69
37
 
70
- @string_io.string.should match /Starting '#{@vm_info.first}'/
71
- end
38
+ command = Fission::Command::Start.new @target_vm << '--headless'
39
+ command.execute
72
40
 
73
- it 'should output an error and exit if the fusion app is running' do
74
- Fission::Fusion.should_receive(:is_running?).and_return(true)
75
- Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(true)
76
- Fission::VM.should_receive(:all_running).and_return([])
77
- Fission::VM.should_receive(:new).with(@vm_info.first).and_return(@vm_mock)
78
- @vm_mock.should_not_receive(:start)
79
-
80
- lambda {
81
- command = Fission::Command::Start.new @vm_info << '--headless'
82
- command.execute
83
- }.should raise_error SystemExit
84
-
85
- @string_io.string.should match /Fusion GUI is currently running/
86
- @string_io.string.should match /A VM cannot be started in headless mode when the Fusion GUI is running/
87
- @string_io.string.should match /Exit the Fusion GUI and try again/
41
+ @string_io.string.should match /Starting '#{@target_vm.first}'/
42
+ @string_io.string.should match /VM '#{@target_vm.first}' started/
88
43
  end
89
44
  end
45
+
90
46
  end
91
47
 
92
48
  describe 'help' do
93
49
  it 'should output info for this command' do
94
50
  output = Fission::Command::Start.help
95
51
 
96
- output.should match /start vm \[options\]/
52
+ output.should match /start vm_name \[options\]/
97
53
  output.should match /--headless/
98
54
  end
99
55
  end
@@ -1,30 +1,65 @@
1
1
  require File.expand_path('../../../spec_helper.rb', __FILE__)
2
2
 
3
3
  describe Fission::Command::Status do
4
+ include_context 'command_setup'
5
+
4
6
  before do
5
- @string_io = StringIO.new
6
- Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
7
+ @all_response_mock = mock('response')
8
+ @vm_1 = Fission::VM.new 'foo'
9
+ @vm_2 = Fission::VM.new 'bar'
10
+ @vm_3 = Fission::VM.new 'baz'
11
+ @vm_4 = Fission::VM.new 'blah'
7
12
  end
8
13
 
9
14
  describe 'execute' do
10
15
  before do
11
- Fission::VM.stub!(:all).and_return(['foo', 'bar', 'baz'])
12
- Fission::VM.stub!(:all_running).and_return(['foo', 'baz'])
16
+ @all_response_mock.stub_as_successful [@vm_1, @vm_2, @vm_3, @vm_4]
17
+
18
+ Fission::VM.should_receive(:all).and_return(@all_response_mock)
19
+ Fission::VM.stub(:all_running).and_return(@all_running_response_mock)
13
20
  end
14
21
 
15
- it 'should output the VMs which are running' do
16
- command = Fission::Command::Status.new
17
- command.execute
22
+ describe 'when successful' do
23
+ before do
24
+ @all_running_response_mock.stub_as_successful [@vm_1, @vm_3]
25
+ end
26
+
27
+ it 'should output the VMs which are running' do
28
+ command = Fission::Command::Status.new
29
+ command.execute
30
+
31
+ @string_io.string.should match /foo.+\[running\]/
32
+ @string_io.string.should match /baz.+\[running\]/
33
+ end
34
+
35
+ it 'should output the VMs which are not running' do
36
+ command = Fission::Command::Status.new
37
+ command.execute
38
+
39
+ @string_io.string.should match /bar.+\[not running\]/
40
+ end
41
+
42
+ it 'should output the VMs which are suspended' do
43
+ @vm_4.stub(:suspend_file_exists?).and_return(true)
44
+ command = Fission::Command::Status.new
45
+ command.execute
46
+
47
+ @string_io.string.should match /blah.+\[suspended\]/
48
+ end
18
49
 
19
- @string_io.string.should match /foo.+[running]/
20
- @string_io.string.should match /baz.+[running]/
21
50
  end
22
51
 
23
- it 'should output the VMs which are not running' do
24
- command = Fission::Command::Status.new
25
- command.execute
52
+ describe 'when unsuccessful' do
53
+ before do
54
+ @all_running_response_mock.stub_as_unsuccessful
55
+ end
56
+
57
+ it 'should output an error and exit if there was an error getting the list of running VMs' do
58
+ command = Fission::Command::Status.new
59
+ lambda { command.execute }.should raise_error SystemExit
26
60
 
27
- @string_io.string.should match /bar.+[not running]/
61
+ @string_io.string.should match /There was an error getting the list of running VMs.+it blew up/m
62
+ end
28
63
  end
29
64
  end
30
65
 
@@ -1,68 +1,51 @@
1
1
  require File.expand_path('../../../spec_helper.rb', __FILE__)
2
2
 
3
3
  describe Fission::Command::Stop do
4
+ include_context 'command_setup'
5
+
4
6
  before do
5
- @vm_info = ['foo']
6
- @string_io = StringIO.new
7
- Fission.stub!(:ui).and_return(Fission::UI.new(@string_io))
7
+ @target_vm = ['foo']
8
+ Fission::VM.stub(:new).and_return(@vm_mock)
9
+
10
+ @stop_response_mock = mock('stop_response')
11
+
12
+ @vm_mock.stub(:name).and_return(@target_vm.first)
8
13
  end
9
14
 
10
15
  describe 'execute' do
11
- it "should output an error and the help when no VM argument is passed in" do
12
- Fission::Command::Stop.should_receive(:help)
16
+ subject { Fission::Command::Stop }
13
17
 
14
- lambda {
15
- command = Fission::Command::Stop.new
16
- command.execute
17
- }.should raise_error SystemExit
18
+ it_should_not_accept_arguments_of [], 'stop'
18
19
 
19
- @string_io.string.should match /Incorrect arguments for stop command/
20
- end
21
-
22
- it "should output an error and exit if it can't find the vm" do
23
- Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(false)
20
+ it 'should stop the vm' do
21
+ @stop_response_mock.should_receive(:successful?).and_return(true)
22
+ @vm_mock.should_receive(:stop).and_return(@stop_response_mock)
24
23
 
25
- lambda {
26
- command = Fission::Command::Stop.new @vm_info
27
- command.execute
28
- }.should raise_error SystemExit
24
+ command = Fission::Command::Stop.new @target_vm
25
+ command.execute
29
26
 
30
- @string_io.string.should match /Unable to find the VM #{@vm_info.first}/
27
+ @string_io.string.should match /Stopping '#{@target_vm.first}'/
28
+ @string_io.string.should match /VM '#{@target_vm.first}' stopped/
31
29
  end
32
30
 
31
+ it 'should output an error and exit if there was an error stopping the vm' do
32
+ @stop_response_mock.stub_as_unsuccessful
33
33
 
34
- it "should output and exit if the vm is not running" do
35
- Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(true)
36
- Fission::VM.should_receive(:all_running).and_return([])
34
+ @vm_mock.should_receive(:stop).and_return(@stop_response_mock)
37
35
 
38
- lambda {
39
- command = Fission::Command::Stop.new @vm_info
40
- command.execute
41
- }.should raise_error SystemExit
36
+ command = Fission::Command::Stop.new @target_vm
37
+ lambda { command.execute }.should raise_error SystemExit
42
38
 
43
- @string_io.string.should match /VM '#{@vm_info.first}' is not running/
39
+ @string_io.string.should match /Stopping '#{@target_vm.first}'/
40
+ @string_io.string.should match /There was an error stopping the VM.+it blew up.+/m
44
41
  end
45
-
46
- it 'should try to stop the vm if it is not running' do
47
- @vm_mock = mock('vm_mock')
48
- Fission::VM.should_receive(:exists?).with(@vm_info.first).and_return(true)
49
- Fission::VM.should_receive(:all_running).and_return(@vm_info)
50
- Fission::VM.should_receive(:new).with(@vm_info.first).and_return(@vm_mock)
51
- @vm_mock.should_receive(:stop)
52
-
53
- command = Fission::Command::Stop.new @vm_info
54
- command.execute
55
-
56
- @string_io.string.should match /Stopping '#{@vm_info.first}'/
57
- end
58
-
59
42
  end
60
43
 
61
44
  describe 'help' do
62
45
  it 'should output info for this command' do
63
46
  output = Fission::Command::Stop.help
64
47
 
65
- output.should match /stop vm/
48
+ output.should match /stop vm_name/
66
49
  end
67
50
  end
68
51
  end