right_agent 2.0.7-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +82 -0
  3. data/Rakefile +113 -0
  4. data/lib/right_agent.rb +59 -0
  5. data/lib/right_agent/actor.rb +182 -0
  6. data/lib/right_agent/actor_registry.rb +76 -0
  7. data/lib/right_agent/actors/agent_manager.rb +232 -0
  8. data/lib/right_agent/agent.rb +1149 -0
  9. data/lib/right_agent/agent_config.rb +480 -0
  10. data/lib/right_agent/agent_identity.rb +210 -0
  11. data/lib/right_agent/agent_tag_manager.rb +237 -0
  12. data/lib/right_agent/audit_formatter.rb +107 -0
  13. data/lib/right_agent/clients.rb +31 -0
  14. data/lib/right_agent/clients/api_client.rb +383 -0
  15. data/lib/right_agent/clients/auth_client.rb +247 -0
  16. data/lib/right_agent/clients/balanced_http_client.rb +369 -0
  17. data/lib/right_agent/clients/base_retry_client.rb +495 -0
  18. data/lib/right_agent/clients/right_http_client.rb +279 -0
  19. data/lib/right_agent/clients/router_client.rb +493 -0
  20. data/lib/right_agent/command.rb +30 -0
  21. data/lib/right_agent/command/agent_manager_commands.rb +150 -0
  22. data/lib/right_agent/command/command_client.rb +136 -0
  23. data/lib/right_agent/command/command_constants.rb +33 -0
  24. data/lib/right_agent/command/command_io.rb +126 -0
  25. data/lib/right_agent/command/command_parser.rb +87 -0
  26. data/lib/right_agent/command/command_runner.rb +118 -0
  27. data/lib/right_agent/command/command_serializer.rb +63 -0
  28. data/lib/right_agent/connectivity_checker.rb +179 -0
  29. data/lib/right_agent/console.rb +65 -0
  30. data/lib/right_agent/core_payload_types.rb +44 -0
  31. data/lib/right_agent/core_payload_types/cookbook.rb +61 -0
  32. data/lib/right_agent/core_payload_types/cookbook_position.rb +46 -0
  33. data/lib/right_agent/core_payload_types/cookbook_repository.rb +116 -0
  34. data/lib/right_agent/core_payload_types/cookbook_sequence.rb +70 -0
  35. data/lib/right_agent/core_payload_types/dev_repositories.rb +100 -0
  36. data/lib/right_agent/core_payload_types/dev_repository.rb +76 -0
  37. data/lib/right_agent/core_payload_types/event_categories.rb +38 -0
  38. data/lib/right_agent/core_payload_types/executable_bundle.rb +130 -0
  39. data/lib/right_agent/core_payload_types/login_policy.rb +72 -0
  40. data/lib/right_agent/core_payload_types/login_user.rb +79 -0
  41. data/lib/right_agent/core_payload_types/planned_volume.rb +94 -0
  42. data/lib/right_agent/core_payload_types/recipe_instantiation.rb +73 -0
  43. data/lib/right_agent/core_payload_types/repositories_bundle.rb +50 -0
  44. data/lib/right_agent/core_payload_types/right_script_attachment.rb +95 -0
  45. data/lib/right_agent/core_payload_types/right_script_instantiation.rb +94 -0
  46. data/lib/right_agent/core_payload_types/runlist_policy.rb +44 -0
  47. data/lib/right_agent/core_payload_types/secure_document.rb +66 -0
  48. data/lib/right_agent/core_payload_types/secure_document_location.rb +63 -0
  49. data/lib/right_agent/core_payload_types/software_repository_instantiation.rb +61 -0
  50. data/lib/right_agent/daemonize.rb +35 -0
  51. data/lib/right_agent/dispatched_cache.rb +109 -0
  52. data/lib/right_agent/dispatcher.rb +272 -0
  53. data/lib/right_agent/enrollment_result.rb +221 -0
  54. data/lib/right_agent/exceptions.rb +87 -0
  55. data/lib/right_agent/history.rb +145 -0
  56. data/lib/right_agent/log.rb +460 -0
  57. data/lib/right_agent/minimal.rb +46 -0
  58. data/lib/right_agent/monkey_patches.rb +30 -0
  59. data/lib/right_agent/monkey_patches/ruby_patch.rb +55 -0
  60. data/lib/right_agent/monkey_patches/ruby_patch/array_patch.rb +29 -0
  61. data/lib/right_agent/monkey_patches/ruby_patch/darwin_patch.rb +24 -0
  62. data/lib/right_agent/monkey_patches/ruby_patch/linux_patch.rb +24 -0
  63. data/lib/right_agent/monkey_patches/ruby_patch/linux_patch/file_patch.rb +30 -0
  64. data/lib/right_agent/monkey_patches/ruby_patch/object_patch.rb +49 -0
  65. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch.rb +32 -0
  66. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/file_patch.rb +60 -0
  67. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/process_patch.rb +63 -0
  68. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/stdio_patch.rb +27 -0
  69. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/time_patch.rb +55 -0
  70. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/win32ole_patch.rb +34 -0
  71. data/lib/right_agent/multiplexer.rb +102 -0
  72. data/lib/right_agent/offline_handler.rb +270 -0
  73. data/lib/right_agent/operation_result.rb +300 -0
  74. data/lib/right_agent/packets.rb +673 -0
  75. data/lib/right_agent/payload_formatter.rb +104 -0
  76. data/lib/right_agent/pending_requests.rb +128 -0
  77. data/lib/right_agent/pid_file.rb +159 -0
  78. data/lib/right_agent/platform.rb +770 -0
  79. data/lib/right_agent/platform/unix/darwin/platform.rb +102 -0
  80. data/lib/right_agent/platform/unix/linux/platform.rb +305 -0
  81. data/lib/right_agent/platform/unix/platform.rb +226 -0
  82. data/lib/right_agent/platform/windows/mingw/platform.rb +447 -0
  83. data/lib/right_agent/platform/windows/mswin/platform.rb +236 -0
  84. data/lib/right_agent/platform/windows/platform.rb +1808 -0
  85. data/lib/right_agent/protocol_version_mixin.rb +69 -0
  86. data/lib/right_agent/retryable_request.rb +195 -0
  87. data/lib/right_agent/scripts/agent_controller.rb +543 -0
  88. data/lib/right_agent/scripts/agent_deployer.rb +400 -0
  89. data/lib/right_agent/scripts/common_parser.rb +160 -0
  90. data/lib/right_agent/scripts/log_level_manager.rb +192 -0
  91. data/lib/right_agent/scripts/stats_manager.rb +268 -0
  92. data/lib/right_agent/scripts/usage.rb +58 -0
  93. data/lib/right_agent/secure_identity.rb +92 -0
  94. data/lib/right_agent/security.rb +32 -0
  95. data/lib/right_agent/security/cached_certificate_store_proxy.rb +77 -0
  96. data/lib/right_agent/security/certificate.rb +102 -0
  97. data/lib/right_agent/security/certificate_cache.rb +89 -0
  98. data/lib/right_agent/security/distinguished_name.rb +56 -0
  99. data/lib/right_agent/security/encrypted_document.rb +83 -0
  100. data/lib/right_agent/security/rsa_key_pair.rb +76 -0
  101. data/lib/right_agent/security/signature.rb +86 -0
  102. data/lib/right_agent/security/static_certificate_store.rb +85 -0
  103. data/lib/right_agent/sender.rb +792 -0
  104. data/lib/right_agent/serialize.rb +29 -0
  105. data/lib/right_agent/serialize/message_pack.rb +107 -0
  106. data/lib/right_agent/serialize/secure_serializer.rb +151 -0
  107. data/lib/right_agent/serialize/secure_serializer_initializer.rb +47 -0
  108. data/lib/right_agent/serialize/serializable.rb +151 -0
  109. data/lib/right_agent/serialize/serializer.rb +159 -0
  110. data/lib/right_agent/subprocess.rb +38 -0
  111. data/lib/right_agent/tracer.rb +124 -0
  112. data/right_agent.gemspec +101 -0
  113. data/spec/actor_registry_spec.rb +80 -0
  114. data/spec/actor_spec.rb +162 -0
  115. data/spec/agent_config_spec.rb +235 -0
  116. data/spec/agent_identity_spec.rb +78 -0
  117. data/spec/agent_spec.rb +734 -0
  118. data/spec/agent_tag_manager_spec.rb +319 -0
  119. data/spec/clients/api_client_spec.rb +423 -0
  120. data/spec/clients/auth_client_spec.rb +272 -0
  121. data/spec/clients/balanced_http_client_spec.rb +576 -0
  122. data/spec/clients/base_retry_client_spec.rb +635 -0
  123. data/spec/clients/router_client_spec.rb +594 -0
  124. data/spec/clients/spec_helper.rb +111 -0
  125. data/spec/command/agent_manager_commands_spec.rb +51 -0
  126. data/spec/command/command_io_spec.rb +93 -0
  127. data/spec/command/command_parser_spec.rb +79 -0
  128. data/spec/command/command_runner_spec.rb +107 -0
  129. data/spec/command/command_serializer_spec.rb +51 -0
  130. data/spec/connectivity_checker_spec.rb +83 -0
  131. data/spec/core_payload_types/dev_repositories_spec.rb +64 -0
  132. data/spec/core_payload_types/dev_repository_spec.rb +33 -0
  133. data/spec/core_payload_types/executable_bundle_spec.rb +67 -0
  134. data/spec/core_payload_types/login_user_spec.rb +102 -0
  135. data/spec/core_payload_types/recipe_instantiation_spec.rb +81 -0
  136. data/spec/core_payload_types/right_script_attachment_spec.rb +65 -0
  137. data/spec/core_payload_types/right_script_instantiation_spec.rb +79 -0
  138. data/spec/core_payload_types/spec_helper.rb +23 -0
  139. data/spec/dispatched_cache_spec.rb +136 -0
  140. data/spec/dispatcher_spec.rb +324 -0
  141. data/spec/enrollment_result_spec.rb +53 -0
  142. data/spec/history_spec.rb +246 -0
  143. data/spec/log_spec.rb +192 -0
  144. data/spec/monkey_patches/eventmachine_spec.rb +62 -0
  145. data/spec/multiplexer_spec.rb +48 -0
  146. data/spec/offline_handler_spec.rb +340 -0
  147. data/spec/operation_result_spec.rb +208 -0
  148. data/spec/packets_spec.rb +461 -0
  149. data/spec/pending_requests_spec.rb +136 -0
  150. data/spec/platform/spec_helper.rb +216 -0
  151. data/spec/platform/unix/darwin/platform_spec.rb +181 -0
  152. data/spec/platform/unix/linux/platform_spec.rb +540 -0
  153. data/spec/platform/unix/spec_helper.rb +149 -0
  154. data/spec/platform/windows/mingw/platform_spec.rb +222 -0
  155. data/spec/platform/windows/mswin/platform_spec.rb +259 -0
  156. data/spec/platform/windows/spec_helper.rb +720 -0
  157. data/spec/retryable_request_spec.rb +306 -0
  158. data/spec/secure_identity_spec.rb +50 -0
  159. data/spec/security/cached_certificate_store_proxy_spec.rb +62 -0
  160. data/spec/security/certificate_cache_spec.rb +71 -0
  161. data/spec/security/certificate_spec.rb +49 -0
  162. data/spec/security/distinguished_name_spec.rb +46 -0
  163. data/spec/security/encrypted_document_spec.rb +55 -0
  164. data/spec/security/rsa_key_pair_spec.rb +55 -0
  165. data/spec/security/signature_spec.rb +66 -0
  166. data/spec/security/static_certificate_store_spec.rb +58 -0
  167. data/spec/sender_spec.rb +1045 -0
  168. data/spec/serialize/message_pack_spec.rb +131 -0
  169. data/spec/serialize/secure_serializer_spec.rb +132 -0
  170. data/spec/serialize/serializable_spec.rb +90 -0
  171. data/spec/serialize/serializer_spec.rb +197 -0
  172. data/spec/spec.opts +2 -0
  173. data/spec/spec.win32.opts +1 -0
  174. data/spec/spec_helper.rb +130 -0
  175. data/spec/tracer_spec.rb +114 -0
  176. metadata +447 -0
