image_optimize 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,97 @@
1
+ # Author: cary@rightscale.com
2
+ # Copyright 2014 RightScale, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'image_bundle'))
18
+
19
+ describe ImageOptimize::ImageBundleBase, "Image Bundle Utilities" do
20
+
21
+ describe "Base Class" do
22
+ it "can be created" do
23
+ ImageOptimize::ImageBundleBase.new("instance_client", "api_client")
24
+ end
25
+ end
26
+
27
+ describe "EC2 EBS Implementation" do
28
+ let(:instance_client) { double("instance_client") }
29
+ let(:api_client) { double("api_client") }
30
+
31
+ it "initializes" do
32
+ ImageOptimize::ImageBundleEc2EBS.any_instance.stub(:load_meta_data)
33
+ ib = ImageOptimize::ImageBundleEc2EBS.new(
34
+ "instance_client",
35
+ "api_client",
36
+ "aws_access_key",
37
+ "aws_secret_key"
38
+ )
39
+ ib.should_not == nil
40
+ end
41
+ end
42
+
43
+ describe "EC2 S3 Implementation" do
44
+ let(:instance_client) { double("instance_client") }
45
+ let(:api_client) { double("api_client") }
46
+
47
+ it "initializes" do
48
+ ImageOptimize::ImageBundleEc2S3.any_instance.stub(:load_meta_data)
49
+ ib = ImageOptimize::ImageBundleEc2S3.new(
50
+ "instance_client",
51
+ "api_client",
52
+ "aws_access_key",
53
+ "aws_secret_key",
54
+ "aws_account_number",
55
+ "x509_key_file",
56
+ "x509_cert_file",
57
+ "s3_bucket"
58
+ )
59
+ ib.instance_variable_get(:@bundle_dir).should == "/mnt/ephemeral/bundle" # default value
60
+ ib.instance_variable_get(:@no_filter).should == nil
61
+ end
62
+
63
+ it "initializes with bundle dir" do
64
+ ImageOptimize::ImageBundleEc2S3.any_instance.stub(:load_meta_data)
65
+ ib = ImageOptimize::ImageBundleEc2S3.new(
66
+ "instance_client",
67
+ "api_client",
68
+ "aws_access_key",
69
+ "aws_secret_key",
70
+ "aws_account_number",
71
+ "x509_key_file",
72
+ "x509_cert_file",
73
+ "s3_bucket",
74
+ "/mnt/ephemeral"
75
+ )
76
+ ib.instance_variable_get(:@bundle_dir).should == "/mnt/ephemeral"
77
+ end
78
+
79
+ it "initializes with no-filter option" do
80
+ ImageOptimize::ImageBundleEc2S3.any_instance.stub(:load_meta_data)
81
+ ib = ImageOptimize::ImageBundleEc2S3.new(
82
+ "instance_client",
83
+ "api_client",
84
+ "aws_access_key",
85
+ "aws_secret_key",
86
+ "aws_account_number",
87
+ "x509_key_file",
88
+ "x509_cert_file",
89
+ "s3_bucket",
90
+ "/mnt/ephemeral",
91
+ "true"
92
+ )
93
+ ib.instance_variable_get(:@no_filter).should == true
94
+ end
95
+ end
96
+
97
+ end
@@ -0,0 +1,194 @@
1
+ # Author: cary@rightscale.com
2
+ # Copyright 2014 RightScale, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'app', 'image_optimizer'))
18
+
19
+ describe ImageOptimize::Optimizer, "Image Bundle Controller" do
20
+
21
+ before(:each) do
22
+ # dont log stuff
23
+ Logger.any_instance.stub(:info)
24
+ Logger.any_instance.stub(:error)
25
+ Logger.any_instance.stub(:debug)
26
+ end
27
+
28
+ it "requires aws_secret_key specified" do
29
+ ARGV.replace [
30
+ '--aws-access-key',"awsaccesskey",
31
+ '--aws-secret-key',"awssecretkey",
32
+ '--api-user',"someone@rightscale.com",
33
+ '--api-password',"supersecret",
34
+ '--aws-account-number',"8675309",
35
+
36
+ '--aws-image-type','S3',
37
+ '--aws-s3-bundle-directory', "/mnt/ephemeral/foo",
38
+ '--aws-s3-key-path', "/tmp/key/path",
39
+ '--aws-s3-cert-path', "/tmp/cert/path",
40
+ '--aws-s3-image-bucket', "myimagebucket.example.com",
41
+ '--aws-s3-bundle-no-filter'
42
+ ]
43
+ api_stub = double("ApiClient15", :log => nil, :get_client => nil)
44
+ bundler_stub = double("Bundler", :log => nil)
45
+ RightScale::ApiClient15.should_receive(:new).and_return(api_stub)
46
+ ImageOptimize::ImageBundleEc2S3.any_instance.stub(:load_meta_data)
47
+ optimizer = ImageOptimize::Optimizer.new
48
+ optimizer.parse_args
49
+ optimizer.send(:setup_logging)
50
+ lambda{ optimizer.configure }.should_not raise_error
51
+ end
52
+
53
+ it "fails if no aws_secret_key is specified" do
54
+ optimizer = ImageOptimize::Optimizer.new
55
+ optimizer.parse_args
56
+ optimizer.send(:setup_logging)
57
+ lambda{ optimizer.configure }.should raise_error
58
+ end
59
+
60
+ it "can be created for EC2 EBS" do
61
+ ENV['API_USER_EMAIL']="someone@rightscale.com"
62
+ ENV['API_USER_PASSWORD']="supersecret"
63
+ ENV['AWS_SECRET_KEY']="awssecretkey"
64
+ ENV['AWS_ACCESS_KEY']="awsaccesskey"
65
+ @aws_s3_bundle_no_filter = true
66
+
67
+ api_stub = double("ApiClient15", :log => nil, :get_client => nil)
68
+ bundler_stub = double("Bundler", :log => nil)
69
+ RightScale::ApiClient15.should_receive(:new).and_return(api_stub)
70
+ ImageOptimize::ImageBundleEc2EBS.should_receive(:new).and_return(bundler_stub)
71
+ optimizer = ImageOptimize::Optimizer.new
72
+ optimizer.parse_args
73
+ optimizer.send(:setup_logging)
74
+ optimizer.configure
75
+ end
76
+
77
+ it "can be created for EC2 S3" do
78
+ ENV['API_USER_EMAIL']="someone@rightscale.com"
79
+ ENV['API_USER_PASSWORD']="supersecret"
80
+ ENV['AWS_SECRET_KEY']="awssecretkey"
81
+ ENV['AWS_ACCESS_KEY']="awsaccesskey"
82
+ ENV['AWS_ACCOUNT_NUMBER']="1234567890"
83
+
84
+ @aws_s3_bundle_no_filter = true
85
+
86
+ ARGV.replace [
87
+ '--aws-image-type','S3'
88
+ ]
89
+
90
+ api_stub = double("ApiClient15", :log => nil, :get_client => nil)
91
+ RightScale::ApiClient15.should_receive(:new).and_return(api_stub)
92
+ ImageOptimize::ImageBundleEc2S3.any_instance.stub(:load_meta_data)
93
+ io = ImageOptimize::Optimizer.new
94
+ io.parse_args
95
+ io.send(:setup_logging)
96
+ io.configure
97
+
98
+ ib = io.instance_variable_get(:@image_util)
99
+ end
100
+
101
+ it "parses command-line parameters" do
102
+ ENV['API_USER_EMAIL']="someone@rightscale.com"
103
+ ENV['API_USER_PASSWORD']="supersecret"
104
+ ENV['AWS_SECRET_KEY']="awssecretkey"
105
+ ENV['AWS_ACCESS_KEY']="awsaccesskey"
106
+ ENV['AWS_ACCOUNT_NUMBER']="1234567890"
107
+ @aws_s3_image_bucket="deleteme"
108
+ key_path="foo"
109
+ cert_path="bar"
110
+ image_type = "EBS"
111
+ aws_s3_bundle_directory = "/mnt/ephemeral/foo"
112
+ @aws_s3_bundle_no_filter = true
113
+
114
+ image_type = "S3"
115
+
116
+ ARGV.replace [
117
+ '--aws-image-type', image_type,
118
+ '--aws-s3-bundle-directory',aws_s3_bundle_directory,
119
+ '--aws-s3-key-path', key_path,
120
+ '--aws-s3-cert-path', cert_path,
121
+ '--aws-s3-image-bucket', @aws_s3_image_bucket,
122
+ '--aws-s3-bundle-no-filter'
123
+ ]
124
+ optimizer = ImageOptimize::Optimizer.new
125
+ args = optimizer.parse_args
126
+ args[:api_user].should == ENV['API_USER_EMAIL']
127
+ args[:api_password].should == ENV['API_USER_PASSWORD']
128
+ args[:aws_secret_key].should == ENV['AWS_SECRET_KEY']
129
+ args[:aws_access_key].should == ENV['AWS_ACCESS_KEY']
130
+ args[:aws_account_number].should == ENV['AWS_ACCOUNT_NUMBER']
131
+ args[:aws_s3_image_bucket].should == @aws_s3_image_bucket
132
+ args[:aws_image_type].should == image_type
133
+ args[:aws_s3_bundle_directory].should == aws_s3_bundle_directory
134
+ args[:aws_s3_bundle_no_filter].should == @aws_s3_bundle_no_filter
135
+ args[:aws_s3_key_path].should == key_path
136
+ args[:aws_s3_cert_path].should == cert_path
137
+ end
138
+
139
+ it "processes the run command without errors" do
140
+ ENV['API_USER_EMAIL']="someone@rightscale.com"
141
+ ENV['API_USER_PASSWORD']="supersecret"
142
+ ENV['AWS_SECRET_KEY']="awssecretkey"
143
+ ENV['AWS_ACCESS_KEY']="awsaccesskey"
144
+ ENV['AWS_ACCOUNT_NUMBER']="1234567890"
145
+
146
+ aws_s3_image_bucket = "deleteme"
147
+ key_path="foo"
148
+ cert_path="bar"
149
+ image_type = "S3"
150
+ aws_s3_bundle_directory = "/mnt/ephemeral/foo"
151
+ @aws_s3_bundle_no_filter = true
152
+
153
+ ARGV.replace [
154
+ '--aws-image-type', image_type,
155
+ '--aws-s3-bundle-directory', aws_s3_bundle_directory,
156
+ '--aws-s3-key-path', key_path,
157
+ '--aws-s3-cert-path', cert_path,
158
+ '--aws-s3-image-bucket', aws_s3_image_bucket,
159
+ '--aws-s3-bundle-no-filter',
160
+ '--no-cleanup'
161
+ ]
162
+
163
+ # mock some stuff
164
+ api_stub = double("ApiClient15", :log => nil, :get_client => nil)#right_api_client_stub)
165
+ RightScale::ApiClient15.should_receive(:new).and_return(api_stub)
166
+ ImageOptimize::ImageBundleEc2S3.any_instance.stub(:load_meta_data)
167
+ ImageOptimize::ImageBundleEc2S3.any_instance.stub(:snapshot_instance)
168
+ ImageOptimize::ImageBundleEc2S3.any_instance.stub(:register_image)
169
+ ImageOptimize::ImageBundleEc2S3.any_instance.stub(:add_image_to_next_instance)
170
+
171
+ # run some stuff
172
+ optimizer = ImageOptimize::Optimizer.new
173
+ optimizer.should_receive(:prepare_image).at_most(0).times
174
+ optimizer.should_receive(:unique_name)
175
+ optimizer.run
176
+
177
+ # check argument parsing
178
+ args = optimizer.instance_variable_get(:@args)
179
+ args[:api_user].should == ENV['API_USER_EMAIL']
180
+ args[:api_password].should == ENV['API_USER_PASSWORD']
181
+ args[:aws_secret_key].should == ENV['AWS_SECRET_KEY']
182
+ args[:aws_access_key].should == ENV['AWS_ACCESS_KEY']
183
+ args[:aws_account_number].should == ENV['AWS_ACCOUNT_NUMBER']
184
+ args[:aws_s3_image_bucket].should == aws_s3_image_bucket
185
+ args[:aws_image_type].should == image_type
186
+ args[:aws_s3_bundle_directory].should == aws_s3_bundle_directory
187
+ args[:aws_s3_bundle_no_filter].should == @aws_s3_bundle_no_filter
188
+ args[:aws_s3_key_path].should == key_path
189
+ args[:aws_s3_cert_path].should == cert_path
190
+
191
+ end
192
+
193
+
194
+ end
@@ -0,0 +1,50 @@
1
+ # Author: cary@rightscale.com
2
+ # Copyright 2014 RightScale, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ describe "Image Optimize Functional Test" do
18
+
19
+ # you must own this bucket
20
+ # do to a known issue in the EC2 tools, the bucket must already exist
21
+ S3_BUCKET_NAME = "cp2-pub-cached-images"
22
+
23
+ before(:all) do
24
+ #XXX: this should to be detected from VM, but simply set in env before running the test
25
+ # ENV['IMAGE_TYPE'] = 'S3'
26
+ ec2_zone = `curl http://169.254.169.254/latest/meta-data/placement/availability-zone/`
27
+ @region = /(.*\-.*\-[1-9]*)/.match(ec2_zone).captures.first
28
+ puts "Detected EC2 region #{@region}"
29
+ end
30
+
31
+ it "creates an instance facing api connection" do
32
+ cwd = File.dirname(__FILE__)
33
+ secrets_dir = "#{cwd}/../.secrets"
34
+
35
+ command = ". #{secrets_dir}/creds; bin/image_optimize --aws-image-type #{ENV['IMAGE_TYPE']} --aws-s3-image-bucket #{S3_BUCKET_NAME} --aws-s3-key-path #{secrets_dir}/x509.key --aws-s3-cert-path #{secrets_dir}/x509.cert --aws-s3-bundle-directory /mnt/ephemeral/bundle --verbose --no-cleanup"
36
+
37
+ puts "COMMAND: #{command}"
38
+ output = ""
39
+ IO.popen("#{command} 2>&1") do |data|
40
+ while line = data.gets
41
+ puts "\e[33m#{line}\e[0m" # 33 = yellow text
42
+ output << line
43
+ end
44
+ end
45
+ process_status = $?
46
+ puts "OUTPUT: #{output}"
47
+ process_status.exitstatus.should == 0
48
+ end
49
+
50
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_optimize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-23 00:00:00.000000000 Z
12
+ date: 2014-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types
@@ -110,10 +110,40 @@ dependencies:
110
110
  description: Bundle a running server into a new image that will be used on next launch
