fission 0.4.0 → 0.5.0.beta.1

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.
Files changed (79) hide show
  1. data/.ruby-gemset +1 -0
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +7 -0
  4. data/CHANGELOG.md +12 -3
  5. data/README.md +45 -19
  6. data/bin/fission +1 -1
  7. data/fission.gemspec +3 -2
  8. data/lib/fission.rb +15 -0
  9. data/lib/fission/action/shell_executor.rb +37 -0
  10. data/lib/fission/action/snapshot/creator.rb +81 -0
  11. data/lib/fission/action/snapshot/deleter.rb +85 -0
  12. data/lib/fission/action/snapshot/lister.rb +90 -0
  13. data/lib/fission/action/snapshot/reverter.rb +81 -0
  14. data/lib/fission/action/vm/cloner.rb +191 -0
  15. data/lib/fission/action/vm/deleter.rb +73 -0
  16. data/lib/fission/action/vm/lister.rb +138 -0
  17. data/lib/fission/action/vm/starter.rb +88 -0
  18. data/lib/fission/action/vm/stopper.rb +79 -0
  19. data/lib/fission/action/vm/suspender.rb +68 -0
  20. data/lib/fission/cli.rb +21 -117
  21. data/lib/fission/command.rb +39 -0
  22. data/lib/fission/command/clone.rb +11 -6
  23. data/lib/fission/command/delete.rb +11 -6
  24. data/lib/fission/command/info.rb +62 -0
  25. data/lib/fission/command/snapshot_create.rb +9 -3
  26. data/lib/fission/command/snapshot_delete.rb +38 -0
  27. data/lib/fission/command/snapshot_list.rb +9 -3
  28. data/lib/fission/command/snapshot_revert.rb +9 -3
  29. data/lib/fission/command/start.rb +11 -6
  30. data/lib/fission/command/status.rb +9 -1
  31. data/lib/fission/command/stop.rb +9 -3
  32. data/lib/fission/command/suspend.rb +11 -6
  33. data/lib/fission/command_helpers.rb +18 -4
  34. data/lib/fission/command_line_parser.rb +189 -0
  35. data/lib/fission/config.rb +1 -1
  36. data/lib/fission/fusion.rb +3 -4
  37. data/lib/fission/lease.rb +2 -1
  38. data/lib/fission/metadata.rb +6 -1
  39. data/lib/fission/response.rb +17 -9
  40. data/lib/fission/version.rb +1 -1
  41. data/lib/fission/vm.rb +142 -382
  42. data/lib/fission/vm_configuration.rb +79 -0
  43. data/spec/fission/action/execute_shell_command_spec.rb +25 -0
  44. data/spec/fission/action/snapshot/creator_spec.rb +77 -0
  45. data/spec/fission/action/snapshot/deleter_spec.rb +84 -0
  46. data/spec/fission/action/snapshot/lister_spec.rb +67 -0
  47. data/spec/fission/action/snapshot/reverter_spec.rb +76 -0
  48. data/spec/fission/action/vm/cloner_spec.rb +198 -0
  49. data/spec/fission/action/vm/deleter_spec.rb +79 -0
  50. data/spec/fission/action/vm/lister_spec.rb +164 -0
  51. data/spec/fission/action/vm/starter_spec.rb +88 -0
  52. data/spec/fission/action/vm/stopper_spec.rb +71 -0
  53. data/spec/fission/action/vm/suspender_spec.rb +59 -0
  54. data/spec/fission/cli_spec.rb +32 -157
  55. data/spec/fission/command/clone_spec.rb +9 -3
  56. data/spec/fission/command/delete_spec.rb +11 -3
  57. data/spec/fission/command/info_spec.rb +130 -0
  58. data/spec/fission/command/snapshot_create_spec.rb +11 -3
  59. data/spec/fission/command/snapshot_delete_spec.rb +74 -0
  60. data/spec/fission/command/snapshot_list_spec.rb +11 -3
  61. data/spec/fission/command/snapshot_revert_spec.rb +11 -3
  62. data/spec/fission/command/start_spec.rb +11 -3
  63. data/spec/fission/command/status_spec.rb +16 -5
  64. data/spec/fission/command/stop_spec.rb +11 -3
  65. data/spec/fission/command/suspend_spec.rb +11 -3
  66. data/spec/fission/command_helpers_spec.rb +27 -5
  67. data/spec/fission/command_line_parser_spec.rb +267 -0
  68. data/spec/fission/command_spec.rb +16 -1
  69. data/spec/fission/config_spec.rb +3 -3
  70. data/spec/fission/fusion_spec.rb +11 -6
  71. data/spec/fission/lease_spec.rb +81 -45
  72. data/spec/fission/metadata_spec.rb +29 -6
  73. data/spec/fission/response_spec.rb +20 -9
  74. data/spec/fission/ui_spec.rb +1 -1
  75. data/spec/fission/vm_configuration_spec.rb +132 -0
  76. data/spec/fission/vm_spec.rb +393 -750
  77. data/spec/helpers/command_helpers.rb +1 -1
  78. metadata +93 -15
  79. data/.rvmrc +0 -1
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper.rb', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Fission::Command do
4
4
  describe 'new' do
