snapshot_reload 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
5
+ *.sublime-*
6
+ /testdata/
7
+ /tmp/
8
+ *.gz
9
+ README.html
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p327@snapshot_reload"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.16.20 ()" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in snapshot_reload.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ snapshot_reload (0.0.1)
5
+ fog
6
+ methadone (~> 1.2.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ aruba (0.5.1)
12
+ childprocess (~> 0.3.6)
13
+ cucumber (>= 1.1.1)
14
+ rspec-expectations (>= 2.7.0)
15
+ builder (3.1.4)
16
+ childprocess (0.3.6)
17
+ ffi (~> 1.0, >= 1.0.6)
18
+ cucumber (1.2.1)
19
+ builder (>= 2.1.2)
20
+ diff-lcs (>= 1.1.3)
21
+ gherkin (~> 2.11.0)
22
+ json (>= 1.4.6)
23
+ diff-lcs (1.1.3)
24
+ excon (0.13.4)
25
+ ffi (1.2.0)
26
+ fog (1.3.1)
27
+ builder
28
+ excon (~> 0.13.0)
29
+ formatador (~> 0.2.0)
30
+ mime-types
31
+ multi_json (~> 1.0)
32
+ net-scp (~> 1.0.4)
33
+ net-ssh (>= 2.1.3)
34
+ nokogiri (~> 1.5.0)
35
+ ruby-hmac
36
+ formatador (0.2.1)
37
+ gherkin (2.11.5)
38
+ json (>= 1.4.6)
39
+ json (1.7.5)
40
+ methadone (1.2.3)
41
+ bundler
42
+ mime-types (1.19)
43
+ multi_json (1.3.7)
44
+ net-scp (1.0.4)
45
+ net-ssh (>= 1.99.1)
46
+ net-ssh (2.5.2)
47
+ nokogiri (1.5.5)
48
+ rake (0.9.5)
49
+ rdoc (3.12)
50
+ json (~> 1.4)
51
+ rspec (2.12.0)
52
+ rspec-core (~> 2.12.0)
53
+ rspec-expectations (~> 2.12.0)
54
+ rspec-mocks (~> 2.12.0)
55
+ rspec-core (2.12.1)
56
+ rspec-expectations (2.12.0)
57
+ diff-lcs (~> 1.1.3)
58
+ rspec-mocks (2.12.0)
59
+ ruby-hmac (0.4.0)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ aruba
66
+ rake (~> 0.9.2)
67
+ rdoc
68
+ rspec
69
+ snapshot_reload!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tamara Temple
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # SnapshotReload
2
+
3
+ SnapshotReload is a ruby gem that pulls down a gzipped database snapshot, and
4
+ reloads it into a database.
5
+
6
+ This gem is part of the suite of tools needed to bring up the Q* server environments
7
+ for nightly testing of the novu web site code using obfuscated production data
8
+ (All participants' personal data has been scrubbed.)
9
+
10
+ The gem will work during the nightly chef deploy to the Q* servers.
11
+
12
+ ## Installation
13
+
14
+ Clone the repo from github:
15
+
16
+ $ git clone git@github.com:novu/snapshot_reload.git
17
+
18
+ Then, install the gem:
19
+
20
+ $ gem install snapshot_reload
21
+
22
+ ## Usage
23
+
24
+ The gem has a complete usage output, run snapshot_reload -h for the current listing.
25
+
26
+ This is what it looks like at version 1.0.0:
27
+
28
+ Usage: snapshot_reload [options] config
29
+
30
+ Redeploy the obfuscated data from production to other servers
31
+
32
+ v1.0.0
33
+
34
+ Options:
35
+ -h, --help Show command line help
36
+ -e, --env ENVIRONMENT Environment to use in configuration file
37
+ Will use ENV['RAILS_ENV'] if not specified and the envar exists
38
+ Otherwise will use qa
39
+ -s, --source S3SOURCE Provide the AWS S3 source of the obfuscated data
40
+ Optional flag. Default value is s3://novu_backups/db_backups/clean-mysqldump.sql.gz
41
+ -c, --aws-conf AWS_CONFIG Provide an alternative AWS configuration file containing log in credentials
42
+ Optional flag. Default value is /opt/novu/.s3cfg
43
+ -k, --aws-key AWSKEY Provide the AWS key for logging in. Overrides value in AWS_CONFIG and default if given
44
+ Required if --aws-secret is specified
45
+ -y, --aws-secret AWSSECRET Provide the AWS secret key for logging in. Overrides value in AWS_CONFIG and default if given.
46
+ Required if --aws-key is specified.
47
+ -n, --dry-run Don't run anything, just show what would be run
48
+ -v, --verbose Provide lots of information about what is happening
49
+ -q, --quiet Be completely silent. Overrides --verbose switch
50
+ --version Show help/version info
51
+ --log-level LEVEL Set the logging level
52
+ (debug|info|warn|error|fatal)
53
+ (Default: info)
54
+
55
+ Arguments:
56
+
57
+ config
58
+ Configuration file in same format as Rails config/database.yml file
59
+
60
+ ## Discussion
61
+
62
+ This gem implements the steps necessary to stand up an obfuscated copy of the production database for http://www.novu.com in the Q* server
63
+ environments (Qdev, Qrel, and Qnext). It is meant to be installed with the chef deployments for these servers. It can also be used to get any
64
+ gzipped snapshot of the application database (does not have to be obfuscated production data) and stand it up to any database environment.
65
+ This makes it useful for individual developers and testers, as it can stand up a database on a local machine, or another server environment,
66
+ independently of chef. All you need is the gzipped file as `source`, and the database credentials in `config`.
67
+
68
+ ## Examples
69
+
70
+ ### The default, standing up the Qdev server via chef recipe:
71
+
72
+ $ snapshot_reload /opt/novu/current/config/database.yml
73
+
74
+ The standard location of the application's database configuration file is given, the RAILS_ENV is set to 'qa' and the default S3
75
+ credentials are stored in /opt/novu/.s3cfg
76
+
77
+ ### Install a snapshot of nightly cleaned production data into your local database
78
+
79
+ You will need to obtain S3 credentials that give you access to the (non-production) buckets, see nvse@novu.com to obtain if you don't
80
+ have any. Put them into a file that looks like a standard .ini key = value file:
81
+
82
+ access_key = YOURAWSACCESSKEY
83
+ secret_key = YOURAWSSECRETACCESSKEY
84
+
85
+ No quotes, etc, just the values. The keys must be given as shown, at the start of the line. White space around the '=' is optional.
86
+
87
+ Then issue:
88
+
89
+ $ snapshot_reload -c path/to/aws/credentials -e development path/to/database.yml
90
+
91
+ and the data will be loaded from the S3 bucket into the database specified by the development environment in the configuration file.
92
+
93
+ ### If you have a local gzipped copy of data to load, you can specify that as well:
94
+
95
+ $ snapshot_reload --source path/to/sql.gz -e development path/to/database.yml
96
+
97
+ This will load the data in the sql.gz file into the database specified by the 'development' environment in the configuration file.
98
+
99
+
100
+ ## Author
101
+
102
+ Tamara Temple <tamara.temple@novu.com>
103
+
104
+ ## Copyright, Licensing
105
+
106
+ Copyright &copy; Novu, LLC. All rights reserverd. For internal and private use only.
107
+
108
+ ## Contributing
109
+
110
+ 1. Fork it
111
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
112
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
113
+ 4. Push to the branch (`git push origin my-new-feature`)
114
+ 5. Create new Pull Request
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = snapshot_reload - DESCRIBE YOUR GEM
2
+
3
+ Author:: YOUR NAME (YOUR EMAIL)
4
+ Copyright:: Copyright (c) 2012 YOUR NAME
5
+
6
+
7
+ DESCRIBE YOUR GEM HERE
8
+
9
+ == Links
10
+
11
+ * {Source on Github}[LINK TO GITHUB]
12
+ * RDoc[LINK TO RDOC.INFO]
13
+
14
+ == Install
15
+
16
+ == Examples
17
+
18
+ == Contributing
19
+
data/Rakefile ADDED
@@ -0,0 +1,66 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+
29
+ begin
30
+ require 'rspec/core/rake_task'
31
+ rescue LoadError
32
+ dump_load_path
33
+ raise
34
+ end
35
+
36
+ require 'cucumber'
37
+ require 'cucumber/rake/task'
38
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
39
+ require 'rdoc/task'
40
+
41
+ include Rake::DSL
42
+
43
+ Bundler::GemHelper.install_tasks
44
+
45
+
46
+ RSpec::Core::RakeTask.new do |t|
47
+ # Put spec opts in a file named .rspec in root
48
+ end
49
+
50
+
51
+ CUKE_RESULTS = 'results.html'
52
+ CLEAN << CUKE_RESULTS
53
+ Cucumber::Rake::Task.new(:features) do |t|
54
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
55
+ t.fork = false
56
+ end
57
+
58
+ Rake::RDocTask.new do |rd|
59
+
60
+ rd.main = "README.rdoc"
61
+
62
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
63
+ end
64
+
65
+ task :default => [:spec,:features]
66
+
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ =begin
4
+
5
+ Main script for snapshot_reload
6
+
7
+ +Copyright:+ (c) 2012, Novu, LLC
8
+ +License:+ All rights reserved. For internal and private use only.
9
+ +Author:+ Tamara Temple <tamara.temple@novu.com>
10
+
11
+ Makes use of methadone gem
12
+
13
+ =end
14
+
15
+ # TODO: expand help text
16
+
17
+ require 'optparse'
18
+ require 'methadone'
19
+ require 'snapshot_reload'
20
+
21
+ class App
22
+ include Methadone::Main
23
+ include Methadone::CLILogging
24
+
25
+ main do |config|
26
+ debug("config: #{config.to_s}")
27
+ debug("options: #{options.to_s}")
28
+ snapshot_reload = SnapshotReload::SnapshotReload.new(config, options)
29
+ end
30
+
31
+ description SnapshotReload::SUMMARY
32
+
33
+ on("-e", "--env ENVIRONMENT", "Environment to use in configuration file",
34
+ "Will use ENV['RAILS_ENV'] if not specified and the envar exists",
35
+ "Otherwise will use #{SnapshotReload::DEFAULT_ENVIRONMENT}")
36
+
37
+ on("-s", "--source S3SOURCE", "Provide the AWS S3 source of the obfuscated data",
38
+ "Optional flag. Default value is #{SnapshotReload::DEFAULT_S3_SOURCE}")
39
+
40
+ on("-c", "--aws-conf AWS_CONFIG",
41
+ "Provide an alternative AWS configuration file containing log in credentials",
42
+ "Optional flag. Default value is #{SnapshotReload::DEFAULT_AWS_CREDS}")
43
+
44
+ on("-k", "--aws-key AWSKEY",
45
+ "Provide the AWS key for logging in. Overrides value in AWS_CONFIG and default if given",
46
+ "Required if --aws-secret is specified")
47
+
48
+ on("-y", "--aws-secret AWSSECRET",
49
+ "Provide the AWS secret key for logging in. Overrides value in AWS_CONFIG and default if given.",
50
+ "Required if --aws-key is specified.")
51
+
52
+ on("-n", "--dry-run",
53
+ "Don't run anything, just show what would be run")
54
+
55
+ on('-v', '--verbose',
56
+ "Provide lots of information about what is happening")
57
+
58
+ on('-q', '--quiet',
59
+ "Be completely silent. Overrides --verbose switch")
60
+
61
+ arg :config, :required,
62
+ "Configuration file in same format as Rails config/database.yml file"
63
+
64
+
65
+ version SnapshotReload::VERSION
66
+
67
+ use_log_level_option
68
+
69
+ go!
70
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # +Copyright+:: (c) 2012, Novu, LLC
3
+ # +License+:: All rights reserved. For internal and private use only.
4
+ # +Author+:: Tamara Temple <tamara.temple@novu.com>
5
+ #
6
+
7
+ Feature: Live testing of application
8
+ In order to reload a snapshot into a database
9
+ As a developer
10
+ I want to run the application with real credentials
11
+ And and a real database configuration
12
+
13
+
14
+ Scenario Outline: run snapshot_reload with real credentials and configuration
15
+ Given a file named "<config>" exists
16
+ Given a file named "<creds>" exists
17
+ When I run `snapshot_reload --log-level debug --verbose --aws-conf ../../<creds> --source s3://<bucket>/<folder>/<file> ../../<config>`
18
+ Then the exit status should be 0
19
+ And the output should match /.*Getting <folder>.<file> from <bucket>, range bytes=\d+-\d+.*/
20
+ And the output should match /.*Wrote \d+ bytes to <file>.*/
21
+ And the output should contain "SQL file: <file>"
22
+ And the output should match /.*Command issued: mysqladmin.*drop.*/
23
+ And the output should match /.*Command issued: mysqladmin.*create.*/
24
+ And the output should match /.*Command issued: gunzip .* | mysql .* drop.*/
25
+
26
+ Scenarios: test data
27
+ | config | creds | bucket | folder | file |
28
+ | testdata/config.yml | testdata/my-aws-cred | tam-test-2 | db-backups | novu-2012-12-11.sql.gz |
29
+