visor-image 0.0.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 (43) hide show
  1. data/bin/visor +423 -0
  2. data/bin/visor-image +10 -0
  3. data/config/server.rb +14 -0
  4. data/lib/image/auth.rb +147 -0
  5. data/lib/image/cli.rb +397 -0
  6. data/lib/image/client.rb +490 -0
  7. data/lib/image/meta.rb +219 -0
  8. data/lib/image/routes/delete_all_images.rb +40 -0
  9. data/lib/image/routes/delete_image.rb +62 -0
  10. data/lib/image/routes/get_image.rb +78 -0
  11. data/lib/image/routes/get_images.rb +54 -0
  12. data/lib/image/routes/get_images_detail.rb +54 -0
  13. data/lib/image/routes/head_image.rb +51 -0
  14. data/lib/image/routes/post_image.rb +189 -0
  15. data/lib/image/routes/put_image.rb +205 -0
  16. data/lib/image/server.rb +307 -0
  17. data/lib/image/store/cumulus.rb +126 -0
  18. data/lib/image/store/file_system.rb +119 -0
  19. data/lib/image/store/hdfs.rb +149 -0
  20. data/lib/image/store/http.rb +78 -0
  21. data/lib/image/store/lunacloud.rb +126 -0
  22. data/lib/image/store/s3.rb +121 -0
  23. data/lib/image/store/store.rb +39 -0
  24. data/lib/image/store/walrus.rb +130 -0
  25. data/lib/image/version.rb +5 -0
  26. data/lib/visor-image.rb +30 -0
  27. data/spec/lib/client_spec.rb +0 -0
  28. data/spec/lib/meta_spec.rb +230 -0
  29. data/spec/lib/routes/delete_image_spec.rb +98 -0
  30. data/spec/lib/routes/get_image_spec.rb +78 -0
  31. data/spec/lib/routes/get_images_detail_spec.rb +104 -0
  32. data/spec/lib/routes/get_images_spec.rb +104 -0
  33. data/spec/lib/routes/head_image_spec.rb +51 -0
  34. data/spec/lib/routes/post_image_spec.rb +112 -0
  35. data/spec/lib/routes/put_image_spec.rb +109 -0
  36. data/spec/lib/server_spec.rb +62 -0
  37. data/spec/lib/store/cumulus_spec.rb +0 -0
  38. data/spec/lib/store/file_system_spec.rb +32 -0
  39. data/spec/lib/store/http_spec.rb +56 -0
  40. data/spec/lib/store/s3_spec.rb +37 -0
  41. data/spec/lib/store/store_spec.rb +36 -0
  42. data/spec/lib/store/walrus_spec.rb +0 -0
  43. metadata +217 -0