@@ -13,6 +13,13 @@ describe Fission::Command do
13
13
  end
14
14
  end
15
15
 
16
+ describe 'command_name' do
17
+ it 'should return the pretty command name' do
18
+ cmd = Fission::Command.new
19
+ cmd.command_name(Fission::Command::SnapshotList.new).should == 'snapshot list'
20
+ end
21
+ end
22
+
16
23
  describe 'help' do
17
24
  it 'should call option_parser on a new instance' do
18
25
  @new_instance_mock = mock('new_instance')
@@ -22,6 +29,14 @@ describe Fission::Command do
22
29
  end
23
30
  end
24
31
 
32
+ describe 'summary' do
33
+ it "should raise an exception that it's not implemented" do
34
+ lambda {
35
+ Fission::Command.new.summary
36
+ }.should raise_error NotImplementedError
37
+ end
38
+ end
39
+
25
40
  describe 'ui' do
26
41
  it 'should load a ui object' do
27
42
  Fission::Command.new.ui.should be_a Fission::UI
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper.rb', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Fission::Config do
4
4
  describe "init" do
@@ -49,7 +49,7 @@ describe Fission::Config do
49
49
 
50
50
  it 'should set vmrun_cmd' do
51
51
  @config = Fission::Config.new
52
- @config.attributes['vmrun_cmd'].should == '/Library/Application\ Support/VMware\ Fusion/vmrun -T fusion'
52
+ @config.attributes['vmrun_cmd'].should == "'/Library/Application Support/VMware Fusion/vmrun' -T fusion"
53
53
  end
54
54
 
55
55
  it 'should set the vmrun_cmd correctly if there is a user specified vmrun bin' do
@@ -58,7 +58,7 @@ describe Fission::Config do
58
58
  end
59
59
 
60
60
  @config = Fission::Config.new
61
- @config.attributes['vmrun_cmd'].should == '/var/tmp/vmrun_bin -T fusion'
61
+ @config.attributes['vmrun_cmd'].should == "'/var/tmp/vmrun_bin' -T fusion"
62
62
  end
63
63
 
64
64
  it 'should use the fusion default lease file' do
@@ -1,21 +1,26 @@
1
- require File.expand_path('../../spec_helper.rb', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Fission::Fusion do
4
4
  describe 'self.running?' do
5
5
  before do
6
6
  @cmd = "ps -ef | grep -v grep | "
7
- @cmd << "grep -c #{Fission.config['gui_bin'].gsub(' ', '\ ')} 2>&1"
7
+ @cmd << "grep -c '#{Fission.config['gui_bin']}' 2>&1"
8
+ @executor = mock 'executor'
8
9
  end
9
10
 
10
11
  it 'should return a successful response and true if the fusion app is running' do
11
- Fission::Fusion.should_receive(:`).with(@cmd).
12
- and_return("1\n")
12
+ @executor.should_receive(:execute).and_return({'output' => "1\n"})
13
+ Fission::Action::ShellExecutor.should_receive(:new).
14
+ with(@cmd).
15
+ and_return(@executor)
13
16
  Fission::Fusion.running?.should == true
14
17
  end
15
18
 
16
19
  it 'should return a successful response and false if the fusion app is not running' do
17
- Fission::Fusion.should_receive(:`).with(@cmd).
18
- and_return("0\n")
20
+ @executor.should_receive(:execute).and_return({'output' => "0\n"})
21
+ Fission::Action::ShellExecutor.should_receive(:new).
22
+ with(@cmd).
23
+ and_return(@executor)
19
24
  Fission::Fusion.running?.should == false
20
25
  end
21
26
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper.rb', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Fission::Lease do
4
4
  before do
@@ -6,14 +6,22 @@ describe Fission::Lease do
6
6
  :mac_address => '00:0c:29:2b:af:50',
7
7
  :start => '2011/10/11 01:50:58',
8
8
  :end => '2011/10/11 02:20:58' },
