You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/05/22 22:19:37 UTC
[21/50] [abbrv] git commit: EC2: Fixed cucumber tests for Amazon EC2
EC2: Fixed cucumber tests for Amazon EC2
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/ba7bfd77
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/ba7bfd77
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/ba7bfd77
Branch: refs/heads/master
Commit: ba7bfd77448acce5b8df472e7e11a160ea9cf552
Parents: ac1e1de
Author: Michal Fojtik <mf...@redhat.com>
Authored: Wed May 16 13:55:12 2012 +0200
Committer: Michal fojtik <mf...@redhat.com>
Committed: Tue May 22 22:17:37 2012 +0200
----------------------------------------------------------------------
server/views/storage_volumes/show.xml.haml | 2 +-
tests/ec2/images.feature | 2 +
tests/ec2/step_definitions/instances_steps.rb | 2 +-
.../ec2/step_definitions/storage_volumes_steps.rb | 1 +
tests/ec2/support/ec2_mock_driver.rb | 72 +++++++++++++
tests/ec2/support/env.rb | 27 +++--
tests/ec2/support/method_serializer.rb | 83 +++++++++++++++
7 files changed, 175 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ba7bfd77/server/views/storage_volumes/show.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/storage_volumes/show.xml.haml b/server/views/storage_volumes/show.xml.haml
index f9f5f25..ccd1baa 100644
--- a/server/views/storage_volumes/show.xml.haml
+++ b/server/views/storage_volumes/show.xml.haml
@@ -30,4 +30,4 @@
- if @storage_volume.actions
%actions
- @storage_volume.actions.each do |action|
- %link{:rel => action, :method => action_method(action, :storage_volumes), :href => self.send("#{action}_storage_volume_url", @storage_volume.id)}
+ %link{:rel => action, :method => :post, :href => self.send("#{action}_storage_volume_url", @storage_volume.id)}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ba7bfd77/tests/ec2/images.feature
----------------------------------------------------------------------
diff --git a/tests/ec2/images.feature b/tests/ec2/images.feature
index 9fdd721..139b385 100644
--- a/tests/ec2/images.feature
+++ b/tests/ec2/images.feature
@@ -13,6 +13,7 @@ Feature: Listing and showing images
| owner_id |
| state |
| actions |
+ | hardware_profiles |
And each image should have 'href' attribute with valid URL
And this URI should be available in XML, JSON, HTML format
@@ -32,6 +33,7 @@ Feature: Listing and showing images
| owner_id |
| state |
| actions |
+ | hardware_profiles |
And this URI should be available in XML, JSON, HTML format
Scenario: Filtering images by owner_id
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ba7bfd77/tests/ec2/step_definitions/instances_steps.rb
----------------------------------------------------------------------
diff --git a/tests/ec2/step_definitions/instances_steps.rb b/tests/ec2/step_definitions/instances_steps.rb
index 5489394..b8dd871 100644
--- a/tests/ec2/step_definitions/instances_steps.rb
+++ b/tests/ec2/step_definitions/instances_steps.rb
@@ -116,7 +116,7 @@ When /^client want to '(\w+)' created instance$/ do |action|
end
Then /^client should get created instance$/ do
- last_response.status.should == 200
+ last_response.status.should == 202
#get last_response.headers['Location']
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ba7bfd77/tests/ec2/step_definitions/storage_volumes_steps.rb
----------------------------------------------------------------------
diff --git a/tests/ec2/step_definitions/storage_volumes_steps.rb b/tests/ec2/step_definitions/storage_volumes_steps.rb
index afd2f37..a6cd0a4 100644
--- a/tests/ec2/step_definitions/storage_volumes_steps.rb
+++ b/tests/ec2/step_definitions/storage_volumes_steps.rb
@@ -72,6 +72,7 @@ end
Then /^storage_volume should be attached to this instance$/ do
get "/api/storage_volumes/vol-de30ccb4"
+ puts last_response.body
(output_xml/"/storage_volume/mount/instance").first['id'].should == 'i-7f6a021e'
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ba7bfd77/tests/ec2/support/ec2_mock_driver.rb
----------------------------------------------------------------------
diff --git a/tests/ec2/support/ec2_mock_driver.rb b/tests/ec2/support/ec2_mock_driver.rb
new file mode 100644
index 0000000..c4a6778
--- /dev/null
+++ b/tests/ec2/support/ec2_mock_driver.rb
@@ -0,0 +1,72 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require_relative './method_serializer'
+
+# Create 'mock' version of original driver client/gem:
+
+module Mock
+
+ class Ec2 < Aws::Ec2
+
+ include MethodSerializer::Cache
+
+ def self.cached_methods
+ [
+ :describe_images,
+ :describe_images_by_owner,
+ :describe_availability_zones,
+ :launch_instances,
+ :describe_instances,
+ :reboot_instances,
+ :create_tag,
+ :delete_tag,
+ :describe_tags,
+ :terminate_instances,
+ :describe_key_pairs,
+ :create_key_pair,
+ :delete_key_pair,
+ :create_volume,
+ :get_console_output,
+ :describe_volumes,
+ :delete_volume,
+ :attach_volume,
+ :detach_volume,
+ :describe_snapshots,
+ :associate_address,
+ :try_create_snapshot,
+ ]
+ end
+
+ MethodSerializer::Cache::wrap_methods(self, :cache_dir => File.join(File.dirname(__FILE__)))
+ end
+
+end
+
+Deltacloud::Drivers::Ec2::Ec2Driver.class_eval do
+ alias_method :original_new_client, :new_client
+
+ def new_client(credentials, provider = :ec2)
+ auth_credentials = { :access_key_id => credentials.user, :secret_access_key => credentials.password}
+ if provider == :elb
+ Mock::ELB.new(auth_credentials)
+ elsif provider == :s3
+ Mock::S3.new(auth_credentials)
+ else
+ Mock::Ec2.new(auth_credentials[:access_key_id], auth_credentials[:secret_access_key])
+ end
+ end
+
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ba7bfd77/tests/ec2/support/env.rb
----------------------------------------------------------------------
diff --git a/tests/ec2/support/env.rb b/tests/ec2/support/env.rb
index 5eb006a..39dd5ee 100644
--- a/tests/ec2/support/env.rb
+++ b/tests/ec2/support/env.rb
@@ -1,26 +1,29 @@
require 'rubygems'
require 'nokogiri'
-
-SERVER_DIR = File::expand_path(File::join(File::dirname(__FILE__), "../../../server"))
-$top_srcdir = SERVER_DIR
-$:.unshift File::join($top_srcdir, 'lib')
-Dir.chdir(SERVER_DIR)
-
-API_VERSION = "9.9.9"
-API_ROOT_URL = "/api"
+require 'rack/test'
ENV['API_DRIVER'] = 'ec2'
-ENV.delete('API_VERBOSE')
-
-load File.join($top_srcdir, 'lib', 'deltacloud', 'server.rb')
-require 'rack/test'
+#CONFIG = {
+# :username => 'AKIAI77KNAA7ZXRLL7GQ',
+# :password => 'idJ9vktNaDWAK0LWVVE/526ONvJmTl2Crto/s8Ok'
+#}
CONFIG = {
:username => 'mockuser',
:password => 'mockpassword'
}
+load File.join(File.dirname(__FILE__), '..', '..', '..', 'server', 'lib', 'deltacloud_rack.rb')
+
+Deltacloud::configure do |server|
+ server.root_url '/api'
+ server.version '0.5.0'
+ server.klass 'Deltacloud::API'
+end.require_frontend!
+
+require_relative './ec2_mock_driver'
+
World do
include Rack::Test::Methods
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ba7bfd77/tests/ec2/support/method_serializer.rb
----------------------------------------------------------------------
diff --git a/tests/ec2/support/method_serializer.rb b/tests/ec2/support/method_serializer.rb
new file mode 100644
index 0000000..ff5e542
--- /dev/null
+++ b/tests/ec2/support/method_serializer.rb
@@ -0,0 +1,83 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+require 'base64'
+require 'digest'
+
+module MethodSerializer
+
+ module Cache
+
+ def cache_dir
+ storage_dir = $methods_cache_dir || File.join(File.dirname(__FILE__), 'cache')
+ class_dir = self.class.name.split('::').last
+ class_dir ||= self.class.name
+ File.join(storage_dir, class_dir.downcase)
+ end
+
+ def serialize_data(method_name, args, data)
+ File.open(cache_file_name(method_name, args), 'w') do |f|
+ f.puts(Base64.encode64(Marshal.dump(data)))
+ end
+ return data
+ end
+
+ def deserialize_data(method_name, args)
+ begin
+ data = File.readlines(cache_file_name(method_name, args)).join
+ Marshal.load(Base64.decode64(data))
+ rescue Errno::ENOENT
+ return false
+ end
+ end
+
+ def args_hash(args)
+ if args.class == Hash
+ args = args.to_a.collect {|i| [i[0].to_s, i[1]]}.sort
+ end
+ Digest::SHA1.hexdigest(args.to_s)
+ end
+
+ def cache_file_name(method_name, args)
+ FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
+ method_name = $scenario_prefix ? "#{$scenario_prefix}_#{method_name}" : method_name
+ File.join(cache_dir, "#{method_name}.#{args_hash(args)}")
+ end
+
+ def self.wrap_methods(c, opts={})
+ $methods_cache_dir = opts[:cache_dir]
+ $scenario_prefix = nil
+ c.class_eval do
+ cached_methods.each do |m|
+ next if c.instance_methods(false).include?("original_#{m}")
+ alias_method "original_#{m}".to_sym, m.to_sym
+ define_method m.to_sym do |*args|
+ args = args.first if args.size.eql?(1) and not args.first.class.eql?(Array)
+ output = deserialize_data(m, args)
+ unless output
+ output = method("original_#{m}".to_sym).to_proc[args]
+ return serialize_data(m, args, output)
+ else
+ return output
+ end
+ end
+ end
+ end
+ end
+
+ end
+
+end
+