@@ -0,0 +1,109 @@
1
+ require "spec_helper"
2
+
3
+ describe Visor::Image::Server do
4
+ include Visor::Common::Util
5
+
6
+ let(:test_api) { Visor::Image::Server }
7
+ let(:err) { Proc.new { fail "API request failed" } }
8
+
9
+ let(:accept_json) { {'Accept' => 'application/json'} }
10
+ let(:accept_xml) { {'Accept' => 'application/xml'} }
11
+
12
+ let(:parse_opts) { {symbolize_names: true} }
13
+ let(:valid_post) { {name: 'server_spec', architecture: 'i386', access: 'public'} }
14
+ let(:put_headers) { push_meta_into_headers(valid_post) }
15
+ let(:api_options) { {config: File.expand_path(File.join(File.dirname(__FILE__), '../../../', 'config/server.rb'))} }
16
+
17
+ inserted = []
18
+
19
+ before(:all) do
20
+ EM.synchrony do
21
+ inserted << DB.post_image(valid_post)[:_id]
22
+ EM.stop
23
+ end
24
+ @id = inserted.sample
25
+ end
26
+
27
+ after(:all) do
28
+ EM.synchrony do
29
+ inserted.each { |id| DB.delete_image(id) }
30
+ EM.stop
31
+ end
32
+ end
33
+
34
+ #
35
+ # PUT /images/<id>
36
+ #
37
+ describe "PUT /images/:id" do
38
+
39
+ it "should update an image metadata and return it as response's body" do
40
+ with_api(test_api, api_options) do
41
+ put_request({:path => "/images/#{@id}", :head => put_headers}, err) do |c|
42
+ meta = parse_body(c)
43
+ meta.should_not be_empty
44
+ meta[:name].should == valid_post[:name]
45
+ end
46
+ end
47
+ end
48
+
49
+ it "should return a JSON string if no accept header provided" do
50
+ with_api(test_api, api_options) do
51
+ put_request({:path => "/images/#{@id}", :head => put_headers}, err) do |c|
52
+ c.response.should match /\{/
53
+ end
54
+ end
55
+ end
56
+
57
+ it "should return a JSON string if accepted" do
58
+ with_api(test_api, api_options) do
59
+ put_request({:path => "/images/#{@id}", :head => put_headers.merge(accept_json)}, err) do |c|
60
+ c.response.should match /\{/
61
+ end
62
+ end
63
+ end
64
+
65
+ it "should return a XML document if accepted" do
66
+ with_api(test_api, api_options) do
67
+ put_request({:path => "/images/#{@id}", :head => put_headers.merge(accept_xml)}, err) do |c|
68
+ c.response.should match /\<?xml/
69
+ end
70
+ end
71
+ end
72
+
73
+ it "should raise a 400 error if meta validation fails" do
74
+ with_api(test_api, api_options) do
75
+ headers = put_headers.merge('x-image-meta-store' => 'invalid one')
76
+ put_request({:path => "/images/#{@id}", :head => headers, :body => 'something'}, err) do |c|
77
+ assert_400 c
78
+ end
79
+ end
80
+ end
81
+
82
+ it "should raise a 400 error if no headers neither body provided" do
83
+ with_api(test_api, api_options) do
84
+ put_request({:path => "/images/#{@id}"}, err) do |c|
85
+ assert_400 c
86
+ end
87
+ end
88
+ end
89
+
90
+ it "should raise a 400 error if location header and body are both provided" do
91
+ with_api(test_api, api_options) do
92
+ headers = put_headers.merge('x-image-meta-location' => 'file:///path/file.iso')
93
+ put_request({:path => "/images/#{@id}", :head => headers, :body => 'something'}, err) do |c|
94
+ assert_400 c
95
+ end
96
+ end
97
+ end
98
+
99
+ it "should raise a 400 error if store is HTTP" do
100
+ with_api(test_api, api_options) do
101
+ headers = put_headers.merge('x-image-meta-store' => 'http')
102
+ put_request({:path => "/images/#{@id}", :head => headers, :body => 'something'}, err) do |c|
103
+ assert_400 c
104
+ end
105
+ end
106
+ end
107
+
108
+ end
109
+ end
@@ -0,0 +1,62 @@
1
+ require "spec_helper"
2
+
3
+ describe Visor::Image::Server do
4
+
5
+ let(:test_api) { Visor::Image::Server }
6
+ let(:err) { Proc.new { fail "API request failed" } }
7
+ let(:accept) { {'Accept' => 'application/json'} }
8
+ let(:api_options) { {config: File.expand_path(File.join(File.dirname(__FILE__), '../..', 'config/server.rb'))} }
9
+
10
+ #
11
+ # Assert allowed methods by path
12
+ #
13
+ describe "On /images" do
14
+ it "should only accept GET and POST methods" do
15
+ with_api(test_api, api_options) do
16
+ put_request({path: '/images', head: accept}, err) do |c|
17
+ assert_405(c, %w(GET POST))
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "On /images/:id" do
24
+ it "should only accept GET, HED, PUT and DELETE methods" do
25
+ with_api(test_api, api_options) do
26
+ post_request({path: '/images/fake', head: accept}, err) do |c|
27
+ assert_405(c, %w(DELETE GET HEAD PUT))
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ #
34
+ # Not Found
35
+ #
36
+ describe "Operation on a not implemented path" do
37
+ it "should raise a 404 error for a GET request" do
38
+ with_api(test_api, api_options) do
39
+ get_request({:path => '/fake'}, err) { |c| assert_404_path_or_op c }
40
+ end
41
+ end
42
+
43
+ it "should raise a 404 error for a POST request" do
44
+ with_api(test_api, api_options) do
45
+ post_request({:path => '/fake'}, err) { |c| assert_404_path_or_op c }
46
+ end
47
+ end
48
+
49
+ it "should raise a 404 error for a PUT request" do
50
+ with_api(test_api, api_options) do
51
+ put_request({:path => '/fake'}, err) { |c| assert_404_path_or_op c }
52
+ end
53
+ end
54
+
55
+ it "should raise a 404 error for a POST request" do
56
+ with_api(test_api, api_options) do
57
+ delete_request({:path => '/fake'}, err) { |c| assert_404_path_or_op c }
58
+ end
59
+ end
60
+ end
61
+ end
62
+
File without changes
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe Visor::Image::Store::HTTP do
4
+
5
+ let(:klass) { Visor::Image::Store::FileSystem }
6
+
7
+ let(:file_uri) { 'file:///path/to/my_image.iso' }
8
+ let(:file_conf) { {:file => :configmock} }
9
+
10
+ let(:duplicated) { Visor::Common::Exception::Duplicated }
11
+ let(:unauthorized) { Visor::Common::Exception::Forbidden }
12
+ let(:not_found) { Visor::Common::Exception::NotFound }
13
+
14
+ describe "#initialize" do
15
+ it "should initialize a filesystem store class" do
16
+ klass.new(file_uri, file_conf).should be_a Visor::Image::Store::FileSystem
17
+ end
18
+
19
+ it "should parse uri and assign instance variables" do
20
+ fs = klass.new(file_uri, file_conf)
21
+ fs.uri.should be_a URI
22
+ fs.fp.should == '/path/to/my_image.iso'
23
+ end
24
+ end
25
+
26
+ describe "#file_exists?" do
27
+ it "should raise NotFound exception if file doesnt exist" do
28
+ fs = klass.new(file_uri, file_conf)
29
+ proc { fs.file_exists? }.should raise_exception not_found
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe Visor::Image::Store::HTTP do
4
+
5
+ let(:klass) { Visor::Image::Store::HTTP }
6
+
7
+ let(:http_uri) { 'http://www.ubuntu.com/start-download?distro=server&bits=64&release=latest' }
8
+ let(:http_conf) { {:http => :configmock} }
9
+
10
+ let(:unsupported_store) { Visor::Common::Exception::UnsupportedStore }
11
+ let(:not_found) { Visor::Common::Exception::NotFound }
12
+
13
+ before(:all) do
14
+ @valid_http = Visor::Image::Store::HTTP.new(http_uri)
15
+ @invalid_http = Visor::Image::Store::HTTP.new('http://a1g2.fake.com/')
16
+ end
17
+
18
+ describe "#initialize" do
19
+ it "should initialize http store class" do
20
+ @valid_http.should be_a Visor::Image::Store::HTTP
21
+ end
22
+ end
23
+
24
+ describe "#file_exists?" do
25
+ it "should return an array with exist flag, size and checksum" do
26
+ EM.synchrony do
27
+ @valid_http.file_exists?.should be_a Array
28
+ EM.stop
29
+ end
30
+ end
31
+
32
+ #it "should assert that a valid http file exists" do
33
+ # EM.synchrony do
34
+ # @valid_http.file_exists?[0].should be true
35
+ # EM.stop
36
+ # end
37
+ #end
38
+ #
39
+ #it "should also return the size and checksum of the file" do
40
+ # EM.synchrony do
41
+ # result = @valid_http.file_exists?
42
+ # result[1].should be_a Fixnum
43
+ # result[2].should be_a String
44
+ # EM.stop
45
+ # end
46
+ #end
47
+
48
+ #it "should raise NotFound exception if file doesnt exist" do
49
+ # EM.synchrony do
50
+ # proc { @invalid_http.file_exists? }.should raise_exception not_found
51
+ # EM.stop
52
+ # end
53
+ #end
54
+ end
55
+
56
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+
4
+ describe Visor::Image::Store::S3 do
5
+
6
+ let(:klass) { Visor::Image::Store::S3 }
7
+
8
+ let(:s3_uri) { 's3://access_key:secret_key@s3.amazonaws.com/bucket/my_image.iso' }
9
+ let(:s3_conf) { {:s3 => {:access_key => 'access_key',
10
+ :secret_key => 'secret_key',
11
+ :bucket => 'bucket'}} }
12
+
13
+ let(:not_found) { Visor::Common::Exception::NotFound }
14
+
15
+ describe "#initialize" do
16
+ it "should initialize http store class" do
17
+ s3 = Visor::Image::Store::S3.new(s3_uri, s3_conf)
18
+ s3.should be_a Visor::Image::Store::S3
19
+ end
20
+
21
+ it "should parse uri and assign it to the instance variables" do
22
+ s3 = Visor::Image::Store::S3.new(s3_uri, s3_conf)
23
+ s3.access_key.should == 'access_key'
24
+ s3.secret_key.should == 'secret_key'
25
+ s3.bucket.should == 'bucket'
26
+ s3.file.should == 'my_image.iso'
27
+ end
28
+
29
+ it "should parse uri and assign it to the instance variables" do
30
+ s3 = Visor::Image::Store::S3.new('', s3_conf)
31
+ s3.access_key.should == 'access_key'
32
+ s3.secret_key.should == 'secret_key'
33
+ s3.bucket.should == 'bucket'
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe Visor::Image::Store do
4
+ include Visor::Image::Store
5
+
6
+ let(:s3_uri) { 's3://access_key:secret_key@s3.amazonaws.com/bucket/my_image.iso' }
7
+ let(:file_uri) { 'file:///path/to/my_image.iso' }
8
+ let(:http_uri) { 'http://www.domain.com/path-to-image-file' }
9
+
10
+ let(:s3_conf) { {:s3 => :configmock} }
11
+ let(:file_conf) { {:file => :configmock} }
12
+ let(:http_conf) { {:http => :configmock} }
13
+
14
+ let(:unsupported_store) { Visor::Common::Exception::UnsupportedStore }
15
+
16
+ describe "#get_backend" do
17
+ it "should return the correct store backend class from an uri" do
18
+ get_backend(s3_uri, s3_conf).should be_a Visor::Image::Store::S3
19
+ get_backend(file_uri, file_conf).should be_a Visor::Image::Store::FileSystem
20
+ get_backend(http_uri, http_conf).should be_a Visor::Image::Store::HTTP
21
+ end
22
+
23
+ it "should return the correct store backend class from its name" do
24
+ get_backend('file', file_conf).should be_a Visor::Image::Store::FileSystem
25
+ get_backend('http', http_conf).should be_a Visor::Image::Store::HTTP
26
+ end
27
+
28
+ it "should raise an UnsupportedStore exception if bad uri" do
29
+ proc { get_backend(s3_uri.sub('s3', 's2'), s3_conf) }.should raise_exception unsupported_store
30
+ end
31
+
32
+ it "should raise an UnsupportedStore exception if bad name" do
33
+ proc { get_backend('filee', s3_conf) }.should raise_exception unsupported_store
34
+ end
35
+ end
36
+ end
File without changes
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: visor-image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - João Pereira
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: yard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: goliath
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: em-http-request
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: s3restful
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: progressbar
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: The VISOR Image System, the VISOR front-end API.
111
+ email: joaodrp@gmail.com
112
+ executables:
113
+ - visor
114
+ - visor-image
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - lib/image/auth.rb
119
+ - lib/image/cli.rb
120
+ - lib/image/client.rb
121
+ - lib/image/meta.rb
122
+ - lib/image/routes/delete_all_images.rb
123
+ - lib/image/routes/delete_image.rb
124
+ - lib/image/routes/get_image.rb
125
+ - lib/image/routes/get_images.rb
126
+ - lib/image/routes/get_images_detail.rb
127
+ - lib/image/routes/head_image.rb
128
+ - lib/image/routes/post_image.rb
129
+ - lib/image/routes/put_image.rb
130
+ - lib/image/server.rb
131
+ - lib/image/store/cumulus.rb
132
+ - lib/image/store/file_system.rb
133
+ - lib/image/store/hdfs.rb
134
+ - lib/image/store/http.rb
135
+ - lib/image/store/lunacloud.rb
136
+ - lib/image/store/s3.rb
137
+ - lib/image/store/store.rb
138
+ - lib/image/store/walrus.rb
139
+ - lib/image/version.rb
140
+ - lib/visor-image.rb
141
+ - config/server.rb
142
+ - spec/lib/client_spec.rb
143
+ - spec/lib/meta_spec.rb
144
+ - spec/lib/routes/delete_image_spec.rb
145
+ - spec/lib/routes/get_image_spec.rb
146
+ - spec/lib/routes/get_images_detail_spec.rb
147
+ - spec/lib/routes/get_images_spec.rb
148
+ - spec/lib/routes/head_image_spec.rb
149
+ - spec/lib/routes/post_image_spec.rb
150
+ - spec/lib/routes/put_image_spec.rb
151
+ - spec/lib/server_spec.rb
152
+ - spec/lib/store/cumulus_spec.rb
153
+ - spec/lib/store/file_system_spec.rb
154
+ - spec/lib/store/http_spec.rb
155
+ - spec/lib/store/s3_spec.rb
156
+ - spec/lib/store/store_spec.rb
157
+ - spec/lib/store/walrus_spec.rb
158
+ - bin/visor
159
+ - bin/visor-image
160
+ homepage: http://cvisor.org
161
+ licenses: []
162
+ post_install_message: ! '
163
+
164
+
165
+ ****************************** VISOR ******************************
166
+
167
+
168
+ visor-image was successfully installed!
169
+
170
+
171
+ Generate the VISOR configuration file for this machine (if not already done) by
172
+ running the ''visor-config'' command.
173
+
174
+
175
+ *******************************************************************
176
+
177
+
178
+ '
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: 1.9.2
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 1.8.24
197
+ signing_key:
198
+ specification_version: 3
199
+ summary: ! 'VISOR: Virtual Images Management Service for Cloud Infrastructures'
200
+ test_files:
201
+ - spec/lib/client_spec.rb
202
+ - spec/lib/meta_spec.rb
203
+ - spec/lib/routes/delete_image_spec.rb
204
+ - spec/lib/routes/get_image_spec.rb
205
+ - spec/lib/routes/get_images_detail_spec.rb
206
+ - spec/lib/routes/get_images_spec.rb
207
+ - spec/lib/routes/head_image_spec.rb
208
+ - spec/lib/routes/post_image_spec.rb
209
+ - spec/lib/routes/put_image_spec.rb
210
+ - spec/lib/server_spec.rb
211
+ - spec/lib/store/cumulus_spec.rb
212
+ - spec/lib/store/file_system_spec.rb
213
+ - spec/lib/store/http_spec.rb
214
+ - spec/lib/store/s3_spec.rb
215
+ - spec/lib/store/store_spec.rb
216
+ - spec/lib/store/walrus_spec.rb
217
+ has_rdoc: