mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1181 from MorphGlobal/openstack/update
General Update of Test Mocks (WIP) + `update_image_members` Request
This commit is contained in:
commit
d8b1d464c3
44 changed files with 503 additions and 343 deletions
|
@ -1,3 +1,5 @@
|
|||
require 'time'
|
||||
|
||||
module Fog
|
||||
class Time < ::Time
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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
|
||||
|
@ -226,6 +243,7 @@ module Fog
|
|||
|
||||
class Real
|
||||
attr_reader :auth_token
|
||||
attr_reader :auth_token_expiration
|
||||
attr_reader :current_user
|
||||
attr_reader :current_tenant
|
||||
|
||||
|
@ -338,6 +356,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)
|
||||
|
|
|
@ -53,32 +53,79 @@ module Fog
|
|||
|
||||
|
||||
class Mock
|
||||
attr_reader :auth_token
|
||||
attr_reader :auth_token_expiration
|
||||
attr_reader :current_user
|
||||
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
|
||||
|
||||
unless self.data[:users].values.detect {|user| user['name'] == @openstack_username}
|
||||
id = Fog::Mock.random_numbers(6).to_s
|
||||
self.data[:users][id] = {
|
||||
'id' => id,
|
||||
'name' => options[:openstack_username],
|
||||
'email' => "#{options[:openstack_username]}@mock.com",
|
||||
@auth_token = Fog::Mock.random_base64(64)
|
||||
@auth_token_expiration = (Time.now.utc + 86400).iso8601
|
||||
|
||||
@admin_tenant = self.data[:tenants].values.find do |u|
|
||||
u['name'] == 'admin'
|
||||
end
|
||||
|
||||
if @openstack_tenant
|
||||
@current_tenant = self.data[:tenants].values.find do |u|
|
||||
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' => @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' => @openstack_username,
|
||||
'email' => "#{@openstack_username}@mock.com",
|
||||
'tenantId' => Fog::Mock.random_numbers(6).to_s,
|
||||
'enabled' => true
|
||||
}
|
||||
else
|
||||
@current_user_id = @current_user['id']
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -91,11 +138,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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -24,6 +22,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
|
||||
|
@ -35,8 +34,7 @@ module Fog
|
|||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {
|
||||
:users => {},
|
||||
:tenants => {}
|
||||
:images => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -48,6 +46,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]}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -44,7 +44,7 @@ module Fog
|
|||
def create
|
||||
requires :name
|
||||
merge_attributes(connection.create_image(self.attributes).body['image'])
|
||||
self
|
||||
self
|
||||
end
|
||||
|
||||
def update
|
||||
|
@ -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']
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
'attachments' => []
|
||||
'id' => Fog::Mock.random_numbers(2),
|
||||
'display_name' => name,
|
||||
'display_description' => description,
|
||||
'size' => size,
|
||||
'status' => 'creating',
|
||||
'snapshot_id' => '4',
|
||||
'volume_type' => nil,
|
||||
'availability_zone' => 'nova',
|
||||
'created_at' => Time.now,
|
||||
'attachments' => []
|
||||
}
|
||||
}
|
||||
response
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -21,15 +21,15 @@ 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,
|
||||
'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,
|
||||
'attachments' => []
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,9 +57,9 @@ module Fog
|
|||
"name" => "test",
|
||||
"description" => "this is a test"
|
||||
}
|
||||
] unless self.data.empty?
|
||||
]
|
||||
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",
|
||||
|
|
|
@ -21,25 +21,25 @@ 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" => Fog::Mock.random_hex(32),
|
||||
"created_at" => Time.now },
|
||||
{ "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" => Fog::Mock.random_hex(32),
|
||||
"created_at" => Time.now }
|
||||
]
|
||||
response.body = { 'volumes' => self.data[:volumes] }
|
||||
response
|
||||
|
|
|
@ -20,10 +20,10 @@ module Fog
|
|||
response.status = [200, 204][rand(1)]
|
||||
response.body = {
|
||||
'tenant' => {
|
||||
'id' => '1',
|
||||
'description' => 'Has access to everything',
|
||||
'id' => "df9a815161eba9b76cc748fd5c5af73e",
|
||||
'description' => attributes['description'] || 'normal tenant',
|
||||
'enabled' => true,
|
||||
'name' => 'admin'
|
||||
'name' => attributes['name'] || 'default'
|
||||
}
|
||||
}
|
||||
response
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,35 +4,33 @@ 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-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',
|
||||
|
@ -49,30 +47,30 @@ 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"=>{}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,49 +19,10 @@ 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"=>[{
|
||||
"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
|
||||
|
|
|
@ -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]}"
|
||||
|
@ -35,26 +38,28 @@ 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"=>{}
|
||||
}
|
||||
}
|
||||
image = self.images.last
|
||||
response.body = {
|
||||
'image'=> {
|
||||
'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' => image.checksum,
|
||||
'id' => attributes[:id],
|
||||
'deleted' => false,
|
||||
'protected' => false,
|
||||
'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
|
||||
|
||||
end
|
||||
|
|
37
lib/fog/openstack/requests/image/update_image_members.rb
Normal file
37
lib/fog/openstack/requests/image/update_image_members.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
'size' => 3,
|
||||
'volumeId' => '4',
|
||||
'status' => 'online',
|
||||
'createdAt' => Time.now
|
||||
'display_name' => 'Snapshot1',
|
||||
'display_description' => 'Volume1 snapshot',
|
||||
'size' => 1,
|
||||
'volume_id' => '1',
|
||||
'status' => 'available',
|
||||
'created_at' => Time.now
|
||||
}
|
||||
}
|
||||
response
|
||||
|
|
|
@ -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,
|
||||
'attchments' => []
|
||||
'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,
|
||||
'attachments' => []
|
||||
}
|
||||
}
|
||||
response
|
||||
|
|
|
@ -22,26 +22,26 @@ module Fog
|
|||
response.status = 200
|
||||
self.data[:volumes] ||= [
|
||||
{ "status" => "available",
|
||||
"displayDescription" => "",
|
||||
"availabilityZone" => "nova",
|
||||
"displayName" => "test 1",
|
||||
"display_description" => "test 1 desc",
|
||||
"availability_zone" => "nova",
|
||||
"display_name" => "Volume1",
|
||||
"attachments" => [{}],
|
||||
"volumeType" => nil,
|
||||
"snapshotId" => nil,
|
||||
"volume_type" => nil,
|
||||
"snapshot_id" => nil,
|
||||
"size" => 1,
|
||||
"id" => 6,
|
||||
"createdAt" => "2012-03-30 05:31:00.655058",
|
||||
"id" => 1,
|
||||
"created_at" => Time.now,
|
||||
"metadata" => {} },
|
||||
{ "status" => "available",
|
||||
"displayDescription" => "",
|
||||
"availabilityZone" => "nova",
|
||||
"displayName" => "test 2",
|
||||
"display_description" => "test 2 desc",
|
||||
"availability_zone" => "nova",
|
||||
"display_name" => "Volume2",
|
||||
"attachments" => [{}],
|
||||
"volumeType" => nil,
|
||||
"snapshotId" => nil,
|
||||
"volume_type" => nil,
|
||||
"snapshot_id" => nil,
|
||||
"size" => 1,
|
||||
"id" => 8,
|
||||
"createdAt" => "2012-03-30 16:14:55.582717",
|
||||
"id" => 2,
|
||||
"created_at" => Time.now,
|
||||
"metadata" => {} }
|
||||
]
|
||||
response.body = { 'volumes' => self.data[:volumes] }
|
||||
|
|
|
@ -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]}
|
||||
|
|
|
@ -31,5 +31,6 @@ Shindo.tests("Fog::Image[:openstack] | image", ['openstack']) do
|
|||
tests('#destroy').succeeds do
|
||||
@instance.destroy == true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -11,6 +11,8 @@ Shindo.tests('Fog::Compute[:openstack] | quota requests', ['openstack']) do
|
|||
'instances' => Fixnum,
|
||||
'volumes' => Fixnum,
|
||||
'cores' => Fixnum,
|
||||
'security_groups' => Fog::Nullable::Integer,
|
||||
'security_group_rules' => Fog::Nullable::Integer,
|
||||
'id' => String
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,19 +3,18 @@ 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' => Fog::Nullable::String,
|
||||
'availability_zone' => String,
|
||||
'attachments' => Array,
|
||||
'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
|
||||
|
@ -23,7 +22,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
|
||||
|
|
|
@ -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.tenants.first, openstack.users.first).body
|
||||
openstack.current_tenant['id'], user['id']).body
|
||||
end
|
||||
|
||||
tests('#create_tenant').formats({'tenant' => @tenant_format}) do
|
||||
|
|
|
@ -1,75 +1,96 @@
|
|||
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,
|
||||
'updated_at' => String,
|
||||
'deleted' => Fog::Boolean,
|
||||
'protected' => Fog::Boolean,
|
||||
'is_public' => Fog::Boolean,
|
||||
'status' => String,
|
||||
'min_ram' => Integer,
|
||||
'owner' => Fog::Nullable::String,
|
||||
'properties' => Fog::Nullable::Hash
|
||||
'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
|
||||
Fog::Image[:openstack].list_public_images.body
|
||||
end
|
||||
|
||||
tests('#list_public_images_detailed').formats({'images' => [@image_format]}) do
|
||||
Fog::Image[:openstack].list_public_images.body
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue