rightimage_tools 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/util.rb +5 -2
- data/spec/id_list_spec.rb +30 -0
- data/spec/mci_spec.rb +97 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/util_spec.rb +254 -0
- metadata +9 -4
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ Jeweler::Tasks.new do |gem|
|
|
21
21
|
gem.homepage = "http://github.com/rightscale/rightimage_tools"
|
22
22
|
gem.license = "MIT"
|
23
23
|
gem.summary = %Q{A set of tools to support the building of RightImages}
|
24
|
-
gem.files = %w(LICENSE.txt VERSION README.rdoc Rakefile Gemfile) + FileList["{bin,lib}/**/*"].to_a
|
24
|
+
gem.files = %w(LICENSE.txt VERSION README.rdoc Rakefile Gemfile) + FileList["{bin,lib,spec}/**/*"].to_a
|
25
25
|
gem.executables = %w(image_mover mci_merge update_s3_index)
|
26
26
|
gem.description = gem.summary
|
27
27
|
gem.email = "peter.schroeter@rightscale.com"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/util.rb
CHANGED
@@ -29,7 +29,10 @@ module RightImage
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.rightimage_package_version(version, build_number=nil)
|
32
|
-
|
32
|
+
unless version.to_s =~ /^[0-9]*\.[0-9]*$/ or
|
33
|
+
version.to_s =~ /^2\d\d\d\.\d\d.\d\d$/
|
34
|
+
raise ArgumentError, "rightimage version must be a 'N.N' or 'YYYY.MM.DD' format."
|
35
|
+
end
|
33
36
|
ver = "#{version.to_s}"
|
34
37
|
ver << ".#{build_number}" if build_number
|
35
38
|
ver
|
@@ -47,4 +50,4 @@ module RightImage
|
|
47
50
|
|
48
51
|
|
49
52
|
end
|
50
|
-
end
|
53
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'flexmock/rspec'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe RightImage::IdList do
|
5
|
+
before(:each) do
|
6
|
+
mock_logger = flexmock('Logger')
|
7
|
+
mock_logger.should_receive(:info)
|
8
|
+
|
9
|
+
@id_list = RightImage::IdList.new(mock_logger)
|
10
|
+
@id_list.clear
|
11
|
+
#{"ami-96f200ff":{"storage_type":"EBS"},"ami-8af200e3":{}}
|
12
|
+
#{"ami-08f30161":{"storage_type":"EBS"},"ami-fcf20095":{"storage_type":"EBS"}}
|
13
|
+
@id_list.add("ami-8af200e3\n")
|
14
|
+
|
15
|
+
@id_list = RightImage::IdList.new(mock_logger)
|
16
|
+
@id_list.add("ami-foo\n", "EBS")
|
17
|
+
|
18
|
+
@images = @id_list.to_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should contain two images" do
|
22
|
+
@images.size.should == 2
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should contain one EBS images" do
|
26
|
+
ebs_images = @images.select { |k, v| v["storage_type"] && v["storage_type"] == "EBS" }
|
27
|
+
ebs_images.size.should == 1
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/mci_spec.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'flexmock/rspec'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe RightImageTools::MCI do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@mci = RightImageTools::MCI.new
|
8
|
+
|
9
|
+
@mock_mci_name = "Mock_RightImage_Ubuntu_10.04_x64_v5.7"
|
10
|
+
@mock_ami = "ami-2ehahaha"
|
11
|
+
|
12
|
+
@mock_mci = flexmock(MultiCloudImage,
|
13
|
+
:is_head_version => true,
|
14
|
+
:name => @mock_mci_name,
|
15
|
+
:rs_id => "10000",
|
16
|
+
:version=>0,
|
17
|
+
:href=>"https://my.rightscale.com/api/acct/99999/multi_cloud_images/10000")
|
18
|
+
|
19
|
+
@mock_mci_setting1 = flexmock(MultiCloudImageCloudSettingInternal,
|
20
|
+
:href=>"https://my.rightscale.com/api/acct/99999/multi_cloud_image_cloud_settings/20000",
|
21
|
+
:aws_instance_type =>"m1.large",
|
22
|
+
:image_name => @mock_mci_name,
|
23
|
+
:image_href => "https://my.rightscale.com/api/acct/0/ec2_images/#{@mock_ami}?cloud_id=5",
|
24
|
+
:cloud_id=>5,
|
25
|
+
:cloud=>"AWS AP-Tokyo")
|
26
|
+
|
27
|
+
@mock_mci_i = flexmock(MultiCloudImageInternal,
|
28
|
+
:is_head_version => @mock_mci.is_head_version,
|
29
|
+
:name=>@mock_mci.name,
|
30
|
+
:rs_id => @mock_mci.rs_id,
|
31
|
+
:version=>@mock_mci.version,
|
32
|
+
:href=>@mock_mci.href,
|
33
|
+
:multi_cloud_image_cloud_settings=>[@mock_mci_setting1])
|
34
|
+
end
|
35
|
+
|
36
|
+
# it "finds a MCI for gateway cloud (cloudstack)" do
|
37
|
+
# pending "TODO"
|
38
|
+
# end
|
39
|
+
# it "creates a MCI for gateway cloud (cloudstack)" do
|
40
|
+
# pending "TODO"
|
41
|
+
# end
|
42
|
+
# it "associates an image for a gateway cloud (cloudstack)" do
|
43
|
+
# pending "TODO"
|
44
|
+
# end
|
45
|
+
# it "replaces an image association for a gateway cloud (cloudstack)" do
|
46
|
+
# pending "TODO"
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
it "finds a MCI for EC2 cloud" do
|
50
|
+
flexmock(MultiCloudImage).should_receive(:find_all).and_return([@mock_mci])
|
51
|
+
flexmock(MultiCloudImageInternal).should_receive(:find).with(10000).and_return(@mock_mci_i)
|
52
|
+
|
53
|
+
@mci.find_mci(6, @mock_mci_name).rs_id.should == "10000"
|
54
|
+
end
|
55
|
+
it "creates a MCI for EC2 mock cloud" do
|
56
|
+
flexmock(MultiCloudImageInternal).should_receive(:create).with(
|
57
|
+
:name=>@mock_mci_name,
|
58
|
+
:description => "blah"
|
59
|
+
).and_return(flexmock(MultiCloudImageInternal))
|
60
|
+
@mci.create_mci(6, @mock_mci_name, "blah")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "associates an image to an EC2 cloud" do
|
64
|
+
flexmock(MultiCloudImage).should_receive(:find_all).and_return([@mock_mci])
|
65
|
+
flexmock(MultiCloudImageInternal).should_receive(:find).with(10000).and_return(@mock_mci_i)
|
66
|
+
flexmock(Tag).should_receive(:set).and_return(flexmock(Tag, :code=>"204"))
|
67
|
+
flexmock(MultiCloudImageCloudSettingInternal).should_receive(:create)
|
68
|
+
|
69
|
+
@mci.add_image_to_mci(
|
70
|
+
:cloud_id=>6,
|
71
|
+
:name=>@mock_mci_name,
|
72
|
+
:image_id=>"ami-b1ahb1ah")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "replaces an image association for an EC2 cloud" do
|
76
|
+
flexmock(MultiCloudImage).should_receive(:find_all).and_return([@mock_mci])
|
77
|
+
flexmock(MultiCloudImageInternal).should_receive(:find).with(10000).and_return(@mock_mci_i)
|
78
|
+
flexmock(Tag).should_receive(:set).and_return(flexmock(Tag, :code=>"204"))
|
79
|
+
flexmock(MultiCloudImageCloudSettingInternal).should_receive(:destroy).and_return(flexmock("Response",:code=>"200"))
|
80
|
+
flexmock(MultiCloudImageCloudSettingInternal).should_receive(:create)
|
81
|
+
|
82
|
+
@mci.add_image_to_mci(
|
83
|
+
:cloud_id=>5,
|
84
|
+
:name=>@mock_mci_name,
|
85
|
+
:image_id=>"ami-b1ahb1ah")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "sets a default description correctly" do
|
89
|
+
flexmock(MultiCloudImageInternal).should_receive(:create).with(
|
90
|
+
:name=>@mock_mci_name,
|
91
|
+
:description => "Development build: Ubuntu 10.04 with 64-bit architecture (x64) and RightLink 5.7."
|
92
|
+
).and_return(@mock_mci)
|
93
|
+
|
94
|
+
@mci.create_mci(5, @mock_mci_name)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rightimage_tools'
|
6
|
+
require 'flexmock'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'logger'
|
9
|
+
|
10
|
+
|
11
|
+
# Requires supporting files with custom matchers and macros, etc,
|
12
|
+
# in ./support/ and its subdirectories.
|
13
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
14
|
+
Dir["#{File.dirname(__FILE__)}/../lib/**/*.rb"].each {|f| require f}
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.mock_with :flexmock
|
18
|
+
end
|
19
|
+
|
data/spec/util_spec.rb
ADDED
@@ -0,0 +1,254 @@
|
|
1
|
+
require 'flexmock/rspec'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
PREFIX = "image_prefix"
|
5
|
+
OS_NAME = "os_name"
|
6
|
+
OS_VERSION = "os_version"
|
7
|
+
OS_ARCH = "os_arch"
|
8
|
+
OS_MODIFER = "os_modifier"
|
9
|
+
STORAGE_TYPE = "storage_type"
|
10
|
+
RELEASE_LEVEL = "Beta"
|
11
|
+
RIGHT_IMAGE_VERSION = "1.20"
|
12
|
+
SUFFIX = "suffix"
|
13
|
+
|
14
|
+
|
15
|
+
describe RightImage::Util, ".create_mci_name" do
|
16
|
+
before(:each) do
|
17
|
+
|
18
|
+
@name = RightImage::Util.create_mci_name(PREFIX,
|
19
|
+
OS_NAME,
|
20
|
+
OS_VERSION,
|
21
|
+
OS_ARCH ,
|
22
|
+
OS_MODIFER,
|
23
|
+
"1.20",
|
24
|
+
STORAGE_TYPE,
|
25
|
+
RELEASE_LEVEL, SUFFIX)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not have any blank fields" do
|
29
|
+
@name.include?("__").should == false
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should display two digit version number" do
|
33
|
+
(@name =~ /_v[0-9]\.[0-9][0-9]/).should_not == nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should display prefix" do
|
37
|
+
@name.include?(PREFIX).should == true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should display OS_NAME" do
|
41
|
+
@name.include?(OS_NAME).should == true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should display OS_VERSION" do
|
45
|
+
@name.include?(OS_VERSION).should == true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should display OS_ARCH" do
|
49
|
+
@name.include?(OS_ARCH).should == true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should display OS_MODIFER" do
|
53
|
+
@name.include?(OS_MODIFER).should == true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should display RIGHT_IMAGE_VERSION" do
|
57
|
+
@name.include?(RIGHT_IMAGE_VERSION.to_s).should == true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should display STORAGE_TYPE" do
|
61
|
+
@name.include?(STORAGE_TYPE).should == true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should display RELEASE_LEVEL" do
|
65
|
+
@name.include?(RELEASE_LEVEL).should == true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should display SUFFIX" do
|
69
|
+
@name.include?(SUFFIX.capitalize).should == true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe RightImage::Util, ".create_mci_name S3" do
|
74
|
+
before(:each) do
|
75
|
+
@name = RightImage::Util.create_mci_name(PREFIX,
|
76
|
+
OS_NAME,
|
77
|
+
OS_VERSION,
|
78
|
+
OS_ARCH ,
|
79
|
+
OS_MODIFER,
|
80
|
+
1.20,
|
81
|
+
"S3",
|
82
|
+
RELEASE_LEVEL, SUFFIX)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not have any blank fields" do
|
86
|
+
@name.include?("__").should == false
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should not display S3" do
|
90
|
+
@name.include?("S3").should_not == true
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
describe RightImage::Util, ".create_mci_name GA" do
|
96
|
+
|
97
|
+
before(:each) do
|
98
|
+
@name = RightImage::Util.create_mci_name(PREFIX,
|
99
|
+
OS_NAME,
|
100
|
+
OS_VERSION,
|
101
|
+
OS_ARCH ,
|
102
|
+
OS_MODIFER,
|
103
|
+
1.20,
|
104
|
+
STORAGE_TYPE,
|
105
|
+
"GA", SUFFIX)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should not have any blank fields" do
|
109
|
+
@name.include?("__").should == false
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should not display GA" do
|
113
|
+
@name.include?("GA").should_not == true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe RightImage::Util, "rightimage_version" do
|
118
|
+
|
119
|
+
it "should display two digit version number" do
|
120
|
+
@version = RightImage::Util.rightimage_version(4.3)
|
121
|
+
(@version =~ /^[0-9]\.[0-9]$/).should_not == nil
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should display three digit version number" do
|
125
|
+
@version = RightImage::Util.rightimage_version(4.3, 2)
|
126
|
+
(@version =~ /^[0-9]\.[0-9]\.[0-9]$/).should_not == nil
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should display four digit version number" do
|
130
|
+
@version = RightImage::Util.rightimage_version(4.3, 2, 1)
|
131
|
+
(@version =~ /^[0-9]\.[0-9]\.[0-9]\.[0-9]$/).should_not == nil
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should hide fourth digit if zero" do
|
135
|
+
@version = RightImage::Util.rightimage_version(4.3, 2, 0)
|
136
|
+
(@version =~ /^[0-9]\.[0-9]\.[0-9]$/).should_not == nil
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should fail if version is N.N.N format" do
|
140
|
+
lambda {
|
141
|
+
@version = RightImage::Util.rightimage_version("4.3.5")
|
142
|
+
}.should raise_error(Exception)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should fail if version is N format" do
|
146
|
+
lambda {
|
147
|
+
@version = RightImage::Util.rightimage_version(4)
|
148
|
+
}.should raise_error(Exception)
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
describe RightImage::Util, ".create_image_name GA" do
|
154
|
+
|
155
|
+
before(:each) do
|
156
|
+
@name = RightImage::Util.create_image_name("RightImage", \
|
157
|
+
"osname", \
|
158
|
+
"9.10", \
|
159
|
+
"x64", \
|
160
|
+
nil, \
|
161
|
+
1.20, \
|
162
|
+
3, \
|
163
|
+
0,
|
164
|
+
"S3",
|
165
|
+
"GA")
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should not have any blank fields" do
|
169
|
+
@name.include?("__").should == false
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should display a three digit version number without zero build digit" do
|
173
|
+
(@name =~ /_v[0-9]\.[0-9]\.[0-9]/).should_not == nil
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should display version number without 4th build digit" do
|
177
|
+
(@name =~ /_v[0-9]\.[0-9]\.[0-9]\.0/).should == nil
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should not display GA" do
|
181
|
+
@name.include?("GA").should == false
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should not display S3" do
|
185
|
+
@name.include?("S3").should == false
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should display RightImage" do
|
189
|
+
@name.include?("RightImage").should == true
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should include trailing zero on version number" do
|
193
|
+
@name.include?("9.10").should == true
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe RightImage::Util, ".create_image_name Beta EBS" do
|
198
|
+
before(:each) do
|
199
|
+
@name = RightImage::Util.create_image_name("RightImage", \
|
200
|
+
"osname", \
|
201
|
+
"99.99", \
|
202
|
+
"x64", \
|
203
|
+
nil, \
|
204
|
+
1.2, \
|
205
|
+
3, \
|
206
|
+
4,
|
207
|
+
"EBS",
|
208
|
+
"Beta")
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should not have any blank fields" do
|
212
|
+
@name.include?("__").should == false
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should display a four digit version number" do
|
216
|
+
(@name =~ /_v[0-9]\.[0-9]\.[0-9]\.[0-9]/).should_not == nil
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should display Beta" do
|
220
|
+
@name.include?("Beta").should == true
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should display EBS" do
|
224
|
+
@name.include?("EBS").should == true
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe RightImage::Util, ".create_image_name Alpha S3 Dev" do
|
229
|
+
before(:each) do
|
230
|
+
@name = RightImage::Util.create_image_name("RightImage", \
|
231
|
+
"osname", \
|
232
|
+
"99.99", \
|
233
|
+
"x64", \
|
234
|
+
nil, \
|
235
|
+
1.2, \
|
236
|
+
3, \
|
237
|
+
4,
|
238
|
+
"EBS",
|
239
|
+
"Alpha",
|
240
|
+
"dev0")
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should not have any blank fields" do
|
244
|
+
@name.include?("__").should == false
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should display Alpha" do
|
248
|
+
@name.include?("Alpha").should == true
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should display capitalized dev0" do
|
252
|
+
@name.include?("Dev0").should == true
|
253
|
+
end
|
254
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rightimage_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter Schroeter
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02
|
18
|
+
date: 2012-03-02 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -146,6 +146,11 @@ files:
|
|
146
146
|
- lib/rightimage_tools.rb
|
147
147
|
- lib/s3_html_indexer.rb
|
148
148
|
- lib/util.rb
|
149
|
+
- spec/id_list_spec.rb
|
150
|
+
- spec/mci_spec.rb
|
151
|
+
- spec/spec.opts
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
- spec/util_spec.rb
|
149
154
|
homepage: http://github.com/rightscale/rightimage_tools
|
150
155
|
licenses:
|
151
156
|
- MIT
|