chef_backup 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/lib/chef_backup/config.rb +17 -17
  3. data/lib/chef_backup/data_map.rb +18 -12
  4. data/lib/chef_backup/deep_merge.rb +145 -0
  5. data/lib/chef_backup/helpers.rb +46 -10
  6. data/lib/chef_backup/logger.rb +11 -6
  7. data/lib/chef_backup/mash.rb +226 -0
  8. data/lib/chef_backup/runner.rb +17 -21
  9. data/lib/chef_backup/strategy/backup/custom.rb +1 -2
  10. data/lib/chef_backup/strategy/backup/ebs.rb +3 -6
  11. data/lib/chef_backup/strategy/backup/lvm.rb +2 -4
  12. data/lib/chef_backup/strategy/backup/object.rb +2 -4
  13. data/lib/chef_backup/strategy/backup/tar.rb +26 -10
  14. data/lib/chef_backup/strategy/restore/tar.rb +69 -43
  15. data/lib/chef_backup/strategy.rb +10 -10
  16. data/lib/chef_backup/version.rb +1 -1
  17. data/lib/chef_backup.rb +8 -8
  18. metadata +21 -161
  19. data/.gitignore +0 -23
  20. data/.kitchen.yml +0 -30
  21. data/.rubocop.yml +0 -21
  22. data/.travis.yml +0 -6
  23. data/Gemfile +0 -4
  24. data/Guardfile +0 -22
  25. data/README.md +0 -21
  26. data/Rakefile +0 -44
  27. data/chef_backup.gemspec +0 -33
  28. data/spec/fixtures/chef-server-running.json +0 -589
  29. data/spec/spec_helper.rb +0 -98
  30. data/spec/unit/data_map_spec.rb +0 -59
  31. data/spec/unit/helpers_spec.rb +0 -88
  32. data/spec/unit/runner_spec.rb +0 -185
  33. data/spec/unit/shared_examples/helpers.rb +0 -20
  34. data/spec/unit/strategy/backup/lvm_spec.rb +0 -0
  35. data/spec/unit/strategy/backup/shared_examples/backup.rb +0 -92
  36. data/spec/unit/strategy/backup/tar_spec.rb +0 -327
  37. data/spec/unit/strategy/restore/lvm_spec.rb +0 -0
  38. data/spec/unit/strategy/restore/shared_examples/restore.rb +0 -84
  39. data/spec/unit/strategy/restore/tar_spec.rb +0 -255
  40. data/spec/unit/strategy_spec.rb +0 -36
