misty 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/lib/misty/auth.rb +22 -11
- data/lib/misty/auth/auth_v2.rb +2 -12
- data/lib/misty/auth/auth_v3.rb +2 -12
- data/lib/misty/http/client.rb +13 -12
- data/lib/misty/microversion.rb +63 -0
- data/lib/misty/misty.rb +5 -10
- data/lib/misty/openstack/cinder/v3.rb +2 -0
- data/lib/misty/openstack/ironic/v1.rb +2 -6
- data/lib/misty/openstack/magnum/v1.rb +0 -4
- data/lib/misty/openstack/manila/v2.rb +4 -8
- data/lib/misty/openstack/nova/v2_1.rb +7 -8
- data/lib/misty/openstack/swift/v1.rb +4 -0
- data/lib/misty/service.rb +6 -13
- data/lib/misty/version.rb +1 -1
- data/test/integration/test_helper.rb +2 -0
- data/test/unit/auth_test.rb +4 -4
- data/test/unit/cloud/services_test.rb +4 -1
- data/test/unit/http/client_test.rb +0 -6
- data/test/unit/{openstack/microversion_test.rb → microversion_test.rb} +7 -7
- data/test/unit/service_helper.rb +2 -2
- data/test/unit/test_helper.rb +2 -0
- metadata +6 -6
- data/lib/misty/openstack/microversion.rb +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a18dd08ce931589520a2cffc3a0680fc43e97d1
|
4
|
+
data.tar.gz: cc92b5a1fa75a36b6702094f2fdaf88aa5153879
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4e83f60c35a1a28fd96a9b3066d90d2fab52b5bad92ececbe35c690add1cc2c07118b5f6c50b789d43a136a28860a7fe1ce4602aabe58095414cd18978465cb
|
7
|
+
data.tar.gz: 51295685e0f48004e97216b5423b6f32c8ac2ac3861c226efe4c6af834567b50fafb2dd559493e78cd505da9fcb7da0af49038345e200d7778a1983be7569c76
|
data/README.md
CHANGED
@@ -264,7 +264,7 @@ The following options are applied to each service unless specifically provided f
|
|
264
264
|
Default: `:ruby`
|
265
265
|
|
266
266
|
### Services Options
|
267
|
-
Each service can
|
267
|
+
Each service can have specific parameters.
|
268
268
|
|
269
269
|
```ruby
|
270
270
|
openstack = Misty::Cloud.new(:auth => auth, :identity => {}, :compute => {})
|
@@ -279,7 +279,10 @@ The following options are available:
|
|
279
279
|
Type: String
|
280
280
|
* :base_url
|
281
281
|
Allows to force the base URL for every requests.
|
282
|
-
Type: String
|
282
|
+
Type: String
|
283
|
+
* :headers
|
284
|
+
Optional headers
|
285
|
+
Type: Hash
|
283
286
|
* :interface
|
284
287
|
Allows to provide an alternate interface. Allowed values are "public", "internal" or "admin"
|
285
288
|
Type: String
|
data/lib/misty/auth.rb
CHANGED
@@ -32,11 +32,9 @@ module Misty
|
|
32
32
|
raise URLError, 'No URL provided' if auth[:url].nil? || auth[:url].empty?
|
33
33
|
@uri = URI.parse(auth[:url])
|
34
34
|
@config = config
|
35
|
-
# autheticate
|
36
35
|
@credentials = set_credentials(auth)
|
37
36
|
@token, @catalog, @expires = set(authenticate)
|
38
37
|
end
|
39
|
-
#byebug unless config.is_a?(Misty::Cloud::Config)
|
40
38
|
end
|
41
39
|
|
42
40
|
def authenticate
|
@@ -44,10 +42,9 @@ module Misty
|
|
44
42
|
@uri, ssl_verify_mode: @config.ssl_verify_mode, log: @config.log
|
45
43
|
) do |connection|
|
46
44
|
response = connection.post(self.class.path, @credentials.to_json,
|
47
|
-
|
45
|
+
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
|
48
46
|
unless response.code =~ /200|201/
|
49
|
-
raise AuthenticationError,
|
50
|
-
"Response code=#{response.code}, Msg=#{response.msg}"
|
47
|
+
raise AuthenticationError, "Response code=#{response.code}, Msg=#{response.msg}"
|
51
48
|
end
|
52
49
|
response
|
53
50
|
end
|
@@ -60,18 +57,32 @@ module Misty
|
|
60
57
|
Time.parse(@expires) < Time.now.utc
|
61
58
|
end
|
62
59
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
def get_url(service_names, region_id, interface)
|
61
|
+
find_url(get_service(service_names), region_id, interface)
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_service(service_names)
|
65
|
+
@catalog.each do |service|
|
66
|
+
return service if service_names.include?(service['type'])
|
68
67
|
end
|
69
|
-
raise CatalogError, "No service
|
68
|
+
raise CatalogError, "No service '#{service_names}' found."
|
70
69
|
end
|
71
70
|
|
72
71
|
def get_token
|
73
72
|
@token, @catalog, @expires = set(authenticate) if expired?
|
74
73
|
@token
|
75
74
|
end
|
75
|
+
|
76
|
+
def find_url(service, region_id, interface)
|
77
|
+
if service['endpoints']
|
78
|
+
service['endpoints'].each do |endpoint|
|
79
|
+
if (url = self.class.get_url(endpoint, region_id, interface))
|
80
|
+
return url
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
message = "No endpoint found: service '#{service['type']}', region '#{region_id}', interface '#{interface}'"
|
85
|
+
raise CatalogError, message
|
86
|
+
end
|
76
87
|
end
|
77
88
|
end
|
data/lib/misty/auth/auth_v2.rb
CHANGED
@@ -6,12 +6,8 @@ module Misty
|
|
6
6
|
'/v2.0/tokens'
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
if endpoint['region'] == region && endpoint["#{interface}URL"]
|
12
|
-
return endpoint["#{interface}URL"]
|
13
|
-
end
|
14
|
-
end
|
9
|
+
def self.get_url(endpoint, region_id, interface)
|
10
|
+
return endpoint["#{interface}URL"] if endpoint['region'] == region_id && endpoint["#{interface}URL"]
|
15
11
|
end
|
16
12
|
|
17
13
|
def credentials
|
@@ -41,12 +37,6 @@ module Misty
|
|
41
37
|
}
|
42
38
|
end
|
43
39
|
|
44
|
-
def get_endpoint_url(endpoints, region, interface)
|
45
|
-
endpoint = endpoints.select { |ep| !ep[interface].empty? }
|
46
|
-
raise CatalogError, "No endpoint available for region '#{region}' and interface '#{interface}'" unless endpoint
|
47
|
-
endpoint[0][interface]
|
48
|
-
end
|
49
|
-
|
50
40
|
def set(response)
|
51
41
|
payload = JSON.load(response.body)
|
52
42
|
token = payload['access']['token']['id']
|
data/lib/misty/auth/auth_v3.rb
CHANGED
@@ -6,12 +6,8 @@ module Misty
|
|
6
6
|
'/v3/auth/tokens'
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
if endpoint['region_id'] == region && endpoint['interface'] == interface
|
12
|
-
return endpoint['url']
|
13
|
-
end
|
14
|
-
end
|
9
|
+
def self.get_url(endpoint, region_id, interface)
|
10
|
+
return endpoint['url'] if endpoint['region_id'] == region_id && endpoint['interface'] == interface
|
15
11
|
end
|
16
12
|
|
17
13
|
def credentials
|
@@ -34,12 +30,6 @@ module Misty
|
|
34
30
|
}
|
35
31
|
end
|
36
32
|
|
37
|
-
def get_endpoint_url(endpoints, region, interface)
|
38
|
-
endpoint = endpoints.select { |ep| ep['region_id'] == region && ep['interface'] == interface }
|
39
|
-
raise CatalogError, "No endpoint available for region '#{region}' and interface '#{interface}'" unless endpoint
|
40
|
-
endpoint[0]['url']
|
41
|
-
end
|
42
|
-
|
43
33
|
def scope
|
44
34
|
return @project.identity if @project
|
45
35
|
return @domain.identity if @domain
|
data/lib/misty/http/client.rb
CHANGED
@@ -37,22 +37,24 @@ module Misty
|
|
37
37
|
# :base_path => nil
|
38
38
|
# URL can be forced (Helps when setup is broken)
|
39
39
|
# :base_url => nil
|
40
|
+
# Optional headers
|
41
|
+
# :headers => {}
|
40
42
|
# Endpoint type (admin, public or internal)
|
41
|
-
#
|
43
|
+
# :interface => "public"
|
42
44
|
# Region ID
|
43
45
|
# :region_id => "regionOne"
|
44
46
|
# Service name
|
45
47
|
# The Service names are pre defined but more can be added using this option.
|
46
48
|
# :service_name
|
47
49
|
# SSL Verify Mode
|
48
|
-
#
|
50
|
+
# :ssl_verify_mode => true
|
49
51
|
# (micro)version: Can be numbered (3.1) or by state (CURRENT, LATEST or SUPPORTED)
|
50
52
|
# :version => "CURRENT"
|
51
53
|
def initialize(auth, config, options)
|
52
54
|
@auth = auth
|
53
55
|
@config = config
|
54
56
|
@options = setup(options)
|
55
|
-
@uri = URI.parse(@auth.
|
57
|
+
@uri = URI.parse(@auth.get_url(@options.service_names, @options.region_id, @options.interface))
|
56
58
|
@base_path = @options.base_path ? @options.base_path : @uri.path
|
57
59
|
@base_path = @base_path.chomp('/')
|
58
60
|
@version = nil
|
@@ -70,15 +72,14 @@ module Misty
|
|
70
72
|
''
|
71
73
|
end
|
72
74
|
|
73
|
-
def headers_default
|
74
|
-
Misty::HEADER_JSON
|
75
|
-
end
|
76
|
-
|
77
75
|
def headers
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
header = {}
|
77
|
+
header.merge!({'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
78
|
+
header.merge!('X-Auth-Token' => @auth.get_token.to_s)
|
79
|
+
header.merge!(@config.headers) if @config.headers
|
80
|
+
header.merge!(@options.headers) if @options.headers
|
81
|
+
header.merge!(microversion_header) if microversion
|
82
|
+
header
|
82
83
|
end
|
83
84
|
|
84
85
|
private
|
@@ -95,7 +96,7 @@ module Misty
|
|
95
96
|
options.region_id = params[:region_id] ? params[:region_id] : @config.region_id
|
96
97
|
options.service_names = params[:service_name] ? self.class.service_names << params[:service_name] : self.class.service_names
|
97
98
|
options.ssl_verify_mode = params[:ssl_verify_mode] ? params[:ssl_verify_mode] : @config.ssl_verify_mode
|
98
|
-
options.headers = params[:headers]
|
99
|
+
options.headers = params[:headers] ? params[:headers] : {}
|
99
100
|
options.version = params[:version] ? params[:version] : 'CURRENT'
|
100
101
|
|
101
102
|
unless INTERFACES.include?(options.interface)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Misty
|
2
|
+
module Microversion
|
3
|
+
class VersionError < RuntimeError; end
|
4
|
+
|
5
|
+
VERSION_STATES = %w{CURRENT LATEST SUPPORTED}
|
6
|
+
|
7
|
+
def initialize(auth, cloud, options)
|
8
|
+
super
|
9
|
+
@microversion = true
|
10
|
+
@version = version_get(@options.version)
|
11
|
+
end
|
12
|
+
|
13
|
+
def microversion_header
|
14
|
+
{'X-Openstack-API-Version' => "#{baseclass.downcase} #{@version}" }
|
15
|
+
end
|
16
|
+
|
17
|
+
def version_get(version_option)
|
18
|
+
if VERSION_STATES.include?(version_option)
|
19
|
+
return version_by_state(version_option)
|
20
|
+
else
|
21
|
+
return version_by_number(version_option)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def versions
|
26
|
+
@versions ||= versions_fetch
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def version_by_number(number)
|
32
|
+
versions.each do |version|
|
33
|
+
return number if version['min_version'] <= number && version['version'] >= number
|
34
|
+
end
|
35
|
+
raise VersionError, "Version #{number} is out of range of available versions #{versions}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def version_by_state(state)
|
39
|
+
version_details = nil
|
40
|
+
versions.each do |version|
|
41
|
+
if version['status'] == state
|
42
|
+
version_details = version
|
43
|
+
break
|
44
|
+
end
|
45
|
+
end
|
46
|
+
raise VersionError, "Version #{state} is not available among #{versions}" if version_details.nil?
|
47
|
+
if version_details['version'].empty?
|
48
|
+
@microversion = false
|
49
|
+
return ''
|
50
|
+
end
|
51
|
+
version_details['version']
|
52
|
+
end
|
53
|
+
|
54
|
+
def versions_fetch
|
55
|
+
response = http_get('/', {'Accept'=> 'application/json'})
|
56
|
+
raise VersionError, "Code: #{response.code}, Message: #{response.msg}" unless response.code =~ /2??/
|
57
|
+
data = response.body.is_a?(Hash) ? response.body : JSON.parse(response.body)
|
58
|
+
list = data['versions']
|
59
|
+
raise VersionError, 'Missing version data' unless list
|
60
|
+
list
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/misty/misty.rb
CHANGED
@@ -5,11 +5,11 @@ module Misty
|
|
5
5
|
{ name: :application_catalog, project: :murano, versions: ['v1']},
|
6
6
|
{ name: :alarming, project: :aodh, versions: ['v2']},
|
7
7
|
{ name: :backup, project: :freezer, versions: ['v1']},
|
8
|
-
{ name: :baremetal, project: :ironic,
|
9
|
-
{ name: :block_storage, project: :cinder, versions: ['v2', 'v1']
|
8
|
+
{ name: :baremetal, project: :ironic, microversion: 'v1'},
|
9
|
+
{ name: :block_storage, project: :cinder, microversion: 'v3', versions: ['v2', 'v1']},
|
10
10
|
{ name: :clustering, project: :senlin, versions: ['v1']},
|
11
|
-
{ name: :compute, project: :nova,
|
12
|
-
{ name: :container_infrastructure_management, project: :magnum,
|
11
|
+
{ name: :compute, project: :nova, microversion: 'v2.1'},
|
12
|
+
{ name: :container_infrastructure_management, project: :magnum, microversion: 'v1'},
|
13
13
|
{ name: :data_processing, project: :sahara, versions: ['v1.1']},
|
14
14
|
{ name: :data_protection_orchestration, project: :karbor, versions: ['v1']},
|
15
15
|
{ name: :database, project: :trove, versions: ['v1.0']},
|
@@ -24,14 +24,9 @@ module Misty
|
|
24
24
|
{ name: :object_storage, project: :swift, versions: ['v1']},
|
25
25
|
{ name: :orchestration, project: :heat, versions: ['v1']},
|
26
26
|
{ name: :search, project: :searchlight, versions: ['v1']},
|
27
|
-
{ name: :shared_file_systems, project: :manila,
|
27
|
+
{ name: :shared_file_systems, project: :manila, microversion: 'v2'}
|
28
28
|
]
|
29
29
|
|
30
|
-
HEADER_JSON = {
|
31
|
-
'Content-Type' => 'application/json',
|
32
|
-
'Accept' => 'application/json'
|
33
|
-
}
|
34
|
-
|
35
30
|
# Default REST content type. Use :json or :ruby
|
36
31
|
CONTENT_TYPE = :ruby
|
37
32
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
+
require 'misty/microversion'
|
2
3
|
require 'misty/openstack/cinder/cinder_v3'
|
3
4
|
|
4
5
|
module Misty
|
@@ -6,6 +7,7 @@ module Misty
|
|
6
7
|
module Cinder
|
7
8
|
class V3 < Misty::HTTP::Client
|
8
9
|
extend Misty::Openstack::CinderV3
|
10
|
+
include Misty::Microversion
|
9
11
|
|
10
12
|
def self.api
|
11
13
|
v3
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
-
require 'misty/
|
2
|
+
require 'misty/microversion'
|
3
3
|
require 'misty/openstack/ironic/ironic_v1'
|
4
4
|
|
5
5
|
module Misty
|
@@ -7,7 +7,7 @@ module Misty
|
|
7
7
|
module Ironic
|
8
8
|
class V1 < Misty::HTTP::Client
|
9
9
|
extend Misty::Openstack::IronicV1
|
10
|
-
include Misty::
|
10
|
+
include Misty::Microversion
|
11
11
|
|
12
12
|
def self.api
|
13
13
|
v1
|
@@ -16,10 +16,6 @@ module Misty
|
|
16
16
|
def self.service_names
|
17
17
|
%w{baremetal}
|
18
18
|
end
|
19
|
-
|
20
|
-
def microversion_header
|
21
|
-
{ 'X-Openstack-Ironic-API-Version' => "#{@version}" }
|
22
|
-
end
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
-
require 'misty/
|
2
|
+
require 'misty/microversion'
|
3
3
|
require 'misty/openstack/manila/manila_v2'
|
4
4
|
|
5
5
|
module Misty
|
6
6
|
module Openstack
|
7
7
|
module Manila
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
class V2 < Misty::HTTP::Client
|
9
|
+
extend Misty::Openstack::ManilaV2
|
10
|
+
include Misty::Microversion
|
11
11
|
|
12
12
|
def self.api
|
13
13
|
v2
|
@@ -16,10 +16,6 @@ module Misty
|
|
16
16
|
def self.service_names
|
17
17
|
%w{shared-file-systems shared}
|
18
18
|
end
|
19
|
-
|
20
|
-
def microversion_header
|
21
|
-
{ 'X-Openstack-Manila-API-Version' => "#{@version}" }
|
22
|
-
end
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'misty/http/client'
|
2
|
-
require 'misty/
|
2
|
+
require 'misty/microversion'
|
3
3
|
require 'misty/openstack/nova/nova_v2_1'
|
4
4
|
|
5
5
|
module Misty
|
@@ -7,7 +7,7 @@ module Misty
|
|
7
7
|
module Nova
|
8
8
|
class V2_1 < Misty::HTTP::Client
|
9
9
|
extend Misty::Openstack::NovaV2_1
|
10
|
-
include Misty::
|
10
|
+
include Misty::Microversion
|
11
11
|
|
12
12
|
def self.api
|
13
13
|
v2_1
|
@@ -27,12 +27,11 @@ module Misty
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def microversion_header
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
30
|
+
# Versions 2.27+ use default OpenStack-API-Version
|
31
|
+
header = super
|
32
|
+
# For prior vesions then remove once depcrecated
|
33
|
+
header.merge!('X-Openstack-Nova-API-Version' => "#{@version}",)
|
34
|
+
header
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
data/lib/misty/service.rb
CHANGED
@@ -10,10 +10,10 @@ module Misty
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_s
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
str = "#{name}: #{project}"
|
14
|
+
str << ", versions: #{@versions}" if @versions
|
15
|
+
str << ", microversion: #{@microversion}" if @microversion
|
16
|
+
str
|
17
17
|
end
|
18
18
|
|
19
19
|
def version(api_version = nil)
|
@@ -23,18 +23,11 @@ module Misty
|
|
23
23
|
default_version
|
24
24
|
end
|
25
25
|
|
26
|
+
private
|
27
|
+
|
26
28
|
def default_version
|
27
29
|
return @microversion if @microversion
|
28
30
|
return self.versions.sort[-1]
|
29
31
|
end
|
30
|
-
|
31
|
-
def version=(val)
|
32
|
-
if @versions.include?(val)
|
33
|
-
@version = val
|
34
|
-
else
|
35
|
-
# Use highest version
|
36
|
-
@version = versions.sort[-1]
|
37
|
-
end
|
38
|
-
end
|
39
32
|
end
|
40
33
|
end
|
data/lib/misty/version.rb
CHANGED
data/test/unit/auth_test.rb
CHANGED
@@ -177,12 +177,12 @@ describe Misty::Auth do
|
|
177
177
|
auth.catalog.must_equal ['catalog_data']
|
178
178
|
end
|
179
179
|
|
180
|
-
it '#
|
180
|
+
it '#get_url' do
|
181
181
|
stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
|
182
182
|
to_return(:status => 200, :body => JSON.dump(auth_response_v3("identity", "keystone")), :headers => {'x-subject-token'=>'token_data'})
|
183
183
|
|
184
184
|
auth = Misty::AuthV3.new(authv3_creds, config)
|
185
|
-
auth.
|
185
|
+
auth.get_url(%w{identity}, 'regionOne', 'public').must_equal 'http://localhost'
|
186
186
|
end
|
187
187
|
end
|
188
188
|
end
|
@@ -289,12 +289,12 @@ describe Misty::Auth do
|
|
289
289
|
auth.catalog.must_equal ['catalog_data']
|
290
290
|
end
|
291
291
|
|
292
|
-
it '#
|
292
|
+
it '#get_url' do
|
293
293
|
stub_request(:post, 'http://localhost:5000/v2.0/tokens').
|
294
294
|
to_return(:status => 200, :body => JSON.dump(auth_response_v2('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'})
|
295
295
|
|
296
296
|
auth = Misty::AuthV2.new(authv2_creds, config)
|
297
|
-
auth.
|
297
|
+
auth.get_url(%w{identity}, 'regionOne', 'public').must_equal 'http://localhost'
|
298
298
|
end
|
299
299
|
end
|
300
300
|
end
|
@@ -33,7 +33,6 @@ describe 'Misty::Cloud' do
|
|
33
33
|
let(:auth_headers) do
|
34
34
|
{ 'Accept' => 'application/json',
|
35
35
|
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
36
|
-
'Content-Type' => 'application/json',
|
37
36
|
'User-Agent' => 'Ruby' }
|
38
37
|
end
|
39
38
|
|
@@ -94,6 +93,10 @@ describe 'Misty::Cloud' do
|
|
94
93
|
with(:body => JSON.dump(auth_body), :headers => auth_headers).
|
95
94
|
to_return(:status => 200, :body => JSON.dump(auth_response_v3('volume', 'cinder')), :headers => token_header)
|
96
95
|
|
96
|
+
stub_request(:get, 'http://localhost/').
|
97
|
+
with(:headers => auth_headers).
|
98
|
+
to_return(:status => 200, :body => JSON.dump(versions), :headers => {})
|
99
|
+
|
97
100
|
cloud.block_storage.must_be_kind_of Misty::Openstack::Cinder::V3
|
98
101
|
end
|
99
102
|
|
@@ -21,12 +21,6 @@ describe Misty::HTTP::Client do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe '#headers_default' do
|
25
|
-
it 'returns hash' do
|
26
|
-
service.headers_default.must_be_kind_of Hash
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
24
|
describe '#headers' do
|
31
25
|
it 'returns hash' do
|
32
26
|
service.headers.must_be_kind_of Hash
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'auth_helper'
|
3
3
|
require 'misty/http/client'
|
4
|
-
require 'misty/
|
4
|
+
require 'misty/microversion'
|
5
5
|
|
6
|
-
describe Misty::
|
6
|
+
describe Misty::Microversion do
|
7
7
|
let(:versions_data) do
|
8
8
|
{ 'versions' =>
|
9
9
|
[{ 'status' => 'SUPPORTED',
|
@@ -23,7 +23,7 @@ describe Misty::HTTP::Microversion do
|
|
23
23
|
let(:microversion_service) do
|
24
24
|
auth = Minitest::Mock.new
|
25
25
|
|
26
|
-
def auth.
|
26
|
+
def auth.get_url(*args)
|
27
27
|
'http://localhost'
|
28
28
|
end
|
29
29
|
|
@@ -39,7 +39,7 @@ describe Misty::HTTP::Microversion do
|
|
39
39
|
setup.ssl_verify_mode = Misty::SSL_VERIFY_MODE
|
40
40
|
|
41
41
|
stub_request(:get, 'http://localhost/').
|
42
|
-
with(:headers => {'Accept'=>'application/json'
|
42
|
+
with(:headers => {'Accept'=>'application/json'}).
|
43
43
|
to_return(:status => 200, :body => JSON.dump(versions_data), :headers => {})
|
44
44
|
|
45
45
|
Misty::Openstack::Nova::V2_1.new(auth, setup, {})
|
@@ -57,19 +57,19 @@ describe Misty::HTTP::Microversion do
|
|
57
57
|
it 'fails when version is not within supporterd interval' do
|
58
58
|
proc do
|
59
59
|
microversion_service.version_get('2.0')
|
60
|
-
end.must_raise Misty::
|
60
|
+
end.must_raise Misty::Microversion::VersionError
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'fails when LATEST version is not available' do
|
64
64
|
proc do
|
65
65
|
microversion_service.version_get('LATEST')
|
66
|
-
end.must_raise Misty::
|
66
|
+
end.must_raise Misty::Microversion::VersionError
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'fails when using an invalid version State' do
|
70
70
|
proc do
|
71
71
|
microversion_service.version_get('OTHER')
|
72
|
-
end.must_raise Misty::
|
72
|
+
end.must_raise Misty::Microversion::VersionError
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
data/test/unit/service_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'misty/http/client'
|
2
2
|
|
3
3
|
def request_header
|
4
|
-
{'Accept'=>
|
4
|
+
{'Accept' => 'application/json'}
|
5
5
|
end
|
6
6
|
|
7
7
|
def service(content_type = :ruby)
|
8
8
|
auth = Minitest::Mock.new
|
9
9
|
|
10
|
-
def auth.
|
10
|
+
def auth.get_url(*args)
|
11
11
|
'http://localhost'
|
12
12
|
end
|
13
13
|
|
data/test/unit/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: misty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilles Dubreuil
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/misty/http/method_builder.rb
|
139
139
|
- lib/misty/http/net_http.rb
|
140
140
|
- lib/misty/http/request.rb
|
141
|
+
- lib/misty/microversion.rb
|
141
142
|
- lib/misty/misty.rb
|
142
143
|
- lib/misty/openstack/aodh/aodh_v2.rb
|
143
144
|
- lib/misty/openstack/aodh/v2.rb
|
@@ -173,7 +174,6 @@ files:
|
|
173
174
|
- lib/misty/openstack/magnum/v1.rb
|
174
175
|
- lib/misty/openstack/manila/manila_v2.rb
|
175
176
|
- lib/misty/openstack/manila/v2.rb
|
176
|
-
- lib/misty/openstack/microversion.rb
|
177
177
|
- lib/misty/openstack/murano/murano_v1.rb
|
178
178
|
- lib/misty/openstack/murano/v1.rb
|
179
179
|
- lib/misty/openstack/neutron/neutron_v2_0.rb
|
@@ -216,9 +216,9 @@ files:
|
|
216
216
|
- test/unit/http/direct_test.rb
|
217
217
|
- test/unit/http/method_builder_test.rb
|
218
218
|
- test/unit/http/request_test.rb
|
219
|
+
- test/unit/microversion_test.rb
|
219
220
|
- test/unit/misty_test.rb
|
220
221
|
- test/unit/openstack/APIs_test.rb
|
221
|
-
- test/unit/openstack/microversion_test.rb
|
222
222
|
- test/unit/service_helper.rb
|
223
223
|
- test/unit/services_test.rb
|
224
224
|
- test/unit/test_helper.rb
|
@@ -235,7 +235,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
235
235
|
requirements:
|
236
236
|
- - ">="
|
237
237
|
- !ruby/object:Gem::Version
|
238
|
-
version: '
|
238
|
+
version: '2.3'
|
239
239
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
240
240
|
requirements:
|
241
241
|
- - ">="
|
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
243
|
version: '0'
|
244
244
|
requirements: []
|
245
245
|
rubyforge_project:
|
246
|
-
rubygems_version: 2.6.
|
246
|
+
rubygems_version: 2.6.13
|
247
247
|
signing_key:
|
248
248
|
specification_version: 4
|
249
249
|
summary: Misty is an OpenStack API client
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Misty
|
2
|
-
# TODO: move to Openstack module
|
3
|
-
module HTTP
|
4
|
-
module Microversion
|
5
|
-
class VersionError < RuntimeError; end
|
6
|
-
|
7
|
-
VERSION_STATES = %w{CURRENT LATEST SUPPORTED}
|
8
|
-
|
9
|
-
def initialize(auth, cloud, options)
|
10
|
-
super
|
11
|
-
@microversion = true
|
12
|
-
@version = version_get(@options.version)
|
13
|
-
end
|
14
|
-
|
15
|
-
def version_get(version_option)
|
16
|
-
if VERSION_STATES.include?(version_option)
|
17
|
-
return version_by_state(version_option)
|
18
|
-
else
|
19
|
-
return version_by_number(version_option)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def versions
|
24
|
-
@versions ||= versions_fetch
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def version_by_number(number)
|
30
|
-
versions.each do |version|
|
31
|
-
return number if version['min_version'] <= number && version['version'] >= number
|
32
|
-
end
|
33
|
-
raise VersionError, "Version #{number} is out of range of available versions #{versions}"
|
34
|
-
end
|
35
|
-
|
36
|
-
def version_by_state(state)
|
37
|
-
version_details = nil
|
38
|
-
versions.each do |version|
|
39
|
-
if version['status'] == state
|
40
|
-
version_details = version
|
41
|
-
break
|
42
|
-
end
|
43
|
-
end
|
44
|
-
raise VersionError, "Version #{state} is not available among #{versions}" if version_details.nil?
|
45
|
-
if version_details['version'].empty?
|
46
|
-
@microversion = false
|
47
|
-
return ''
|
48
|
-
end
|
49
|
-
version_details['version']
|
50
|
-
end
|
51
|
-
|
52
|
-
def versions_fetch
|
53
|
-
response = http_get('/', headers_default)
|
54
|
-
raise VersionError, "Code: #{response.code}, Message: #{response.msg}" unless response.code =~ /2??/
|
55
|
-
data = response.body.is_a?(Hash) ? response.body : JSON.parse(response.body)
|
56
|
-
list = data['versions']
|
57
|
-
raise VersionError, 'Missing version data' unless list
|
58
|
-
list
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|