111
111
  email:
112
112
  - cary@rightscale.com
113
- executables: []
113
+ executables:
114
+ - image_optimize
114
115
  extensions: []
115
116
  extra_rdoc_files: []
116
- files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .ruby-version
121
+ - CHANGELOG.md
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE
125
+ - README.md
126
+ - Rakefile
127
+ - VERSION
128
+ - bin/image_optimize
129
+ - image_optimize.gemspec
130
+ - lib/api_client_15.rb
131
+ - lib/app/image_optimizer.rb
132
+ - lib/image_bundle.rb
133
+ - lib/image_bundle/image_bundle_base.rb
134
+ - lib/image_bundle/image_bundle_ec2.rb
135
+ - lib/image_bundle/image_bundle_ec2_ebs.rb
136
+ - lib/image_bundle/image_bundle_ec2_s3.rb
137
+ - lib/mixins/command.rb
138
+ - lib/mixins/common.rb
139
+ - rightscale/rightscript.sh
140
+ - setup.sh
141
+ - spec/api_client_spec.rb
142
+ - spec/command_spec.rb
143
+ - spec/image_bundle_ec2_spec.rb
144
+ - spec/image_bundle_spec.rb
145
+ - spec/image_optimizer_spec.rb
146
+ - test/image_optimize_test.rb
117
147
  homepage: ''
118
148
  licenses: []
119
149
  post_install_message:
@@ -126,17 +156,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
156
  - - ! '>='
127
157
  - !ruby/object:Gem::Version
128
158
  version: '0'
159
+ segments:
160
+ - 0
161
+ hash: 1039956523122922011
129
162
  required_rubygems_version: !ruby/object:Gem::Requirement
130
163
  none: false
131
164
  requirements:
132
165
  - - ! '>='
133
166
  - !ruby/object:Gem::Version
134
167
  version: '0'
168
+ segments:
169
+ - 0
170
+ hash: 1039956523122922011
135
171
  requirements: []
136
172
  rubyforge_project:
137
173
  rubygems_version: 1.8.23
138
174
  signing_key:
139
175
  specification_version: 3
140
176
  summary: Bundle a running server into a new image that will be used on next launch
141
- test_files: []
142
- has_rdoc:
177
+ test_files:
178
+ - spec/api_client_spec.rb
179
+ - spec/command_spec.rb
180
+ - spec/image_bundle_ec2_spec.rb
181
+ - spec/image_bundle_spec.rb
182
+ - spec/image_optimizer_spec.rb
183
+ - test/image_optimize_test.rb