@@ -1,327 +0,0 @@
1
- require 'spec_helper'
2
- require 'chef/mixin/deep_merge'
3
- require_relative 'shared_examples/backup'
4
-
5
- describe ChefBackup::Strategy::TarBackup do
6
- set_common_variables
7
-
8
- subject { described_class.new }
9
-
10
- before do
11
- use_default_running_config
12
- allow(subject).to receive(:tmp_dir).and_return(tmp_dir)
13
- allow(subject).to receive(:backup_time).and_return(backup_time)
14
- end
15
-
16
- describe '.backup' do
17
- before do
18
- %i(write_manifest dump_db stop_service create_tarball cleanup
19
- start_service export_tarball
20
- ).each do |method|
21
- allow(subject).to receive(method).and_return(true)
22
- end
23
-
24
- allow(subject).to receive(:enabled_services).and_return(enabled_services)
25
- allow(subject).to receive(:all_services).and_return(all_services)
26
- allow(subject).to receive(:dump_db).and_return(true)
27
- end
28
-
29
- context 'when config_only is true' do
30
- before do
31
- private_chef('backup' => { 'config_only' => true })
32
- end
33
-
34
- it_behaves_like 'a tar based backup'
35
- it_behaves_like 'a tar based frontend'
36
- end
37
-
38
- context 'on a frontend' do
39
- before { private_chef('role' => 'frontend') }
40
-
41
- it_behaves_like 'a tar based backup'
42
- it_behaves_like 'a tar based frontend'
43
- end
44
-
45
- context 'on a backend' do
46
- before { private_chef('role' => 'backend') }
47
-
48
- context 'during an online backup' do
49
- before do
50
- private_chef('role' => 'backend', 'backup' => { 'mode' => 'online' })
51
- end
52
-
53
- it_behaves_like 'a tar based backup'
54
- it_behaves_like 'a tar based online backend'
55
- end
56
-
57
- context 'during an offline backup' do
58
- it_behaves_like 'a tar based backup'
59
- it_behaves_like 'a tar based offline backend'
60
- end
61
-
62
- context 'when no mode is configured' do
63
- before do
64
- private_chef('role' => 'backend', 'backup' => { 'mode' => nil })
65
- end
66
-
67
- it_behaves_like 'a tar based backup'
68
- it_behaves_like 'a tar based offline backend'
69
- end
70
- end
71
-
72
- context 'on a standalone' do
73
- before { private_chef('role' => 'standalone') }
74
-
75
- context 'during an online backup' do
76
- before do
77
- private_chef('role' => 'standalone',
78
- 'backup' => { 'mode' => 'online' })
79
- end
80
-
81
- it_behaves_like 'a tar based backup'
82
- it_behaves_like 'a tar based online backend'
83
- end
84
-
85
- context 'during an offline backup' do
86
- it_behaves_like 'a tar based backup'
87
- it_behaves_like 'a tar based offline backend'
88
- end
89
-
90
- context 'when no mode is configured' do
91
- before do
92
- private_chef('role' => 'standalone', 'backup' => { 'mode' => nil })
93
- end
94
-
95
- it_behaves_like 'a tar based backup'
96
- it_behaves_like 'a tar based offline backend'
97
- end
98
- end
99
- end
100
-
101
- describe '.dump_db' do
102
- let(:dump_cmd) do
103
- ['/opt/opscode/embedded/bin/chpst',
104
- '-u opscode-pgsql',
105
- '/opt/opscode/embedded/bin/pg_dumpall',
106
- "> #{tmp_dir}/chef_backup-#{backup_time}.sql"
107
- ].join(' ')
108
- end
109
-
110
- let(:pg_options) { ["PGOPTIONS=#{ChefBackup::Helpers::DEFAULT_PG_OPTIONS}"] }
111
- let(:tmp_dir) { '/tmp/notaswear' }
112
- let(:backup_time) { Time.now }
113
-
114
- before do
115
- allow(subject).to receive(:tmp_dir).and_return(tmp_dir)
116
- allow(subject).to receive(:backup_time).and_return(backup_time)
117
- allow(subject).to receive(:shell_out!).with(dump_cmd, env: pg_options).and_return(true)
118
- private_chef('postgresql' => { 'username' => 'opscode-pgsql' })
119
- subject.data_map.add_service('postgresql', '/data/dir')
120
- end
121
-
122
- %w(backend standalone).each do |role|
123
- context "on a #{role}" do
124
- before do
125
- private_chef('role' => role)
126
- end
127
-
128
- it 'dumps the db' do
129
- expect(subject).to receive(:shell_out!).with(dump_cmd, env: pg_options)
130
- subject.dump_db
131
- end
132
-
133
- it 'updates the data map' do
134
- subject.dump_db
135
- expect(subject.data_map.services['postgresql'])
136
- .to include('pg_dump_success' => true)
137
- end
138
-
139
- it 'adds the postgresql username to the data map' do
140
- subject.dump_db
141
- expect(subject.data_map.services['postgresql'])
142
- .to include('username' => 'opscode-pgsql')
143
- end
144
- end
145
- end
146
-
147
- context 'on a frontend' do
148
- before { private_chef('role' => 'frontend') }
149
-
150
- it "doesn't dump the db" do
151
- expect(subject).to_not receive(:shell_out).with(/pg_dumpall/)
152
- subject.dump_db
153
- end
154
- end
155
- end
156
-
157
- describe '.create_tarball' do
158
- before do
159
- allow(subject).to receive(:data_map).and_return(data_map)
160
- allow(Dir).to receive(:[]).and_return(%w(sql.sql manifest.json))
161
- end
162
-
163
- it 'creates a tarball with all items in the temp directory' do
164
- cmd = [
165
- "tar -czf #{tmp_dir}/chef-backup-#{backup_time}.tgz",
166
- data_map.services.map { |_, v| v['data_dir'] }.compact.join(' '),
167
- data_map.configs.map { |_, v| v['data_dir'] }.compact.join(' '),
168
- Dir["#{tmp_dir}/*"].map { |f| File.basename(f) }.join(' ')
169
- ].join(' ').strip
170
-
171
- allow(subject).to receive(:shell_out).with(cmd, cdw: tmp_dir)
172
- expect(subject).to receive(:shell_out).with(cmd, cwd: tmp_dir)
173
- subject.create_tarball
174
- end
175
- end
176
-
177
- describe '.export_tarball' do
178
- before do
179
- allow(subject).to receive(:export_dir).and_return('/mnt/chef-backups')
180
- end
181
-
182
- it 'moves the tarball to the archive location' do
183
- cmd = "rsync -chaz #{tmp_dir}/chef-backup-#{backup_time}.tgz"
184
- cmd << " #{export_dir}/"
185
-
186
- allow(subject).to receive(:shell_out).with(cmd)
187
- expect(subject).to receive(:shell_out).with(cmd)
188
- subject.export_tarball
189
- end
190
- end
191
-
192
- describe '.write_manifest' do
193
- let(:manifest) do
194
- { 'some' =>
195
- {
196
- 'nested' => {
197
- 'hash' => true
198
- },
199
- 'another' => true
200
- }
201
- }
202
- end
203
-
204
- let(:file) { double('file', write: true) }
205
-
206
- before do
207
- allow(subject).to receive(:manifest).and_return(manifest)
208
- allow(subject).to receive(:tmp_dir).and_return(tmp_dir)
209
- allow(File).to receive(:open).and_yield(file)
210
- end
211
-
212
- it 'converts the manifest to json' do
213
- json_manifest = JSON.pretty_generate(subject.manifest)
214
- expect(file).to receive(:write).with(json_manifest)
215
- subject.write_manifest
216
- end
217
-
218
- it 'writes a json file to the tmp_dir' do
219
- expect(File).to receive(:open).with("#{tmp_dir}/manifest.json", 'w')
220
- subject.write_manifest
221
- end
222
- end
223
-
224
- describe '.populate_data_map' do
225
- let(:services) { %w(opscode-solr4 bookshelf rabbitmq) }
226
- let(:configs) { %w(opscode opscode-manage opscode-analytics) }
227
- let(:config) do
228
- { 'bookshelf' => { 'data_dir' => '/bookshelf/data' },
229
- 'opscode-solr4' => { 'data_dir' => '/solr4/data' },
230
- 'rabbitmq' => { 'data_dir' => '/rabbitmq/data' }
231
- }
232
- end
233
-
234
- before do
235
- allow(subject).to receive(:data_map).and_return(data_map)
236
- allow(subject).to receive(:stateful_services).and_return(services)
237
- allow(subject).to receive(:config_directories).and_return(configs)
238
- %w(add_service add_config add_ha_info).each do |method|
239
- allow(data_map).to receive(method.to_sym).and_return(true)
240
- end
241
- end
242
-
243
- %w(frontend backend standalone).each do |role|
244
- context "on a #{role}" do
245
- before { private_chef(config.merge('role' => role)) }
246
-
247
- it 'populates the data map with config directories' do
248
- configs.each do |config|
249
- expect(subject.data_map)
250
- .to receive(:add_config)
251
- .with(config, "/etc/#{config}")
252
- end
253
-
254
- subject.populate_data_map
255
- end
256
- end
257
- end
258
-
259
- %w(backend standalone).each do |role|
260
- context "on a #{role}" do
261
- before { private_chef(config.merge('role' => role)) }
262
-
263
- it 'populates the data map with service directories' do
264
- services.each do |service|
265
- expect(subject.data_map)
266
- .to receive(:add_service)
267
- .with(service, config[service]['data_dir'])
268
- end
269
-
270
- subject.populate_data_map
271
- end
272
-
273
- it 'populates the data map with the upgrades' do
274
- expect(subject.data_map)
275
- .to receive(:add_service)
276
- .with('upgrades', '/var/opt/opscode/upgrades')
277
-
278
- subject.populate_data_map
279
- end
280
- end
281
- end
282
-
283
- context 'when config_only is true' do
284
- before do
285
- private_chef('role' => 'standalone', 'backup' => { 'config_only' => true })
286
- data_mock = double('DataMap')
287
- allow(subject).to receive(:data_map).and_return(data_mock)
288
- end
289
-
290
- it 'populates the data map with config and upgrade directories only' do
291
- configs.each do |config|
292
- expect(subject.data_map)
293
- .to receive(:add_config)
294
- .with(config, "/etc/#{config}")
295
- end
296
-
297
- expect(subject.data_map)
298
- .to receive(:add_service)
299
- .with('upgrades', '/var/opt/opscode/upgrades')
300
-
301
- subject.populate_data_map
302
- end
303
- end
304
-
305
- context 'on a frontend' do
306
- before { private_chef(config.merge('role' => 'frontend')) }
307
-
308
- it "doesn't populate the data map with the services" do
309
- expect(subject.data_map).to_not receive(:add_service)
310
- end
311
- end
312
- end
313
-
314
- describe '.pg_dump?' do
315
- it 'returns true' do
316
- expect(subject.pg_dump?).to eq(true)
317
- end
318
-
319
- context 'when db dump is disabled' do
320
- before { private_chef('backup' => { 'always_dump_db' => false }) }
321
-
322
- it 'returns false' do
323
- expect(subject.pg_dump?).to eq(false)
324
- end
325
- end
326
- end
327
- end
File without changes
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples 'a tar based restore' do
4
- it "cleanse's the chef server" do
5
- expect(subject).to receive(:cleanse_chef_server).once
6
- subject.restore
7
- end
8
-
9
- it 'restores the configs' do
10
- configs.each do |config|
11
- expect(subject).to receive(:restore_data).with(:configs, config).once
12
- end
13
- subject.restore
14
- end
15
-
16
- it 'touches the bootstrap sentinel file' do
17
- expect(subject).to receive(:touch_sentinel).once
18
- subject.restore
19
- end
20
-
21
- it 'reconfigures the server' do
22
- expect(subject).to receive(:reconfigure_server).once
23
- subject.restore
24
- end
25
-
26
- it 'updates the config' do
27
- expect(subject).to receive(:update_config).once
28
- subject.restore
29
- end
30
-
31
- it 'starts the server' do
32
- expect(subject).to receive(:start_chef_server).once
33
- subject.restore
34
- end
35
-
36
- it 'cleans up the temp directory' do
37
- expect(subject).to receive(:cleanup).once
38
- subject.restore
39
- end
40
- end
41
-
42
- shared_examples 'a tar based frontend restore' do
43
- it 'does not restore services' do
44
- expect(subject).to_not receive(:restore_services)
45
- subject.restore
46
- end
47
-
48
- it 'does not start postgres' do
49
- expect(subject).to_not receive(:start_service).with(:postgresql)
50
- subject.restore
51
- end
52
-
53
- it 'does not attempt to import a database' do
54
- expect(subject).to_not receive(:import_db)
55
- subject.restore
56
- end
57
- end
58
-
59
- shared_examples 'a tar based backend restore' do
60
- it 'restores the stateful services' do
61
- services.each do |service|
62
- expect(subject)
63
- .to receive(:restore_data)
64
- .with(:services, service)
65
- .once
66
- end
67
- subject.restore
68
- end
69
- end
70
-
71
- shared_examples 'a tar based backend restore with db dump' do
72
- it 'restores the db dump' do
73
- expect(subject).to receive(:import_db)
74
- subject.restore
75
- end
76
- end
77
-
78
- shared_examples 'a tar based backend restore without db dump' do
79
- it 'does not try to import a db dump' do
80
- expect(subject).to_not receive(:import_db)
81
- expect(subject).to_not receive(:start_service).with(:postgresql)
82
- subject.restore
83
- end
84
- end
@@ -1,255 +0,0 @@
1
- require 'spec_helper'
2
- require_relative 'shared_examples/restore'
3
-
4
- describe ChefBackup::Strategy::TarRestore do
5
- let(:manifest) do
6
- { 'strategy' => 'tar',
7
- 'backup_time' => '2014-12-02-22-46-58',
8
- 'services' => {
9
- 'rabbitmq' => { 'data_dir' => '/var/opt/opscode/rabbitmq/db' },
10
- 'opscode-solr4' => {
11
- 'data_dir' => '/var/opt/opscode/opscode-solr4/data'
12
- },
13
- 'redis_lb' => { 'data_dir' => '/var/opt/opscode/redis_lb/data' },
14
- 'postgresql' => {
15
- 'data_dir' => '/var/opt/opscode/postgresql/9.2/data',
16
- 'pg_dump_success' => pg_dump_success,
17
- 'username' => 'opscode-pgsql'
18
- },
19
- 'bookshelf' => { 'data_dir' => '/var/opt/opscode/bookshelf/data' }
20
- },
21
- 'configs' => {
22
- 'opscode' => { 'data_dir' => '/etc/opscode' },
23
- 'opscode-manage' => { 'data_dir' => '/etc/opscode-manage' },
24
- 'opscode-reporting' => { 'data_dir' => '/etc/opscode-reporting' },
25
- 'opscode-analytics' => { 'data_dir' => '/etc/opscode-analytics' }
26
- }
27
- }
28
- end
29
-
30
- let(:pg_dump_success) { true }
31
- let(:tarball_path) { '/var/backups/chef-backup-2014-12-02-22-46-58.tgz' }
32
- let(:configs) { manifest['configs'].keys }
33
- let(:services) { manifest['services'].keys }
34
- let(:restore_dir) { ChefBackup::Config['restore_dir'] }
35
-
36
- subject { described_class.new(tarball_path) }
37
-
38
- before(:each) { use_default_cli_args }
39
-
40
- describe '.restore' do
41
- before do
42
- %i(shell_out shell_out! unpack_tarball stop_chef_server ensure_file!
43
- start_chef_server reconfigure_server cleanse_chef_server
44
- update_config import_db touch_sentinel restart_add_ons
45
- ).each do |method|
46
- allow(subject).to receive(method).and_return(true)
47
- end
48
- configs.each do |config|
49
- allow(subject)
50
- .to receive(:restore_data)
51
- .with(:configs, config)
52
- .and_return(true)
53
- end
54
- services.each do |service|
55
- allow(subject)
56
- .to receive(:restore_data)
57
- .with(:services, service)
58
- .and_return(true)
59
- end
60
-
61
- allow(subject).to receive(:tarball_path).and_return(tarball_path)
62
- allow(subject).to receive(:manifest).and_return(manifest)
63
- allow(subject).to receive(:marketplace?).and_return(false)
64
- end
65
-
66
- it_behaves_like 'a tar based restore'
67
-
68
- context 'on a frontend' do
69
- before do
70
- allow(subject).to receive(:frontend?).and_return(true)
71
- end
72
-
73
- it_behaves_like 'a tar based frontend restore'
74
- end
75
-
76
- context 'on a backend' do
77
- before do
78
- allow(subject).to receive(:frontend?).and_return(false)
79
- end
80
-
81
- it_behaves_like 'a tar based backend restore'
82
-
83
- context 'when a db dump is present' do
84
- before do
85
- allow(subject).to receive(:restore_db_dump?).and_return(true)
86
- allow(subject)
87
- .to receive(:start_service).with(:postgresql).and_return(true)
88
- allow(subject).to receive(:import_db).and_return(true)
89
- end
90
-
91
- it_behaves_like 'a tar based backend restore with db dump'
92
- end
93
-
94
- context 'when a db dump is not present' do
95
- before do
96
- allow(subject).to receive(:restore_db_dump?).and_return(false)
97
- end
98
-
99
- it_behaves_like 'a tar based backend restore without db dump'
100
- end
101
- end
102
-
103
- context 'on a standalone' do
104
- before do
105
- allow(subject).to receive(:frontend?).and_return(false)
106
- end
107
-
108
- it_behaves_like 'a tar based backend restore'
109
-
110
- context 'when a db dump is present' do
111
- before do
112
- allow(subject).to receive(:restore_db_dump?).and_return(true)
113
- end
114
-
115
- it_behaves_like 'a tar based backend restore with db dump'
116
- end
117
-
118
- context 'when a db dump is not present' do
119
- before do
120
- allow(subject).to receive(:restore_db_dump?).and_return(false)
121
- end
122
-
123
- it_behaves_like 'a tar based backend restore without db dump'
124
- end
125
-
126
- context 'on a marketplace all-in-one' do
127
- before do
128
- allow(subject).to receive(:marketplace?).and_return(true)
129
- allow(subject).to receive(:reconfigure_marketplace?).and_return(true)
130
- end
131
-
132
- it 'sets up chef-marketplace' do
133
- expect(subject).to receive(:reconfigure_marketplace).once
134
- subject.restore
135
- end
136
-
137
- it_behaves_like 'a tar based backend restore'
138
- end
139
- end
140
- end
141
-
142
- describe '.manifest' do
143
- let(:json) { '{"some":"json"}' }
144
- let(:manifest_json) { File.join(restore_dir, 'manifest.json') }
145
-
146
- it 'parses the manifest from the restore dir' do
147
- allow(subject).to receive(:ensure_file!).and_return(true)
148
- allow(File).to receive(:read).with(manifest_json).and_return(json)
149
- expect(subject.manifest).to eq('some' => 'json')
150
- end
151
-
152
- it 'raises an error if the manifest is invalid' do
153
- expect { subject.manifest }
154
- .to raise_error(
155
- ChefBackup::Strategy::TarRestore::InvalidManifest,
156
- "#{File.join(restore_dir, 'manifest.json')} not found"
157
- )
158
- end
159
- end
160
-
161
- describe '.restore_data' do
162
- before do
163
- ChefBackup::Config['restore_dir'] = restore_dir
164
- allow(subject).to receive(:manifest).and_return(manifest)
165
- allow(subject).to receive(:shell_out!).and_return(true)
166
- allow(File).to receive(:directory?).and_return(true)
167
- end
168
-
169
- context 'with config data' do
170
- it 'rsyncs the config from the restore dir to the data_dir' do
171
- source = File.expand_path(
172
- File.join(restore_dir, manifest['configs']['opscode']['data_dir']))
173
- destination = manifest['configs']['opscode']['data_dir']
174
- cmd = "rsync -chaz --delete #{source}/ #{destination}"
175
-
176
- expect(subject).to receive(:shell_out!).with(cmd)
177
- subject.restore_data(:configs, 'opscode')
178
- end
179
- end
180
-
181
- context 'with service data' do
182
- it 'rsyncs the service from the restore dir to the data_dir' do
183
- source = File.expand_path(
184
- File.join(restore_dir, manifest['services']['rabbitmq']['data_dir']))
185
- destination = manifest['services']['rabbitmq']['data_dir']
186
- cmd = "rsync -chaz --delete #{source}/ #{destination}"
187
-
188
- expect(subject).to receive(:shell_out!).with(cmd)
189
- subject.restore_data(:services, 'rabbitmq')
190
- end
191
- end
192
- end
193
-
194
- describe '.import_db' do
195
- let(:pg_options) { ["PGOPTIONS=#{ChefBackup::Helpers::DEFAULT_PG_OPTIONS}"] }
196
-
197
- before do
198
- allow(subject).to receive(:manifest).and_return(manifest)
199
- allow(subject).to receive(:shell_out!).and_return(true)
200
- allow(subject).to receive(:running_config).and_return(running_config)
201
- allow(subject)
202
- .to receive(:start_service).with('postgresql').and_return(true)
203
- end
204
-
205
- context 'without a db dump' do
206
- it 'raises an exception' do
207
- expect { subject.import_db }
208
- .to raise_error(ChefBackup::Exceptions::InvalidDatabaseDump)
209
- end
210
- end
211
-
212
- context 'with a db dump' do
213
- let(:db_sql) do
214
- File.join(restore_dir, "chef_backup-#{manifest['backup_time']}.sql")
215
- end
216
-
217
- let(:import_cmd) do
218
- ['/opt/opscode/embedded/bin/chpst -u opscode-pgsql',
219
- '/opt/opscode/embedded/bin/psql -U opscode-pgsql',
220
- "-d opscode_chef < #{db_sql}"
221
- ].join(' ')
222
- end
223
-
224
- before do
225
- allow(subject)
226
- .to receive(:ensure_file!)
227
- .with(db_sql,
228
- ChefBackup::Exceptions::InvalidDatabaseDump,
229
- "#{db_sql} not found")
230
- .and_return(true)
231
- end
232
-
233
- it 'imports the database' do
234
- expect(subject).to receive(:shell_out!).with(import_cmd, env: pg_options)
235
- subject.import_db
236
- end
237
- end
238
- end
239
-
240
- describe '.touch_sentinel' do
241
- let(:file) { double('File', write: true) }
242
- let(:file_dir) { '/var/opt/opscode' }
243
- let(:file_path) { File.join(file_dir, 'bootstrapped') }
244
-
245
- before do
246
- allow(FileUtils).to receive(:mkdir_p).with(file_dir).and_return(true)
247
- allow(File).to receive(:open).with(file_path, 'w').and_yield(file)
248
- end
249
-
250
- it 'touches the bootstrap sentinel file' do
251
- expect(file).to receive(:write).with('bootstrapped!')
252
- subject.touch_sentinel
253
- end
254
- end
255
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ChefBackup::Strategy do
4
- before do
5
- # Backup Tester
6
- class ChefBackup::Strategy::TestBackup
7
- def initialize(_p = {})
8
- end
9
- end
10
-
11
- # Restore Tester
12
- class ChefBackup::Strategy::TestRestore
13
- def initialize(_p = {})
14
- end
15
- end
16
- end
17
-
18
- after do
19
- described_class.send(:remove_const, :TestBackup)
20
- described_class.send(:remove_const, :TestRestore)
21
- end
22
-
23
- describe '.backup' do
24
- it 'it returns a backup strategy' do
25
- expect(described_class.backup('test'))
26
- .to be_an(ChefBackup::Strategy::TestBackup)
27
- end
28
- end
29
-
30
- describe '.restore' do
31
- it 'it returns a restore strategy' do
32
- expect(described_class.restore('test', '/some/backup.tgz'))
33
- .to be_an(ChefBackup::Strategy::TestRestore)
34
- end
35
- end
36
- end