From: Michal Fojtik <[email protected]>
Signed-off-by: Michal fojtik <[email protected]> --- server/lib/cimi/collections/cloud_entry_point.rb | 9 +++- server/lib/cimi/collections/machines.rb | 4 +- server/lib/cimi/helpers.rb | 22 ++++++---- server/lib/cimi/models.rb | 15 +++---- server/lib/cimi/models/volume.rb | 2 +- server/lib/cimi/server.rb | 9 +--- server/lib/deltacloud_rack.rb | 4 +- server/spec/spec_helper.rb | 6 ++- .../features/step_definitions/machines_steps.rb | 1 + .../features/step_definitions/volumes_steps.rb | 4 +- server/tests/cimi/features/support/env.rb | 44 +++++++++++++++----- 11 files changed, 75 insertions(+), 45 deletions(-) diff --git a/server/lib/cimi/collections/cloud_entry_point.rb b/server/lib/cimi/collections/cloud_entry_point.rb index 8232e61..f5f2233 100644 --- a/server/lib/cimi/collections/cloud_entry_point.rb +++ b/server/lib/cimi/collections/cloud_entry_point.rb @@ -23,7 +23,14 @@ module CIMI::Collections operation :index do description "list all resources of the cloud" control do - redirect Deltacloud[:root_url] + if params[:force_auth] + return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials) + end + entry_point = CIMI::Model::CloudEntryPoint.create(self) + respond_to do |format| + format.xml { entry_point.to_xml } + format.json { entry_point.to_json } + end end end end diff --git a/server/lib/cimi/collections/machines.rb b/server/lib/cimi/collections/machines.rb index 0abf63a..cadbcad 100644 --- a/server/lib/cimi/collections/machines.rb +++ b/server/lib/cimi/collections/machines.rb @@ -85,7 +85,7 @@ module CIMI::Collections end end - operation :restart do + action :restart do description "Start specific machine." control do machine = Machine.find(params[:id], self) @@ -101,7 +101,7 @@ module CIMI::Collections end end - operation :start do + action :start do description "Start specific machine." control do machine = Machine.find(params[:id], self) diff --git a/server/lib/cimi/helpers.rb b/server/lib/cimi/helpers.rb index b0fc9e3..05d2621 100644 --- a/server/lib/cimi/helpers.rb +++ b/server/lib/cimi/helpers.rb @@ -16,20 +16,28 @@ module Deltacloud; end module CIMI; end +require_relative '../deltacloud/drivers/features' + +# Declare namespace for CIMI models +# + +module CIMI + module Model; end + + class FakeCollection + extend Sinatra::Rabbit::Features + include Deltacloud::InstanceFeatures + end +end + require_relative '../deltacloud/drivers' require_relative '../deltacloud/models' require_relative '../deltacloud/helpers/driver_helper' require_relative '../deltacloud/helpers/auth_helper' require_relative '../deltacloud/helpers/url_helper' -require_relative '../deltacloud/helpers/assets_helper' require_relative '../deltacloud/helpers/deltacloud_helper' require_relative '../deltacloud/helpers/rabbit_helper' require_relative '../deltacloud/helpers/rabbit_helper' -require_relative '../deltacloud/core_ext/string' -require_relative '../deltacloud/core_ext/array' -require_relative '../deltacloud/core_ext/hash' -require_relative '../deltacloud/core_ext/integer' -require_relative '../deltacloud/core_ext/proc' require_relative './helpers/cimi_helper' require_relative './models' @@ -43,9 +51,9 @@ module CIMI::Collections helpers Deltacloud::Helpers::Drivers helpers Sinatra::AuthHelper helpers Sinatra::UrlForHelper - helpers Sinatra::StaticAssets::Helpers helpers Rack::RespondTo::Helpers helpers Deltacloud::Helpers::Application + helpers CIMIHelper register Rack::RespondTo diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb index b0793ee..1214497 100644 --- a/server/lib/cimi/models.rb +++ b/server/lib/cimi/models.rb @@ -13,18 +13,15 @@ # License for the specific language governing permissions and limitations # under the License. # - -require_relative '../deltacloud/drivers/features' - -# Declare namespace for CIMI models -# - module CIMI module Model; end +end - class FakeCollection - extend Sinatra::Rabbit::Features - include Deltacloud::InstanceFeatures +unless Kernel.respond_to?(:require_relative) + module Kernel + def require_relative(path) + require File.join(File.dirname(caller[0]), path.to_str) + end end end diff --git a/server/lib/cimi/models/volume.rb b/server/lib/cimi/models/volume.rb index 9c106e2..111a4e5 100644 --- a/server/lib/cimi/models/volume.rb +++ b/server/lib/cimi/models/volume.rb @@ -81,7 +81,7 @@ class CIMI::Model::Volume < CIMI::Model::Base def self.create_volume(params, context) volume_config = CIMI::Model::VolumeConfiguration.find(params[:volume_config_id], context) opts = {:capacity=>volume_config.capacity[:quantity], :snapshot_id=>params[:volume_image_id] } - storage_volume = self.driver.create_storage_volume(context.credentials, opts) + storage_volume = context.driver.create_storage_volume(context.credentials, opts) from_storage_volume(storage_volume, context) end diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb index c34dba9..58c1688 100644 --- a/server/lib/cimi/server.rb +++ b/server/lib/cimi/server.rb @@ -46,14 +46,7 @@ module CIMI include CIMI::Model get Deltacloud[:root_url] do - if params[:force_auth] - return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials) - end - entry_point = CIMI::Model::CloudEntryPoint.create(self) - respond_to do |format| - format.xml { entry_point.to_xml } - format.json { entry_point.to_json } - end + redirect Deltacloud[:root_url] + '/cloudEntryPoint', 301 end end diff --git a/server/lib/deltacloud_rack.rb b/server/lib/deltacloud_rack.rb index b795731..a52354c 100644 --- a/server/lib/deltacloud_rack.rb +++ b/server/lib/deltacloud_rack.rb @@ -34,7 +34,7 @@ module Deltacloud end def self.configure(&block) - config(Server.new(&block)) + @config = Server.new(&block) self end @@ -45,7 +45,7 @@ module Deltacloud def self.require_frontend! ENV['API_FRONTEND'] ||= 'deltacloud' require File.join(File.dirname(__FILE__), ENV['API_FRONTEND'], 'server.rb') - config.klass eval(self[:klass]) + config.klass eval('::'+self[:klass]) end class Server diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb index 8599a71..22809e2 100644 --- a/server/spec/spec_helper.rb +++ b/server/spec/spec_helper.rb @@ -17,10 +17,12 @@ require 'rubygems' require 'pp' require 'rspec/core' -require 'deltacloud/core_ext' -require 'cimi/model' require 'xmlsimple' +load File.join(File.dirname(__FILE__), '..', 'lib', 'deltacloud', 'core_ext', 'array.rb') +load File.join(File.dirname(__FILE__), '..', 'lib', 'deltacloud', 'core_ext', 'string.rb') +load File.join(File.dirname(__FILE__), '..', 'lib', 'cimi', 'models.rb') + DATA_DIR = File::join(File::expand_path(File::dirname(__FILE__)), 'cimi', 'data') def parse_xml(xml, opts = {}) diff --git a/server/tests/cimi/features/step_definitions/machines_steps.rb b/server/tests/cimi/features/step_definitions/machines_steps.rb index 0843ccf..c11d535 100644 --- a/server/tests/cimi/features/step_definitions/machines_steps.rb +++ b/server/tests/cimi/features/step_definitions/machines_steps.rb @@ -82,6 +82,7 @@ When /^client executes (\w+) operation on created Machine$/ do |operation| header 'Content-Type', 'application/xml' if operation == 'delete' delete "/cimi/machines/%s" % new_machine.name + puts last_response.body last_response.status.should == 200 last_response.body.should be_empty @delete_operation = true diff --git a/server/tests/cimi/features/step_definitions/volumes_steps.rb b/server/tests/cimi/features/step_definitions/volumes_steps.rb index 9aa6ea2..fc93be0 100644 --- a/server/tests/cimi/features/step_definitions/volumes_steps.rb +++ b/server/tests/cimi/features/step_definitions/volumes_steps.rb @@ -37,7 +37,7 @@ When /^client GET the Volumes Collection$/ do header 'Content-Type', 'application/xml' get "/cimi/volumes" last_response.status.should == 200 - @@volume_collection = VolumeCollection.from_xml(last_response.body) + @@volume_collection = CIMI::Model::VolumeCollection.from_xml(last_response.body) end Then /^client should get a list of volumes$/ do @@ -69,7 +69,7 @@ When /^client specifies a running Machine using$/ do |machine| header 'Content-Type', 'application/xml' get "/cimi/machines/#{@machine_id}?format=xml" last_response.status.should==200 - @@machine = Machine.from_xml(last_response.body) + @@machine = CIMI::Model::Machine.from_xml(last_response.body) @@machine.name.should == @machine_id @@machine.state.should == "STARTED" end diff --git a/server/tests/cimi/features/support/env.rb b/server/tests/cimi/features/support/env.rb index c5e2bf0..f8372bf 100644 --- a/server/tests/cimi/features/support/env.rb +++ b/server/tests/cimi/features/support/env.rb @@ -1,21 +1,47 @@ require 'rubygems' require 'nokogiri' +require 'rack/test' -ENV['API_DRIVER'] = 'mock' ENV['API_FRONTEND'] = 'cimi' -ENV.delete('API_VERBOSE') - -$top_srcdir = File.join(File.dirname(__FILE__), '..', '..', '..', '..') -$:.unshift File.join($top_srcdir, 'lib') -load File.join($top_srcdir, 'lib', 'cimi', 'server.rb') +load File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'deltacloud_rack.rb') -require 'rack/test' +Deltacloud::configure do |server| + server.root_url '/cimi' + server.version '1.0.0' + server.klass 'CIMI::API' +end.require_frontend! def last_xml_response Nokogiri::XML(last_response.body) end +class IndexEntrypoint < Sinatra::Base + get "/" do + redirect Deltacloud[:root_url], 301 + end +end + +=begin +def app + Rack::URLMap.new( + "/" => IndexEntrypoint.new, + Deltacloud[:root_url] => CIMI::API, + "/stylesheets" => Rack::Directory.new( "public/stylesheets" ), + "/javascripts" => Rack::Directory.new( "public/javascripts" ) + ) +end +=end + +def app + Rack::Builder.new { + map '/' do + use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public" + run Rack::Cascade.new([CIMI::API]) + end + } +end + def new_machine @@new_machine end @@ -47,7 +73,3 @@ class String end end - -def app - Sinatra::Application -end -- 1.7.10.1