9
+ { :ip_address => '172.16.248.170',
10
+ :mac_address => '00:0c:29:b3:63:d0',
11
+ :start => '2010/03/01 00:54:52',
12
+ :end => '2010/03/01 01:24:52' },
9
13
  { :ip_address => '172.16.248.132',
10
14
  :mac_address => '00:0c:29:10:23:57',
11
15
  :start => '2010/07/12 21:31:28',
12
16
  :end => '2010/07/12 22:01:28' },
13
- { :ip_address => '172.16.248.130',
17
+ { :ip_address => '172.16.248.150',
14
18
  :mac_address => '00:0c:29:b3:63:d0',
15
19
  :start => '2010/05/27 00:54:52',
16
20
  :end => '2010/05/27 01:24:52' },
21
+ { :ip_address => '172.16.248.130',
22
+ :mac_address => '00:0c:29:b3:63:d0',
23
+ :start => '2010/04/15 00:54:52',
24
+ :end => '2010/04/15 01:24:52' },
17
25
  { :ip_address => '172.16.248.129',
18
26
  :mac_address => '00:0c:29:0a:e9:b3',
19
27
  :start => '2010/02/16 23:16:05',
@@ -26,16 +34,26 @@ lease 172.16.248.197 {
26
34
  ends 2 2011/10/11 02:20:58;
27
35
  hardware ethernet 00:0c:29:2b:af:50;
28
36
  }
37
+ lease 172.16.248.170 {
38
+ starts 4 2010/03/01 00:54:52;
39
+ ends 4 2010/03/01 01:24:52;
40
+ hardware ethernet 00:0c:29:b3:63:d0;
41
+ }
29
42
  lease 172.16.248.132 {
30
43
  starts 1 2010/07/12 21:31:28;
31
44
  ends 1 2010/07/12 22:01:28;
32
45
  hardware ethernet 00:0c:29:10:23:57;
33
46
  }
34
- lease 172.16.248.130 {
47
+ lease 172.16.248.150 {
35
48
  starts 4 2010/05/27 00:54:52;
36
49
  ends 4 2010/05/27 01:24:52;
37
50
  hardware ethernet 00:0c:29:b3:63:d0;
38
51
  }
52
+ lease 172.16.248.130 {
53
+ starts 4 2010/04/15 00:54:52;
54
+ ends 4 2010/04/15 01:24:52;
55
+ hardware ethernet 00:0c:29:b3:63:d0;
56
+ }
39
57
  lease 172.16.248.129 {
40
58
  starts 2 2010/02/16 23:16:05;
41
59
  ends 2 2010/02/16 23:46:05;
@@ -44,10 +62,6 @@ lease 172.16.248.129 {
44
62
  end
45
63
 
46
64
  describe 'new' do
47
- { :ip_address => '127.0.0.1',
48
- :mac_address => '00:00:00:00:00:00',
49
- :start => '2004/07/25 17:18:00',
50
- :end => '2004/07/25 18:18:00' }
51
65
  it 'should set the ip address' do
52
66
  lease = Fission::Lease.new :ip_address => '127.0.0.1'
53
67
  lease.ip_address.should == '127.0.0.1'
@@ -84,52 +98,63 @@ lease 172.16.248.129 {
84
98
  end
85
99
 
86
100
  describe 'self.all' do
87
- it 'should query the configured lease file' do
88
- File.should_receive(:read).with(Fission.config['lease_file']).
89
- and_return('')
90
-
91
- Fission::Lease.all
92
- end
93
101
 
94
- it 'should return a successful response with the list of the found leases' do
95
- File.should_receive(:read).with(Fission.config['lease_file']).
96
- and_return(@lease_file_content)
102
+ context 'when the lease file exists' do
103
+ before do
104
+ File.should_receive(:file?).
105
+ with(Fission.config['lease_file']).
106
+ and_return(true)
107
+ end
97
108
 
98
- example_leases = @lease_info.collect do |lease|
99
- Fission::Lease.new :ip_address => lease[:ip_address],
100
- :mac_address => lease[:mac_address],
101
- :start => DateTime.parse(lease[:start]),
102
- :end => DateTime.parse(lease[:end])
109
+ it 'returns a response with the list of the found leases' do
110
+ File.should_receive(:read).
111
+ with(Fission.config['lease_file']).
112
+ and_return(@lease_file_content)
103
113
 
104
- end
114
+ example_leases = @lease_info.collect do |lease|
115
+ Fission::Lease.new :ip_address => lease[:ip_address],
116
+ :mac_address => lease[:mac_address],
117
+ :start => DateTime.parse(lease[:start]),
118
+ :end => DateTime.parse(lease[:end])
119
+ end
105
120
 
106
- response = Fission::Lease.all
107
- response.should be_a_successful_response
121
+ response = Fission::Lease.all
122
+ response.should be_a_successful_response
108
123
 
109
- response.data.each do |lease|
110
- example_lease = example_leases.select { |l| l.ip_address == lease.ip_address }
124
+ response.data.each do |lease|
125
+ example_lease = example_leases.select { |l| l.ip_address == lease.ip_address }
111
126
 
112
- [:ip_address, :mac_address, :start, :end].each do |attrib|
113
- lease.send(attrib).should == example_lease.first.send(attrib)
127
+ [:ip_address, :mac_address, :start, :end].each do |attrib|
128
+ lease.send(attrib).should == example_lease.first.send(attrib)
129
+ end
114
130
  end
131
+
115
132
  end
116
133
 
117
- end
134
+ it 'a response with an empty list if there are no leases found' do
135
+ File.should_receive(:read).
136
+ with(Fission.config['lease_file']).
137
+ and_return('')
138
+ response = Fission::Lease.all
139
+ response.should be_a_successful_response
140
+ response.data.should == []
141
+ end
118
142
 
119
- it 'should return a successful response with an empty list if there are no leases found' do
120
- File.should_receive(:read).with(Fission.config['lease_file']).
121
- and_return('')
122
- response = Fission::Lease.all
123
- response.should be_a_successful_response
124
- response.data.should == []
125
143
  end
126
144
 
127
- it 'should return an unsuccessful response if the configured lease file does not exist' do
128
- File.should_receive(:file?).with(Fission.config['lease_file']).
129
- and_return(false)
130
- response = Fission::Lease.all
131
- error_string = "Unable to find the lease file '#{Fission.config['lease_file']}'"
132
- response.should be_an_unsuccessful_response(error_string)
145
+ context 'when the lease file does not exist' do
146
+ before do
147
+ File.should_receive(:file?).
148
+ with(Fission.config['lease_file']).
149
+ and_return(false)
150
+ end
151
+
152
+ it 'should return an unsuccessful response if the configured lease file does not exist' do
153
+ response = Fission::Lease.all
154
+ error_string = "Unable to find the lease file '#{Fission.config['lease_file']}'"
155
+ response.should be_an_unsuccessful_response(error_string)
156
+ end
157
+
133
158
  end
134
159
 
135
160
  end
@@ -137,16 +162,27 @@ lease 172.16.248.129 {
137
162
  describe 'self.find_by_mac_address' do
138
163
  describe 'when able to get all of the leases' do
139
164
  before do
140
- File.should_receive(:read).with(Fission.config['lease_file']).
141
- and_return(@lease_file_content)
165
+ File.stub(:file?).and_return(true)
166
+ File.stub(:read).and_return(@lease_file_content)
142
167
  end
143
168
 
144
- it 'should return a response with the lease associated with the provided mac address' do
169
+ context 'when there are multiple leases for the mac address' do
170
+ it 'should return the lease with the latest expiration' do
171
+ response = Fission::Lease.find_by_mac_address '00:0c:29:b3:63:d0'
172
+
173
+ response.should be_a_successful_response
174
+
175
+ response.data.ip_address.should == '172.16.248.150'
176
+ response.data.mac_address.should == '00:0c:29:b3:63:d0'
177
+ response.data.start.should == DateTime.parse('2010/05/27 00:54:52')
178
+ response.data.end.should == DateTime.parse('2010/05/27 01:24:52')
179
+ end
180
+ end
145
181
 
182
+ it 'should return a response with the lease associated with the provided mac address' do
146
183
  response = Fission::Lease.find_by_mac_address '00:0c:29:10:23:57'
147
184
 
148
185
  response.should be_a_successful_response
149
-
150
186
  response.data.ip_address.should == '172.16.248.132'
151
187
  response.data.mac_address.should == '00:0c:29:10:23:57'
152
188
  response.data.start.should == DateTime.parse('2010/07/12 21:31:28')
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper.rb', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Fission::Metadata do
4
4
  before do
@@ -23,13 +23,16 @@ describe Fission::Metadata do
23
23
 
24
24
  describe 'delete_vm_restart_document' do
25
25
  before do
26
- @data = { 'PLRestartDocumentPaths' => ['/vm/foo.vmwarevm', '/vm/bar.vmwarevm']}
26
+ vm_dir = Fission.config['vm_dir']
27
+ @foo_vm_dir = File.join vm_dir, 'foo.vmwarevm'
28
+ @bar_vm_dir = File.join vm_dir, 'bar.vmwarevm'
29
+ @data = { 'PLRestartDocumentPaths' => [@foo_vm_dir, @bar_vm_dir]}
27
30
  @metadata.content = @data
28
31
  end
29
32
 
30
33
  it 'should remove the vm item from the list if the vm path is in the list' do
31
34
  @metadata.delete_vm_restart_document(Fission::VM.new('foo').path)
32
- @metadata.content.should == { 'PLRestartDocumentPaths' => ['/vm/bar.vmwarevm']}
35
+ @metadata.content.should == { 'PLRestartDocumentPaths' => [@bar_vm_dir]}
33
36
  end
34
37
 
35
38
  it 'should not doing anything if the vm is not in the list' do
@@ -47,7 +50,9 @@ describe Fission::Metadata do
47
50
 
48
51
  describe 'delete_vm_favorite_entry' do
49
52
  before do
50
- @data = { 'VMFavoritesListDefaults2' => [{'path' => '/vm/foo.vmwarevm'}] }
53
+ foo_vm_dir = File.join Fission.config['vm_dir'], 'foo.vmwarevm'
54
+
55
+ @data = { 'VMFavoritesListDefaults2' => [{'path' => foo_vm_dir}] }
51
56
  @metadata.content = @data
52
57
  end
53
58
 
@@ -60,6 +65,22 @@ describe Fission::Metadata do
60
65
  @metadata.delete_vm_favorite_entry(Fission::VM.new('bar').path)
61
66
  @metadata.content.should == @data
62
67
  end
68
+
69
+ it 'should ignore VMFavoritesListDefaults2 in Fussion 5' do
70
+ data = {}
71
+ @metadata.content = data
72
+ @metadata.delete_vm_favorite_entry(Fission::VM.new('bar').path)
73
+ @metadata.content.should == data
74
+ end
75
+
76
+ it 'should remove the vm item from the list in Fussion 5' do
77
+ foo_vm_dir = File.join Fission.config['vm_dir'], 'foo.vmwarevm'
78
+ data = {"fusionInitialSessions" => [{"documentPath" => foo_vm_dir}]}
79
+
80
+ @metadata.content = data
81
+ @metadata.delete_vm_favorite_entry(Fission::VM.new('foo').path)
82
+ @metadata.content.should == { 'fusionInitialSessions' => []}
83
+ end
63
84
  end
64
85
 
65
86
  describe 'self.delete_vm_info' do
@@ -68,16 +89,18 @@ describe Fission::Metadata do
68
89
  @md_mock.should_receive(:load)
69
90
  @md_mock.should_receive(:save)
70
91
  Fission::Metadata.stub!(:new).and_return(@md_mock)
92
+
93
+ @foo_vm_dir = File.join Fission.config['vm_dir'], 'foo.vmwarevm'
71
94
  end
72
95
 
73
96
  it 'should remove the vm from the restart document list' do
74
- @md_mock.should_receive(:delete_vm_restart_document).with('/vm/foo.vmwarevm')
97
+ @md_mock.should_receive(:delete_vm_restart_document).with(@foo_vm_dir)
75
98
  @md_mock.stub!(:delete_vm_favorite_entry)
76
99
  Fission::Metadata.delete_vm_info(Fission::VM.new('foo').path)
77
100
  end
78
101
 
79
102
  it 'should remove the vm from the favorite list' do
80
- @md_mock.should_receive(:delete_vm_favorite_entry).with('/vm/foo.vmwarevm')
103
+ @md_mock.should_receive(:delete_vm_favorite_entry).with(@foo_vm_dir)
81
104
  @md_mock.stub!(:delete_vm_restart_document)
82
105
  Fission::Metadata.delete_vm_info(Fission::VM.new('foo').path)
83
106
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper.rb', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Fission::Response do
4
4
  describe 'initialize' do
@@ -58,23 +58,34 @@ describe Fission::Response do
58
58
  end
59
59
  end
60
60
 
61
- describe 'self.from_command' do
61
+ describe 'self.from_shell_executor' do
62
+ before do
63
+ @process_status = mock 'process status'
64
+ end
65
+
62
66
  it 'should return a response object' do
63
- Fission::Response.from_command('').should be_a Fission::Response
67
+ @process_status.stub(:exitstatus).and_return(0)
68
+ executor = {'process_status' => @process_status}
69
+ Fission::Response.from_shell_executor(executor).should be_a Fission::Response
64
70
  end
65
71
 
66
72
  it 'should set the code to the exit status' do
67
- $?.should_receive(:exitstatus).and_return(55)
68
- Fission::Response.from_command('').code.should == 55
73
+ @process_status.stub(:exitstatus).and_return(55)
74
+ executor = {'process_status' => @process_status}
75
+ Fission::Response.from_shell_executor(executor).code.should == 55
69
76
  end
70
77
 
71
78
  it 'should set the message if the command was unsuccessful' do
72
- $?.should_receive(:exitstatus).and_return(55)
73
- Fission::Response.from_command('foo').message.should == 'foo'
79
+ @process_status.stub(:exitstatus).and_return(55)
80
+ executor = {'process_status' => @process_status,
81
+ 'output' => 'foo'}
82
+ Fission::Response.from_shell_executor(executor).message.should == 'foo'
74
83
  end
75
84
  it 'should not set the message if the command was successful' do
76
- $?.should_receive(:exitstatus).and_return(0)
77
- Fission::Response.from_command('foo').message.should == ''
85
+ @process_status.stub(:exitstatus).and_return(0)
86
+ executor = {'process_status' => @process_status,
87
+ 'output' => 'foo'}
88
+ Fission::Response.from_shell_executor(executor).message.should == ''
78
89
  end
79
90
 
80
91
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper.rb', __FILE__)
1
+ require 'spec_helper'
2
2
 
3
3
  describe Fission::UI do
4
4
  before do
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fission::VMConfiguration do
4
+ before do
5
+ @vm = Fission::VM.new 'foo'
6
+ @conf_file_response_mock = mock 'conf_file_response'
7
+ @conf_file_response_mock.stub_as_successful @conf_file_path
8
+ end
9
+
10
+ describe 'config_data' do
11
+ before do
12
+ @vm.stub(:exists?).and_return(true)
13
+ @vm_config = Fission::VMConfiguration.new @vm
14
+ @vm.stub(:conf_file).and_return(@conf_file_response_mock)
15
+ end
16
+
17
+ it "should return an unsuccessful response if the vm doesn't exist" do
18
+ @vm.stub(:exists?).and_return(false)
19
+ @vm_config.config_data.should be_an_unsuccessful_response 'VM does not exist'
20
+ end
21
+
22
+ it 'should return an unsuccessful response if unable to figure out the conf file' do
23
+ @conf_file_response_mock.stub_as_unsuccessful
24
+ @vm_config.config_data.should be_an_unsuccessful_response
25
+ end
26
+
27
+ context 'when the vm exists and the conf file can be found' do
28
+ before do
29
+ @conf_file_io = StringIO.new
30
+ vmx_content = '.encoding = "UTF-8"
31
+ config.version = "8"
32
+ virtualHW.version = "7"
33
+ scsi0.present = "TRUE"
34
+ scsi0.virtualDev = "lsilogic"
35
+ memsize = "384"
36
+ scsi0:0.present = "TRUE"
37
+ scsi0:0.fileName = "u10_04-000001.vmdk"
38
+ ethernet0.present = "TRUE"
39
+ ethernet0.connectionType = "nat"
40
+ ethernet0.wakeOnPcktRcv = "FALSE"
41
+ ethernet0.addressType = "generated"
42
+ ethernet0.linkStatePropagation.enable = "TRUE"
43
+ ehci.present = "TRUE"
44
+ pciBridge4.virtualDev = "pcieRootPort"
45
+ pciBridge4.functions = "8"
46
+ vmci0.present = "TRUE"
47
+ roamingVM.exitBehavior = "go"
48
+ tools.syncTime = "TRUE"
49
+ displayName = "u10_04"
50
+ guestOS = "ubuntu"
51
+ nvram = "u10_04.nvram"
52
+ virtualHW.productCompatibility = "hosted"
53
+ tools.upgrade.policy = "upgradeAtPowerCycle"
54
+ extendedConfigFile = "u10_04.vmxf"
55
+ serial0.present = "FALSE"
56
+ usb.present = "FALSE"
57
+ checkpoint.vmState = "u10_04.vmss"
58
+ ethernet0.generatedAddress = "00:0c:29:c4:94:22"
59
+ uuid.location = "56 4d 4b e9 1a bb 22 3a-b0 91 06 4e b4 c4 94 22"
60
+ uuid.bios = "56 4d 4b e9 1a bb 22 3a-b0 91 06 4e b4 c4 94 22"
61
+ cleanShutdown = "TRUE"
62
+ scsi0:0.redo = ""
63
+ scsi0.pciSlotNumber = "16"
64
+ ethernet0.pciSlotNumber = "32"
65
+ ethernet0.generatedAddressOffset = "0"
66
+ vmci0.id = "-1262185438"
67
+ tools.remindInstall = "TRUE"'
68
+ @conf_file_io.string = vmx_content
69
+ File.should_receive(:readlines).with(@conf_file_path).
70
+ and_return(@conf_file_io.string.split(/$/))
71
+ end
72
+
73
+ it 'should return a successful response' do
74
+ @vm_config.config_data.should be_a_successful_response
75
+ end
76
+
77
+ it 'should return the data as a hash like object' do
78
+ config = @vm_config.config_data
79
+ config.data.should respond_to :keys
80
+ config.data.should respond_to :values
81
+ config.data.should respond_to :each_pair
82
+ config.data.should respond_to :[]
83
+ end
84
+
85
+ it 'should return accurate data' do
86
+ expected_data = { '.encoding' => 'UTF-8',
87
+ 'config.version' => '8',
88
+ 'virtualHW.version' => '7',
89
+ 'scsi0.present' => 'TRUE',
90
+ 'scsi0.virtualDev' => 'lsilogic',
91
+ 'memsize' => '384',
92
+ 'scsi0:0.present' => 'TRUE',
93
+ 'scsi0:0.fileName' => 'u10_04-000001.vmdk',
94
+ 'ethernet0.present' => 'TRUE',
95
+ 'ethernet0.connectionType' => 'nat',
96
+ 'ethernet0.wakeOnPcktRcv' => 'FALSE',
97
+ 'ethernet0.addressType' => 'generated',
98
+ 'ethernet0.linkStatePropagation.enable' => 'TRUE',
99
+ 'ehci.present' => 'TRUE',
100
+ 'pciBridge4.virtualDev' => 'pcieRootPort',
101
+ 'pciBridge4.functions' => '8',
102
+ 'vmci0.present' => 'TRUE',
103
+ 'roamingVM.exitBehavior' => 'go',
104
+ 'tools.syncTime' => 'TRUE',
105
+ 'displayName' => 'u10_04',
106
+ 'guestOS' => 'ubuntu',
107
+ 'nvram' => 'u10_04.nvram',
108
+ 'virtualHW.productCompatibility' => 'hosted',
109
+ 'tools.upgrade.policy' => 'upgradeAtPowerCycle',
110
+ 'extendedConfigFile' => 'u10_04.vmxf',
111
+ 'serial0.present' => 'FALSE',
112
+ 'usb.present' => 'FALSE',
113
+ 'checkpoint.vmState' => 'u10_04.vmss',
114
+ 'ethernet0.generatedAddress' => '00:0c:29:c4:94:22',
115
+ 'uuid.location' => '56 4d 4b e9 1a bb 22 3a-b0 91 06 4e b4 c4 94 22',
116
+ 'uuid.bios' => '56 4d 4b e9 1a bb 22 3a-b0 91 06 4e b4 c4 94 22',
117
+ 'cleanShutdown' => 'TRUE',
118
+ 'scsi0:0.redo' => '',
119
+ 'scsi0.pciSlotNumber' => '16',
120
+ 'ethernet0.pciSlotNumber' => '32',
121
+ 'ethernet0.generatedAddressOffset' => '0',
122
+ 'vmci0.id' => '-1262185438',
123
+ 'tools.remindInstall' => 'TRUE' }
124
+
125
+ config = @vm_config.config_data
126
+ config.data.should == expected_data
127
+ end
128
+
129
+ end
130
+ end
131
+
132
+ end