You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/28 13:52:41 UTC
[PATCH core 1/4] Core: Added 'name' method for base_driver
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/deltacloud/base_driver/base_driver.rb | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
index 931ef5c..68003ed 100644
--- a/server/lib/deltacloud/base_driver/base_driver.rb
+++ b/server/lib/deltacloud/base_driver/base_driver.rb
@@ -22,6 +22,10 @@ module Deltacloud
include ExceptionHandler
+ def name
+ self.class.name.split('::').last.gsub('Driver', '').downcase
+ end
+
def self.exceptions(&block)
ExceptionHandler::exceptions(&block)
end
--
1.7.4.4
[PATCH core 4/4] CIMI: Added Cucumber features for MachineImage
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/Rakefile | 4 +
server/tests/cimi/features/machine_images.feature | 20 +++++++
server/tests/cimi/features/machines.feature | 18 ++++--
.../cimi/features/step_definitions/common_steps.rb | 61 ++++++++++++++++++++
.../features/step_definitions/machines_steps.rb | 30 +---------
server/tests/cimi/features/support/env.rb | 20 +++++++
6 files changed, 120 insertions(+), 33 deletions(-)
create mode 100644 server/tests/cimi/features/machine_images.feature
create mode 100644 server/tests/cimi/features/step_definitions/common_steps.rb
create mode 100644 server/tests/cimi/features/step_definitions/machine_images_steps.rb
diff --git a/server/Rakefile b/server/Rakefile
index 0d52f81..1668474 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -55,6 +55,10 @@ begin
t.cucumber_opts = "tests/cimi/features/machines.feature --format pretty"
t.rcov = false
end
+ Cucumber::Rake::Task.new(:machine_images) do |t|
+ t.cucumber_opts = "tests/cimi/features/machine_images.feature --format pretty"
+ t.rcov = false
+ end
end
rescue LoadError
end
diff --git a/server/tests/cimi/features/machine_images.feature b/server/tests/cimi/features/machine_images.feature
new file mode 100644
index 0000000..f855eac
--- /dev/null
+++ b/server/tests/cimi/features/machine_images.feature
@@ -0,0 +1,20 @@
+Feature: Managing Machines Images
+ In order to interact with the provider
+ We must first be provided a URL to the main entry point (CEP).
+
+Scenario: Listing Machine Images collection
+ Given Cloud Entry Point URL is provided
+ And client retrieve the Cloud Entry Point
+ When client lists Machine Images collection
+ Then client should get list of all Machine Images
+
+Scenario: Querying Machine Image
+ Given Cloud Entry Point URL is provided
+ And client retrieve the Cloud Entry Point
+ When client query for 'img1' Machine Image entity
+ Then client should verify that this Machine Image exists
+ And client should verify that this Machine Image has set
+ | *image_location | mock://img1 |
+ | description | Fedora 10 |
+ | name | img1 |
+ | uri | http://example.org/cimi/machine_images/img1 |
diff --git a/server/tests/cimi/features/machines.feature b/server/tests/cimi/features/machines.feature
index f3264d6..badf427 100644
--- a/server/tests/cimi/features/machines.feature
+++ b/server/tests/cimi/features/machines.feature
@@ -17,19 +17,25 @@ Feature: Managing Machines
Scenario: Querying created Machine
Given Cloud Entry Point URL is provided
And client retrieve the Cloud Entry Point
- When client query for 'sampleMachine1' Machine
- And client should verify that this machine exists
+ When client query for 'sampleMachine1' Machine entity
+ Then client should verify that this machine exists
+ And client should verify that this Machine has set
+ | name | sampleMachine1 ||
+ | description | sampleMachine1Description ||
+ | cpu | 1 ||
+ | memory | quantity | 1740 |
+ | state | RUNNING ||
Scenario: Stopping Machine
Given Cloud Entry Point URL is provided
And client retrieve the Cloud Entry Point
- When client executes stop operation on Machine 'sampleMAchine1'
- Then client should be able to query this Machine
+ When client executes stop operation on Machine 'sampleMachine1'
+ Then client should be able to query for 'sampleMachine1' Machine entity
And client should verify that this machine is stopped
Scenario: Starting Machine
Given Cloud Entry Point URL is provided
And client retrieve the Cloud Entry Point
- When client executes start operation on Machine 'sampleMAchine1'
- Then client should be able to query this Machine
+ When client executes start operation on Machine 'sampleMachine1'
+ Then client should be able to query for 'sampleMachine1' Machine entity
And client should verify that this machine is started
diff --git a/server/tests/cimi/features/step_definitions/common_steps.rb b/server/tests/cimi/features/step_definitions/common_steps.rb
new file mode 100644
index 0000000..9131171
--- /dev/null
+++ b/server/tests/cimi/features/step_definitions/common_steps.rb
@@ -0,0 +1,61 @@
+World(Rack::Test::Methods)
+
+Given /^Cloud Entry Point URL is provided$/ do
+ get '/cimi'
+ last_response.status.should == 301
+ last_response.location.should == "http://example.org/cimi/cloudEntryPoint"
+end
+
+Given /^client retrieve the Cloud Entry Point$/ do
+ get "/cimi/cloudEntryPoint"
+ header 'Accept', 'application/xml'
+ last_response.status.should == 200
+end
+
+When /^client lists ([\w ]+) collection$/ do |col_name|
+ authorize 'mockuser', 'mockpassword'
+ header 'Accept', 'application/xml'
+ get "/cimi/%s" % col_name.to_collection_uri
+ last_response.status.should == 200
+ puts last_response.body
+end
+
+Then /^client should get list of all ([\w ]+)$/ do |col_name|
+ root_name = "#{col_name.to_class_name}Collection"
+ last_xml_response.root.name.should == root_name
+ (last_xml_response/"#{root_name}/name").size.should == 1
+ (last_xml_response/"#{root_name}/name").first.text.should == 'default'
+ (last_xml_response/"#{root_name}/uri").size.should == 1
+ (last_xml_response/"#{root_name}/uri").first.text.should == last_request.url
+ (last_xml_response/"#{root_name}/#{col_name.to_class_name}").size.should == 3
+ (last_xml_response/"#{root_name}/#{col_name.to_class_name}").each do |machine_img|
+ machine_img[:href].should_not be_nil
+ machine_img[:href].should =~ /http:\/\/example\.org\/cimi\/#{col_name.to_collection_uri}\/img(\d)/
+ end
+end
+
+When /^client( should be able to)? query for '(\w+)' ([\w ]+) entity$/ do |s, entity_id, entity_name|
+ authorize 'mockuser', 'mockpassword'
+ header 'Accept', 'application/xml'
+ get "/cimi/%s/%s" % [entity_name.to_entity_uri, entity_id]
+ last_response.status.should == 200
+ puts last_response.body
+ @entity_id = entity_id
+end
+
+Then /^client should verify that this ([\w ]+) exists$/ do |entity_name|
+ root_name = entity_name.to_class_name
+ last_xml_response.root.name.should == root_name
+ @entity = last_xml_response
+end
+
+Then /^client should verify that this ([\w ]+) has set$/ do |entity, attrs|
+ model = CIMI::Model.const_get(entity.to_entity_name).from_xml(last_response.body)
+ attrs.rows_hash.each do |key, value|
+ if key =~ /^\*/
+ model.send(key.gsub(/^\*/, '').intern).href.should == value
+ else
+ model.send(key.intern).to_s.should == value
+ end
+ end
+end
diff --git a/server/tests/cimi/features/step_definitions/machine_images_steps.rb b/server/tests/cimi/features/step_definitions/machine_images_steps.rb
new file mode 100644
index 0000000..e69de29
diff --git a/server/tests/cimi/features/step_definitions/machines_steps.rb b/server/tests/cimi/features/step_definitions/machines_steps.rb
index 54c63a0..d8a6b87 100644
--- a/server/tests/cimi/features/step_definitions/machines_steps.rb
+++ b/server/tests/cimi/features/step_definitions/machines_steps.rb
@@ -1,17 +1,3 @@
-World(Rack::Test::Methods)
-
-Given /^Cloud Entry Point URL is provided$/ do
- get '/cimi'
- last_response.status.should == 301
- last_response.location.should == "http://example.org/cimi/cloudEntryPoint"
-end
-
-Given /^client retrieve the Cloud Entry Point$/ do
- get "/cimi/cloudEntryPoint"
- header 'Accept', 'application/xml'
- last_response.status.should == 200
-end
-
When /^client specifies a Machine Image$/ do |machine_image|
header 'Accept', 'application/xml'
authorize 'mockuser', 'mockpassword'
@@ -48,25 +34,15 @@ When /^client specifies a new Machine using$/ do |machine|
end
Then /^client should be able to create this Machine$/ do
- pending "NOTE: There is an inconsistency between Primer and CIMI spec\n"
+ pending "\nNOTE: There is an inconsistency between Primer and CIMI spec\n" +
+ "The Primer says that client should send just pointners MachineConf and MachineImg\n"+
+ "The CIMI says that full XML need to be provided in order to create a Machine\n\n"
@machine = CIMI::Model::Machine.from_xml(@builder.to_xml)
authorize 'mockuser', 'mockpassword'
post '/cimi/machines', @machine
last_response.status.should == 201
end
-When /^client query for '(\w+)' Machine$/ do |machine_id|
- header 'Accept', 'application/xml'
- authorize 'mockuser', 'mockpassword'
- get "/cimi/machines/%s" % machine_id
-end
-
-Then /^client should verify that this machine exists$/ do
- last_xml_response.root.name == 'Machine'
- last_response.status == 200
- @new_machine = last_xml_response
-end
-
Then /^client should be able to query this Machine$/ do
get "/cimi/machines/%s" % (@new_machine/'')
end
diff --git a/server/tests/cimi/features/support/env.rb b/server/tests/cimi/features/support/env.rb
index 2cd7f73..f55e811 100644
--- a/server/tests/cimi/features/support/env.rb
+++ b/server/tests/cimi/features/support/env.rb
@@ -16,6 +16,26 @@ def last_xml_response
Nokogiri::XML(last_response.body)
end
+class String
+
+ def to_class_name
+ to_entity_name.singularize
+ end
+
+ def to_entity_name
+ self.tr(' ', '')
+ end
+
+ def to_collection_uri
+ self.tr(' ', '_').downcase
+ end
+
+ def to_entity_uri
+ to_collection_uri.pluralize
+ end
+
+end
+
def app
Sinatra::Application
end
--
1.7.4.4
[PATCH core 2/4] CIMI: Moved self.add method to base driver
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/model/base.rb | 2 ++
server/lib/cimi/model/machine_configuration.rb | 2 --
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
index c808692..4fa9014 100644
--- a/server/lib/cimi/model/base.rb
+++ b/server/lib/cimi/model/base.rb
@@ -181,4 +181,6 @@ class CIMI::Model::Base
hash :property, :content => :value do
scalar :name
end
+
+ def self.all(_self); find(:all, _self); end
end
diff --git a/server/lib/cimi/model/machine_configuration.rb b/server/lib/cimi/model/machine_configuration.rb
index e4f8ace..ad7c30e 100644
--- a/server/lib/cimi/model/machine_configuration.rb
+++ b/server/lib/cimi/model/machine_configuration.rb
@@ -46,8 +46,6 @@ class CIMI::Model::MachineConfiguration < CIMI::Model::Base
end
end
- def self.all(_self); find(:all, _self); end
-
private
def self.from_hardware_profile(profile, _self)
--
1.7.4.4
Re: [PATCH core 1/4] Core: Added 'name' method for base_driver
Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK to series
On 28/11/11 14:52, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
>
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
> server/lib/deltacloud/base_driver/base_driver.rb | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
> index 931ef5c..68003ed 100644
> --- a/server/lib/deltacloud/base_driver/base_driver.rb
> +++ b/server/lib/deltacloud/base_driver/base_driver.rb
> @@ -22,6 +22,10 @@ module Deltacloud
>
> include ExceptionHandler
>
> + def name
> + self.class.name.split('::').last.gsub('Driver', '').downcase
> + end
> +
> def self.exceptions(&block)
> ExceptionHandler::exceptions(&block)
> end
[PATCH core 3/4] CIMI: Added MachineImage model
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/cimi/model/machine_image.rb | 21 +++++++++++++++++++++
server/lib/cimi/server.rb | 31 ++++++++-----------------------
2 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/server/lib/cimi/model/machine_image.rb b/server/lib/cimi/model/machine_image.rb
index 18d91d4..779e21c 100644
--- a/server/lib/cimi/model/machine_image.rb
+++ b/server/lib/cimi/model/machine_image.rb
@@ -21,4 +21,25 @@ class CIMI::Model::MachineImage < CIMI::Model::Base
array :operations do
scalar :rel, :href
end
+
+ def self.find(id, _self)
+ images = []
+ if id == :all
+ images = _self.driver.images(_self.credentials)
+ images.map { |image| from_image(image, _self) }
+ else
+ image = _self.driver.image(_self.credentials, id)
+ from_image(image, _self)
+ end
+ end
+
+ def self.from_image(image, _self)
+ self.new(
+ :name => image.id,
+ :uri => _self.machine_image_url(image.id),
+ :description => image.description,
+ :image_location => { :href => "#{_self.driver.name}://#{image.id}" } # FIXME
+ )
+ end
+
end
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 2bd3a39..d1ae7d0 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -130,16 +130,11 @@ global_collection :machine_images do
operation :index do
description "List all machine configurations"
control do
- images = driver.send(:images, credentials, {})
- @dmtf_col_items = []
- if images
- images.map do |image|
- new_item = { "name" => image.name,
- "href" => machine_image_url(image.id) }
- @dmtf_col_items.insert 0, new_item
- end
+ machine_images = MachineImage.all(self)
+ respond_to do |format|
+ format.xml { machine_images.to_xml_cimi_collection(self) }
+ format.json { machine_images.to_json_cimi_collection(self) }
end
- respond_to_collection "machine_image.col.xml"
end
end
@@ -148,20 +143,10 @@ global_collection :machine_images do
with_capability :image
param :id, :string, :required
control do
- @image = driver.send(:image, credentials, { :id => params[:id]} )
- if @image
- #setup the default values for a machine imageion
- resource_default = get_resource_default "machine_image"
- #get the actual values from image
- resource_value = { "name" => @image.name,
- "description" => @image.description,
- "uri" => @image.id,"href" => machine_image_url(@image.id) }
- #mixin actual values get from the specific image
- @dmtfitem = resource_default["dmtfitem"].merge resource_value
- show_resource "machine_images/show", "MachineImage",
- {"property" => "properties", "operation" => "operations"}
- else
- report_error(404)
+ machine_image = MachineImage.find(params[:id], self)
+ respond_to do |format|
+ format.xml { machine_image.to_xml }
+ format.json { machine_image.to_json }
end
end
end
--
1.7.4.4