misty 1.3.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +332 -267
  3. data/lib/misty.rb +1 -1
  4. data/lib/misty/auth.rb +17 -6
  5. data/lib/misty/auth/auth_v2.rb +3 -0
  6. data/lib/misty/auth/auth_v3.rb +13 -5
  7. data/lib/misty/auth/name.rb +3 -3
  8. data/lib/misty/client_pack.rb +2 -2
  9. data/lib/misty/cloud.rb +111 -76
  10. data/lib/misty/config.rb +138 -0
  11. data/lib/misty/{auth/errors.rb → errors.rb} +9 -1
  12. data/lib/misty/http/direct.rb +18 -1
  13. data/lib/misty/http/method_builder.rb +10 -17
  14. data/lib/misty/http/net_http.rb +1 -1
  15. data/lib/misty/http/request.rb +26 -14
  16. data/lib/misty/microversion.rb +22 -41
  17. data/lib/misty/misty.rb +14 -24
  18. data/lib/misty/openstack/cinder/v3.rb +8 -0
  19. data/lib/misty/openstack/ironic/v1.rb +8 -0
  20. data/lib/misty/openstack/magnum/v1.rb +5 -1
  21. data/lib/misty/openstack/manila/v2.rb +8 -0
  22. data/lib/misty/openstack/nova/v2_1.rb +13 -8
  23. data/lib/misty/openstack/service.rb +88 -0
  24. data/lib/misty/openstack/swift/v1.rb +2 -2
  25. data/lib/misty/service.rb +9 -12
  26. data/lib/misty/version.rb +1 -1
  27. data/test/integration/{network_test.rb → networking_test.rb} +8 -8
  28. data/test/integration/test_helper.rb +1 -0
  29. data/test/integration/vcr/{network_using_neutron_v2_0.yml → networking_using_neutron_v2_0.yml} +0 -0
  30. data/test/unit/auth/name_test.rb +31 -27
  31. data/test/unit/auth_helper.rb +4 -4
  32. data/test/unit/auth_test.rb +44 -30
  33. data/test/unit/cloud/config_test.rb +165 -0
  34. data/test/unit/cloud/requests_test.rb +0 -12
  35. data/test/unit/cloud/services_test.rb +41 -12
  36. data/test/unit/cloud_test.rb +35 -44
  37. data/test/unit/http/request_test.rb +1 -1
  38. data/test/unit/microversion_test.rb +59 -35
  39. data/test/unit/misty_test.rb +1 -1
  40. data/test/unit/openstack/service_test.rb +52 -0
  41. data/test/unit/service_helper.rb +23 -20
  42. data/test/unit/services_test.rb +1 -1
  43. data/test/unit/test_helper.rb +0 -4
  44. metadata +37 -22
  45. data/lib/misty/client.rb +0 -104
  46. data/test/unit/client_test.rb +0 -97
@@ -75,7 +75,7 @@ describe Misty do
75
75
  end
76
76
 
77
77
  it 'has dns service' do
78
- service = Misty::services.find { |s| s.name == :domain_name_server}
78
+ service = Misty::services.find { |s| s.name == :dns}
79
79
  validate_service(service)
80
80
  validate_versions(service)
81
81
  end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+ require 'service_helper'
3
+ require 'misty/openstack/service'
4
+
5
+ describe Misty::Openstack::Service do
6
+ describe '#prefix_path_to_ignore' do
7
+ let(:service) do
8
+ service = Object.new
9
+ service.extend(Misty::Openstack::Service)
10
+ service
11
+ end
12
+
13
+ it "returns empty String when undefined in API's module" do
14
+ service.prefix_path_to_ignore.must_be_empty
15
+ end
16
+
17
+ it "returns String when defined in API's module" do
18
+ class << service
19
+ def prefix_path_to_ignore
20
+ '/v3/{tenant_id}'
21
+ end
22
+ end
23
+
24
+ service.prefix_path_to_ignore.must_equal '/v3/{tenant_id}'
25
+ end
26
+ end
27
+
28
+ describe '#requests' do
29
+ it 'returns list of requests' do
30
+ list = service.requests
31
+ list.must_be_kind_of Array
32
+ list.must_include :list_service_profiles
33
+ end
34
+ end
35
+
36
+ describe '#baseclass' do
37
+ it 'returns base class name' do
38
+ service.send(:baseclass).must_equal 'V2_0'
39
+ end
40
+ end
41
+
42
+ describe 'headers' do
43
+ it 'returns default global along with token' do
44
+ service.headers.get.must_equal ({"Accept"=>"application/json; q=1.0"})
45
+ end
46
+
47
+ it 'inject headers parameter' do
48
+ service(content_type = :hash, params = {:headers => {'Oh' => 'my!'}}).
49
+ headers.get.must_equal ({"Accept"=>"application/json; q=1.0", "Oh"=>"my!"})
50
+ end
51
+ end
52
+ end
@@ -1,31 +1,34 @@
1
1
  require 'misty/client_pack'
