Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[openstack] Update Mocks and Cleanup Unused Code

Signed-off-by: Nelvin Driz <nelvindriz@live.com>
  • Loading branch information...
commit b6d68a6c8c4f542cc156b60aea2ab76a0c593222 1 parent bdbe9db
@Keoven Keoven authored
View
7 lib/fog/openstack/compute.rb
@@ -214,9 +214,10 @@ def self.reset
def initialize(options={})
@openstack_username = options[:openstack_username]
- @openstack_tenant = options[:openstack_tenant]
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
+ @current_tenant = options[:openstack_tenant]
+
@auth_token = Fog::Mock.random_base64(64)
@auth_token_expiration = (Time.now.utc + 86400).iso8601
@@ -231,11 +232,11 @@ def initialize(options={})
end
def data
- self.class.data["#{@openstack_username}-#{@openstack_tenant}"]
+ self.class.data["#{@openstack_username}-#{@current_tenant}"]
end
def reset_data
- self.class.data.delete("#{@openstack_username}-#{@openstack_tenant}")
+ self.class.data.delete("#{@openstack_username}-#{@current_tenant}")
end
def credentials
View
2  lib/fog/openstack/identity.rb
@@ -87,7 +87,7 @@ def initialize(options={})
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_auth_uri = URI.parse(options[:openstack_auth_url])
@openstack_management_url = @openstack_auth_uri.to_s
@auth_token = Fog::Mock.random_base64(64)
View
6 lib/fog/openstack/models/compute/tenants.rb
@@ -13,7 +13,11 @@ def all
def usages(start_date = nil, end_date = nil, details = false)
connection.list_usages(start_date, end_date, details).body['tenant_usages']
- end
+ end
+
+ def find_by_id(id)
+ self.find {|tenant| tenant.id == id}
+ end
end # class Tenants
end # class OpenStack
end # module Compute
View
2  lib/fog/openstack/requests/compute/create_security_group.rb
@@ -23,7 +23,7 @@ def create_security_group(name, description)
class Mock
def create_security_group(name, description)
- tenant_id = Fog::Identity.new(:provider => 'OpenStack').current_tenant['id']
+ tenant_id = Fog::Identity::OpenStack::Mock.data[current_tenant][:tenants].keys.first
security_group_id = Fog::Mock.random_numbers(2).to_i
self.data[:security_groups][security_group_id] = {
'tenant_id' => tenant_id,
View
1  lib/fog/openstack/requests/compute/create_security_group_rule.rb
@@ -27,6 +27,7 @@ def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port,
class Mock
def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
+ parent_group_id = parent_group_id.to_i
response = Excon::Response.new
response.status = 200
response.headers = {
View
39 lib/fog/openstack/requests/compute/list_security_groups.rb
@@ -19,45 +19,6 @@ def list_security_groups(server_id = nil)
class Mock
def list_security_groups
- self.data[:security_groups] ||= [
- { "rules" => [
- { "from_port" => 44,
- "group" => {},
- "ip_protocol" => "tcp",
- "to_port" => 55,
- "parent_group_id" => 1,
- "ip_range" => {"cidr"=>"10.10.10.10/24"},
- "id" => Fog::Mock.random_numbers(2).to_i
- },
- { "from_port" => 2,
- "group" => {},
- "ip_protocol" => "tcp",
- "to_port" => 3,
- "parent_group_id" => 1,
- "ip_range" => {"cidr"=>"10.10.10.10/24"},
- "id" => Fog::Mock.random_numbers(2).to_i
- } ],
- "tenant_id" => @openstack_tenant,
- "id" => Fog::Mock.random_numbers(2).to_i,
- "name" => "default",
- "description" => "default"
- },
- {
- "rules" => [
- { "from_port" => 44,
- "group" => {},
- "ip_protocol" => "tcp",
- "to_port" => 55,
- "parent_group_id" => 2,
- "ip_range" => { "cidr"=>"10.10.10.10/24" },
- "id"=> Fog::Mock.random_numbers(2).to_i
- } ],
- "tenant_id" => @openstack_tenant,
- "id" => Fog::Mock.random_numbers(2).to_i,
- "name" => "test",
- "description" => "this is a test"
- }
- ]
Excon::Response.new(
:body => { 'security_groups' => self.data[:security_groups].values },
:headers => {
Please sign in to comment.
Something went wrong with that request. Please try again.