Skip to content

Commit 04dd91d

Browse files
authored
Merge pull request #223 from gildub/mock-to-test1
Moving Mock to test: part 1
2 parents 07dc9ec + 705283e commit 04dd91d

File tree

9 files changed

+328
-300
lines changed

9 files changed

+328
-300
lines changed

lib/fog/identity/openstack.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ def self.new(args = {})
3232
service
3333
end
3434

35-
class Mock
36-
attr_reader :config
37-
38-
def initialize(options = {})
39-
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
40-
@config = options
41-
end
42-
end
43-
4435
class Real
4536
include Fog::OpenStack::Core
4637

lib/fog/identity/openstack/v2.rb

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -66,108 +66,6 @@ class V2 < Fog::Service
6666
request :get_ec2_credential
6767
request :list_ec2_credentials
6868

69-
class Mock
70-
attr_reader :auth_token
71-
attr_reader :auth_token_expiration
72-
attr_reader :current_user
73-
attr_reader :current_tenant
74-
attr_reader :unscoped_token
75-
76-
def self.data
77-
@users ||= {}
78-
@roles ||= {}
79-
@tenants ||= {}
80-
@ec2_credentials ||= Hash.new { |hash, key| hash[key] = {} }
81-
@user_tenant_membership ||= {}
82-
83-
@data ||= Hash.new do |hash, key|
84-
hash[key] = {
85-
:users => @users,
86-
:roles => @roles,
87-
:tenants => @tenants,
88-
:ec2_credentials => @ec2_credentials,
89-
:user_tenant_membership => @user_tenant_membership
90-
}
91-
end
92-
end
93-
94-
def self.reset!
95-
@data = nil
96-
@users = nil
97-
@roles = nil
98-
@tenants = nil
99-
@ec2_credentials = nil
100-
end
101-
102-
def initialize(options = {})
103-
@openstack_username = options[:openstack_username] || 'admin'
104-
@openstack_tenant = options[:openstack_tenant] || 'admin'
105-
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
106-
@openstack_management_url = @openstack_auth_uri.to_s
107-
108-
@auth_token = Fog::Mock.random_base64(64)
109-
@auth_token_expiration = (Time.now.utc + 86400).iso8601
110-
111-
@admin_tenant = data[:tenants].values.find do |u|
112-
u['name'] == 'admin'
113-
end
114-
115-
if @openstack_tenant
116-
@current_tenant = data[:tenants].values.find do |u|
117-
u['name'] == @openstack_tenant
118-
end
119-
120-
if @current_tenant
121-
@current_tenant_id = @current_tenant['id']
122-
else
123-
@current_tenant_id = Fog::Mock.random_hex(32)
124-
@current_tenant = data[:tenants][@current_tenant_id] = {
125-
'id' => @current_tenant_id,
126-
'name' => @openstack_tenant
127-
}
128-
end
129-
else
130-
@current_tenant = @admin_tenant
131-
end
132-
133-
@current_user = data[:users].values.find do |u|
134-
u['name'] == @openstack_username
135-
end
136-
@current_tenant_id = Fog::Mock.random_hex(32)
137-
138-
if @current_user
139-
@current_user_id = @current_user['id']
140-
else
141-
@current_user_id = Fog::Mock.random_hex(32)
142-
@current_user = data[:users][@current_user_id] = {
143-
'id' => @current_user_id,
144-
'name' => @openstack_username,
145-
'email' => "#{@openstack_username}@mock.com",
146-
'tenantId' => Fog::Mock.random_numbers(6).to_s,
147-
'enabled' => true
148-
}
149-
end
150-
end
151-
152-
def data
153-
self.class.data[@openstack_username]
154-
end
155-
156-
def reset_data
157-
self.class.data.delete(@openstack_username)
158-
end
159-
160-
def credentials
161-
{:provider => 'openstack',
162-
:openstack_auth_url => @openstack_auth_uri.to_s,
163-
:openstack_auth_token => @auth_token,
164-
:openstack_management_url => @openstack_management_url,
165-
:openstack_current_user_id => @openstack_current_user_id,
166-
:current_user => @current_user,
167-
:current_tenant => @current_tenant}
168-
end
169-
end
170-
17169
class Real < Fog::Identity::OpenStack::Real
17270
private
17371