@@ -0,0 +1,540 @@
1
+ #
2
+ # Copyright (c) 2013 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require ::File.expand_path('../../spec_helper', __FILE__)
24
+
25
+ describe RightScale::Platform do
26
+
27
+ include PlatformSpecHelper
28
+
29
+ context 'unix/linux' do
30
+
31
+ # required by before_all_platform_tests
32
+ # called by before(:all) so not defined using let().
33
+ def expected_genus; :unix; end
34
+ def expected_species; :linux; end
35
+
36
+ before(:all) do
37
+ before_all_platform_tests
38
+ end
39
+
40
+ after(:all) do
41
+ after_all_platform_tests
42
+ end
43
+
44
+ before(:each) do
45
+ before_each_platform_test
46
+ end
47
+
48
+ after(:each) do
49
+ after_each_platform_test
50
+ end
51
+
52
+ context 'statics' do
53
+ subject { platform_class }
54
+
55
+ it 'should be linux' do
56
+ subject.unix?.should be_true
57
+ subject.windows?.should be_false
58
+ subject.linux?.should be_true
59
+ subject.darwin?.should be_false
60
+ end
61
+ end
62
+
63
+ context 'initialization' do
64
+ let(:lsb_help_cmd) { 'lsb_release --help >/dev/null 2>&1' }
65
+
66
+ context 'when lsb_release is available' do
67
+ it 'should initialize from lsb_release data' do
68
+ platform_instance.
69
+ should_receive(:execute).
70
+ with(lsb_help_cmd).
71
+ and_return("lsb_release\nhelp\ndump\n").
72
+ once
73
+ platform_instance.
74
+ should_receive(:execute).
75
+ with('lsb_release -is', { :raise_on_failure => false }).
76
+ and_return("Ubuntu\n").
77
+ once
78
+ platform_instance.
79
+ should_receive(:execute).
80
+ with('lsb_release -rs', { :raise_on_failure => false }).
81
+ and_return("11.04\n").
82
+ once
83
+ platform_instance.
84
+ should_receive(:execute).
85
+ with('lsb_release -cs', { :raise_on_failure => false }).
86
+ and_return("natty\n").
87
+ once
88
+ platform_instance.send(:initialize_species)
89
+ platform_instance.flavor.should == 'ubuntu'
90
+ platform_instance.release.should == '11.04'
91
+ platform_instance.codename.should == 'natty'
92
+ platform_instance.ubuntu?.should be_true
93
+ platform_instance.centos?.should be_false
94
+ platform_instance.suse?.should be_false
95
+ platform_instance.rhel?.should be_false
96
+ end
97
+ end # when lsb_release is available
98
+
99
+ context 'when lsb_release is not available' do
100
+ before(:each) do
101
+ platform_instance.
102
+ should_receive(:execute).
103
+ with(lsb_help_cmd).
104
+ and_raise(described_class::CommandError).
105
+ once
106
+ end
107
+
108
+ context 'when fedora release is available' do
109
+ it 'should be fedora' do
110
+ file_mock = flexmock(::File)
111
+ file_mock.
112
+ should_receive(:exist?).
113
+ with(described_class::FEDORA_REL).
114
+ and_return(true).
115
+ once
116
+ file_mock.
117
+ should_receive(:read).
118
+ with(described_class::FEDORA_REL).
119
+ and_return("Fedora release 7 (Moonshine)\n").
120
+ once
121
+ platform_instance.send(:initialize_species)
122
+ platform_instance.flavor.should == 'fedora'
123
+ platform_instance.release.should == '7'
124
+ platform_instance.codename.should == 'Moonshine'
125
+ platform_instance.ubuntu?.should be_false
126
+ platform_instance.centos?.should be_false
127
+ platform_instance.suse?.should be_false
128
+ platform_instance.rhel?.should be_false
129
+ end
130
+ end # when fedora release is available
131
+
132
+ context 'when fedora release is not available' do
133
+ it 'should be unknown' do
134
+ file_mock = flexmock(::File)
135
+ file_mock.
136
+ should_receive(:exist?).
137
+ with(described_class::FEDORA_REL).
138
+ and_return(false).
139
+ once
140
+ platform_instance.send(:initialize_species)
141
+ platform_instance.flavor.should == 'unknown'
142
+ platform_instance.release.should == 'unknown'
143
+ platform_instance.codename.should == 'unknown'
144
+ platform_instance.ubuntu?.should be_false
145
+ platform_instance.centos?.should be_false
146
+ platform_instance.suse?.should be_false
147
+ platform_instance.rhel?.should be_false
148
+ end
149
+ end # when fedora release is not available
150
+ end # when lsb_release is not available
151
+ end # initialization
152
+
153
+ context :controller do
154
+ subject { described_class.controller }
155
+
156
+ context '#reboot' do
157
+ it 'should call init 6 under unix' do
158
+ platform_class.should_receive(:execute).with('init 6 2>&1', {}).and_return('')
159
+ subject.reboot.should be_true
160
+ end
161
+ end # reboot
162
+
163
+ context '#shutdown' do
164
+ it 'should call init 0 under unix' do
165
+ platform_class.should_receive(:execute).with('init 0 2>&1', {}).and_return('')
166
+ subject.shutdown.should be_true
167
+ end
168
+ end # shutdown
169
+ end # controller
170
+
171
+ context :filesystem do
172
+ subject { described_class.filesystem }
173
+
174
+ it_should_behave_like 'supports unix platform filesystem'
175
+ end
176
+
177
+ context :installer do
178
+ subject { installer = described_class.installer; flexmock(installer) }
179
+
180
+ context :install do
181
+ let(:packages) { %w[foo bar] }
182
+
183
+ let(:installer_data) do
184
+ {
185
+ :aptitude => {
186
+ :command => "apt-get install -y #{packages.join(' ')} 2>&1",
187
+ :failure => "E: Couldn't find package #{packages.last}"
188
+ },
189
+ :yum => {
190
+ :command => "yum install -y #{packages.join(' ')} 2>&1",
191
+ :failure => "No package #{packages.last} available."
192
+ },
193
+ :zypper => {
194
+ :command => "zypper --no-gpg-checks -n #{packages.join(' ')} 2>&1",
195
+ :failure => "Package '#{packages.last}' not found."
196
+ }
197
+ }
198
+ end
199
+
200
+ before(:each) do
201
+ installer_data.keys.each do |installer_kind|
202
+ quiz = (installer_kind.to_s + '?').to_sym
203
+ subject.should_receive(quiz).and_return do
204
+ installer_kind == expected_installer_kind
205
+ end
206
+ end
207
+ end
208
+
209
+ shared_examples_for 'supports linux platform installer install' do
210
+ it 'should succeed if no packages are specified' do
211
+ subject.install([]).should == true
212
+ end
213
+
214
+ it 'should succeed if all packages install successfully' do
215
+ platform_class.
216
+ should_receive(:execute).
217
+ with(installer_data[expected_installer_kind][:command], {}).
218
+ and_return('ok')
219
+ subject.install(packages).should == true
220
+ end
221
+
222
+ it 'should fail if one more packages are not found' do
223
+ platform_class.
224
+ should_receive(:execute).
225
+ with(installer_data[expected_installer_kind][:command], {}).
226
+ and_return(installer_data[expected_installer_kind][:failure])
227
+ expect { subject.install(packages) }.
228
+ to raise_error(
229
+ described_class::Installer::PackageNotFound,
230
+ 'The following packages were not available: bar')
231
+ end
232
+ end
233
+
234
+ [:aptitude, :yum, :zypper].each do |eik|
235
+ context eik do
236
+ let(:expected_installer_kind) { eik }
237
+
238
+ it_should_behave_like 'supports linux platform installer install'
239
+ end
240
+ end
241
+
242
+ context 'given no installers' do
243
+ let(:expected_installer_kind) { nil }
244
+
245
+ it 'should fail if no installers are found' do
246
+ expect { subject.install(packages) }.
247
+ to raise_error(
248
+ described_class::Installer::PackageManagerNotFound,
249
+ 'No package manager binary (apt, yum, zypper) found in /usr/bin')
250
+ end
251
+ end
252
+ end # install
253
+ end # installer
254
+
255
+ context :shell do
256
+ subject { described_class.shell }
257
+
258
+ # required by 'supports any platform shell'
259
+ def instrument_booted_at(booted_at)
260
+ mock_file = flexmock(::File)
261
+ mock_file.should_receive(:read).with('/proc/stat').and_return(
262
+ <<EOF
263
+ ...
264
+ ctxt 234567
265
+ btime #{booted_at.to_i}
266
+ processes 2345
267
+ ...
268
+ EOF
269
+ )
270
+ mock_file.should_receive(:read).with('/proc/uptime').and_return do
271
+ uptime = yield
272
+ "#{uptime.to_f} #{0.99 * uptime.to_f}"
273
+ end
274
+ true
275
+ end
276
+
277
+ it_should_behave_like 'supports unix platform shell'
278
+ end
279
+
280
+ context :rng do
281
+ subject { described_class.rng }
282
+
283
+ it_should_behave_like 'supports unix platform rng'
284
+ end
285
+
286
+ context :process do
287
+ subject { described_class.process }
288
+
289
+ it_should_behave_like 'supports unix platform process'
290
+ end
291
+
292
+ context :volume_manager do
293
+ let(:blkid_cmd) { 'blkid 2>&1' }
294
+
295
+ subject { platform_class.volume_manager }
296
+
297
+ context :volumes do
298
+ it 'can parse volumes from blkid output' do
299
+ expected_volumes = [
300
+ {
301
+ :device => '/dev/xvdh1',
302
+ :sec_type => 'msdos',
303
+ :label => 'METADATA',
304
+ :uuid => '681B-8C5D',
305
+ :type => 'vfat',
306
+ :filesystem => 'vfat'
307
+ },
308
+ {
309
+ :device => '/dev/xvdb1',
310
+ :label => 'SWAP-xvdb1',
311
+ :uuid => 'd51fcca0-6b10-4934-a572-f3898dfd8840',
312
+ :type => 'swap',
313
+ :filesystem => 'swap'
314
+ },
315
+ {
316
+ :device => '/dev/xvda1',
317
+ :uuid => 'f4746f9c-0557-4406-9267-5e918e87ca2e',
318
+ :type => 'ext3',
319
+ :filesystem => 'ext3'
320
+ },
321
+ {
322
+ :device => '/dev/xvda2',
323
+ :uuid => '14d88b9e-9fe6-4974-a8d6-180acdae4016',
324
+ :type => 'ext3',
325
+ :filesystem => 'ext3'
326
+ }
327
+ ]
328
+ platform_class.should_receive(:execute).with(blkid_cmd, {}).and_return(
329
+ <<EOF
330
+ /dev/xvdh1: SEC_TYPE="msdos" LABEL="METADATA" UUID="681B-8C5D" TYPE="vfat"
331
+ /dev/xvdb1: LABEL="SWAP-xvdb1" UUID="d51fcca0-6b10-4934-a572-f3898dfd8840" TYPE="swap"
332
+ /dev/xvda1: UUID="f4746f9c-0557-4406-9267-5e918e87ca2e" TYPE="ext3"
333
+ /dev/xvda2: UUID="14d88b9e-9fe6-4974-a8d6-180acdae4016" TYPE="ext3"
334
+ EOF
335
+ ).once
336
+ subject.volumes.should == expected_volumes
337
+ end
338
+
339
+ it 'can parse volumes with hyphens or underscores (lvm use case)' do
340
+ expected_volumes = [
341
+ {
342
+ :device => '/dev/vg-rightscale-data_storage1/lvol0',
343
+ :uuid => 'ee34706d-866f-476e-9da4-6a18745456a4',
344
+ :type => 'xfs',
345
+ :filesystem => 'xfs'
346
+ }
347
+ ]
348
+ platform_class.should_receive(:execute).with(blkid_cmd, {}).and_return(
349
+ <<EOF
350
+ /dev/vg-rightscale-data_storage1/lvol0: UUID="ee34706d-866f-476e-9da4-6a18745456a4" TYPE="xfs"
351
+ EOF
352
+ ).once
353
+ subject.volumes.should == expected_volumes
354
+ end
355
+
356
+ it 'can parse volumes with periods' do
357
+ expected_volumes = [
358
+ {
359
+ :device => '/dev/please.dont.do.this',
360
+ :uuid => 'ee34706d-866f-476e-9da4-6a18745456a4',
361
+ :type => 'xfs',
362
+ :filesystem => 'xfs'
363
+ }
364
+ ]
365
+ platform_class.should_receive(:execute).with(blkid_cmd, {}).and_return(
366
+ <<EOF
367
+ /dev/please.dont.do.this: UUID="ee34706d-866f-476e-9da4-6a18745456a4" TYPE="xfs"
368
+ EOF
369
+ ).once
370
+ subject.volumes.should == expected_volumes
371
+ end
372
+
373
+ it 'raises a parser error when blkid output is malformed' do
374
+ platform_class.should_receive(:execute).with(blkid_cmd, {}).and_return('gibberish').once
375
+ expect { subject.volumes }.
376
+ to raise_error(described_class::VolumeManager::ParserError)
377
+ end
378
+
379
+ it 'returns an empty list of volumes when blkid output is empty' do
380
+ platform_class.should_receive(:execute).with(blkid_cmd, {}).and_return('').once
381
+ subject.volumes.should == []
382
+ end
383
+
384
+ it 'can filter results with single condition and single match' do
385
+ expected_volumes = [
386
+ {
387
+ :device => '/dev/xvdh1',
388
+ :sec_type => 'msdos',
389
+ :label => 'METADATA',
390
+ :uuid => '681B-8C5D',
391
+ :type => 'vfat',
392
+ :filesystem => 'vfat'
393
+ }
394
+ ]
395
+ platform_class.should_receive(:execute).with(blkid_cmd, {}).and_return(
396
+ <<EOF
397
+ /dev/xvdh1: SEC_TYPE="msdos" LABEL="METADATA" UUID="681B-8C5D" TYPE="vfat"
398
+ /dev/xvdb1: LABEL="SWAP-xvdb1" UUID="d51fcca0-6b10-4934-a572-f3898dfd8840" TYPE="swap"
399
+ /dev/xvda1: UUID="f4746f9c-0557-4406-9267-5e918e87ca2e" TYPE="ext3"
400
+ /dev/xvda2: UUID="14d88b9e-9fe6-4974-a8d6-180acdae4016" TYPE="ext3"
401
+ EOF
402
+ ).once
403
+ subject.volumes(:uuid => expected_volumes[0][:uuid]).should == expected_volumes
404
+ end
405
+
406
+ it 'can filter results with multiple matches' do
407
+ expected_volumes = [
408
+ {
409
+ :device => '/dev/xvda1',
410
+ :uuid => 'f4746f9c-0557-4406-9267-5e918e87ca2e',
411
+ :type => 'ext3',
412
+ :filesystem => 'ext3'
413
+ },
414
+ {
415
+ :device => '/dev/xvda2',
416
+ :uuid => '14d88b9e-9fe6-4974-a8d6-180acdae4016',
417
+ :type => 'ext3',
418
+ :filesystem => 'ext3'
419
+ }
420
+ ]
421
+ platform_class.should_receive(:execute).with(blkid_cmd, {}).and_return(
422
+ <<EOF
423
+ /dev/xvdh1: SEC_TYPE="msdos" LABEL="METADATA" UUID="681B-8C5D" TYPE="vfat"
424
+ /dev/xvdb1: LABEL="SWAP-xvdb1" UUID="d51fcca0-6b10-4934-a572-f3898dfd8840" TYPE="swap"
425
+ /dev/xvda1: UUID="f4746f9c-0557-4406-9267-5e918e87ca2e" TYPE="ext3"
426
+ /dev/xvda2: UUID="14d88b9e-9fe6-4974-a8d6-180acdae4016" TYPE="ext3"
427
+ EOF
428
+ ).once
429
+ subject.volumes(:filesystem => 'ext3', :type => 'ext3').should == expected_volumes
430
+ end
431
+ end
432
+
433
+ context :mount_volume do
434
+ it 'mounts the specified volume if it is not already mounted' do
435
+ platform_class.
436
+ should_receive(:execute).
437
+ with('mount 2>&1', {}).
438
+ and_return(
439
+ <<EOF
440
+ /dev/xvda2 on / type ext3 (rw,noatime,errors=remount-ro)
441
+ proc on /proc type proc (rw,noexec,nosuid,nodev)
442
+ EOF
443
+ )
444
+ platform_class.
445
+ should_receive(:execute).
446
+ with('mount -t vfat /dev/xvdh1 /var/spool/softlayer 2>&1', {}).
447
+ and_return('')
448
+ subject.mount_volume(
449
+ { :device => '/dev/xvdh1', :filesystem => 'vfat' },
450
+ '/var/spool/softlayer')
451
+ end
452
+
453
+ it 'does not attempt to re-mount the volume' do
454
+ platform_class.
455
+ should_receive(:execute).
456
+ with('mount 2>&1', {}).
457
+ and_return(
458
+ <<EOF
459
+ /dev/xvda2 on / type ext3 (rw,noatime,errors=remount-ro)
460
+ proc on /proc type proc (rw,noexec,nosuid,nodev)
461
+ /dev/xvdh1 on /var/spool/softlayer type vfat (rw) [METADATA]
462
+ EOF
463
+ )
464
+ platform_class.
465
+ should_receive(:execute).
466
+ with('mount -t vfat /dev/xvdh1 /var/spool/softlayer 2>&1', {}).
467
+ and_return('')
468
+ subject.mount_volume(
469
+ {:device => '/dev/xvdh1', :filesystem => 'vfat'},
470
+ '/var/spool/softlayer')
471
+ end
472
+
473
+ it 'raises argument error when the volume parameter is not a hash' do
474
+ expect { subject.mount_volume('', '') }.
475
+ to raise_error(ArgumentError)
476
+ end
477
+
478
+ it 'raises argument error when the volume parameter is a hash but does not contain :device' do
479
+ expect { subject.mount_volume({}, '') }.
480
+ to raise_error(ArgumentError)
481
+ end
482
+
483
+ it 'raises volume error when the device is already mounted to a different mountpoint' do
484
+ platform_class.
485
+ should_receive(:execute).
486
+ with('mount 2>&1', {}).
487
+ and_return(
488
+ <<EOF
489
+ /dev/xvda2 on / type ext3 (rw,noatime,errors=remount-ro)
490
+ proc on /proc type proc (rw,noexec,nosuid,nodev)
491
+ none on /sys type sysfs (rw,noexec,nosuid,nodev)
492
+ none on /sys/kernel/debug type debugfs (rw)
493
+ none on /sys/kernel/security type securityfs (rw)
494
+ none on /dev type devtmpfs (rw,mode=0755)
495
+ none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
496
+ none on /dev/shm type tmpfs (rw,nosuid,nodev)
497
+ none on /var/run type tmpfs (rw,nosuid,mode=0755)
498
+ none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
499
+ none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
500
+ /dev/xvda1 on /boot type ext3 (rw,noatime)
501
+ /dev/xvdh1 on /mnt type vfat (rw) [METADATA]
502
+ EOF
503
+ )
504
+ expect do
505
+ subject.mount_volume(
506
+ { :device => '/dev/xvdh1' }, '/var/spool/softlayer')
507
+ end.to raise_error(described_class::VolumeManager::VolumeError)
508
+ end
509
+
510
+ it 'raises volume error when a different device is already mounted to the specified mountpoint' do
511
+ platform_class.
512
+ should_receive(:execute).
513
+ with('mount 2>&1', {}).
514
+ and_return(
515
+ <<EOF
516
+ /dev/xvda2 on / type ext3 (rw,noatime,errors=remount-ro)
517
+ proc on /proc type proc (rw,noexec,nosuid,nodev)
518
+ none on /sys type sysfs (rw,noexec,nosuid,nodev)
519
+ none on /sys/kernel/debug type debugfs (rw)
520
+ none on /sys/kernel/security type securityfs (rw)
521
+ none on /dev type devtmpfs (rw,mode=0755)
522
+ none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
523
+ none on /dev/shm type tmpfs (rw,nosuid,nodev)
524
+ none on /var/run type tmpfs (rw,nosuid,mode=0755)
525
+ none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
526
+ none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
527
+ /dev/xvda1 on /boot type ext3 (rw,noatime)
528
+ /dev/xvdh2 on /var/spool/softlayer type vfat (rw) [METADATA]
529
+ EOF
530
+ )
531
+ expect do
532
+ subject.mount_volume(
533
+ { :device => '/dev/xvdh1' }, '/var/spool/softlayer')
534
+ end.to raise_error(described_class::VolumeManager::VolumeError)
535
+ end
536
+
537
+ end # mount_volume
538
+ end # volume_manager
539
+ end # under unix/linux
540
+ end # RightScale::Platform