2
+ require 'auth_helper'
2
3
 
3
4
  def request_header
4
5
  {'Accept' => 'application/json; q=1.0'}
5
6
  end
6
7
 
7
- def service(content_type = :ruby, params = {})
8
- auth = Minitest::Mock.new
8
+ def service(param_content_type = :hash, params = {})
9
+ arg = {
10
+ :auth => {
11
+ :url => 'http://localhost:5000',
12
+ :user_id => 'user_id',
13
+ :password => 'secret',
14
+ :project_id => 'project_id',
15
+ :ssl_verify_mode => false
16
+ },
17
+ :content_type => param_content_type,
18
+ }
19
+ arg.merge!(params)
9
20
 
10
- def auth.get_url(*args)
11
- 'http://localhost'
12
- end
21
+ stub_request(:post, "http://localhost:5000/v3/auth/tokens").
22
+ with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\"user_id\",\"password\":\"secret\"}}},\"scope\":{\"project\":{\"id\":\"project_id\"}}}}",
23
+ :headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
24
+ to_return(:status => 200, :body => JSON.dump(auth_response_v3('networking', 'neutron')), :headers => {'x-subject-token'=>'token_data'})
13
25
 
14
- def auth.get_token
15
- 'token_id'
16
- end
26
+ config = Misty::Config.new(arg)
17
27
 
18
- setup = Misty::Cloud::Config.new
19
- setup.content_type = content_type
20
- setup.log = Logger.new('/dev/null')
21
- setup.interface = Misty::INTERFACE
22
- setup.region_id = Misty::REGION_ID
23
- setup.ssl_verify_mode = Misty::SSL_VERIFY_MODE
24
- setup.headers = Misty::HTTP::Header.new('Accept' => 'application/json; q=1.0')
28
+ # TODO: remove
29
+ # stub_request(:post, 'http://localhost:5000/v3/auth/tokens').
30
+ # with(:body => "{\"auth\":{\"identity\":{\"methods\":[\"password\"],\"password\":{\"user\":{\"id\":\"user_id\",\"password\":\"secret\"}}},\"scope\":{\"project\":{\"id\":\"project_id\"}}}}").
31
+ # to_return(:status => 200, :body => JSON.dump(auth_response_v3('identity', 'keystone')), :headers => {'x-subject-token'=>'token_data'})
25
32
 
26
- stub_request(:get, 'http://localhost/').
27
- with(:headers => request_header).
28
- to_return(:status => 200, :body => '', :headers => {})
29
-
30
- Misty::Openstack::Neutron::V2_0.new(auth, setup, params)
33
+ Misty::Openstack::Neutron::V2_0.new(config.get_service(:networking))
31
34
  end
@@ -13,7 +13,7 @@ describe 'Services' do
13
13
  service.project.must_equal :project_name
14
14
  service.versions.must_include 'v1'
15
15
  service.microversion.must_equal 'v3'
16
- service.version.must_equal 'v3'
16
+ service.default_version.must_equal 'v3'
17
17
  services.to_s.must_equal %Q{service_name: project_name, versions: ["v1", "v2.0"], microversion: v3\n}
18
18
  end
19
19
  end
@@ -4,7 +4,3 @@ require 'minitest/autorun'
4
4
  require 'webmock/minitest'
