chef_backup 0.0.1.dev.2 → 0.1.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 (40) hide show
  1. checksums.yaml +5 -5
  2. data/lib/chef_backup.rb +8 -8
  3. data/lib/chef_backup/config.rb +22 -12
  4. data/lib/chef_backup/data_map.rb +23 -9
  5. data/lib/chef_backup/deep_merge.rb +145 -0
  6. data/lib/chef_backup/helpers.rb +169 -27
  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 +19 -14
  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 +116 -35
  16. data/lib/chef_backup/strategy/restore/tar.rb +103 -38
  17. data/lib/chef_backup/version.rb +1 -1
  18. metadata +22 -170
  19. data/.gitignore +0 -23
  20. data/.kitchen.yml +0 -30
  21. data/.rubocop.yml +0 -17
  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 -584
  29. data/spec/spec_helper.rb +0 -103
  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 -74
  36. data/spec/unit/strategy/backup/tar_spec.rb +0 -294
  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 -238
  40. data/spec/unit/strategy_spec.rb +0 -36
@@ -1,238 +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
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
- end
64
-
65
- it_behaves_like 'a tar based restore'
66
-
67
- context 'on a frontend' do
68
- before do
69
- allow(subject).to receive(:frontend?).and_return(true)
70
- end
71
-
72
- it_behaves_like 'a tar based frontend restore'
73
- end
74
-
75
- context 'on a backend' do
76
- before do
77
- allow(subject).to receive(:frontend?).and_return(false)
78
- end
79
-
80
- it_behaves_like 'a tar based backend restore'
81
-
82
- context 'when a db dump is present' do
83
- before do
84
- allow(subject).to receive(:restore_db_dump?).and_return(true)
85
- allow(subject)
86
- .to receive(:start_service).with(:postgresql).and_return(true)
87
- allow(subject).to receive(:import_db).and_return(true)
88
- end
89
-
90
- it_behaves_like 'a tar based backend restore with db dump'
91
- end
92
-
93
- context 'when a db dump is not present' do
94
- before do
95
- allow(subject).to receive(:restore_db_dump?).and_return(false)
96
- end
97
-
98
- it_behaves_like 'a tar based backend restore without db dump'
99
- end
100
- end
101
-
102
- context 'on a standalone' do
103
- before do
104
- allow(subject).to receive(:frontend?).and_return(false)
105
- end
106
-
107
- it_behaves_like 'a tar based backend restore'
108
-
109
- context 'when a db dump is present' do
110
- before do
111
- allow(subject).to receive(:restore_db_dump?).and_return(true)
112
- end
113
-
114
- it_behaves_like 'a tar based backend restore with db dump'
115
- end
116
-
117
- context 'when a db dump is not present' do
118
- before do
119
- allow(subject).to receive(:restore_db_dump?).and_return(false)
120
- end
121
-
122
- it_behaves_like 'a tar based backend restore without db dump'
123
- end
124
- end
125
- end
126
-
127
- describe '.manifest' do
128
- let(:json) { "{\"some\":\"json\"}" }
129
- let(:manifest_json) { File.join(restore_dir, 'manifest.json') }
130
-
131
- it 'parses the manifest from the restore dir' do
132
- allow(subject).to receive(:ensure_file!).and_return(true)
133
- allow(File).to receive(:read).with(manifest_json).and_return(json)
134
- expect(subject.manifest).to eq('some' => 'json')
135
- end
136
-
137
- it 'raises an error if the manifest is invalid' do
138
- expect { subject.manifest }
139
- .to raise_error(
140
- ChefBackup::Strategy::TarRestore::InvalidManifest,
141
- "#{File.join(restore_dir, 'manifest.json')} not found"
142
- )
143
- end
144
- end
145
-
146
- describe '.restore_data' do
147
- before do
148
- ChefBackup::Config['restore_dir'] = restore_dir
149
- allow(subject).to receive(:manifest).and_return(manifest)
150
- allow(subject).to receive(:shell_out!).and_return(true)
151
- allow(File).to receive(:directory?).and_return(true)
152
- end
153
-
154
- context 'with config data' do
155
- it 'rsyncs the config from the restore dir to the data_dir' do
156
- source = File.expand_path(
157
- File.join(restore_dir, manifest['configs']['opscode']['data_dir']))
158
- destination = manifest['configs']['opscode']['data_dir']
159
- cmd = "rsync -chaz --delete #{source}/ #{destination}"
160
-
161
- expect(subject).to receive(:shell_out!).with(cmd)
162
- subject.restore_data(:configs, 'opscode')
163
- end
164
- end
165
-
166
- context 'with service data' do
167
- it 'rsyncs the service from the restore dir to the data_dir' do
168
- source = File.expand_path(
169
- File.join(restore_dir, manifest['services']['rabbitmq']['data_dir']))
170
- destination = manifest['services']['rabbitmq']['data_dir']
171
- cmd = "rsync -chaz --delete #{source}/ #{destination}"
172
-
173
- expect(subject).to receive(:shell_out!).with(cmd)
174
- subject.restore_data(:services, 'rabbitmq')
175
- end
176
- end
177
- end
178
-
179
- describe '.import_db' do
180
- before do
181
- allow(subject).to receive(:manifest).and_return(manifest)
182
- allow(subject).to receive(:shell_out!).and_return(true)
183
- allow(subject).to receive(:running_config).and_return(running_config)
184
- allow(subject)
185
- .to receive(:start_service).with('postgresql').and_return(true)
186
- end
187
-
188
- context 'without a db dump' do
189
- it 'raises an exception' do
190
- expect { subject.import_db }
191
- .to raise_error(ChefBackup::Exceptions::InvalidDatabaseDump)
192
- end
193
- end
194
-
195
- context 'with a db dump' do
196
- let(:db_sql) do
197
- File.join(restore_dir, "chef_backup-#{manifest['backup_time']}.sql")
198
- end
199
-
200
- let(:import_cmd) do
201
- ['/opt/opscode/embedded/bin/chpst -u opscode-pgsql',
202
- '/opt/opscode/embedded/bin/psql -U opscode-pgsql',
203
- "-d opscode_chef < #{db_sql}"
204
- ].join(' ')
205
- end
206
-
207
- before do
208
- allow(subject)
209
- .to receive(:ensure_file!)
210
- .with(db_sql,
211
- ChefBackup::Exceptions::InvalidDatabaseDump,
212
- "#{db_sql} not found")
213
- .and_return(true)
214
- end
215
-
216
- it 'imports the database' do
217
- expect(subject).to receive(:shell_out!).with(import_cmd)
218
- subject.import_db
219
- end
220
- end
221
- end
222
-
223
- describe '.touch_sentinel' do
224
- let(:file) { double('File', write: true) }
225
- let(:file_dir) { '/var/opt/opscode' }
226
- let(:file_path) { File.join(file_dir, 'bootstrapped') }
227
-
228
- before do
229
- allow(FileUtils).to receive(:mkdir_p).with(file_dir).and_return(true)
230
- allow(File).to receive(:open).with(file_path, 'w').and_yield(file)
231
- end
232
-
233
- it 'touches the bootstrap sentinel file' do
234
- expect(file).to receive(:write).with('bootstrapped!')
235
- subject.touch_sentinel
236
- end
237
- end
238
- 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