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/24 17:25:20 UTC

[PATCH core 2/2] CIMI: Added Cucumber feature for Machine model

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/Rakefile                                    |    6 ++
 server/tests/cimi/features/machines.feature        |   35 +++++++++
 .../features/step_definitions/machines_steps.rb    |   80 ++++++++++++++++++++
 server/tests/cimi/features/support/env.rb          |   21 +++++
 4 files changed, 142 insertions(+), 0 deletions(-)
 create mode 100644 server/tests/cimi/features/machines.feature
 create mode 100644 server/tests/cimi/features/step_definitions/machines_steps.rb
 create mode 100644 server/tests/cimi/features/support/env.rb

diff --git a/server/Rakefile b/server/Rakefile
index 53fb7bf..0d52f81 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -50,6 +50,12 @@ begin
       end
     end
   end
+  namespace :cimi do
+    Cucumber::Rake::Task.new(:machines) do |t|
+      t.cucumber_opts = "tests/cimi/features/machines.feature --format pretty"
+      t.rcov = false
+    end
+  end
 rescue LoadError
 end
 
diff --git a/server/tests/cimi/features/machines.feature b/server/tests/cimi/features/machines.feature
new file mode 100644
index 0000000..f3264d6
--- /dev/null
+++ b/server/tests/cimi/features/machines.feature
@@ -0,0 +1,35 @@
+Feature: Managing Machines
+  In order to interact with the provider
+  We must first be provided a URL to the main entry point (CEP).
+
+  Scenario: Create a New Machine
+    Given Cloud Entry Point URL is provided
+    And client retrieve the Cloud Entry Point
+    When client specifies a Machine Image
+      | machineImage | http://example.com/cimi/machine_images/img1 |
+    And client specifies a Machine Configuration
+      |   machineConfig | http://example.com/cimi/machine_configurations/m1-small |
+    And client specifies a new Machine using
+      | name | sampleMachine1 |
+      | description | sampleMachine1Description |
+    Then client should be able to create this Machine
+
+  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
+
+  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
+    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
+    And client should verify that this machine is started
diff --git a/server/tests/cimi/features/step_definitions/machines_steps.rb b/server/tests/cimi/features/step_definitions/machines_steps.rb
new file mode 100644
index 0000000..54c63a0
--- /dev/null
+++ b/server/tests/cimi/features/step_definitions/machines_steps.rb
@@ -0,0 +1,80 @@
+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'
+  get machine_image.raw[0][1]
+  last_response.status.should == 200
+  @machine_image = CIMI::Model::MachineImage.from_xml(last_response.body)
+  @machine_image.should_not be_nil
+  @machine_image.uri.should == machine_image.raw[0][1]
+end
+
+When /^client specifies a Machine Configuration$/ do |machine_conf|
+  header 'Accept', 'application/xml'
+  authorize 'mockuser', 'mockpassword'
+  get machine_conf.raw[0][1]
+  last_response.status.should == 200
+  @machine_configuration = CIMI::Model::MachineImage.from_xml(last_response.body)
+  @machine_configuration.should_not be_nil
+  @machine_configuration.uri.should == machine_conf.raw[0][1]
+end
+
+When /^client specifies a new Machine using$/ do |machine|
+  @machine_image.should_not be_nil
+  @machine_configuration.should_not be_nil
+  @builder = Nokogiri::XML::Builder.new do |xml|
+    xml.Machine(:xmlns => CMWG_NAMESPACE) {
+      xml.name machine.raw[0][1]
+      xml.description machine.raw[1][1]
+      xml.MachineTemplate {
+        xml.MachineConfig( :href => @machine_configuration.uri )
+        xml.MachineImage( :href => @machine_image.uri )
+      }
+    }
+  end
+end
+
+Then /^client should be able to create this Machine$/ do
+  pending "NOTE: There is an inconsistency between Primer and CIMI spec\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
+
+When /^client executes (\w+) operation on Machine '(\w+)'$/ do |operation, machine_id|
+  pending # express the regexp above with the code you wish you had
+end
+
+Then /^client should verify that this machine is (\w+)$/ do |status|
+  pending # express the regexp above with the code you wish you had
+end
diff --git a/server/tests/cimi/features/support/env.rb b/server/tests/cimi/features/support/env.rb
new file mode 100644
index 0000000..2cd7f73
--- /dev/null
+++ b/server/tests/cimi/features/support/env.rb
@@ -0,0 +1,21 @@
+require 'rubygems'
+require 'nokogiri'
+
+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')
+
+require 'rack/test'
+
+def last_xml_response
+  Nokogiri::XML(last_response.body)
+end
+
+def app
+  Sinatra::Application
+end
-- 
1.7.4.4