5
5
  require 'misty'
6
6
  require 'pry-byebug'
7
-
8
- module Misty
9
- LOG_FILE = '/dev/null'
10
- end
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: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilles Dubreuil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-06 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -45,47 +45,61 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.10'
47
47
  - !ruby/object:Gem::Dependency
48
- name: rake
48
+ name: minitest
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '10.0'
53
+ version: '5.10'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '10.0'
60
+ version: '5.10'
61
61
  - !ruby/object:Gem::Dependency
62
- name: minitest
62
+ name: pry-byebug
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '5.10'
67
+ version: '3.4'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '5.10'
74
+ version: '3.4'
75
75
  - !ruby/object:Gem::Dependency
76
- name: webmock
76
+ name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '2.3'
81
+ version: '10.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '2.3'
88
+ version: '10.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rdoc
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '6.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '6.0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: vcr
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -101,21 +115,20 @@ dependencies:
101
115
  - !ruby/object:Gem::Version
102
116
  version: '3.0'
103
117
  - !ruby/object:Gem::Dependency
104
- name: pry-byebug
118
+ name: webmock
105
119
  requirement: !ruby/object:Gem::Requirement
106
120
  requirements:
107
121
  - - "~>"
108
122
  - !ruby/object:Gem::Version
109
- version: '3.4'
123
+ version: '2.3'
110
124
  type: :development
111
125
  prerelease: false
112
126
  version_requirements: !ruby/object:Gem::Requirement
113
127
  requirements:
114
128
  - - "~>"
115
129
  - !ruby/object:Gem::Version
116
- version: '3.4'
117
- description: Misty is a dedicated HTTP client for OpenStack providing dynamic APIs
118
- requests management.
130
+ version: '2.3'
131
+ description: Misty is a HTTP client for OpenStack APIs, aiming to be slick and dynamic.
119
132
  email:
120
133
  - gilles@redhat.com
121
134
  executables: []
@@ -130,12 +143,12 @@ files:
130
143
  - lib/misty/auth.rb
131
144
  - lib/misty/auth/auth_v2.rb
132
145
  - lib/misty/auth/auth_v3.rb
133
- - lib/misty/auth/errors.rb
134
146
  - lib/misty/auth/name.rb
135
147
  - lib/misty/autoload.rb
136
- - lib/misty/client.rb
137
148
  - lib/misty/client_pack.rb
138
149
  - lib/misty/cloud.rb
150
+ - lib/misty/config.rb
151
+ - lib/misty/errors.rb
139
152
  - lib/misty/http/direct.rb
140
153
  - lib/misty/http/header.rb
141
154
  - lib/misty/http/method_builder.rb
@@ -192,6 +205,7 @@ files:
192
205
  - lib/misty/openstack/searchlight/v1.rb
193
206
  - lib/misty/openstack/senlin/senlin_v1.rb
194
207
  - lib/misty/openstack/senlin/v1.rb
208
+ - lib/misty/openstack/service.rb
195
209
  - lib/misty/openstack/swift/swift_v1.rb
196
210
  - lib/misty/openstack/swift/v1.rb
197
211
  - lib/misty/openstack/tacker/tacker_v1_0.rb
@@ -204,16 +218,16 @@ files:
204
218
  - lib/misty/services.rb
205
219
  - lib/misty/version.rb
206
220
  - test/integration/compute_test.rb
207
- - test/integration/network_test.rb
221
+ - test/integration/networking_test.rb
208
222
  - test/integration/orchestration_test.rb
209
223
  - test/integration/test_helper.rb
210
224
  - test/integration/vcr/compute_using_nova_v2_1.yml
211
- - test/integration/vcr/network_using_neutron_v2_0.yml
225
+ - test/integration/vcr/networking_using_neutron_v2_0.yml
212
226
  - test/integration/vcr/orchestration_using_heat_v1.yml
213
227
  - test/unit/auth/name_test.rb
214
228
  - test/unit/auth_helper.rb
215
229
  - test/unit/auth_test.rb
216
- - test/unit/client_test.rb
230
+ - test/unit/cloud/config_test.rb
217
231
  - test/unit/cloud/requests_test.rb
