visor-meta 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.
- data/bin/visor-meta +8 -0
- data/lib/meta/backends/base.rb +302 -0
- data/lib/meta/backends/mongo_db.rb +195 -0
- data/lib/meta/backends/mysql_db.rb +235 -0
- data/lib/meta/cli.rb +333 -0
- data/lib/meta/client.rb +313 -0
- data/lib/meta/server.rb +295 -0
- data/lib/meta/version.rb +5 -0
- data/lib/visor-meta.rb +12 -0
- data/spec/lib/backends/base_spec.rb +209 -0
- data/spec/lib/backends/mongo_db_spec.rb +152 -0
- data/spec/lib/backends/mysql_db_spec.rb +164 -0
- data/spec/lib/client_spec.rb +179 -0
- data/spec/lib/server_spec.rb +214 -0
- metadata +209 -0
@@ -0,0 +1,214 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include Visor::Meta::Backends
|
4
|
+
|
5
|
+
describe Visor::Meta::Server do
|
6
|
+
#TODO: kernel/ramdisk tests not working (commented below)
|
7
|
+
let(:parse_opts) { {symbolize_names: true} }
|
8
|
+
|
9
|
+
let(:valid_post) { {image: {name: 'server_spec', architecture: 'i386'}} }
|
10
|
+
let(:invalid_post) { {image: {name: 'server_spec', architecture: 'i386', access: 'invalid'}} }
|
11
|
+
|
12
|
+
let(:valid_update) { {image: {architecture: 'x86_64'}} }
|
13
|
+
let(:invalid_update) { {image: {architecture: 'this is not valid'}} }
|
14
|
+
|
15
|
+
inserted_ids = []
|
16
|
+
|
17
|
+
def images_from(last_response, single_image = false)
|
18
|
+
response = JSON.parse(last_response.body, parse_opts)
|
19
|
+
single_image ? response[:image] : response[:images]
|
20
|
+
end
|
21
|
+
|
22
|
+
def message_from(last_response)
|
23
|
+
JSON.parse(last_response.body, parse_opts)[:message]
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_all
|
27
|
+
get '/images'
|
28
|
+
images = images_from(last_response)
|
29
|
+
images.each { |image| delete "/images/#{image[:_id]}" }
|
30
|
+
end
|
31
|
+
|
32
|
+
before(:each) do
|
33
|
+
post '/images', valid_post.to_json
|
34
|
+
@valid_id = JSON.parse(last_response.body, parse_opts)[:image][:_id]
|
35
|
+
inserted_ids << @valid_id
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:all) do
|
39
|
+
inserted_ids.each { |id| delete("/images/#{id}") }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "GET on /images" do
|
43
|
+
before(:each) do
|
44
|
+
get '/images'
|
45
|
+
last_response.should be_ok
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return an array" do
|
49
|
+
images = images_from(last_response)
|
50
|
+
images.should be_a Array
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return only brief information fields" do
|
54
|
+
images = images_from(last_response)
|
55
|
+
images.each { |img| (img.keys - Base::BRIEF).should be_empty }
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should filter results" do
|
59
|
+
get "/images?name=#{valid_post[:image][:name]}"
|
60
|
+
images = images_from(last_response)
|
61
|
+
images.each { |img| img[:name].should == valid_post[:image][:name] }
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should raise an 404 error if no public images found" do
|
65
|
+
#delete_all
|
66
|
+
#get '/images'
|
67
|
+
#last_response.status.should == 404
|
68
|
+
#message_from(last_response).should match /no image found/
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "GET on /images/detail" do
|
73
|
+
before(:each) do
|
74
|
+
get '/images/detail'
|
75
|
+
last_response.should be_ok
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return an array" do
|
79
|
+
images = images_from(last_response)
|
80
|
+
images.should be_a Array
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return only detail information fields" do
|
84
|
+
images = images_from(last_response)
|
85
|
+
images.each { |img| (img.keys & Base::DETAIL_EXC).should be_empty }
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should filter results" do
|
89
|
+
get "/images?name=#{valid_post[:image][:name]}"
|
90
|
+
images = images_from(last_response)
|
91
|
+
images.each { |img| img[:name].should == valid_post[:image][:name] }
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should raise an 404 error if no public images found" do
|
95
|
+
#delete_all
|
96
|
+
#get '/images/detail'
|
97
|
+
#last_response.status.should == 404
|
98
|
+
#message_from(last_response).should match /no image found/
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "GET on /images/:id" do
|
103
|
+
before(:each) do
|
104
|
+
get "/images/#{@valid_id}"
|
105
|
+
last_response.should be_ok
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return a hash with the image meta" do
|
109
|
+
image = images_from(last_response, true)
|
110
|
+
image.should be_a Hash
|
111
|
+
image[:name].should == "server_spec"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should return only detail information fields" do
|
115
|
+
image = images_from(last_response, true)
|
116
|
+
(image.keys & Base::DETAIL_EXC).should be_empty
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should raise a 404 error if image not found" do
|
120
|
+
get "/images/fake_id"
|
121
|
+
last_response.status.should == 404
|
122
|
+
message_from(last_response).should match /No image found/
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "POST on /images" do
|
127
|
+
it "should create a new image and return its metadata" do
|
128
|
+
post '/images', valid_post.to_json
|
129
|
+
last_response.should be_ok
|
130
|
+
image = images_from(last_response, true)
|
131
|
+
image[:_id].should be_a String
|
132
|
+
image[:name].should == valid_post[:image][:name]
|
133
|
+
inserted_ids << image[:_id]
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should raise a 400 error if meta validation fails" do
|
137
|
+
post '/images', invalid_post.to_json
|
138
|
+
last_response.status.should == 400
|
139
|
+
message_from(last_response).should match /access/
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should raise a 404 error if referenced an invalid kernel/ramdisk image" do
|
143
|
+
#post '/images', valid_post.merge(kernel: "fake_id").to_json
|
144
|
+
#message_from(last_response).should match /no image found/
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "PUT on /images/:id" do
|
149
|
+
it "should update an existing image metadata and return it" do
|
150
|
+
put "/images/#{@valid_id}", valid_update.to_json
|
151
|
+
last_response.should be_ok
|
152
|
+
image = images_from(last_response, true)
|
153
|
+
image[:_id].should be_a String
|
154
|
+
image[:architecture].should == valid_update[:image][:architecture]
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should raise a 400 error if meta validation fails" do
|
158
|
+
put "/images/#{@valid_id}", invalid_update.to_json
|
159
|
+
last_response.status.should == 400
|
160
|
+
message_from(last_response).should match /architecture/
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should raise a 404 error if referenced an invalid kernel/ramdisk image" do
|
164
|
+
#put "/images/#{@valid_id}", valid_update.merge(kernel: "fake_id").to_json
|
165
|
+
#message_from(last_response).should match /No image found/
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "DELETE on /images/:id" do
|
170
|
+
|
171
|
+
it "should delete an image metadata" do
|
172
|
+
delete "/images/#{@valid_id}"
|
173
|
+
last_response.should be_ok
|
174
|
+
|
175
|
+
image = images_from(last_response, true)
|
176
|
+
image.should be_a Hash
|
177
|
+
image[:_id].should == @valid_id
|
178
|
+
|
179
|
+
get "/images/#{@valid_id}"
|
180
|
+
last_response.body.should =~ /No image found/
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should raise a 404 error if image not found" do
|
184
|
+
delete "/images/fake_id"
|
185
|
+
last_response.status.should == 404
|
186
|
+
message_from(last_response).should match /No image found/
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "Operation on a not implemented path" do
|
191
|
+
after(:each) do
|
192
|
+
last_response.status.should == 404
|
193
|
+
message_from(last_response).should match /Invalid operation or path/
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should raise a 404 error for a GET request" do
|
197
|
+
get "/fake"
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should raise a 404 error for a POST request" do
|
201
|
+
post "/fake"
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should raise a 404 error for a PUT request" do
|
205
|
+
put "/fake"
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should raise a 404 error for a POST request" do
|
209
|
+
delete "/fake"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: visor-meta
|
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: rack-test
|
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: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
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: mongo
|
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: bson_ext
|
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: mysql2
|
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
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: sinatra
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: thin
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: The VISOR Meta System, responsible for maintaining image metadata.
|
143
|
+
email: joaodrp@gmail.com
|
144
|
+
executables:
|
145
|
+
- visor-meta
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- lib/meta/backends/base.rb
|
150
|
+
- lib/meta/backends/mongo_db.rb
|
151
|
+
- lib/meta/backends/mysql_db.rb
|
152
|
+
- lib/meta/cli.rb
|
153
|
+
- lib/meta/client.rb
|
154
|
+
- lib/meta/server.rb
|
155
|
+
- lib/meta/version.rb
|
156
|
+
- lib/visor-meta.rb
|
157
|
+
- spec/lib/backends/base_spec.rb
|
158
|
+
- spec/lib/backends/mongo_db_spec.rb
|
159
|
+
- spec/lib/backends/mysql_db_spec.rb
|
160
|
+
- spec/lib/client_spec.rb
|
161
|
+
- spec/lib/server_spec.rb
|
162
|
+
- bin/visor-meta
|
163
|
+
homepage: http://cvisor.org
|
164
|
+
licenses: []
|
165
|
+
post_install_message: ! '
|
166
|
+
|
167
|
+
|
168
|
+
****************************** VISOR ******************************
|
169
|
+
|
170
|
+
|
171
|
+
visor-meta was successfully installed!
|
172
|
+
|
173
|
+
|
174
|
+
Generate the VISOR configuration file for this machine (if not already done) by
|
175
|
+
running the ''visor-config'' command.
|
176
|
+
|
177
|
+
|
178
|
+
*******************************************************************
|
179
|
+
|
180
|
+
|
181
|
+
'
|
182
|
+
rdoc_options: []
|
183
|
+
require_paths:
|
184
|
+
- lib
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - ! '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: 1.9.2
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
+
none: false
|
193
|
+
requirements:
|
194
|
+
- - ! '>='
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
requirements: []
|
198
|
+
rubyforge_project:
|
199
|
+
rubygems_version: 1.8.24
|
200
|
+
signing_key:
|
201
|
+
specification_version: 3
|
202
|
+
summary: ! 'VISOR: Virtual Images Management Service for Cloud Infrastructures'
|
203
|
+
test_files:
|
204
|
+
- spec/lib/backends/base_spec.rb
|
205
|
+
- spec/lib/backends/mongo_db_spec.rb
|
206
|
+
- spec/lib/backends/mysql_db_spec.rb
|
207
|
+
- spec/lib/client_spec.rb
|
208
|
+
- spec/lib/server_spec.rb
|
209
|
+
has_rdoc:
|