From 83e291704fe808cefb4c45fe4ae7d4d285fdf388 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 26 Sep 2012 16:36:55 -0700 Subject: [PATCH 01/24] Added RDS describe_events --- lib/fog/aws/parsers/rds/base.rb | 34 +++++++++++++++ lib/fog/aws/parsers/rds/event_list.rb | 38 +++++++++++++++++ lib/fog/aws/requests/rds/describe_events.rb | 46 +++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 lib/fog/aws/parsers/rds/base.rb create mode 100644 lib/fog/aws/parsers/rds/event_list.rb create mode 100644 lib/fog/aws/requests/rds/describe_events.rb diff --git a/lib/fog/aws/parsers/rds/base.rb b/lib/fog/aws/parsers/rds/base.rb new file mode 100644 index 000000000..9704882b6 --- /dev/null +++ b/lib/fog/aws/parsers/rds/base.rb @@ -0,0 +1,34 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/base' + + # Base parser for ResponseMetadata, RequestId + class Base < Fog::Parsers::Base + + def reset + super + @response = { 'ResponseMetadata' => {} } + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = value + else + super + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/event_list.rb b/lib/fog/aws/parsers/rds/event_list.rb new file mode 100644 index 000000000..1ec14dd79 --- /dev/null +++ b/lib/fog/aws/parsers/rds/event_list.rb @@ -0,0 +1,38 @@ +module Fog + module Parsers + module AWS + module RDS + require 'fog/aws/parsers/rds/base' + + class EventListParser < Base + + def reset + super + @response['Events'] = [] + end + + def start_element(name, attrs = []) + super + case name + when 'Event'; then @event = {} + end + + end + + def end_element(name) + case name + when 'Date' + @event[name] = DateTime.parse(value.strip) + when 'Message', 'SourceIdentifier', 'SourceType' + @event[name] = value ? value.strip : name + when 'Event' + @response['Events'] << @event unless @event.empty? + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/requests/rds/describe_events.rb b/lib/fog/aws/requests/rds/describe_events.rb new file mode 100644 index 000000000..bce7b8d18 --- /dev/null +++ b/lib/fog/aws/requests/rds/describe_events.rb @@ -0,0 +1,46 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/event_list' + + # Returns a list of service events + # + # === Parameters (optional) + # * options <~Hash> (optional): + # * :start_time <~DateTime> - starting time for event records + # * :end_time <~DateTime> - ending time for event records + # * :duration <~DateTime> - time span for event records + # * :marker <~String> - marker provided in the previous request + # * :max_records <~Integer> - the maximum number of records to include + # * :source_identifier <~DateTime> - identifier of the event source + # * :source_type <~DateTime> - event type, one of: + # (cache-cluster | cache-parameter-group | cache-security-group) + # === Returns + # * response <~Excon::Response>: + # * body <~Hash> + def describe_events(options = {}) + request( + 'Action' => 'DescribeEvents', + 'StartTime' => options[:sart_time], + 'EndTime' => options[:end_time], + 'Duration' => options[:duration], + 'Marker' => options[:marker], + 'MaxRecords' => options[:max_records], + 'SourceIdentifier' => options[:source_identifier], + 'SourceType' => options[:source_type], + :parser => Fog::Parsers::AWS::RDS::EventListParser.new + ) + end + + end + + class Mock + def describe_events + Fog::Mock.not_implemented + end + end + end + end +end From 0c536a543e231aedd69ebdf5e4c59ca11270d596 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 26 Sep 2012 16:36:55 -0700 Subject: [PATCH 02/24] Created describe events for RDS --- lib/fog/aws/parsers/rds/base.rb | 34 +++++++++++++++ lib/fog/aws/parsers/rds/event_list.rb | 38 +++++++++++++++++ lib/fog/aws/requests/rds/describe_events.rb | 46 +++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 lib/fog/aws/parsers/rds/base.rb create mode 100644 lib/fog/aws/parsers/rds/event_list.rb create mode 100644 lib/fog/aws/requests/rds/describe_events.rb diff --git a/lib/fog/aws/parsers/rds/base.rb b/lib/fog/aws/parsers/rds/base.rb new file mode 100644 index 000000000..9704882b6 --- /dev/null +++ b/lib/fog/aws/parsers/rds/base.rb @@ -0,0 +1,34 @@ +module Fog + module Parsers + module AWS + module RDS + + require 'fog/aws/parsers/rds/base' + + # Base parser for ResponseMetadata, RequestId + class Base < Fog::Parsers::Base + + def reset + super + @response = { 'ResponseMetadata' => {} } + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'RequestId' + @response['ResponseMetadata'][name] = value + else + super + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/event_list.rb b/lib/fog/aws/parsers/rds/event_list.rb new file mode 100644 index 000000000..1ec14dd79 --- /dev/null +++ b/lib/fog/aws/parsers/rds/event_list.rb @@ -0,0 +1,38 @@ +module Fog + module Parsers + module AWS + module RDS + require 'fog/aws/parsers/rds/base' + + class EventListParser < Base + + def reset + super + @response['Events'] = [] + end + + def start_element(name, attrs = []) + super + case name + when 'Event'; then @event = {} + end + + end + + def end_element(name) + case name + when 'Date' + @event[name] = DateTime.parse(value.strip) + when 'Message', 'SourceIdentifier', 'SourceType' + @event[name] = value ? value.strip : name + when 'Event' + @response['Events'] << @event unless @event.empty? + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/requests/rds/describe_events.rb b/lib/fog/aws/requests/rds/describe_events.rb new file mode 100644 index 000000000..bce7b8d18 --- /dev/null +++ b/lib/fog/aws/requests/rds/describe_events.rb @@ -0,0 +1,46 @@ +module Fog + module AWS + class RDS + class Real + + require 'fog/aws/parsers/rds/event_list' + + # Returns a list of service events + # + # === Parameters (optional) + # * options <~Hash> (optional): + # * :start_time <~DateTime> - starting time for event records + # * :end_time <~DateTime> - ending time for event records + # * :duration <~DateTime> - time span for event records + # * :marker <~String> - marker provided in the previous request + # * :max_records <~Integer> - the maximum number of records to include + # * :source_identifier <~DateTime> - identifier of the event source + # * :source_type <~DateTime> - event type, one of: + # (cache-cluster | cache-parameter-group | cache-security-group) + # === Returns + # * response <~Excon::Response>: + # * body <~Hash> + def describe_events(options = {}) + request( + 'Action' => 'DescribeEvents', + 'StartTime' => options[:sart_time], + 'EndTime' => options[:end_time], + 'Duration' => options[:duration], + 'Marker' => options[:marker], + 'MaxRecords' => options[:max_records], + 'SourceIdentifier' => options[:source_identifier], + 'SourceType' => options[:source_type], + :parser => Fog::Parsers::AWS::RDS::EventListParser.new + ) + end + + end + + class Mock + def describe_events + Fog::Mock.not_implemented + end + end + end + end +end From 155b0c915791e0c3277e0b95e03f1ed0ca11f944 Mon Sep 17 00:00:00 2001 From: Alvin Garcia Date: Wed, 18 Jul 2012 13:31:01 +0800 Subject: [PATCH 03/24] [openstack|image] Added update_members function --- lib/fog/openstack/image.rb | 1 + lib/fog/openstack/models/image/image.rb | 5 +++ .../requests/image/update_image_members.rb | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 lib/fog/openstack/requests/image/update_image_members.rb diff --git a/lib/fog/openstack/image.rb b/lib/fog/openstack/image.rb index 3ae6460c6..5b034f99b 100644 --- a/lib/fog/openstack/image.rb +++ b/lib/fog/openstack/image.rb @@ -24,6 +24,7 @@ module Fog request :create_image request :update_image request :get_image_members + request :update_image_members request :get_shared_images request :add_member_to_image request :remove_member_from_image diff --git a/lib/fog/openstack/models/image/image.rb b/lib/fog/openstack/models/image/image.rb index 51d6847cf..8d805e619 100644 --- a/lib/fog/openstack/models/image/image.rb +++ b/lib/fog/openstack/models/image/image.rb @@ -69,6 +69,11 @@ module Fog connection.remove_member_from_image(self.id, member_id) end + def update_members(members) + requires :id + connection.update_image_members(self.id, members) + end + def members requires :id connection.get_image_members(self.id).body['members'] diff --git a/lib/fog/openstack/requests/image/update_image_members.rb b/lib/fog/openstack/requests/image/update_image_members.rb new file mode 100644 index 000000000..a7010fd61 --- /dev/null +++ b/lib/fog/openstack/requests/image/update_image_members.rb @@ -0,0 +1,37 @@ +module Fog + module Image + class OpenStack + class Real + def update_image_members(image_id, members) + # Sample members + # [ + # {'member_id' => 'tenant1', 'can_share' => true }, + # {'member_id' => 'tenant2', 'can_share' => false } + # ] + data = { 'memberships' => members } + + request( + :body => MultiJson.encode(data), + :expects => [200, 202], + :method => 'PUT', + :path => "images/#{image_id}/members" + ) + end + end # class Real + + class Mock + def update_image_members(image_id, members) + response = Excon::Response.new + response.status = [200, 202][rand(1)] + response.body = { + 'members' => [ + { 'member_id'=>'ff528b20431645ebb5fa4b0a71ca002f', 'can_share' => false }, + { 'member_id'=>'ff528b20431645ebb5fa4b0a71ca002f', 'can_share' => true } + ] + } + response + end + end # class Mock + end # class OpenStack + end # module Identity +end # module Fog From b8335b83a01ee39cffd8e4cd80b8c78a628c6584 Mon Sep 17 00:00:00 2001 From: Alfonso Juan Dillera Date: Wed, 18 Jul 2012 13:26:33 +0800 Subject: [PATCH 04/24] [openstack|compute] Added auth_token_expiration. --- lib/fog/openstack.rb | 2 ++ lib/fog/openstack/compute.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/fog/openstack.rb b/lib/fog/openstack.rb index f1b7d46c7..902b6879b 100644 --- a/lib/fog/openstack.rb +++ b/lib/fog/openstack.rb @@ -148,11 +148,13 @@ module Fog mgmt_url = svc['endpoints'].detect{|x| x[@endpoint_type]}[@endpoint_type] identity_url = identity_svc['endpoints'].detect{|x| x['publicURL']}['publicURL'] if identity_svc token = body['access']['token']['id'] + expires = body['access']['token']['expires'] { :user => user, :tenant => tenant, :token => token, + :expires => expires, :server_management_url => mgmt_url, :identity_public_endpoint => identity_url, :current_user_id => body['access']['user']['id'] diff --git a/lib/fog/openstack/compute.rb b/lib/fog/openstack/compute.rb index 8aefe93e0..a469e9b4a 100644 --- a/lib/fog/openstack/compute.rb +++ b/lib/fog/openstack/compute.rb @@ -226,6 +226,7 @@ module Fog class Real attr_reader :auth_token + attr_reader :auth_token_expiration attr_reader :current_user attr_reader :current_tenant @@ -338,6 +339,7 @@ module Fog @openstack_must_reauthenticate = false @auth_token = credentials[:token] + @auth_token_expiration = credentials[:expires] @openstack_management_url = credentials[:server_management_url] @openstack_identity_public_endpoint = credentials[:identity_public_endpoint] uri = URI.parse(@openstack_management_url) From db489caaa4d71b2bcabd53c945b0e26ea7b93f9d Mon Sep 17 00:00:00 2001 From: Alvin Garcia Date: Wed, 18 Jul 2012 13:50:11 +0800 Subject: [PATCH 05/24] [openstack|image] Added updateable attributes --- lib/fog/openstack/requests/image/update_image.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/fog/openstack/requests/image/update_image.rb b/lib/fog/openstack/requests/image/update_image.rb index df9a06b6d..7daba7876 100644 --- a/lib/fog/openstack/requests/image/update_image.rb +++ b/lib/fog/openstack/requests/image/update_image.rb @@ -11,6 +11,9 @@ module Fog "x-image-meta-container-format" => attributes[:container_format], "x-image-meta-size" => attributes[:size], "x-image-meta-is-public" => attributes[:is_public], + "x-image-meta-min-ram" => attributes[:min_ram], + "x-image-meta-min-disk" => attributes[:min_disk], + "x-image-meta-checksum" => attributes[:checksum], "x-image-meta-owner" => attributes[:owner] } @@ -21,7 +24,7 @@ module Fog end request( - :headers => data, + :headers => data, :expects => 200, :method => 'PUT', :path => "images/#{attributes[:id]}" From 8beec31665b8a9de34d6c14649f2e2d3f534591e Mon Sep 17 00:00:00 2001 From: Alvin Garcia Date: Thu, 19 Jul 2012 11:04:20 +0800 Subject: [PATCH 06/24] [openstack|image] Added optional attributes to set on create image --- lib/fog/openstack/requests/image/create_image.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/fog/openstack/requests/image/create_image.rb b/lib/fog/openstack/requests/image/create_image.rb index e07a4c047..860620969 100644 --- a/lib/fog/openstack/requests/image/create_image.rb +++ b/lib/fog/openstack/requests/image/create_image.rb @@ -13,6 +13,9 @@ module Fog "x-image-meta-container-format" => attributes[:container_format], "x-image-meta-size" => attributes[:size], "x-image-meta-is-public" => attributes[:is_public], + "x-image-meta-min-ram" => attributes[:min_ram], + "x-image-meta-min-disk" => attributes[:min_disk], + "x-image-meta-checksum" => attributes[:checksum], "x-image-meta-owner" => attributes[:owner], "x-glance-api-copy-from" => attributes[:copy_from] } From 7c72e5394fd99ee276ca2c046be64c55f93d21fe Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Tue, 14 Aug 2012 16:32:23 +0800 Subject: [PATCH 07/24] [openstack] Authentication Mocks Signed-off-by: Nelvin Driz --- lib/fog/core/time.rb | 2 ++ lib/fog/openstack/compute.rb | 19 +++++++++++++++++- lib/fog/openstack/identity.rb | 37 ++++++++++++++++++++++++++++++----- lib/fog/openstack/image.rb | 10 ++++++++++ lib/fog/openstack/volume.rb | 10 ++++++++++ 5 files changed, 72 insertions(+), 6 deletions(-) diff --git a/lib/fog/core/time.rb b/lib/fog/core/time.rb index f2394c23a..61d97dedb 100644 --- a/lib/fog/core/time.rb +++ b/lib/fog/core/time.rb @@ -1,3 +1,5 @@ +require 'time' + module Fog class Time < ::Time diff --git a/lib/fog/openstack/compute.rb b/lib/fog/openstack/compute.rb index a469e9b4a..02bd85dda 100644 --- a/lib/fog/openstack/compute.rb +++ b/lib/fog/openstack/compute.rb @@ -152,9 +152,13 @@ module Fog # Hosts request :list_hosts request :get_host_details - + class Mock + attr_reader :auth_token + attr_reader :auth_token_expiration + attr_reader :current_user + attr_reader :current_tenant def self.data @data ||= Hash.new do |hash, key| @@ -205,6 +209,19 @@ module Fog def initialize(options={}) @openstack_username = options[:openstack_username] @openstack_tenant = options[:openstack_tenant] + @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) + + @auth_token = Fog::Mock.random_base64(64) + @auth_token_expiration = (Time.now.utc + 86400).iso8601 + + management_url = URI.parse(options[:openstack_auth_url]) + management_url.port = 8774 + management_url.path = '/v1.1/1' + @openstack_management_url = management_url.to_s + + identity_public_endpoint = URI.parse(options[:openstack_auth_url]) + identity_public_endpoint.port = 5000 + @openstack_identity_public_endpoint = identity_public_endpoint.to_s end def data diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index 724e32a9c..94544485e 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -53,6 +53,11 @@ module Fog class Mock + attr_reader :auth_token + attr_reader :auth_token_expiration + attr_reader :current_user + attr_reader :current_tenant + def self.data @data ||= Hash.new do |hash, key| hash[key] = { @@ -69,6 +74,26 @@ module Fog def initialize(options={}) @openstack_username = options[:openstack_username] + @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) + @openstack_management_url = @openstack_auth_uri.to_s + + @current_user_id = 1 + @current_user = { + 'username' => 'admin', + 'name' => 'admin', + 'id' => 1, + 'roles' => [ + { 'id' => 1, 'name' => 'admin' }, + { 'id' => 2, 'name' => 'Member' } + ] + } + + @auth_token = Fog::Mock.random_base64(64) + @auth_token_expiration = (Time.now.utc + 86400).iso8601 + @current_tenant = { + 'id' => 1, + 'name' => 'admin' + } unless self.data[:users].values.detect {|user| user['name'] == @openstack_username} id = Fog::Mock.random_numbers(6).to_s @@ -91,11 +116,13 @@ module Fog end def credentials - { :provider => 'openstack', - :openstack_auth_url => @openstack_auth_uri.to_s, - :openstack_auth_token => @auth_token, - :openstack_management_url => @openstack_management_url, - :openstack_current_user_id => @openstack_current_user_id} + { :provider => 'openstack', + :openstack_auth_url => @openstack_auth_uri.to_s, + :openstack_auth_token => @auth_token, + :openstack_management_url => @openstack_management_url, + :openstack_current_user_id => @openstack_current_user_id, + :current_user => @current_user, + :current_tenant => @current_tenant} end end diff --git a/lib/fog/openstack/image.rb b/lib/fog/openstack/image.rb index 5b034f99b..364521c7c 100644 --- a/lib/fog/openstack/image.rb +++ b/lib/fog/openstack/image.rb @@ -49,6 +49,16 @@ module Fog def initialize(options={}) require 'multi_json' @openstack_username = options[:openstack_username] + @openstack_tenant = options[:openstack_tenant] + @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) + + @auth_token = Fog::Mock.random_base64(64) + @auth_token_expiration = (Time.now.utc + 86400).iso8601 + + management_url = URI.parse(options[:openstack_auth_url]) + management_url.port = 9292 + management_url.path = '/v1' + @openstack_management_url = management_url.to_s @data ||= { :users => {} } unless @data[:users].find {|u| u['name'] == options[:openstack_username]} diff --git a/lib/fog/openstack/volume.rb b/lib/fog/openstack/volume.rb index 99ad4d0bc..0e41e1a2a 100644 --- a/lib/fog/openstack/volume.rb +++ b/lib/fog/openstack/volume.rb @@ -48,6 +48,16 @@ module Fog def initialize(options={}) require 'multi_json' @openstack_username = options[:openstack_username] + @openstack_tenant = options[:openstack_tenant] + @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) + + @auth_token = Fog::Mock.random_base64(64) + @auth_token_expiration = (Time.now.utc + 86400).iso8601 + + management_url = URI.parse(options[:openstack_auth_url]) + management_url.port = 8776 + management_url.path = '/v1' + @openstack_management_url = management_url.to_s @data ||= { :users => {} } unless @data[:users].find {|u| u['name'] == options[:openstack_username]} From d50fe64007502c7a81340fc3f3a89fd0e7775b7c Mon Sep 17 00:00:00 2001 From: "Philip Mark M. Deazeta" Date: Thu, 16 Aug 2012 11:27:35 +0800 Subject: [PATCH 08/24] [openstack] Changed volumes attributes of mocks from camelcase to snakecase Change in snaphot_id Added mcks for volume attach and detach Conflicts: lib/fog/openstack/requests/compute/create_volume.rb lib/fog/openstack/requests/compute/get_volume_details.rb lib/fog/openstack/requests/compute/list_volumes.rb --- .../requests/compute/attach_volume.rb | 10 +++++++ .../requests/compute/create_volume.rb | 14 ++++----- .../compute/create_volume_snapshot.rb | 17 ++++++++++- .../requests/compute/detach_volume.rb | 5 ++++ .../requests/compute/get_snapshot_details.rb | 8 ++--- .../requests/compute/get_volume_details.rb | 20 ++++++------- .../requests/compute/list_volumes.rb | 30 ++++++++++--------- .../requests/volume/create_volume.rb | 20 ++++++------- .../requests/volume/create_volume_snapshot.rb | 17 ++++++++++- .../requests/volume/get_snapshot_details.rb | 10 +++---- .../requests/volume/get_volume_details.rb | 12 ++++---- .../openstack/requests/volume/list_volumes.rb | 24 +++++++-------- 12 files changed, 117 insertions(+), 70 deletions(-) diff --git a/lib/fog/openstack/requests/compute/attach_volume.rb b/lib/fog/openstack/requests/compute/attach_volume.rb index 1474d9ede..dcfd7ad91 100644 --- a/lib/fog/openstack/requests/compute/attach_volume.rb +++ b/lib/fog/openstack/requests/compute/attach_volume.rb @@ -21,6 +21,16 @@ module Fog end class Mock + def attach_volume(volume_id, server_id, device) + response = Excon::Response.new + response.status = 200 + response.body ={ "volumeAttachment" => { + "id" => volume_id, + "volumeId" => volume_id + } + } + response + end end end diff --git a/lib/fog/openstack/requests/compute/create_volume.rb b/lib/fog/openstack/requests/compute/create_volume.rb index 0b5ccaf52..8bf5f7d4f 100644 --- a/lib/fog/openstack/requests/compute/create_volume.rb +++ b/lib/fog/openstack/requests/compute/create_volume.rb @@ -34,15 +34,15 @@ module Fog response.body = { 'volume' => { 'id' => Fog::Mock.random_numbers(2), - 'displayName' => name, - 'displayDescription' => description, + 'display_name' => name, + 'display_description' => description, 'size' => size, 'status' => 'creating', - 'snapshotId' => '4', - 'volumeType' => nil, - 'availabilityZone' => 'nova', - 'createdAt' => Time.now, - 'attachments' => [] + 'snapshot_id' => '4', + 'volume_type' => nil, + 'availability_zone' => 'nova', + 'created_at' => Time.now, + 'attchments' => [] } } response diff --git a/lib/fog/openstack/requests/compute/create_volume_snapshot.rb b/lib/fog/openstack/requests/compute/create_volume_snapshot.rb index 65e257d52..c5f9a9e47 100644 --- a/lib/fog/openstack/requests/compute/create_volume_snapshot.rb +++ b/lib/fog/openstack/requests/compute/create_volume_snapshot.rb @@ -24,7 +24,22 @@ module Fog end class Mock - + def create_volume_snapshot(volume_id, name, description, force=false) + response = Excon::Response.new + response.status = 202 + response.body = { + "snapshot"=> { + "status"=>"creating", + "display_name"=>name, + "created_at"=>Time.now, + "display_description"=>description, + "volume_id"=>volume_id, + "id"=>"5", + "size"=>1 + } + } + response + end end end diff --git a/lib/fog/openstack/requests/compute/detach_volume.rb b/lib/fog/openstack/requests/compute/detach_volume.rb index 8d8ddc88d..1b838ca40 100644 --- a/lib/fog/openstack/requests/compute/detach_volume.rb +++ b/lib/fog/openstack/requests/compute/detach_volume.rb @@ -14,6 +14,11 @@ module Fog end class Mock + def detach_volume(server_id, attachment_id) + response = Excon::Response.new + response.status = 202 + response + end end end diff --git a/lib/fog/openstack/requests/compute/get_snapshot_details.rb b/lib/fog/openstack/requests/compute/get_snapshot_details.rb index 605e056e9..5e4355dd1 100644 --- a/lib/fog/openstack/requests/compute/get_snapshot_details.rb +++ b/lib/fog/openstack/requests/compute/get_snapshot_details.rb @@ -22,12 +22,12 @@ module Fog response.body = { 'snapshot' => { 'id' => '1', - 'displayName' => Fog::Mock.random_letters(rand(8) + 5), - 'displayDescription' => Fog::Mock.random_letters(rand(12) + 10), + 'display_name' => Fog::Mock.random_letters(rand(8) + 5), + 'display_description' => Fog::Mock.random_letters(rand(12) + 10), 'size' => 3, - 'volumeId' => '4', + 'volume_id' => '4', 'status' => 'online', - 'createdAt' => Time.now + 'created_at' => Time.now } } response diff --git a/lib/fog/openstack/requests/compute/get_volume_details.rb b/lib/fog/openstack/requests/compute/get_volume_details.rb index eb96c1658..b0f913eb6 100644 --- a/lib/fog/openstack/requests/compute/get_volume_details.rb +++ b/lib/fog/openstack/requests/compute/get_volume_details.rb @@ -21,16 +21,16 @@ module Fog response.status = 200 response.body = { 'volume' => { - 'id' => '1', - 'displayName' => Fog::Mock.random_letters(rand(8) + 5), - 'displayDescription' => Fog::Mock.random_letters(rand(12) + 10), - 'size' => 3, - 'volumeType' => nil, - 'snapshotId' => '4', - 'status' => 'online', - 'availabilityZone' => 'nova', - 'createdAt' => Time.now, - 'attachments' => [] + 'id' => '1', + 'display_name' => Fog::Mock.random_letters(rand(8) + 5), + 'display_description' => Fog::Mock.random_letters(rand(12) + 10), + 'size' => 3, + 'volume_type' => nil, + 'snapshot_id' => '4', + 'status' => 'online', + 'availability_zone' => 'nova', + 'created_at' => Time.now, + 'attchments' => [] } } response diff --git a/lib/fog/openstack/requests/compute/list_volumes.rb b/lib/fog/openstack/requests/compute/list_volumes.rb index 6510c23e2..8538401e8 100644 --- a/lib/fog/openstack/requests/compute/list_volumes.rb +++ b/lib/fog/openstack/requests/compute/list_volumes.rb @@ -21,25 +21,27 @@ module Fog response.status = 200 self.data[:volumes] ||= [ { "status" => "available", - "displayDescription" => "", - "availabilityZone" => "nova", - "displayName" => "test 1", + "display_description" => "", + "availability_zone" => "nova", + "display_name" => "test 1", "attachments" => [{}], - "volumeType" => nil, - "snapshotId" => Fog::Mock.random_numbers(2), + "volume_type" => nil, + "snapshot_id" => nil, "size" => 1, - "id" => "6", - "createdAt" => Time.now }, + "id" => 6, + "created_at" => "2012-03-30 05:31:00.655058", + "metadata" => {} }, { "status" => "available", - "displayDescription" => "", - "availabilityZone" => "nova", - "displayName" => "test 2", + "display_description" => "", + "availability_zone" => "nova", + "display_name" => "test 2", "attachments" => [{}], - "volumeType" => nil, - "snapshotId" => Fog::Mock.random_numbers(2), + "volume_type" => nil, + "snapshot_id" => nil, "size" => 1, - "id" => "8", - "createdAt" => Time.now} + "id" => 8, + "created_at" => "2012-03-30 16:14:55.582717", + "metadata" => {} } ] response.body = { 'volumes' => self.data[:volumes] } response diff --git a/lib/fog/openstack/requests/volume/create_volume.rb b/lib/fog/openstack/requests/volume/create_volume.rb index 3931d8c76..116aa8a56 100644 --- a/lib/fog/openstack/requests/volume/create_volume.rb +++ b/lib/fog/openstack/requests/volume/create_volume.rb @@ -33,16 +33,16 @@ module Fog response.status = 202 response.body = { 'volume' => { - 'id' => Fog::Mock.random_numbers(2), - 'displayName' => name, - 'displayDescription' => description, - 'size' => size, - 'status' => 'creating', - 'snapshotId' => '4', - 'volumeType' => nil, - 'availabilityZone' => 'nova', - 'createdAt' => Time.now, - 'attchments' => [] + 'id' => Fog::Mock.random_numbers(2), + 'display_name' => name, + 'display_description' => description, + 'size' => size, + 'status' => 'creating', + 'snapshot_id' => options["snapshot_id"] || nil, + 'volume_type' => nil, + 'availability_zone' => 'nova', + 'created_at' => Time.now, + 'attachments' => [] } } response diff --git a/lib/fog/openstack/requests/volume/create_volume_snapshot.rb b/lib/fog/openstack/requests/volume/create_volume_snapshot.rb index ca3a11a74..1d202eb04 100644 --- a/lib/fog/openstack/requests/volume/create_volume_snapshot.rb +++ b/lib/fog/openstack/requests/volume/create_volume_snapshot.rb @@ -24,7 +24,22 @@ module Fog end class Mock - + def create_volume_snapshot(volume_id, name, description, force=false) + response = Excon::Response.new + response.status = 202 + response.body = { + "snapshot"=> { + "status"=>"creating", + "display_name"=>name, + "created_at"=>Time.now, + "display_description"=>description, + "volume_id"=>volume_id, + "id"=>"5", + "size"=>1 + } + } + response + end end end diff --git a/lib/fog/openstack/requests/volume/get_snapshot_details.rb b/lib/fog/openstack/requests/volume/get_snapshot_details.rb index 8030ba1ff..e82ee379f 100644 --- a/lib/fog/openstack/requests/volume/get_snapshot_details.rb +++ b/lib/fog/openstack/requests/volume/get_snapshot_details.rb @@ -22,12 +22,12 @@ module Fog response.body = { 'snapshot' => { 'id' => '1', - 'displayName' => Fog::Mock.random_letters(rand(8) + 5), - 'displayDescription' => Fog::Mock.random_letters(rand(12) + 10), + 'display_name' => Fog::Mock.random_letters(rand(8) + 5), + 'display_description' => Fog::Mock.random_letters(rand(12) + 10), 'size' => 3, - 'volumeId' => '4', - 'status' => 'online', - 'createdAt' => Time.now + 'volume_id' => '4', + 'status' => 'available', + 'created_at' => Time.now } } response diff --git a/lib/fog/openstack/requests/volume/get_volume_details.rb b/lib/fog/openstack/requests/volume/get_volume_details.rb index 97ab49bdd..3a64faeec 100644 --- a/lib/fog/openstack/requests/volume/get_volume_details.rb +++ b/lib/fog/openstack/requests/volume/get_volume_details.rb @@ -22,14 +22,14 @@ module Fog response.body = { 'volume' => { 'id' => '1', - 'displayName' => Fog::Mock.random_letters(rand(8) + 5), - 'displayDescription' => Fog::Mock.random_letters(rand(12) + 10), + 'display_name' => Fog::Mock.random_letters(rand(8) + 5), + 'display_description' => Fog::Mock.random_letters(rand(12) + 10), 'size' => 3, - 'volumeType' => nil, - 'snapshotId' => '4', + 'volume_type' => nil, + 'snapshot_id' => '4', 'status' => 'online', - 'availabilityZone' => 'nova', - 'createdAt' => Time.now, + 'availability_zone' => 'nova', + 'created_at' => Time.now, 'attchments' => [] } } diff --git a/lib/fog/openstack/requests/volume/list_volumes.rb b/lib/fog/openstack/requests/volume/list_volumes.rb index 39900ce20..09ca99e3e 100644 --- a/lib/fog/openstack/requests/volume/list_volumes.rb +++ b/lib/fog/openstack/requests/volume/list_volumes.rb @@ -22,26 +22,26 @@ module Fog response.status = 200 self.data[:volumes] ||= [ { "status" => "available", - "displayDescription" => "", - "availabilityZone" => "nova", - "displayName" => "test 1", + "display_description" => "", + "availability_zone" => "nova", + "display_name" => "test 1", "attachments" => [{}], - "volumeType" => nil, - "snapshotId" => nil, + "volume_type" => nil, + "snapshot_id" => nil, "size" => 1, "id" => 6, - "createdAt" => "2012-03-30 05:31:00.655058", + "created_at" => "2012-03-30 05:31:00.655058", "metadata" => {} }, { "status" => "available", - "displayDescription" => "", - "availabilityZone" => "nova", - "displayName" => "test 2", + "display_description" => "", + "availability_zone" => "nova", + "display_name" => "test 2", "attachments" => [{}], - "volumeType" => nil, - "snapshotId" => nil, + "volume_type" => nil, + "snapshot_id" => nil, "size" => 1, "id" => 8, - "createdAt" => "2012-03-30 16:14:55.582717", + "created_at" => "2012-03-30 16:14:55.582717", "metadata" => {} } ] response.body = { 'volumes' => self.data[:volumes] } From 8d065175388bdff4478fc63e87a583a55b6b4dfc Mon Sep 17 00:00:00 2001 From: Alvin Garcia Date: Fri, 17 Aug 2012 15:54:39 +0800 Subject: [PATCH 09/24] [openstack|image] Fixed update image and list public images mocks --- lib/fog/openstack/requests/image/list_public_images_detailed.rb | 2 +- lib/fog/openstack/requests/image/update_image.rb | 2 +- tests/openstack/requests/image/image_tests.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fog/openstack/requests/image/list_public_images_detailed.rb b/lib/fog/openstack/requests/image/list_public_images_detailed.rb index d040121ce..63b14a026 100644 --- a/lib/fog/openstack/requests/image/list_public_images_detailed.rb +++ b/lib/fog/openstack/requests/image/list_public_images_detailed.rb @@ -19,7 +19,7 @@ module Fog end # class Real class Mock - def list_public_images_detailed + def list_public_images_detailed(attribute=nil, query=nil) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = {"images"=>[{ diff --git a/lib/fog/openstack/requests/image/update_image.rb b/lib/fog/openstack/requests/image/update_image.rb index 7daba7876..44698e428 100644 --- a/lib/fog/openstack/requests/image/update_image.rb +++ b/lib/fog/openstack/requests/image/update_image.rb @@ -56,7 +56,7 @@ module Fog "min_ram"=>0, "owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0", "properties"=>{} - } + }.merge(Hash[attributes.map { |key, val| [key.to_s, val] }]) } response diff --git a/tests/openstack/requests/image/image_tests.rb b/tests/openstack/requests/image/image_tests.rb index 6b6d5c7e0..b49e22380 100644 --- a/tests/openstack/requests/image/image_tests.rb +++ b/tests/openstack/requests/image/image_tests.rb @@ -56,7 +56,7 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do end tests('#list_public_images_detailed').formats({'images' => [@image_format]}) do - Fog::Image[:openstack].list_public_images.body + Fog::Image[:openstack].list_public_images_detailed.body end tests('#create_image').formats({'image' => @image_format}) do From baca5dd34b0302a1af56a18134844b31da773227 Mon Sep 17 00:00:00 2001 From: Alfonso Juan Dillera Date: Fri, 31 Aug 2012 18:52:52 +0800 Subject: [PATCH 10/24] [openstack|compute] Fixed security groups typos Conflicts: lib/fog/openstack/requests/compute/list_security_groups.rb --- lib/fog/openstack/models/compute/security_group.rb | 2 +- lib/fog/openstack/requests/compute/list_security_groups.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fog/openstack/models/compute/security_group.rb b/lib/fog/openstack/models/compute/security_group.rb index 7b629e35c..3359f97f3 100644 --- a/lib/fog/openstack/models/compute/security_group.rb +++ b/lib/fog/openstack/models/compute/security_group.rb @@ -17,7 +17,7 @@ module Fog def save requires :name, :description data = connection.create_security_group(name, description) - merge_attributes(data.body['security_group']) + merge_attributes(data.body['security_groups']) true end diff --git a/lib/fog/openstack/requests/compute/list_security_groups.rb b/lib/fog/openstack/requests/compute/list_security_groups.rb index 812ddee55..5c8f4c5b0 100644 --- a/lib/fog/openstack/requests/compute/list_security_groups.rb +++ b/lib/fog/openstack/requests/compute/list_security_groups.rb @@ -19,7 +19,7 @@ module Fog class Mock def list_security_groups - self.data[:security_groups] = [ + self.data[:security_groups] ||= [ { "rules" => [ { "from_port" => 44, "group" => {}, @@ -57,7 +57,7 @@ module Fog "name" => "test", "description" => "this is a test" } - ] unless self.data.empty? + ] Excon::Response.new( :body => { 'security_groups' => self.data[:security_groups] }, :headers => { From a36abe3c525a5afee413ab26d8acf3db5dee4752 Mon Sep 17 00:00:00 2001 From: "Philip Mark M. Deazeta" Date: Sat, 1 Sep 2012 02:03:28 +0800 Subject: [PATCH 11/24] [openstack] Updated mocks for quota, image, tenant and volumes Conflicts: lib/fog/openstack/requests/compute/get_quota.rb lib/fog/openstack/requests/compute/get_quota_defaults.rb lib/fog/openstack/requests/identity/list_roles_for_user_on_tenant.rb --- .../requests/identity/create_tenant.rb | 6 +-- .../openstack/requests/image/create_image.rb | 43 +++++++++---------- .../openstack/requests/volume/list_volumes.rb | 12 +++--- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/lib/fog/openstack/requests/identity/create_tenant.rb b/lib/fog/openstack/requests/identity/create_tenant.rb index ca81b4680..b854fa55d 100644 --- a/lib/fog/openstack/requests/identity/create_tenant.rb +++ b/lib/fog/openstack/requests/identity/create_tenant.rb @@ -20,10 +20,10 @@ module Fog response.status = [200, 204][rand(1)] response.body = { 'tenant' => { - 'id' => '1', - 'description' => 'Has access to everything', + 'id' => "#{ Fog::Mock.random_hex(32) }", + 'description' => attributes['description'], 'enabled' => true, - 'name' => 'admin' + 'name' => attributes['name'] } } response diff --git a/lib/fog/openstack/requests/image/create_image.rb b/lib/fog/openstack/requests/image/create_image.rb index 860620969..702a7c41f 100644 --- a/lib/fog/openstack/requests/image/create_image.rb +++ b/lib/fog/openstack/requests/image/create_image.rb @@ -52,30 +52,29 @@ module Fog def create_image(attributes) response = Excon::Response.new response.status = 201 - response.body = {"image"=> - {"name"=>"new image", - "size"=>0, - "min_disk"=>0, - "disk_format"=>nil, - "created_at"=>"2012-02-24T06:45:00", - "container_format"=>nil, - "deleted_at"=>nil, - "updated_at"=>"2012-02-24T06:45:00", - "checksum"=>nil, - "id"=>"e41304f3-2453-42b4-9829-2e220a737395", - "deleted"=>false, - "protected"=>false, - "is_public"=>false, - "status"=>"queued", - "min_ram"=>0, - "owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0", - "properties"=>{} - } - } + response.body = { + "image"=> { + "name" => attributes[:name], + "size" => 0, + "min_disk" => 0, + "disk_format" => attributes[:disk_format], + "created_at" => Time.now, + "container_format" => attributes['container_format'], + "deleted_at" => nil, + "updated_at" => Time.now, + "checksum" => nil, + "id" => "#{ Fog::Mock.random_hex(32) }", + "deleted" => false, + "protected" => false, + "is_public" => attributes[:is_public], + "status" => "queued", + "min_ram" => 0, + "owner" => attributes[:owner], + "properties" => attributes[:properties] + } + } response - end - end end end diff --git a/lib/fog/openstack/requests/volume/list_volumes.rb b/lib/fog/openstack/requests/volume/list_volumes.rb index 09ca99e3e..7c9bdd4c7 100644 --- a/lib/fog/openstack/requests/volume/list_volumes.rb +++ b/lib/fog/openstack/requests/volume/list_volumes.rb @@ -22,26 +22,26 @@ module Fog response.status = 200 self.data[:volumes] ||= [ { "status" => "available", - "display_description" => "", + "display_description" => "test 1 desc", "availability_zone" => "nova", "display_name" => "test 1", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, - "id" => 6, - "created_at" => "2012-03-30 05:31:00.655058", + "id" => 1, + "created_at" => Time.now, "metadata" => {} }, { "status" => "available", - "display_description" => "", + "display_description" => "test 2 desc", "availability_zone" => "nova", "display_name" => "test 2", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, "size" => 1, - "id" => 8, - "created_at" => "2012-03-30 16:14:55.582717", + "id" => 2, + "created_at" => Time.now, "metadata" => {} } ] response.body = { 'volumes' => self.data[:volumes] } From 609995ccbee0f28d5c2daf9f787516d0ca80546e Mon Sep 17 00:00:00 2001 From: "Philip Mark M. Deazeta" Date: Mon, 3 Sep 2012 14:40:34 +0800 Subject: [PATCH 12/24] [openstack] Fixed mocks for failing shindo tests reverted back to double quoted string Conflicts: lib/fog/openstack/identity.rb lib/fog/openstack/requests/compute/get_volume_details.rb lib/fog/openstack/requests/compute/list_security_groups.rb lib/fog/openstack/requests/identity/list_tenants.rb lib/fog/openstack/requests/image/create_image.rb lib/fog/openstack/requests/image/list_public_images.rb lib/fog/openstack/requests/image/list_public_images_detailed.rb lib/fog/openstack/requests/image/update_image.rb tests/openstack/requests/compute/volume_tests.rb --- lib/fog/openstack/identity.rb | 10 +- .../requests/compute/create_volume.rb | 8 +- .../requests/compute/get_volume_details.rb | 2 +- .../requests/identity/create_tenant.rb | 6 +- .../openstack/requests/identity/get_tenant.rb | 2 +- .../openstack/requests/image/create_image.rb | 67 ++++++----- .../requests/image/list_public_images.rb | 32 ++---- .../openstack/requests/image/update_image.rb | 41 +++---- .../requests/volume/get_snapshot_details.rb | 8 +- .../requests/volume/get_volume_details.rb | 8 +- .../openstack/requests/volume/list_volumes.rb | 4 +- .../openstack/requests/compute/quota_tests.rb | 2 + .../requests/compute/volume_tests.rb | 22 ++-- .../requests/identity/tenant_tests.rb | 2 +- tests/openstack/requests/image/image_tests.rb | 106 +++++++++++------- 15 files changed, 161 insertions(+), 159 deletions(-) diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index 94544485e..bf3935d57 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -81,22 +81,22 @@ module Fog @current_user = { 'username' => 'admin', 'name' => 'admin', - 'id' => 1, + 'id' => Fog::Mock.random_hex(32), 'roles' => [ - { 'id' => 1, 'name' => 'admin' }, - { 'id' => 2, 'name' => 'Member' } + { 'id' => Fog::Mock.random_hex(32), 'name' => 'admin' }, + { 'id' => Fog::Mock.random_hex(32), 'name' => 'Member' } ] } @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 @current_tenant = { - 'id' => 1, + 'id' => Fog::Mock.random_hex(32), 'name' => 'admin' } unless self.data[:users].values.detect {|user| user['name'] == @openstack_username} - id = Fog::Mock.random_numbers(6).to_s + id = Fog::Mock.random_hex(32) self.data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], diff --git a/lib/fog/openstack/requests/compute/create_volume.rb b/lib/fog/openstack/requests/compute/create_volume.rb index 8bf5f7d4f..1a8a2fced 100644 --- a/lib/fog/openstack/requests/compute/create_volume.rb +++ b/lib/fog/openstack/requests/compute/create_volume.rb @@ -33,16 +33,16 @@ module Fog response.status = 202 response.body = { 'volume' => { - 'id' => Fog::Mock.random_numbers(2), + 'id' => Fog::Mock.random_numbers(2), 'display_name' => name, 'display_description' => description, - 'size' => size, - 'status' => 'creating', + 'size' => size, + 'status' => 'creating', 'snapshot_id' => '4', 'volume_type' => nil, 'availability_zone' => 'nova', 'created_at' => Time.now, - 'attchments' => [] + 'attachments' => [] } } response diff --git a/lib/fog/openstack/requests/compute/get_volume_details.rb b/lib/fog/openstack/requests/compute/get_volume_details.rb index b0f913eb6..9ca085ed5 100644 --- a/lib/fog/openstack/requests/compute/get_volume_details.rb +++ b/lib/fog/openstack/requests/compute/get_volume_details.rb @@ -30,7 +30,7 @@ module Fog 'status' => 'online', 'availability_zone' => 'nova', 'created_at' => Time.now, - 'attchments' => [] + 'attachments' => [] } } response diff --git a/lib/fog/openstack/requests/identity/create_tenant.rb b/lib/fog/openstack/requests/identity/create_tenant.rb index b854fa55d..72fc7ae57 100644 --- a/lib/fog/openstack/requests/identity/create_tenant.rb +++ b/lib/fog/openstack/requests/identity/create_tenant.rb @@ -20,10 +20,10 @@ module Fog response.status = [200, 204][rand(1)] response.body = { 'tenant' => { - 'id' => "#{ Fog::Mock.random_hex(32) }", - 'description' => attributes['description'], + 'id' => "df9a815161eba9b76cc748fd5c5af73e", + 'description' => attributes['description'] || 'normal tenant', 'enabled' => true, - 'name' => attributes['name'] + 'name' => attributes['name'] || 'default' } } response diff --git a/lib/fog/openstack/requests/identity/get_tenant.rb b/lib/fog/openstack/requests/identity/get_tenant.rb index aac3c4d20..875f084d2 100644 --- a/lib/fog/openstack/requests/identity/get_tenant.rb +++ b/lib/fog/openstack/requests/identity/get_tenant.rb @@ -17,7 +17,7 @@ module Fog response.status = [200, 204][rand(1)] response.body = { 'tenant' => { - 'id' => '1', + 'id' => id, 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin' diff --git a/lib/fog/openstack/requests/image/create_image.rb b/lib/fog/openstack/requests/image/create_image.rb index 702a7c41f..139ac896b 100644 --- a/lib/fog/openstack/requests/image/create_image.rb +++ b/lib/fog/openstack/requests/image/create_image.rb @@ -7,35 +7,32 @@ module Fog data = { - "Content-Type"=>"application/octet-stream", - "x-image-meta-name" => attributes[:name], - "x-image-meta-disk-format" => attributes[:disk_format], - "x-image-meta-container-format" => attributes[:container_format], - "x-image-meta-size" => attributes[:size], - "x-image-meta-is-public" => attributes[:is_public], - "x-image-meta-min-ram" => attributes[:min_ram], - "x-image-meta-min-disk" => attributes[:min_disk], - "x-image-meta-checksum" => attributes[:checksum], - "x-image-meta-owner" => attributes[:owner], - "x-glance-api-copy-from" => attributes[:copy_from] + 'Content-Type'=>'application/octet-stream', + 'x-image-meta-name' => attributes[:name], + 'x-image-meta-disk-format' => attributes[:disk_format], + 'x-image-meta-container-format' => attributes[:container_format], + 'x-image-meta-size' => attributes[:size], + 'x-image-meta-is-public' => attributes[:is_public], + 'x-image-meta-min-ram' => attributes[:min_ram], + 'x-image-meta-min-disk' => attributes[:min_disk], + 'x-image-meta-checksum' => attributes[:checksum], + 'x-image-meta-owner' => attributes[:owner], + 'x-glance-api-copy-from' => attributes[:copy_from] } body = String.new if attributes[:location] - file = File.open(attributes[:location], "rb") - body = file + body = File.open(attributes[:location], "rb") end unless attributes[:properties].nil? attributes[:properties].each do |key,value| - data["x-image-meta-property-#{key}"] = value + data['x-image-meta-property-#{key}'] = value end end - - request( - :headers => data, + :headers => data, :body => body, :expects => 201, :method => 'POST', @@ -53,24 +50,24 @@ module Fog response = Excon::Response.new response.status = 201 response.body = { - "image"=> { - "name" => attributes[:name], - "size" => 0, - "min_disk" => 0, - "disk_format" => attributes[:disk_format], - "created_at" => Time.now, - "container_format" => attributes['container_format'], - "deleted_at" => nil, - "updated_at" => Time.now, - "checksum" => nil, - "id" => "#{ Fog::Mock.random_hex(32) }", - "deleted" => false, - "protected" => false, - "is_public" => attributes[:is_public], - "status" => "queued", - "min_ram" => 0, - "owner" => attributes[:owner], - "properties" => attributes[:properties] + 'image'=> { + 'name' => attributes[:name], + 'size' => Fog::Mock.random_numbers(8).to_i, + 'min_disk' => 0, + 'disk_format' => attributes[:disk_format], + 'created_at' => Time.now.to_s, + 'container_format' => attributes[:container_format], + 'deleted_at' => nil, + 'updated_at' => Time.now.to_s, + 'checksum' => Fog::Mock.random_hex(32), + 'id' => Fog::Mock.random_hex(32), + 'deleted' => false, + 'protected' => false, + 'is_public' => false, + 'status' => 'queued', + 'min_ram' => 0, + 'owner' => attributes[:owner], + 'properties' => attributes[:properties] } } response diff --git a/lib/fog/openstack/requests/image/list_public_images.rb b/lib/fog/openstack/requests/image/list_public_images.rb index 8c69982cc..5047be913 100644 --- a/lib/fog/openstack/requests/image/list_public_images.rb +++ b/lib/fog/openstack/requests/image/list_public_images.rb @@ -16,31 +16,13 @@ module Fog response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { - "images"=>[{ - "name"=>"mock-image-name", - "size"=>25165824, - "disk_format"=>"ami", - "container_format"=>"ami", - "id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e", - "checksum"=>"2f81976cae15c16ef0010c51e3a6c163"}, - {"name"=>"new image", - "size"=>0, - "min_disk"=>0, - "disk_format"=>nil, - "created_at"=>"2012-02-24T06:45:00", - "container_format"=>nil, - "deleted_at"=>nil, - "updated_at"=>"2012-02-24T06:45:00", - "checksum"=>nil, - "id"=>"e41304f3-2453-42b4-9829-2e220a737395", - "deleted"=>false, - "protected"=>false, - "is_public"=>false, - "status"=>"queued", - "min_ram"=>0, - "owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0", - "properties"=>{} - }] + "images"=>[{ + "name" => Fog::Mock.random_letters(10), + "size" => Fog::Mock.random_numbers(8).to_i, + "disk_format" => "iso", + "container_format" => "bare", + "id" => Fog::Mock.random_hex(36), + "checksum" => Fog::Mock.random_hex(32)}] } response end # def list_tenants diff --git a/lib/fog/openstack/requests/image/update_image.rb b/lib/fog/openstack/requests/image/update_image.rb index 44698e428..7071a3961 100644 --- a/lib/fog/openstack/requests/image/update_image.rb +++ b/lib/fog/openstack/requests/image/update_image.rb @@ -38,26 +38,27 @@ module Fog def update_image(attributes) response = Excon::Response.new response.status = 200 - response.body = {"image"=> - {"name"=>"edit test image", - "size"=>0, - "min_disk"=>0, - "disk_format"=>nil, - "created_at"=>"2012-02-24T06:45:00", - "container_format"=>nil, - "deleted_at"=>nil, - "updated_at"=>"2012-02-24T06:45:00", - "checksum"=>nil, - "id"=>"e41304f3-2453-42b4-9829-2e220a737395", - "deleted"=>false, - "protected"=>false, - "is_public"=>false, - "status"=>"queued", - "min_ram"=>0, - "owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0", - "properties"=>{} - }.merge(Hash[attributes.map { |key, val| [key.to_s, val] }]) - } + response.body = { + 'image'=> { + 'name' => attributes[:name], + 'size' => Fog::Mock.random_numbers(8).to_i, + 'min_disk' => 0, + 'disk_format' => 'iso', + 'created_at' => Time.now.to_s, + 'container_format' => 'bare', + 'deleted_at' => nil, + 'updated_at' => Time.now.to_s, + 'checksum' => Fog::Mock.random_hex(32), + 'id' => attributes[:id], + 'deleted' => false, + 'protected' => false, + 'is_public' => false, + 'status' => 'queued', + 'min_ram' => 0, + 'owner' => Fog::Mock.random_hex(32), + 'properties' => {} + } + } response end diff --git a/lib/fog/openstack/requests/volume/get_snapshot_details.rb b/lib/fog/openstack/requests/volume/get_snapshot_details.rb index e82ee379f..ebfc13df9 100644 --- a/lib/fog/openstack/requests/volume/get_snapshot_details.rb +++ b/lib/fog/openstack/requests/volume/get_snapshot_details.rb @@ -22,10 +22,10 @@ module Fog response.body = { 'snapshot' => { 'id' => '1', - 'display_name' => Fog::Mock.random_letters(rand(8) + 5), - 'display_description' => Fog::Mock.random_letters(rand(12) + 10), - 'size' => 3, - 'volume_id' => '4', + 'display_name' => 'Snapshot1', + 'display_description' => 'Volume1 snapshot', + 'size' => 1, + 'volume_id' => '1', 'status' => 'available', 'created_at' => Time.now } diff --git a/lib/fog/openstack/requests/volume/get_volume_details.rb b/lib/fog/openstack/requests/volume/get_volume_details.rb index 3a64faeec..9f2426e60 100644 --- a/lib/fog/openstack/requests/volume/get_volume_details.rb +++ b/lib/fog/openstack/requests/volume/get_volume_details.rb @@ -21,16 +21,16 @@ module Fog response.status = 200 response.body = { 'volume' => { - 'id' => '1', + 'id' => '1', 'display_name' => Fog::Mock.random_letters(rand(8) + 5), 'display_description' => Fog::Mock.random_letters(rand(12) + 10), - 'size' => 3, + 'size' => 3, 'volume_type' => nil, 'snapshot_id' => '4', - 'status' => 'online', + 'status' => 'online', 'availability_zone' => 'nova', 'created_at' => Time.now, - 'attchments' => [] + 'attachments' => [] } } response diff --git a/lib/fog/openstack/requests/volume/list_volumes.rb b/lib/fog/openstack/requests/volume/list_volumes.rb index 7c9bdd4c7..3ead9f29d 100644 --- a/lib/fog/openstack/requests/volume/list_volumes.rb +++ b/lib/fog/openstack/requests/volume/list_volumes.rb @@ -24,7 +24,7 @@ module Fog { "status" => "available", "display_description" => "test 1 desc", "availability_zone" => "nova", - "display_name" => "test 1", + "display_name" => "Volume1", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, @@ -35,7 +35,7 @@ module Fog { "status" => "available", "display_description" => "test 2 desc", "availability_zone" => "nova", - "display_name" => "test 2", + "display_name" => "Volume2", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, diff --git a/tests/openstack/requests/compute/quota_tests.rb b/tests/openstack/requests/compute/quota_tests.rb index a62ec1283..3be76cc0c 100644 --- a/tests/openstack/requests/compute/quota_tests.rb +++ b/tests/openstack/requests/compute/quota_tests.rb @@ -11,6 +11,8 @@ Shindo.tests('Fog::Compute[:openstack] | quota requests', ['openstack']) do 'instances' => Fixnum, 'volumes' => Fixnum, 'cores' => Fixnum, + 'security_groups' => Fixnum, + 'security_group_rules' => Fixnum, 'id' => String } diff --git a/tests/openstack/requests/compute/volume_tests.rb b/tests/openstack/requests/compute/volume_tests.rb index 78972e8f4..13b4922b4 100644 --- a/tests/openstack/requests/compute/volume_tests.rb +++ b/tests/openstack/requests/compute/volume_tests.rb @@ -3,16 +3,16 @@ require 'fog/openstack' Shindo.tests('Fog::Compute[:openstack] | volume requests', ['openstack']) do @volume_format = { - 'id' => String, - 'displayName' => String, - 'size' => Integer, - 'displayDescription' => String, - 'status' => String, - 'snapshotId' => String, - 'availabilityZone' => String, - 'attachments' => Array, - 'volumeType' => NilClass, - 'createdAt' => Time + 'id' => String, + 'display_name' => String, + 'size' => Integer, + 'display_description' => String, + 'status' => String, + 'snapshot_id' => String, + 'availability_zone' => String, + 'attachments' => Array, + 'volume_type' => NilClass, + 'created_at' => Time } @@ -23,7 +23,7 @@ Shindo.tests('Fog::Compute[:openstack] | volume requests', ['openstack']) do tests('#get_volume_detail').formats({'volume' => @volume_format}) do pending unless Fog.mocking? - Fog::Compute[:openstack].get_volume_details(0).body + Fog::Compute[:openstack].get_volume_details(1).body end tests('#create_volume').formats({'volume' => @volume_format}) do diff --git a/tests/openstack/requests/identity/tenant_tests.rb b/tests/openstack/requests/identity/tenant_tests.rb index 6660e2092..8dd2616a3 100644 --- a/tests/openstack/requests/identity/tenant_tests.rb +++ b/tests/openstack/requests/identity/tenant_tests.rb @@ -23,7 +23,7 @@ Shindo.tests('Fog::Identity[:openstack] | tenant requests', ['openstack']) do openstack = Fog::Identity[:openstack] openstack.list_roles_for_user_on_tenant( - openstack.tenants.first, openstack.users.first).body + openstack.current_tenant['id'], openstack.current_user['id']).body end tests('#create_tenant').formats({'tenant' => @tenant_format}) do diff --git a/tests/openstack/requests/image/image_tests.rb b/tests/openstack/requests/image/image_tests.rb index b49e22380..c53b06ef0 100644 --- a/tests/openstack/requests/image/image_tests.rb +++ b/tests/openstack/requests/image/image_tests.rb @@ -1,52 +1,72 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do + openstack = Fog::Identity[:openstack] + @image_attributes = { + :name => 'new image', + :owner => openstack.current_tenant['id'], + :is_public => 'true', + :copy_from => 'http://website.com/image.iso', + :disk_format => 'iso', + :properties=> + {:user_id => openstack.current_user['id'], + :owner_id => openstack.current_tenant['id']}, + :container_format => 'bare' } @image_format = { + 'name' => String, + 'container_format' => String, + 'disk_format' => String, + 'checksum' => String, + 'id' => String, + 'size' => Integer + } + + @detailed_image_format = { 'id' => String, 'name' => String, - 'size' => Fog::Nullable::Integer, - 'disk_format' => Fog::Nullable::String, - 'container_format' => Fog::Nullable::String, - 'checksum' => Fog::Nullable::String, - 'min_disk' => Fog::Nullable::Integer, - 'created_at' => Fog::Nullable::String, + 'size' => Integer, + 'disk_format' => String, + 'container_format' => String, + 'checksum' => String, + 'min_disk' => Integer, + 'created_at' => String, 'deleted_at' => Fog::Nullable::String, - 'updated_at' => Fog::Nullable::String, - 'deleted' => Fog::Nullable::Boolean, - 'protected' => Fog::Nullable::Boolean, - 'is_public' => Fog::Nullable::Boolean, - 'status' => Fog::Nullable::String, - 'min_ram' => Fog::Nullable::Integer, - 'owner' => Fog::Nullable::String, - 'properties' => Fog::Nullable::Hash + 'updated_at' => String, + 'deleted' => Fog::Boolean, + 'protected' => Fog::Boolean, + 'is_public' => Fog::Boolean, + 'status' => String, + 'min_ram' => Integer, + 'owner' => String, + 'properties' => Hash } @image_meta_format ={ - "X-Image-Meta-Is_public"=>String, - "X-Image-Meta-Min_disk"=>Fog::Nullable::String, - "X-Image-Meta-Property-Ramdisk_id"=>Fog::Nullable::String, - "X-Image-Meta-Disk_format"=>Fog::Nullable::String, - "X-Image-Meta-Created_at"=>String, - "X-Image-Meta-Container_format"=>Fog::Nullable::String, - "Etag"=>String, - "Location"=>String, - "X-Image-Meta-Protected"=>String, - "Date"=>String, - "X-Image-Meta-Name"=>String, - "X-Image-Meta-Min_ram"=>String, - "Content-Type"=>String, - "X-Image-Meta-Updated_at"=>String, - "X-Image-Meta-Property-Kernel_id"=>Fog::Nullable::String, - "X-Image-Meta-Size"=>String, - "X-Image-Meta-Checksum"=>Fog::Nullable::String, - "X-Image-Meta-Deleted"=>String, - "Content-Length"=>String, - "X-Image-Meta-Owner"=>String, - "X-Image-Meta-Status"=>String, - "X-Image-Meta-Id"=>String} + 'X-Image-Meta-Is_public'=>String, + 'X-Image-Meta-Min_disk'=>Fog::Nullable::String, + 'X-Image-Meta-Property-Ramdisk_id'=>Fog::Nullable::String, + 'X-Image-Meta-Disk_format'=>Fog::Nullable::String, + 'X-Image-Meta-Created_at'=>String, + 'X-Image-Meta-Container_format'=>Fog::Nullable::String, + 'Etag'=>String, + 'Location'=>String, + 'X-Image-Meta-Protected'=>String, + 'Date'=>String, + 'X-Image-Meta-Name'=>String, + 'X-Image-Meta-Min_ram'=>String, + 'Content-Type'=>String, + 'X-Image-Meta-Updated_at'=>String, + 'X-Image-Meta-Property-Kernel_id'=>Fog::Nullable::String, + 'X-Image-Meta-Size'=>String, + 'X-Image-Meta-Checksum'=>Fog::Nullable::String, + 'X-Image-Meta-Deleted'=>String, + 'Content-Length'=>String, + 'X-Image-Meta-Owner'=>String, + 'X-Image-Meta-Status'=>String, + 'X-Image-Meta-Id'=>String} @image_members_format =[ - {"can_share"=>Fog::Nullable::Boolean, - "member_id"=>String + {'can_share'=>Fog::Nullable::Boolean, + 'member_id'=>String } ] @@ -55,21 +75,21 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do Fog::Image[:openstack].list_public_images.body end - tests('#list_public_images_detailed').formats({'images' => [@image_format]}) do + tests('#list_public_images_detailed').formats({'images' => [@detailed_image_format]}) do Fog::Image[:openstack].list_public_images_detailed.body end - tests('#create_image').formats({'image' => @image_format}) do - @instance = Fog::Image[:openstack].create_image({:name => "test image"}).body + tests('#create_image').formats({'image' => @detailed_image_format}) do + @instance = Fog::Image[:openstack].create_image(@image_attributes).body end tests('#get_image').formats(@image_meta_format) do Fog::Image[:openstack].get_image(@instance['image']['id']).headers end - tests('#update_image').formats(@image_format) do + tests('#update_image').formats(@detailed_image_format) do Fog::Image[:openstack].update_image({:id => @instance['image']['id'], - :name => "edit image"}).body['image'] + :name => 'edit image'}).body['image'] end tests('#add_member_to_image').succeeds do From b62e37e0e390832f83d7c1f6ffe5d67d00fbcbcc Mon Sep 17 00:00:00 2001 From: "Philip Mark M. Deazeta" Date: Mon, 3 Sep 2012 17:41:24 +0800 Subject: [PATCH 13/24] [openstack] Updated 'image update' mocks Conflicts: lib/fog/openstack/requests/image/list_public_images_detailed.rb --- .../openstack/requests/image/update_image.rb | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/fog/openstack/requests/image/update_image.rb b/lib/fog/openstack/requests/image/update_image.rb index 7071a3961..7d2631304 100644 --- a/lib/fog/openstack/requests/image/update_image.rb +++ b/lib/fog/openstack/requests/image/update_image.rb @@ -38,25 +38,26 @@ module Fog def update_image(attributes) response = Excon::Response.new response.status = 200 + image = self.images.last response.body = { 'image'=> { - 'name' => attributes[:name], - 'size' => Fog::Mock.random_numbers(8).to_i, - 'min_disk' => 0, - 'disk_format' => 'iso', - 'created_at' => Time.now.to_s, - 'container_format' => 'bare', + 'name' => attributes[:name] || image.name, + 'size' => image.size, + 'min_disk' => (attributes[:min_disk] || image.min_disk).to_i, + 'disk_format' => attributes[:disk_format] || image.disk_format, + 'created_at' => image.created_at, + 'container_format' => attributes[:container_format] || image.container_format, 'deleted_at' => nil, 'updated_at' => Time.now.to_s, - 'checksum' => Fog::Mock.random_hex(32), + 'checksum' => image.checksum, 'id' => attributes[:id], 'deleted' => false, 'protected' => false, - 'is_public' => false, - 'status' => 'queued', - 'min_ram' => 0, - 'owner' => Fog::Mock.random_hex(32), - 'properties' => {} + 'is_public' => attributes[:is_public] || image.is_public, + 'status' => image.status, + 'min_ram' => (attributes[:min_ram] || image.min_ram).to_i, + 'owner' => attributes[:owner] || image.owner, + 'properties' => attributes[:properties] || image.properties } } response From ad0e84be568c17dcf4fd84d43d53d126cc5a019c Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Fri, 7 Sep 2012 09:37:52 +0800 Subject: [PATCH 14/24] [openstack|compute] Fix Server Mocks and `find_by_id` method Conflicts: lib/fog/openstack/requests/identity/update_user.rb --- lib/fog/openstack/models/identity/users.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/fog/openstack/models/identity/users.rb b/lib/fog/openstack/models/identity/users.rb index b1de77209..94e563823 100644 --- a/lib/fog/openstack/models/identity/users.rb +++ b/lib/fog/openstack/models/identity/users.rb @@ -17,7 +17,10 @@ module Fog def find_by_id(id) self.find {|user| user.id == id} || Fog::Identity::OpenStack::User.new( - connection.get_user_by_id(id).body['user']) + connection.get_user_by_id(id).body['user'].merge( + connection: connection + ) + ) end def destroy(id) From b863ba8a10b524f78a46cdde04d8aa65bbdd8956 Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Fri, 7 Sep 2012 16:37:56 +0800 Subject: [PATCH 15/24] [openstack|image] Fix Hash Access on Mock of Create Image Signed-off-by: Nelvin Driz --- .../openstack/requests/image/create_image.rb | 10 +++++----- tests/openstack/requests/image/image_tests.rb | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/fog/openstack/requests/image/create_image.rb b/lib/fog/openstack/requests/image/create_image.rb index 139ac896b..333df3078 100644 --- a/lib/fog/openstack/requests/image/create_image.rb +++ b/lib/fog/openstack/requests/image/create_image.rb @@ -51,12 +51,12 @@ module Fog response.status = 201 response.body = { 'image'=> { - 'name' => attributes[:name], + 'name' => attributes['name'], 'size' => Fog::Mock.random_numbers(8).to_i, 'min_disk' => 0, - 'disk_format' => attributes[:disk_format], + 'disk_format' => attributes['disk_format'], 'created_at' => Time.now.to_s, - 'container_format' => attributes[:container_format], + 'container_format' => attributes['container_format'], 'deleted_at' => nil, 'updated_at' => Time.now.to_s, 'checksum' => Fog::Mock.random_hex(32), @@ -66,8 +66,8 @@ module Fog 'is_public' => false, 'status' => 'queued', 'min_ram' => 0, - 'owner' => attributes[:owner], - 'properties' => attributes[:properties] + 'owner' => attributes['owner'], + 'properties' => attributes['properties'] } } response diff --git a/tests/openstack/requests/image/image_tests.rb b/tests/openstack/requests/image/image_tests.rb index c53b06ef0..deb907a48 100644 --- a/tests/openstack/requests/image/image_tests.rb +++ b/tests/openstack/requests/image/image_tests.rb @@ -1,15 +1,15 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do openstack = Fog::Identity[:openstack] @image_attributes = { - :name => 'new image', - :owner => openstack.current_tenant['id'], - :is_public => 'true', - :copy_from => 'http://website.com/image.iso', - :disk_format => 'iso', - :properties=> - {:user_id => openstack.current_user['id'], - :owner_id => openstack.current_tenant['id']}, - :container_format => 'bare' } + 'name' => 'new image', + 'owner' => openstack.current_tenant['id'], + 'is_public' => 'true', + 'copy_from' => 'http://website.com/image.iso', + 'disk_format' => 'iso', + 'properties' => + {'user_id' => openstack.current_user['id'], + 'owner_id' => openstack.current_tenant['id']}, + 'container_format'=> 'bare' } @image_format = { 'name' => String, From 8f12717d25d2e688dd5f33b402d8633868249f59 Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Mon, 17 Sep 2012 10:20:09 +0800 Subject: [PATCH 16/24] [openstack|identity] Update Identity Mocking Process Signed-off-by: Nelvin Driz Conflicts: lib/fog/openstack/identity.rb --- lib/fog/openstack/identity.rb | 55 ++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index bf3935d57..14f7cdace 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -61,8 +61,8 @@ module Fog def self.data @data ||= Hash.new do |hash, key| hash[key] = { - :users => {}, - :roles => {}, + :users => {}, + :roles => {}, :tenants => {} } end @@ -77,33 +77,46 @@ module Fog @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @openstack_management_url = @openstack_auth_uri.to_s - @current_user_id = 1 - @current_user = { - 'username' => 'admin', - 'name' => 'admin', - 'id' => Fog::Mock.random_hex(32), - 'roles' => [ - { 'id' => Fog::Mock.random_hex(32), 'name' => 'admin' }, - { 'id' => Fog::Mock.random_hex(32), 'name' => 'Member' } - ] - } - @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 - @current_tenant = { - 'id' => Fog::Mock.random_hex(32), - 'name' => 'admin' - } - unless self.data[:users].values.detect {|user| user['name'] == @openstack_username} - id = Fog::Mock.random_hex(32) - self.data[:users][id] = { - 'id' => id, + @admin_tenant = self.data[:tenants].values.find do |u| + u['name'] == 'admin' + end + + if options[:openstack_tenant] + @current_tenant = self.data[:tenants].values.find do |u| + u['name'] == options[:openstack_tenant] + end + + unless @current_tenant + @current_tenant_id = Fog::Mock.random_hex(32) + @current_tenant = self.data[:tenants][@current_tenant_id] = { + 'id' => @current_tenant_id, + 'name' => options[:openstack_tenant] + } + else + @current_tenant_id = @current_tenant['id'] + end + else + @current_tenant = @admin_tenant + end + + @current_user = self.data[:users].values.find do |u| + u['name'] == @openstack_username + end + + unless @current_user + @current_user_id = Fog::Mock.random_hex(32) + @current_user = self.data[:users][@current_user_id] = { + 'id' => @current_user_id, 'name' => options[:openstack_username], 'email' => "#{options[:openstack_username]}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } + else + @current_user_id = @current_user['id'] end end From a8f2aaf004eea5978c210b34acaebd034effef93 Mon Sep 17 00:00:00 2001 From: Alvin Garcia Date: Mon, 17 Sep 2012 10:20:39 +0800 Subject: [PATCH 17/24] [openstack|identity] Update for failing mock test --- tests/openstack/requests/identity/tenant_tests.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/openstack/requests/identity/tenant_tests.rb b/tests/openstack/requests/identity/tenant_tests.rb index 8dd2616a3..68ec5868f 100644 --- a/tests/openstack/requests/identity/tenant_tests.rb +++ b/tests/openstack/requests/identity/tenant_tests.rb @@ -20,10 +20,11 @@ Shindo.tests('Fog::Identity[:openstack] | tenant requests', ['openstack']) do tests('#list_roles_for_user_on_tenant(0,1)'). formats({'roles' => [@role_format]}) do + user = Fog::Identity[:openstack].create_user("testuser", "passw", "e@mail.co", "us3r1d").body['user'] openstack = Fog::Identity[:openstack] openstack.list_roles_for_user_on_tenant( - openstack.current_tenant['id'], openstack.current_user['id']).body + openstack.current_tenant['id'], user['id']).body end tests('#create_tenant').formats({'tenant' => @tenant_format}) do From 92aed2a18d68559903177fdf60aa2e39cf7928ee Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Mon, 17 Sep 2012 16:10:36 +0800 Subject: [PATCH 18/24] [openstack|identity] Update Fog Mocks on Authentication, User and Roles Signed-off-by: Nelvin Driz Conflicts: lib/fog/openstack/identity.rb lib/fog/openstack/requests/identity/delete_role.rb lib/fog/openstack/requests/identity/list_roles.rb --- lib/fog/openstack/identity.rb | 31 ++++++++++++------- .../requests/identity/create_user.rb | 2 +- .../requests/identity/delete_role.rb | 2 +- .../openstack/requests/identity/list_roles.rb | 7 +++++ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index 14f7cdace..1fd1a972d 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -59,21 +59,30 @@ module Fog attr_reader :current_tenant def self.data + @users ||= {} + @roles ||= {} + @tenants ||= {} + @data ||= Hash.new do |hash, key| hash[key] = { - :users => {}, - :roles => {}, - :tenants => {} + :users => @users, + :roles => @roles, + :tenants => @tenants } end end - def self.reset - @data = nil + def self.reset! + @data = nil + @users = nil + @roles = nil + @tenants = nil end def initialize(options={}) - @openstack_username = options[:openstack_username] + require 'multi_json' + @openstack_username = options[:openstack_username] || 'admin' + @openstack_tenant = options[:openstack_tenant] || 'admin' @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @openstack_management_url = @openstack_auth_uri.to_s @@ -84,16 +93,16 @@ module Fog u['name'] == 'admin' end - if options[:openstack_tenant] + if @openstack_tenant @current_tenant = self.data[:tenants].values.find do |u| - u['name'] == options[:openstack_tenant] + u['name'] == @openstack_tenant end unless @current_tenant @current_tenant_id = Fog::Mock.random_hex(32) @current_tenant = self.data[:tenants][@current_tenant_id] = { 'id' => @current_tenant_id, - 'name' => options[:openstack_tenant] + 'name' => @openstack_tenant } else @current_tenant_id = @current_tenant['id'] @@ -110,8 +119,8 @@ module Fog @current_user_id = Fog::Mock.random_hex(32) @current_user = self.data[:users][@current_user_id] = { 'id' => @current_user_id, - 'name' => options[:openstack_username], - 'email' => "#{options[:openstack_username]}@mock.com", + 'name' => @openstack_username, + 'email' => "#{@openstack_username}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } diff --git a/lib/fog/openstack/requests/identity/create_user.rb b/lib/fog/openstack/requests/identity/create_user.rb index 0c8203baa..1e0104898 100644 --- a/lib/fog/openstack/requests/identity/create_user.rb +++ b/lib/fog/openstack/requests/identity/create_user.rb @@ -30,7 +30,7 @@ module Fog response = Excon::Response.new response.status = 200 data = { - 'id' => Fog::Mock.random_numbers(6).to_s, + 'id' => Fog::Mock.random_hex(32), 'name' => name, 'email' => email, 'tenantId' => tenantId, diff --git a/lib/fog/openstack/requests/identity/delete_role.rb b/lib/fog/openstack/requests/identity/delete_role.rb index 78e1b66dc..2600af8b2 100644 --- a/lib/fog/openstack/requests/identity/delete_role.rb +++ b/lib/fog/openstack/requests/identity/delete_role.rb @@ -17,7 +17,7 @@ module Fog def delete_role(role_id) response = Excon::Response.new - if list_roles.body['roles'].map { |r| r['id'] }.include? role_id + if self.data[:roles][role_id] self.data[:roles].delete(role_id) response.status = 204 response diff --git a/lib/fog/openstack/requests/identity/list_roles.rb b/lib/fog/openstack/requests/identity/list_roles.rb index bdb2da682..a6595cd52 100644 --- a/lib/fog/openstack/requests/identity/list_roles.rb +++ b/lib/fog/openstack/requests/identity/list_roles.rb @@ -16,6 +16,13 @@ module Fog class Mock def list_roles + if self.data[:roles].empty? + ['admin', 'Member'].each do |name| + id = Fog::Mock.random_hex(32) + self.data[:roles][id] = {'id' => id, 'name' => name} + end + end + Excon::Response.new( :body => { 'roles' => self.data[:roles].values }, :status => 200 From 00352319544f336b6fa343a3ff377ad6393f9064 Mon Sep 17 00:00:00 2001 From: Nelvin Driz Date: Tue, 2 Oct 2012 13:52:45 +0800 Subject: [PATCH 19/24] [openstack] Fix Failing Shindo Tests Signed-off-by: Nelvin Driz --- lib/fog/core/wait_for.rb | 2 - lib/fog/openstack/image.rb | 5 +- lib/fog/openstack/models/identity/tenants.rb | 8 ++- lib/fog/openstack/models/identity/users.rb | 2 +- lib/fog/openstack/models/image/image.rb | 2 +- .../requests/compute/create_security_group.rb | 26 ++++--- .../compute/create_security_group_rule.rb | 32 ++++----- .../requests/compute/list_security_groups.rb | 2 +- .../requests/compute/list_volumes.rb | 10 ++- .../openstack/requests/image/create_image.rb | 67 +++++++++---------- .../openstack/requests/image/delete_image.rb | 2 - .../image/list_public_images_detailed.rb | 41 +----------- tests/openstack/models/image/image_tests.rb | 1 + .../openstack/requests/compute/image_tests.rb | 7 +- .../openstack/requests/compute/quota_tests.rb | 4 +- .../requests/compute/security_group_tests.rb | 20 +++--- .../requests/compute/volume_tests.rb | 5 +- tests/openstack/requests/image/image_tests.rb | 55 +++++++-------- 18 files changed, 125 insertions(+), 166 deletions(-) diff --git a/lib/fog/core/wait_for.rb b/lib/fog/core/wait_for.rb index c7884dd19..baf94bd0d 100644 --- a/lib/fog/core/wait_for.rb +++ b/lib/fog/core/wait_for.rb @@ -1,5 +1,4 @@ module Fog - def self.wait_for(timeout=Fog.timeout, interval=1, &block) duration = 0 start = Time.now @@ -13,5 +12,4 @@ module Fog { :duration => duration } end end - end diff --git a/lib/fog/openstack/image.rb b/lib/fog/openstack/image.rb index 364521c7c..b410d5e3b 100644 --- a/lib/fog/openstack/image.rb +++ b/lib/fog/openstack/image.rb @@ -3,7 +3,6 @@ require 'fog/openstack' module Fog module Image class OpenStack < Fog::Service - requires :openstack_auth_url recognizes :openstack_auth_token, :openstack_management_url, :persistent, :openstack_service_name, :openstack_tenant, @@ -15,7 +14,6 @@ module Fog model :image collection :images - request_path 'fog/openstack/requests/image' request :list_public_images @@ -36,8 +34,7 @@ module Fog def self.data @data ||= Hash.new do |hash, key| hash[key] = { - :users => {}, - :tenants => {} + :images => {} } end end diff --git a/lib/fog/openstack/models/identity/tenants.rb b/lib/fog/openstack/models/identity/tenants.rb index 634b9858f..6fc3454e5 100644 --- a/lib/fog/openstack/models/identity/tenants.rb +++ b/lib/fog/openstack/models/identity/tenants.rb @@ -12,9 +12,11 @@ module Fog end def find_by_id(id) - self.find {|tenant| tenant.id == id} || - Fog::Identity::OpenStack::Tenant.new( - connection.get_tenant(id).body['tenant']) + cached_tenant = self.find {|tenant| tenant.id == id} + return cached_tenant if cached_tenant + tenant_hash = connection.get_tenant(id).body['tenant'] + Fog::Identity::OpenStack::Tenant.new( + tenant_hash.merge(:connection => connection)) end def destroy(id) diff --git a/lib/fog/openstack/models/identity/users.rb b/lib/fog/openstack/models/identity/users.rb index 94e563823..f34f97923 100644 --- a/lib/fog/openstack/models/identity/users.rb +++ b/lib/fog/openstack/models/identity/users.rb @@ -18,7 +18,7 @@ module Fog self.find {|user| user.id == id} || Fog::Identity::OpenStack::User.new( connection.get_user_by_id(id).body['user'].merge( - connection: connection + 'connection' => connection ) ) end diff --git a/lib/fog/openstack/models/image/image.rb b/lib/fog/openstack/models/image/image.rb index 8d805e619..0c1943290 100644 --- a/lib/fog/openstack/models/image/image.rb +++ b/lib/fog/openstack/models/image/image.rb @@ -44,7 +44,7 @@ module Fog def create requires :name merge_attributes(connection.create_image(self.attributes).body['image']) - self + self end def update diff --git a/lib/fog/openstack/requests/compute/create_security_group.rb b/lib/fog/openstack/requests/compute/create_security_group.rb index 3a31b7401..e114f5f0b 100644 --- a/lib/fog/openstack/requests/compute/create_security_group.rb +++ b/lib/fog/openstack/requests/compute/create_security_group.rb @@ -23,21 +23,25 @@ module Fog class Mock def create_security_group(name, description) + tenant_id = Fog::Identity.new(:provider => 'OpenStack').current_tenant['id'] + security_group_id = Fog::Mock.random_numbers(2).to_i + self.data[:security_groups][security_group_id] = { + 'tenant_id' => tenant_id, + 'rules' => [], + 'id' => security_group_id, + 'name' => name, + 'description' => description + } + response = Excon::Response.new response.status = 200 response.headers = { - "X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be", - "Content-Type" => "application/json", - "Content-Length" => "139", - "Date" => Date.new} + 'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}", + 'Content-Type' => 'application/json', + 'Content-Length' => Fog::Mock.random_numbers(3).to_s, + 'Date' => Date.new} response.body = { - "security_group" => [{ - "rules" => [], - "tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2", - "id" => 999, - "name" => name, - "description" => description - }] + 'security_group' => self.data[:security_groups].values } response end diff --git a/lib/fog/openstack/requests/compute/create_security_group_rule.rb b/lib/fog/openstack/requests/compute/create_security_group_rule.rb index 65f0eff88..6853018d2 100644 --- a/lib/fog/openstack/requests/compute/create_security_group_rule.rb +++ b/lib/fog/openstack/requests/compute/create_security_group_rule.rb @@ -30,24 +30,26 @@ module Fog response = Excon::Response.new response.status = 200 response.headers = { - "X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3", - "Content-Type" => "application/json", - "Content-Length" => "163", - "Date" => Date.new + 'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}", + 'Content-Type' => 'application/json', + 'Content-Length' => Fog::Mock.random_numbers(3).to_s, + 'Date' => Date.new } - response.body = { - "security_group_rule" => { - "from_port" => from_port, - "group" => group_id || {}, - "ip_protocol" => ip_protocol, - "to_port" => to_port, - "parent_group_id" => parent_group_id, - "ip_range" => { - "cidr" => cidr - }, - "id"=>1 + rule = { + 'id' => Fog::Mock.random_numbers(2).to_i, + 'from_port' => from_port, + 'group' => group_id || {}, + 'ip_protocol' => ip_protocol, + 'to_port' => to_port, + 'parent_group_id' => parent_group_id, + 'ip_range' => { + 'cidr' => cidr } } + self.data[:security_groups][parent_group_id]['rules'].push(rule) + response.body = { + 'security_group_rule' => rule + } response end end # mock diff --git a/lib/fog/openstack/requests/compute/list_security_groups.rb b/lib/fog/openstack/requests/compute/list_security_groups.rb index 5c8f4c5b0..a9f9c8d33 100644 --- a/lib/fog/openstack/requests/compute/list_security_groups.rb +++ b/lib/fog/openstack/requests/compute/list_security_groups.rb @@ -59,7 +59,7 @@ module Fog } ] Excon::Response.new( - :body => { 'security_groups' => self.data[:security_groups] }, + :body => { 'security_groups' => self.data[:security_groups].values }, :headers => { "X-Compute-Request-Id" => "req-#{Fog::Mock.random_base64(36)}", "Content-Type" => "application/json", diff --git a/lib/fog/openstack/requests/compute/list_volumes.rb b/lib/fog/openstack/requests/compute/list_volumes.rb index 8538401e8..9fa380d26 100644 --- a/lib/fog/openstack/requests/compute/list_volumes.rb +++ b/lib/fog/openstack/requests/compute/list_volumes.rb @@ -28,9 +28,8 @@ module Fog "volume_type" => nil, "snapshot_id" => nil, "size" => 1, - "id" => 6, - "created_at" => "2012-03-30 05:31:00.655058", - "metadata" => {} }, + "id" => Fog::Mock.random_hex(32), + "created_at" => Time.now }, { "status" => "available", "display_description" => "", "availability_zone" => "nova", @@ -39,9 +38,8 @@ module Fog "volume_type" => nil, "snapshot_id" => nil, "size" => 1, - "id" => 8, - "created_at" => "2012-03-30 16:14:55.582717", - "metadata" => {} } + "id" => Fog::Mock.random_hex(32), + "created_at" => Time.now } ] response.body = { 'volumes' => self.data[:volumes] } response diff --git a/lib/fog/openstack/requests/image/create_image.rb b/lib/fog/openstack/requests/image/create_image.rb index 333df3078..b9503679f 100644 --- a/lib/fog/openstack/requests/image/create_image.rb +++ b/lib/fog/openstack/requests/image/create_image.rb @@ -4,20 +4,18 @@ module Fog class Real def create_image(attributes) - - data = { - 'Content-Type'=>'application/octet-stream', - 'x-image-meta-name' => attributes[:name], - 'x-image-meta-disk-format' => attributes[:disk_format], - 'x-image-meta-container-format' => attributes[:container_format], - 'x-image-meta-size' => attributes[:size], - 'x-image-meta-is-public' => attributes[:is_public], - 'x-image-meta-min-ram' => attributes[:min_ram], - 'x-image-meta-min-disk' => attributes[:min_disk], - 'x-image-meta-checksum' => attributes[:checksum], - 'x-image-meta-owner' => attributes[:owner], - 'x-glance-api-copy-from' => attributes[:copy_from] + 'Content-Type'=>'application/octet-stream', + 'x-image-meta-name' => attributes[:name], + 'x-image-meta-disk-format' => attributes[:disk_format], + 'x-image-meta-container-format' => attributes[:container_format], + 'x-image-meta-size' => attributes[:size], + 'x-image-meta-is-public' => attributes[:is_public], + 'x-image-meta-min-ram' => attributes[:min_ram], + 'x-image-meta-min-disk' => attributes[:min_disk], + 'x-image-meta-checksum' => attributes[:checksum], + 'x-image-meta-owner' => attributes[:owner], + 'x-glance-api-copy-from' => attributes[:copy_from] } body = String.new @@ -49,27 +47,28 @@ module Fog def create_image(attributes) response = Excon::Response.new response.status = 201 - response.body = { - 'image'=> { - 'name' => attributes['name'], - 'size' => Fog::Mock.random_numbers(8).to_i, - 'min_disk' => 0, - 'disk_format' => attributes['disk_format'], - 'created_at' => Time.now.to_s, - 'container_format' => attributes['container_format'], - 'deleted_at' => nil, - 'updated_at' => Time.now.to_s, - 'checksum' => Fog::Mock.random_hex(32), - 'id' => Fog::Mock.random_hex(32), - 'deleted' => false, - 'protected' => false, - 'is_public' => false, - 'status' => 'queued', - 'min_ram' => 0, - 'owner' => attributes['owner'], - 'properties' => attributes['properties'] - } - } + + image_id = Fog::Mock.random_hex(32) + image = self.data[:images][image_id] = { + 'name' => attributes['name'] || attributes[:name], + 'size' => Fog::Mock.random_numbers(8).to_i, + 'min_disk' => 0, + 'disk_format' => attributes['disk_format'] || attributes[:disk_format] || 'raw', + 'created_at' => Time.now.to_s, + 'container_format' => attributes['container_format'] || attributes[:container_format] || 'bare', + 'deleted_at' => nil, + 'updated_at' => Time.now.to_s, + 'checksum' => Fog::Mock.random_hex(32), + 'id' => image_id, + 'deleted' => false, + 'protected' => false, + 'is_public' => false, + 'status' => 'queued', + 'min_ram' => 0, + 'owner' => attributes['owner'] || attributes[:owner], + 'properties' => attributes['properties'] || attributes[:properties] || {} + } + response.body = { 'image'=> image } response end end diff --git a/lib/fog/openstack/requests/image/delete_image.rb b/lib/fog/openstack/requests/image/delete_image.rb index c4e407174..eab8c4707 100644 --- a/lib/fog/openstack/requests/image/delete_image.rb +++ b/lib/fog/openstack/requests/image/delete_image.rb @@ -14,13 +14,11 @@ module Fog end class Mock - def delete_image(image_id) response = Excon::Response.new response.status = 200 response end - end end end diff --git a/lib/fog/openstack/requests/image/list_public_images_detailed.rb b/lib/fog/openstack/requests/image/list_public_images_detailed.rb index 63b14a026..e165df387 100644 --- a/lib/fog/openstack/requests/image/list_public_images_detailed.rb +++ b/lib/fog/openstack/requests/image/list_public_images_detailed.rb @@ -22,46 +22,7 @@ module Fog def list_public_images_detailed(attribute=nil, query=nil) response = Excon::Response.new response.status = [200, 204][rand(1)] - response.body = {"images"=>[{ - "name"=>"cirros-0.3.0-x86_64-blank", - "size"=>25165824, - "min_disk"=>0, - "disk_format"=>"ami", - "created_at"=>"2012-02-21T07:32:26", - "container_format"=>"ami", - "deleted_at"=>nil, - "updated_at"=>"2012-02-21T07:32:29", - "checksum"=>"2f81976cae15c16ef0010c51e3a6c163", - "id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e", - "deleted"=>false, - "protected"=>false, - "is_public"=>true, - "status"=>"active", - "min_ram"=>0, - "owner"=>"ff528b20431645ebb5fa4b0a71ca002f", - "properties"=>{ - "ramdisk_id"=>"b45aa128-cd36-4ad9-a026-1a1c2bfd8fdc", - "kernel_id"=>"cd28951e-e1c2-4bc5-95d3-f0495abbcdc5"} - }, - {"name"=>"new image", - "size"=>0, - "min_disk"=>0, - "disk_format"=>nil, - "created_at"=>"2012-02-24T06:45:00", - "container_format"=>nil, - "deleted_at"=>nil, - "updated_at"=>"2012-02-24T06:45:00", - "checksum"=>nil, - "id"=>"e41304f3-2453-42b4-9829-2e220a737395", - "deleted"=>false, - "protected"=>false, - "is_public"=>false, - "status"=>"queued", - "min_ram"=>0, - "owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0", - "properties"=>{} - }] - } + response.body = {'images' => self.data[:images].values} response end # def list_tenants end # class Mock diff --git a/tests/openstack/models/image/image_tests.rb b/tests/openstack/models/image/image_tests.rb index d7653017e..663453e36 100644 --- a/tests/openstack/models/image/image_tests.rb +++ b/tests/openstack/models/image/image_tests.rb @@ -31,5 +31,6 @@ Shindo.tests("Fog::Image[:openstack] | image", ['openstack']) do tests('#destroy').succeeds do @instance.destroy == true end + end end diff --git a/tests/openstack/requests/compute/image_tests.rb b/tests/openstack/requests/compute/image_tests.rb index 12c62e310..05e1f1266 100644 --- a/tests/openstack/requests/compute/image_tests.rb +++ b/tests/openstack/requests/compute/image_tests.rb @@ -17,12 +17,12 @@ Shindo.tests('Fog::Compute[:openstack] | image requests', ['openstack']) do } tests('success') do - + # Setup @image_id = Fog::Compute[:openstack].images[0].id - unless Fog.mocking? Fog::Compute[:openstack].images.get(@image_id).wait_for { ready? } end + tests("#get_image_details(#{@image_id})").formats(@image_format) do pending if Fog.mocking? Fog::Compute[:openstack].get_image_details(@image_id).body['image'] @@ -36,14 +36,13 @@ Shindo.tests('Fog::Compute[:openstack] | image requests', ['openstack']) do Fog::Compute[:openstack].list_images_detail.body end + # Teardown unless Fog.mocking? Fog::Compute[:openstack].images.get(@image_id).wait_for { ready? } end - end tests('failure') do - tests('#delete_image(0)').raises(Fog::Compute::OpenStack::NotFound) do pending if Fog.mocking? Fog::Compute[:openstack].delete_image(0) diff --git a/tests/openstack/requests/compute/quota_tests.rb b/tests/openstack/requests/compute/quota_tests.rb index 3be76cc0c..2ebe434ad 100644 --- a/tests/openstack/requests/compute/quota_tests.rb +++ b/tests/openstack/requests/compute/quota_tests.rb @@ -11,8 +11,8 @@ Shindo.tests('Fog::Compute[:openstack] | quota requests', ['openstack']) do 'instances' => Fixnum, 'volumes' => Fixnum, 'cores' => Fixnum, - 'security_groups' => Fixnum, - 'security_group_rules' => Fixnum, + 'security_groups' => Fog::Nullable::Integer, + 'security_group_rules' => Fog::Nullable::Integer, 'id' => String } diff --git a/tests/openstack/requests/compute/security_group_tests.rb b/tests/openstack/requests/compute/security_group_tests.rb index 38590da05..f6f9edc58 100644 --- a/tests/openstack/requests/compute/security_group_tests.rb +++ b/tests/openstack/requests/compute/security_group_tests.rb @@ -2,21 +2,21 @@ Shindo.tests('Fog::Compute[:openstack] | security group requests', ['openstack'] @security_group = Hash.new @security_group_rule = Hash.new @security_group_format = { - "rules" => Array, - "tenant_id" => String, - "id" => Integer, - "name" => String, + "id" => Integer, + "rules" => Array, + "tenant_id" => String, + "name" => String, "description" => String } @security_group_rule_format = { - "from_port" => Integer, - "group" => Hash, + "id" => Integer, + "from_port" => Integer, + "to_port" => Integer, "ip_protocol" => String, - "to_port" => Integer, - "parent_group_id" => Integer, - "ip_range" => Hash, - "id" => Integer + "group" => Hash, + "ip_range" => Hash, + "parent_group_id" => Integer } tests('success') do diff --git a/tests/openstack/requests/compute/volume_tests.rb b/tests/openstack/requests/compute/volume_tests.rb index 13b4922b4..90d6830a8 100644 --- a/tests/openstack/requests/compute/volume_tests.rb +++ b/tests/openstack/requests/compute/volume_tests.rb @@ -8,14 +8,13 @@ Shindo.tests('Fog::Compute[:openstack] | volume requests', ['openstack']) do 'size' => Integer, 'display_description' => String, 'status' => String, - 'snapshot_id' => String, + 'snapshot_id' => Fog::Nullable::String, 'availability_zone' => String, 'attachments' => Array, - 'volume_type' => NilClass, + 'volume_type' => Fog::Nullable::String, 'created_at' => Time } - tests('success') do tests('#list_volumes').formats({'volumes' => [@volume_format]}) do Fog::Compute[:openstack].list_volumes.body diff --git a/tests/openstack/requests/image/image_tests.rb b/tests/openstack/requests/image/image_tests.rb index deb907a48..3534f97c5 100644 --- a/tests/openstack/requests/image/image_tests.rb +++ b/tests/openstack/requests/image/image_tests.rb @@ -36,39 +36,40 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do 'is_public' => Fog::Boolean, 'status' => String, 'min_ram' => Integer, - 'owner' => String, + 'owner' => Fog::Nullable::String, 'properties' => Hash } @image_meta_format ={ - 'X-Image-Meta-Is_public'=>String, - 'X-Image-Meta-Min_disk'=>Fog::Nullable::String, - 'X-Image-Meta-Property-Ramdisk_id'=>Fog::Nullable::String, - 'X-Image-Meta-Disk_format'=>Fog::Nullable::String, - 'X-Image-Meta-Created_at'=>String, - 'X-Image-Meta-Container_format'=>Fog::Nullable::String, - 'Etag'=>String, - 'Location'=>String, - 'X-Image-Meta-Protected'=>String, - 'Date'=>String, - 'X-Image-Meta-Name'=>String, - 'X-Image-Meta-Min_ram'=>String, - 'Content-Type'=>String, - 'X-Image-Meta-Updated_at'=>String, - 'X-Image-Meta-Property-Kernel_id'=>Fog::Nullable::String, - 'X-Image-Meta-Size'=>String, - 'X-Image-Meta-Checksum'=>Fog::Nullable::String, - 'X-Image-Meta-Deleted'=>String, - 'Content-Length'=>String, - 'X-Image-Meta-Owner'=>String, - 'X-Image-Meta-Status'=>String, - 'X-Image-Meta-Id'=>String} + 'X-Image-Meta-Is_public'=>String, + 'X-Image-Meta-Min_disk'=>Fog::Nullable::String, + 'X-Image-Meta-Property-Ramdisk_id'=>Fog::Nullable::String, + 'X-Image-Meta-Disk_format'=>Fog::Nullable::String, + 'X-Image-Meta-Created_at'=>String, + 'X-Image-Meta-Container_format'=>Fog::Nullable::String, + 'Etag'=>String, + 'Location'=>String, + 'X-Image-Meta-Protected'=>String, + 'Date'=>String, + 'X-Image-Meta-Name'=>String, + 'X-Image-Meta-Min_ram'=>String, + 'Content-Type'=>String, + 'X-Image-Meta-Updated_at'=>String, + 'X-Image-Meta-Property-Kernel_id'=>Fog::Nullable::String, + 'X-Image-Meta-Size'=>String, + 'X-Image-Meta-Checksum'=>Fog::Nullable::String, + 'X-Image-Meta-Deleted'=>String, + 'Content-Length'=>String, + 'X-Image-Meta-Status'=>String, + 'X-Image-Meta-Owner'=>String, + 'X-Image-Meta-Id'=>String + } @image_members_format =[ - {'can_share'=>Fog::Nullable::Boolean, - 'member_id'=>String - } - ] + {'can_share'=>Fog::Nullable::Boolean, + 'member_id'=>String + } + ] tests('success') do tests('#list_public_images').formats({'images' => [@image_format]}) do From 18803ff91b31755a535d86fe283bf4e5ef1c4b34 Mon Sep 17 00:00:00 2001 From: geemus Date: Tue, 2 Oct 2012 11:01:56 -0500 Subject: [PATCH 20/24] [aws|autoscaling] mark problematic auto_scaling mocked tests as pending see also #1183 --- .../auto_scaling/notification_configuration_tests.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/aws/requests/auto_scaling/notification_configuration_tests.rb b/tests/aws/requests/auto_scaling/notification_configuration_tests.rb index e8730df97..a307b3b94 100644 --- a/tests/aws/requests/auto_scaling/notification_configuration_tests.rb +++ b/tests/aws/requests/auto_scaling/notification_configuration_tests.rb @@ -37,10 +37,12 @@ Shindo.tests('AWS::AutoScaling | notification configuration requests', ['aws', ' tests('success') do tests("#put_notification_configuration(string)").formats(AWS::AutoScaling::Formats::BASIC) do + pending if Fog.mocking? Fog::AWS[:auto_scaling].put_notification_configuration(asg_name, 'autoscaling:TEST_NOTIFICATION', topic_arn).body end tests("#describe_notification_configurations").formats(AWS::AutoScaling::Formats::DESCRIBE_NOTIFICATION_CONFIGURATIONS) do + pending if Fog.mocking? body = Fog::AWS[:auto_scaling].describe_notification_configurations('AutoScalingGroupNames' => asg_name).body notification_configurations = body['DescribeNotificationConfigurationsResult']['NotificationConfigurations'] returns(true, 'exactly 1 configurations') do @@ -54,10 +56,12 @@ Shindo.tests('AWS::AutoScaling | notification configuration requests', ['aws', ' end tests("#put_notification_configuration(array)").formats(AWS::AutoScaling::Formats::BASIC) do + pending if Fog.mocking? Fog::AWS[:auto_scaling].put_notification_configuration(asg_name, ['autoscaling:EC2_INSTANCE_LAUNCH', 'autoscaling:EC2_INSTANCE_TERMINATE'], topic_arn).body end tests("#describe_notification_configurations").formats(AWS::AutoScaling::Formats::DESCRIBE_NOTIFICATION_CONFIGURATIONS) do + pending if Fog.mocking? body = Fog::AWS[:auto_scaling].describe_notification_configurations('AutoScalingGroupName' => asg_name).body notification_configurations = body['DescribeNotificationConfigurationsResult']['NotificationConfigurations'] returns(true, 'exactly 2 configurations') do @@ -74,6 +78,7 @@ Shindo.tests('AWS::AutoScaling | notification configuration requests', ['aws', ' end tests("#describe_notification_configurations(all)").formats(AWS::AutoScaling::Formats::DESCRIBE_NOTIFICATION_CONFIGURATIONS) do + pending if Fog.mocking? body = Fog::AWS[:auto_scaling].describe_notification_configurations().body notification_configurations = body['DescribeNotificationConfigurationsResult']['NotificationConfigurations'] returns(true, 'at least 2 configurations') do @@ -91,10 +96,12 @@ Shindo.tests('AWS::AutoScaling | notification configuration requests', ['aws', ' end tests("#delete_notification_configuration").formats(AWS::AutoScaling::Formats::BASIC) do + pending if Fog.mocking? Fog::AWS[:auto_scaling].delete_notification_configuration(asg_name, topic_arn).body end tests("#describe_notification_configurations").formats(AWS::AutoScaling::Formats::DESCRIBE_NOTIFICATION_CONFIGURATIONS) do + pending if Fog.mocking? body = Fog::AWS[:auto_scaling].describe_notification_configurations('AutoScalingGroupNames' => asg_name).body returns(true) do body['DescribeNotificationConfigurationsResult']['NotificationConfigurations'].empty? From 1b389931b58233d4fc59abbeb31221c3176dbbe6 Mon Sep 17 00:00:00 2001 From: geemus Date: Tue, 2 Oct 2012 11:21:29 -0500 Subject: [PATCH 21/24] [aws|cdn] fix up failing mocked tests around invalidations --- lib/fog/aws/models/cdn/invalidation.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/fog/aws/models/cdn/invalidation.rb b/lib/fog/aws/models/cdn/invalidation.rb index ff710dfe0..53f3e2937 100644 --- a/lib/fog/aws/models/cdn/invalidation.rb +++ b/lib/fog/aws/models/cdn/invalidation.rb @@ -14,6 +14,7 @@ module Fog attribute :paths, :aliases => 'Paths' def initialize(new_attributes={}) + new_attributes[:caller_reference] ||= Time.now.utc.to_i.to_s super(invalidation_to_attributes(new_attributes)) end @@ -29,7 +30,7 @@ module Fog def save requires :paths, :caller_reference raise "Submitted invalidation cannot be submitted again" if identity - response = connection.post_invalidation(distribution.identity, paths, caller_reference || Time.now.to_i.to_s) + response = connection.post_invalidation(distribution.identity, paths, caller_reference) merge_attributes(invalidation_to_attributes(response.body)) true end @@ -47,8 +48,12 @@ module Fog def invalidation_to_attributes(new_attributes={}) invalidation_batch = new_attributes.delete('InvalidationBatch') || {} - new_attributes['Paths'] = invalidation_batch['Path'] - new_attributes['CallerReference'] = invalidation_batch['CallerReference'] + if invalidation_batch['Path'] + new_attributes[:paths] = invalidation_batch['Path'] + end + if invalidation_batch['CallerReference'] + new_attributes[:caller_reference] = invalidation_batch['CallerReference'] + end new_attributes end From bc2054322025c4f9f0832a334bc6d9180d17ae9c Mon Sep 17 00:00:00 2001 From: Sean Hart Date: Tue, 2 Oct 2012 10:35:12 -0700 Subject: [PATCH 22/24] Fixed typos in elasticache and rds describe_events. Added better documentation of describe_events. --- lib/fog/aws/parsers/elasticache/base.rb | 2 -- lib/fog/aws/parsers/rds/base.rb | 2 -- lib/fog/aws/rds.rb | 2 +- .../aws/requests/elasticache/describe_events.rb | 11 +++++++---- lib/fog/aws/requests/rds/describe_events.rb | 16 +++++++++++----- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/fog/aws/parsers/elasticache/base.rb b/lib/fog/aws/parsers/elasticache/base.rb index 6e5238c01..9cac1460c 100644 --- a/lib/fog/aws/parsers/elasticache/base.rb +++ b/lib/fog/aws/parsers/elasticache/base.rb @@ -3,8 +3,6 @@ module Fog module AWS module Elasticache - require 'fog/aws/parsers/elasticache/base' - # Base parser for ResponseMetadata, RequestId class Base < Fog::Parsers::Base diff --git a/lib/fog/aws/parsers/rds/base.rb b/lib/fog/aws/parsers/rds/base.rb index 9704882b6..6e2edafa5 100644 --- a/lib/fog/aws/parsers/rds/base.rb +++ b/lib/fog/aws/parsers/rds/base.rb @@ -3,8 +3,6 @@ module Fog module AWS module RDS - require 'fog/aws/parsers/rds/base' - # Base parser for ResponseMetadata, RequestId class Base < Fog::Parsers::Base diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index 3ba857d0f..b76887029 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -13,7 +13,7 @@ module Fog recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at request_path 'fog/aws/requests/rds' - + request :describe_events request :create_db_instance request :modify_db_instance request :describe_db_instances diff --git a/lib/fog/aws/requests/elasticache/describe_events.rb b/lib/fog/aws/requests/elasticache/describe_events.rb index 1f5402a92..a030099fd 100644 --- a/lib/fog/aws/requests/elasticache/describe_events.rb +++ b/lib/fog/aws/requests/elasticache/describe_events.rb @@ -6,16 +6,19 @@ module Fog require 'fog/aws/parsers/elasticache/event_list' # Returns a list of service events + # + # For more information see: + # http://docs.amazonwebservices.com/AmazonElastiCache/latest/APIReference/API_DescribeEvents.html # # === Parameters (optional) # * options <~Hash> (optional): # * :start_time <~DateTime> - starting time for event records # * :end_time <~DateTime> - ending time for event records - # * :duration <~DateTime> - time span for event records + # * :duration <~Integer> - time span for event records # * :marker <~String> - marker provided in the previous request # * :max_records <~Integer> - the maximum number of records to include - # * :source_identifier <~DateTime> - identifier of the event source - # * :source_type <~DateTime> - event type, one of: + # * :source_identifier <~String> - identifier of the event source + # * :source_type <~String> - event type, one of: # (cache-cluster | cache-parameter-group | cache-security-group) # === Returns # * response <~Excon::Response>: @@ -23,7 +26,7 @@ module Fog def describe_events(options = {}) request( 'Action' => 'DescribeEvents', - 'StartTime' => options[:sart_time], + 'StartTime' => options[:start_time], 'EndTime' => options[:end_time], 'Duration' => options[:duration], 'Marker' => options[:marker], diff --git a/lib/fog/aws/requests/rds/describe_events.rb b/lib/fog/aws/requests/rds/describe_events.rb index bce7b8d18..9fc1d1bfe 100644 --- a/lib/fog/aws/requests/rds/describe_events.rb +++ b/lib/fog/aws/requests/rds/describe_events.rb @@ -6,24 +6,30 @@ module Fog require 'fog/aws/parsers/rds/event_list' # Returns a list of service events - # + # + # For more information see: + # http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/API_DescribeEvents.html + # # === Parameters (optional) # * options <~Hash> (optional): # * :start_time <~DateTime> - starting time for event records # * :end_time <~DateTime> - ending time for event records - # * :duration <~DateTime> - time span for event records + # * :duration <~Integer> - The number of minutes to retrieve events for + # Default = 60 Mins # * :marker <~String> - marker provided in the previous request # * :max_records <~Integer> - the maximum number of records to include - # * :source_identifier <~DateTime> - identifier of the event source + # Default = 100 + # Constraints: min = 20, maximum 100 + # * :source_identifier <~String> - identifier of the event source # * :source_type <~DateTime> - event type, one of: - # (cache-cluster | cache-parameter-group | cache-security-group) + # (db-instance | db-parameter-group | db-security-group | db-snapshot) # === Returns # * response <~Excon::Response>: # * body <~Hash> def describe_events(options = {}) request( 'Action' => 'DescribeEvents', - 'StartTime' => options[:sart_time], + 'StartTime' => options[:start_time], 'EndTime' => options[:end_time], 'Duration' => options[:duration], 'Marker' => options[:marker], From 5b42c4c6514e195b8d01a705bdd3eb44b9d361fc Mon Sep 17 00:00:00 2001 From: Curtis Stewart Date: Tue, 2 Oct 2012 14:19:43 -0500 Subject: [PATCH 23/24] Added outputs 'Description' field to DescribeStacks parser --- lib/fog/aws/parsers/cloud_formation/describe_stacks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fog/aws/parsers/cloud_formation/describe_stacks.rb b/lib/fog/aws/parsers/cloud_formation/describe_stacks.rb index e144308d1..0e79890e5 100644 --- a/lib/fog/aws/parsers/cloud_formation/describe_stacks.rb +++ b/lib/fog/aws/parsers/cloud_formation/describe_stacks.rb @@ -27,7 +27,7 @@ module Fog def end_element(name) if @in_outputs case name - when 'OutputKey', 'OutputValue' + when 'OutputKey', 'OutputValue', 'Description' @output[name] = value when 'member' @stack['Outputs'] << @output From 6cd3cbd11425218cc68c30b5d917e5a8fa5b6f02 Mon Sep 17 00:00:00 2001 From: Sean Hart Date: Tue, 2 Oct 2012 14:39:37 -0700 Subject: [PATCH 24/24] Added test for describe_events.rb. It is very simple, and I'm not familiar with Shindo, so may need some assistance expanding --- tests/aws/requests/rds/describe_events.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/aws/requests/rds/describe_events.rb diff --git a/tests/aws/requests/rds/describe_events.rb b/tests/aws/requests/rds/describe_events.rb new file mode 100644 index 000000000..941b4df68 --- /dev/null +++ b/tests/aws/requests/rds/describe_events.rb @@ -0,0 +1,16 @@ +Shindo.tests('AWS::RDS | describe DB events requests',['aws', 'rds']) do + + tests('success') do + pending if Fog.mocking? + + tests( + '#describe_events' + ).formats(AWS::RDS::Formats::EVENT_LIST) do + AWS[:rds].describe_events().body['Events'] + end + end + + tests('failure') do + #TODO: What constitutes a failure here? + end +end