218
232
  - test/unit/cloud/services_test.rb
219
233
  - test/unit/cloud_test.rb
@@ -225,6 +239,7 @@ files:
225
239
  - test/unit/misty_test.rb
226
240
  - test/unit/openstack/APIs_test.rb
227
241
  - test/unit/openstack/extension_test.rb
242
+ - test/unit/openstack/service_test.rb
228
243
  - test/unit/service_helper.rb
229
244
  - test/unit/services_test.rb
230
245
  - test/unit/test_helper.rb
@@ -249,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
264
  version: '0'
250
265
  requirements: []
251
266
  rubyforge_project:
252
- rubygems_version: 2.6.14
267
+ rubygems_version: 2.6.14.1
253
268
  signing_key:
254
269
  specification_version: 4
255
270
  summary: Misty is an OpenStack API client
@@ -1,104 +0,0 @@
1
- module Misty
2
- module Client
3
- class Options
4
- attr_accessor :base_path, :base_url, :headers, :interface, :region_id,
5
- :service_names, :ssl_verify_mode, :version
6
- end
7
-
8
- class InvalidDataError < StandardError; end
9
-
10
- INTERFACES = %w{admin public internal}
11
-
12
- attr_reader :headers, :microversion
13
-
14
- # Options - Values shown are the default
15
- # Base path can be forced (Not recommended, mainly used for test purposes)
16
- # :base_path => nil
17
- # URL can be forced (Helps when setup is broken)
18
- # :base_url => nil
19
- # Optional headers
20
- # :headers => {}
21
- # Endpoint type (admin, public or internal)
22
- # :interface => "public"
23
- # Region ID
24
- # :region_id => "regionOne"
25
- # Service name
26
- # The Service names are pre defined but more can be added using this option.
27
- # :service_name
28
- # SSL Verify Mode
29
- # :ssl_verify_mode => true
30
- # (micro)version: Can be numbered (3.1) or by state (CURRENT, LATEST or SUPPORTED)
31
- # :version => "CURRENT"
32
- def initialize(auth, config, options = {})
33
- @auth = auth
34
- @config = config
35
- @options = setup(options)
36
- @uri = URI.parse(@auth.get_url(@options.service_names, @options.region_id, @options.interface))
37
- @base_path = @options.base_path ? @options.base_path : @uri.path
38
- @base_path = @base_path.chomp('/')
39
- @version = nil
40
- @microversion = false
41
- @headers = Misty::HTTP::Header.new(@config.headers.get.clone)
42
- @headers.add(microversion_header) if microversion
43
- @headers.add(@options.headers) unless @options.headers.empty?
44
- end
45
-
46
- # Mixing classes to override
47
- # When a catalog provides a base path and the Service API definition containts the generic equivalent as prefix
48
- # then the preifx is redundant and must be removed from the path.
49
- # For example:
50
- # Catalog provides 'http://192.0.2.21:8004/v1/48985e6b8da145699d411f12a3459fca'
51
- # and Service API has '/v1/{tenant_id}/stacks'
52
- # then the path prefix is ignored and path is only '/stacks'
53
- def prefix_path_to_ignore
54
- ''
55
- end
56
-
57
- def requests
58
- requests_api + requests_custom
59
- end
60
-
61
- private
62
-
63
- def baseclass
64
- self.class.to_s.split('::')[-1]
65
- end
66
-
67
- def requests_api
68
- @requests_api_list ||= begin
69
- list = []
70
- api.each do |_path, verbs|
71
- verbs.each do |_verb, requests|
72
- list << requests
73
- end
74
- end
75
- list.flatten!
76
- end
77
- end
78
-
79
- def requests_custom
80
- []
81
- end
82
-
83
- def setup(params)
84
- options = Options.new()
85
- options.base_path = params[:base_path] ? params[:base_path] : nil
86
- options.base_url = params[:base_url] ? params[:base_url] : nil
87
- options.headers = params[:headers] ? params[:headers] : {}
88
- options.interface = params[:interface] ? params[:interface] : @config.interface
89
- options.region_id = params[:region_id] ? params[:region_id] : @config.region_id
90
- options.service_names = params[:service_name] ? service_names << params[:service_name] : service_names
91
- options.ssl_verify_mode = params[:ssl_verify_mode].nil? ? @config.ssl_verify_mode : params[:ssl_verify_mode]
92
- options.version = params[:version] ? params[:version] : 'CURRENT'
93
-
94
- unless INTERFACES.include?(options.interface)
95
- raise InvalidDataError, "Options ':interface' must be one of #{INTERFACES}"
96
- end
97
-
98
- unless options.ssl_verify_mode == !!options.ssl_verify_mode
99
- raise InvalidDataError, "Options ':ssl_verify_mode' must be a boolean"
100
- end
101
- options
102
- end
103
- end
104
- end
@@ -1,97 +0,0 @@
1
- require 'test_helper'
2
- require 'service_helper'
3
- require 'misty/client'
4
-
5
- describe Misty::Client do
6
- describe '#prefix_path_to_ignore' do
7
- let(:client) do
8
- client = Object.new
9
- client.extend(Misty::Client)
10
- client
11
- end
12
-
13
- it "returns empty String when undefined in API's module" do
14
- client.prefix_path_to_ignore.must_be_empty
15
- end
16
-
17
- it "returns String when defined in API's module" do
18
- class << client
19
- def prefix_path_to_ignore
20
- '/v3/{tenant_id}'
21
- end
22
- end
23
-
24
- client.prefix_path_to_ignore.must_equal '/v3/{tenant_id}'
25
- end
26
- end
27
-
28
- describe '#requests' do
29
- it 'returns list of requests' do
30
- list = service.requests
31
- list.must_be_kind_of Array
32
- list.must_include :list_service_profiles
33
- end
34
- end
35
-
36
- describe '#baseclass' do
37
- it 'returns base class name' do
38
- service.send(:baseclass).must_equal 'V2_0'
39
- end
40
- end
41
-
42
- describe '#setup' do
43
- it 'use default options' do
44
- options = service.send(:setup, {})
45
- options.must_be_kind_of Misty::Client::Options
46
- options.base_path.must_be_nil
47
- options.base_url.must_be_nil
48
- options.headers.must_equal ({})
49
- options.interface.must_equal 'public'
50
- options.region_id.must_equal 'regionOne'
51
- options.service_names.must_include 'network'
52
- options.ssl_verify_mode.must_equal true
53
- options.version.must_equal 'CURRENT'
54
- end
55
-
56
- it 'use custom options' do
57
- options = service.send(:setup, {
58
- :base_path => '/test_path',
59
- :base_url => 'test_url',
60
- :headers => {'Key 1' => 'Value 1'},
61
- :region_id => 'regionTwo',
62
- :interface => 'internal',
63
- :ssl_verify_mode => false,
64
- :version => 'LATEST'})
65
- options.base_path.must_equal '/test_path'
66
- options.base_url.must_equal 'test_url'
67
- options.headers.must_equal ({'Key 1' => 'Value 1'})
68
- options.interface.must_equal 'internal'
69
- options.region_id.must_equal 'regionTwo'
70
- options.ssl_verify_mode.must_equal false
71
- options.version.must_equal 'LATEST'
72
- end
73
-
74
- it 'fails with invalid interface' do
75
- proc do
76
- service.send(:setup, {:interface => 'something'})
77
- end.must_raise Misty::Client::InvalidDataError
78
- end
79
-
80
- it 'fails unless ssl_verify_mode is a boolean' do
81
- proc do
82
- service.send(:setup, {:ssl_verify_mode => 'something'})
83
- end.must_raise Misty::Client::InvalidDataError
84
- end
85
- end
86
-
87
- describe 'headers' do
88
- it 'returns default global along with token' do
89
- service.headers.get.must_equal ({"Accept"=>"application/json; q=1.0"})
90
- end
91
-
92
- it 'inject headers parameter' do
93
- service(content_type = :ruby, params = {:headers => {'Oh' => 'my!'}}).
94
- headers.get.must_equal ({"Accept"=>"application/json; q=1.0", "Oh"=>"my!"})
95
- end
96
- end
97
- end