chef_backup 0.0.1 → 0.1.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.rb +8 -8
  3. data/lib/chef_backup/config.rb +17 -17
  4. data/lib/chef_backup/data_map.rb +18 -12
  5. data/lib/chef_backup/deep_merge.rb +145 -0
  6. data/lib/chef_backup/helpers.rb +46 -10
  7. data/lib/chef_backup/logger.rb +2 -2
  8. data/lib/chef_backup/mash.rb +226 -0
  9. data/lib/chef_backup/runner.rb +11 -13
  10. data/lib/chef_backup/strategy.rb +10 -10
  11. data/lib/chef_backup/strategy/backup/custom.rb +1 -2
  12. data/lib/chef_backup/strategy/backup/ebs.rb +3 -6
  13. data/lib/chef_backup/strategy/backup/lvm.rb +2 -4
  14. data/lib/chef_backup/strategy/backup/object.rb +2 -4
  15. data/lib/chef_backup/strategy/backup/tar.rb +23 -7
  16. data/lib/chef_backup/strategy/restore/tar.rb +69 -43
  17. data/lib/chef_backup/version.rb +1 -1
  18. metadata +20 -168
  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,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