lib/fog/identity/openstack/v3.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ class V3 < Fog::Service
116116
request :update_policy
117117
request :delete_policy
118118

119-
class Mock
120-
include Fog::OpenStack::Core
121-
def initialize(options = {})
122-
end
123-
end
124-
125119
def self.get_api_version(uri, connection_options = {})
126120
connection = Fog::Core::Connection.new(uri, false, connection_options)
127121
response = connection.request(:expects => [200],

lib/fog/network/openstack.rb

Lines changed: 0 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
module Fog
42
module Network
53
class OpenStack < Fog::Service
@@ -261,187 +259,6 @@ class OpenStack < Fog::Service
261259
request :update_quota
262260
request :delete_quota
263261

264-
class Mock
265-
def self.data
266-
@data ||= Hash.new do |hash, key|
267-
qos_policy_id = Fog::UUID.uuid
268-
network_id = Fog::UUID.uuid
269-
extension_id = Fog::UUID.uuid
270-
subnet_id = Fog::UUID.uuid
271-
tenant_id = Fog::Mock.random_hex(8)
272-
273-
hash[key] = {
274-
:extensions => {
275-
extension_id => {
276-
'id' => extension_id,
277-
'alias' => 'dvr',
278-
'description' => 'Enables configuration of Distributed Virtual Routers.',
279-
'links' => [],
280-
'name' => 'Distributed Virtual Router'
281-
}
282-
},
283-
:networks => {
284-
network_id => {
285-
'id' => network_id,
286-
'name' => 'Public',
287-
'subnets' => [subnet_id],
288-
'shared' => true,
289-
'status' => 'ACTIVE',
290-
'tenant_id' => tenant_id,
291-
'provider:network:type' => 'vlan',
292-
'router:external' => false,
293-
'admin_state_up' => true,
294-
'qos_policy_id' => qos_policy_id,
295-
'port_security_enabled' => true
296-
},
297-
'e624a36d-762b-481f-9b50-4154ceb78bbb' => {
298-
'id' => 'e624a36d-762b-481f-9b50-4154ceb78bbb',
299-
'name' => 'network_1',
300-
'subnets' => ['2e4ec6a4-0150-47f5-8523-e899ac03026e'],
301-
'shared' => false,
302-
'status' => 'ACTIVE',
303-
'tenant_id' => 'f8b26a6032bc47718a7702233ac708b9',
304-
'provider:network:type' => 'vlan',
305-
'router:external' => false,
306-
'admin_state_up' => true,
307-
'qos_policy_id' => qos_policy_id,
308-
'port_security_enabled' => true
309-
}
310-
},
311-
:ports => {},
312-
:subnets => {
313-
subnet_id => {
314-
'id' => subnet_id,
315-
'name' => "Public",
316-
'network_id' => network_id,
317-
'cidr' => "192.168.0.0/22",
318-
'ip_version' => 4,
319-
'gateway_ip' => Fog::Mock.random_ip,
320-
'allocation_pools' => [],
321-
'dns_nameservers' => [Fog::Mock.random_ip, Fog::Mock.random_ip],
322-
'host_routes' => [Fog::Mock.random_ip],
323-
'enable_dhcp' => true,
324-
'tenant_id' => tenant_id,
325-
}
326-
},
327-
:subnet_pools => {},
328-
:floating_ips => {},
329-
:routers => {},
330-
:lb_pools => {},
331-
:lb_members => {},
332-
:lb_health_monitors => {},
333-
:lb_vips => {},
334-
:lbaas_loadbalancers => {},
335-
:lbaas_listeners => {},
336-
:lbaas_pools => {},
337-
:lbaas_pool_members => {},
338-
:lbaas_health_monitorss => {},
339-
:lbaas_l7policies => {},
340-
:lbaas_l7rules => {},
341-
:vpn_services => {},
342-
:ike_policies => {},
343-
:ipsec_policies => {},
344-
:ipsec_site_connections => {},
345-
:rbac_policies => {},
346-
:quota => {
347-
"subnet" => 10,
348-
"router" => 10,
349-
"port" => 50,
350-
"network" => 10,
351-
"floatingip" => 50
352-
},
353-
:quotas => [
354-
{
355-
"subnet" => 10,
356-
"network" => 10,
357-
"floatingip" => 50,
358-
"tenant_id" => tenant_id,
359-
"router" => 10,
360-
"port" => 30
361-
}
362-
],
363-
:security_groups => {},
364-
:security_group_rules => {},
365-
:network_ip_availabilities => [
366-
{
367-
"network_id" => "4cf895c9-c3d1-489e-b02e-59b5c8976809",
368-
"network_name" => "public",
369-
"subnet_ip_availability" => [
370-
{
371-
"cidr" => "2001:db8::/64",
372-
"ip_version" => 6,
373-
"subnet_id" => "ca3f46c4-c6ff-4272-9be4-0466f84c6077",
374-
"subnet_name" => "ipv6-public-subnet",
375-
"total_ips" => 18446744073709552000,
376-
"used_ips" => 1
377-
},
378-
{
379-
"cidr" => "172.24.4.0/24",
380-
"ip_version" => 4,
381-
"subnet_id" => "cc02efc1-9d47-46bd-bab6-760919c836b5",
382-
"subnet_name" => "public-subnet",
383-
"total_ips" => 253,
384-
"used_ips" => 1
385-
}
386-
],
387-
"project_id" => "1a02cc95f1734fcc9d3c753818f03002",
388-
"tenant_id" => "1a02cc95f1734fcc9d3c753818f03002",
389-
"total_ips" => 253,
390-
"used_ips" => 2
391-
},
392-
{
393-
"network_id" => "6801d9c8-20e6-4b27-945d-62499f00002e",
394-
"network_name" => "private",
395-
"subnet_ip_availability" => [
396-
{
397-
"cidr" => "10.0.0.0/24",
398-
"ip_version" => 4,
399-
"subnet_id" => "44e70d00-80a2-4fb1-ab59-6190595ceb61",
400-
"subnet_name" => "private-subnet",
401-
"total_ips" => 253,
402-
"used_ips" => 2
403-
},
404-
{
405-
"ip_version" => 6,
406-
"cidr" => "fdbf:ac66:9be8::/64",
407-
"subnet_id" => "a90623df-00e1-4902-a675-40674385d74c",
408-
"subnet_name" => "ipv6-private-subnet",
409-
"total_ips" => 18446744073709552000,
410-
"used_ips" => 2
411-
}
412-
],
413-
"project_id" => "d56d3b8dd6894a508cf41b96b522328c",
414-
"tenant_id" => "d56d3b8dd6894a508cf41b96b522328c",
415-
"total_ips" => 18446744073709552000,
416-
"used_ips" => 4
417-
}
418-
]
419-
}
420-
end
421-
end
422-
423-
def self.reset
424-
@data = nil
425-
end
426-
427-
include Fog::OpenStack::Core
428-
429-
def initialize(options = {})
430-
@auth_token = Fog::Mock.random_base64(64)
431-
@auth_token_expiration = (Time.now.utc + 86400).iso8601
432-
433-
initialize_identity options
434-
end
435-
436-
def data
437-
self.class.data["#{@openstack_username}-#{@openstack_tenant}"]
438-
end
439-
440-
def reset_data
441-
self.class.data.delete("#{@openstack_username}-#{@openstack_tenant}")
442-
end
443-
end
444-
445262
class Real
446263
include Fog::OpenStack::Core
447264

test/lib/fog/identity/openstack.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Fog
2+
module Identity
3+
class OpenStack < Fog::Service
4+
class Mock
5+
attr_reader :config
6+
7+
def initialize(options = {})
8+
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
9+
@config = options
10+
end
11+
end
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)