yao 0.12.0 → 0.13.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2ea8c98f6fdefadcfeca2782ed5dde20a91423afc3cc44b925a64fdee3b552a
4
- data.tar.gz: a0993ca6bd8ddb9a222d632e98c77031682b492756be20c164632410da64bed4
3
+ metadata.gz: 9ee889ea30a4ed867e8f34bcb5fd185f194b317320fd8f5797f1a7b24b232e66
4
+ data.tar.gz: 745bb13217eb75907e47732b457ac41cd90330f23becb0936e4c13beabdeb6e3
5
5
  SHA512:
6
- metadata.gz: aa2d0252174bc0e69a7697d6fb8e90aba053105fa416219bb5c7b0800a861fcffee6d1e48d0fdc3d84a38f20cb4790d8030dbafbae65f1548c221ae79dbd7e52
7
- data.tar.gz: ccef8bca36eda0c7191017929f466a9b424ca8ac697e2e0f104519394ccdc022bd7159391ad1cfebbf9590635ca4b74c5a5705823b2fc54a27027877e252bcb5
6
+ metadata.gz: bddf10dfefb8277e6ad2dda817ab08b54ede238586c1f4fd913b8648a257d4c8e79cb7301976cbf02f5991b4ffd8a0199d7a06db604d21a9f63438dea263801f
7
+ data.tar.gz: 2e572a0ca854f98b118cb081daf3a862b3ad60ffcb7e8e0ba58d35d64cdaf40578a507cdd2b578c05b576be5d61c7d92161e251c03e0d6396fa73384599a2520
data/README.md CHANGED
@@ -34,7 +34,8 @@ Yao.configure do
34
34
  # timeout is optional
35
35
  timeout 300
36
36
 
37
- # If your endpoint requires cert & key
37
+ # If your endpoint requires cacert,cert and key
38
+ ca_cert "/path/to/my.ca"
38
39
  client_cert "/path/to/my.pem"
39
40
  client_key "/path/to/my.key"
40
41
 
@@ -5,7 +5,7 @@ require 'yao/token'
5
5
  require 'yao/tokenv3'
6
6
 
7
7
  module Yao
8
- %i(tenant_name username password timeout client_cert client_key region_name
8
+ %i(tenant_name username password timeout ca_cert client_cert client_key region_name
9
9
  identity_api_version user_domain_id user_domain_name project_domain_id project_domain_name).each do |name|
10
10
  Yao.config.param name, nil
11
11
  end
@@ -124,13 +124,17 @@ module Yao
124
124
  end
125
125
 
126
126
  # Client Certificate Authentication
127
- if Yao.config.client_cert && Yao.config.client_key
128
- cert = OpenSSL::X509::Certificate.new(File.read(Yao.config.client_cert))
129
- key = OpenSSL::PKey.read(File.read(Yao.config.client_key))
130
- opt.merge!(ssl: {
131
- client_cert: cert,
132
- client_key: key,
133
- })
127
+ if (Yao.config.client_cert && Yao.config.client_key) || Yao.config.ca_cert
128
+ h = {}
129
+ if Yao.config.client_cert && Yao.config.client_key
130
+ cert = OpenSSL::X509::Certificate.new(File.read(Yao.config.client_cert))
131
+ key = OpenSSL::PKey.read(File.read(Yao.config.client_key))
132
+ h[:client_cert] = cert
133
+ h[:client_key] = key
134
+ end
135
+
136
+ h[:ca_file] = Yao.config.ca_cert if Yao.config.ca_cert
137
+ opt.merge!(ssl: h)
134
138
  end
135
139
  opt
136
140
  end
@@ -1,6 +1,7 @@
1
1
  module Yao
2
2
  class ReadOnlyViolationError < ::StandardError; end
3
3
  class TooManyItemFonud < ::StandardError; end
4
+ class InvalidResponse < ::StandardError; end
4
5
 
5
6
  class ServerError < ::StandardError
6
7
  def initialize(message, requested_env)
@@ -64,6 +64,19 @@ class Faraday::Request::ReadOnly
64
64
  end
65
65
  Faraday::Request.register_middleware read_only: -> { Faraday::Request::ReadOnly }
66
66
 
67
+ class Faraday::Request::UserAgent
68
+ def initialize(app, user_agent=nil)
69
+ @app = app
70
+ @user_agent = user_agent || "Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"
71
+ end
72
+
73
+ def call(env)
74
+ env[:request_headers]['User-Agent'] = @user_agent
75
+ @app.call(env)
76
+ end
77
+ end
78
+ Faraday::Request.register_middleware user_agent: -> { Faraday::Request::UserAgent }
79
+
67
80
  class Faraday::Response::OSDumper < Faraday::Response::Middleware
68
81
  def on_complete(env)
69
82
  require 'pp'
@@ -8,6 +8,7 @@ module Yao::Plugins
8
8
  def call(f, token)
9
9
  f.request :accept, 'application/json'
10
10
  f.request :url_encoded
11
+ f.request :user_agent
11
12
 
12
13
  if token
13
14
  f.request :os_token, token
@@ -5,7 +5,7 @@ module Yao::Resources
5
5
  req.body = query.to_json
6
6
  req.headers['Content-Type'] = 'application/json'
7
7
  end
8
- res.body ? resource_from_json(res.body) : nil
8
+ res.body
9
9
  end
10
10
 
11
11
  private
@@ -7,7 +7,7 @@ module Yao::Resources
7
7
  names.map(&:to_s).each do |name|
8
8
  define_method(name) do
9
9
  if !@data.key?(name) && id
10
- @data = self.class.get(id)
10
+ @data = self.class.get(id).to_hash
11
11
  end
12
12
  self[name]
13
13
  end
@@ -51,6 +51,10 @@ module Yao::Resources
51
51
  @data[name] = value
52
52
  end
53
53
 
54
+ def to_hash
55
+ @data
56
+ end
57
+
54
58
  def id
55
59
  self["id"]
56
60
  end
@@ -25,5 +25,16 @@ module Yao::Resources
25
25
  self.resources_name = "images"
26
26
 
27
27
  extend MetadataAvailable
28
+
29
+ class << self
30
+ private
31
+
32
+ # override Yao::Resources::RestfullyAccessible.resource_from_json
33
+ # @param json [Hash]
34
+ # @return [Yao::Resources::*]
35
+ def resource_from_json(json)
36
+ new(json)
37
+ end
38
+ end
28
39
  end
29
40
  end
@@ -1,5 +1,5 @@
1
1
  require "forwardable"
2
-
2
+ require "deep_merge"
3
3
  module Yao::Resources
4
4
  module RestfullyAccessible
5
5
  def self.extended(base)
@@ -85,12 +85,27 @@ module Yao::Resources
85
85
  else
86
86
  create_url
87
87
  end
88
-
89
- json = GET(url, query).body
88
+ memo_query = query
89
+ res = {}
90
+ loop do
91
+ r = GET(url, query).body
92
+ if r.is_a?(Hash)
93
+ res.deep_merge!(r)
94
+ links = r.find {|k,_| k =~ /links/ }
95
+ if links && links.last.is_a?(Array) && next_link = links.last.find{|s| s["rel"] == "next" }
96
+ uri = URI.parse(next_link["href"])
97
+ query = Hash[URI::decode_www_form(uri.query)] if uri.query
98
+ next
99
+ end
100
+ else
101
+ res = r
102
+ end
103
+ break
104
+ end
90
105
  if return_single_on_querying && !query.empty?
91
- [resource_from_json(json)]
106
+ [resource_from_json(res)]
92
107
  else
93
- resources_from_json(json)
108
+ resources_from_json(res)
94
109
  end
95
110
  end
96
111
 
@@ -211,6 +226,8 @@ module Yao::Resources
211
226
  item = find_by_name(name)
212
227
  if item.size > 1
213
228
  raise Yao::TooManyItemFonud.new("More than one resource exists with the name '#{name}'")
229
+ elsif item.size.zero?
230
+ raise Yao::InvalidResponse.new("No resource exists with the name '#{name}'")
214
231
  end
215
232
  GET(create_url(item.first.id), query)
216
233
  end
@@ -37,7 +37,7 @@ module Yao::Resources
37
37
  def list_for_user(user_name, on:)
38
38
  user = Yao::User.get(user_name)
39
39
  tenant = if api_version_v2?
40
- Yao::Tenant.find_by_name(on)
40
+ Yao::Tenant.get(on)
41
41
  else
42
42
  Yao::Project.get(on)
43
43
  end
@@ -54,7 +54,7 @@ module Yao::Resources
54
54
  role = Yao::Role.get(role_name)
55
55
  user = Yao::User.get(to)
56
56
  tenant = if api_version_v2?
57
- Yao::Tenant.find_by_name(on)
57
+ Yao::Tenant.get(on)
58
58
  else
59
59
  Yao::Project.get(on)
60
60
  end
@@ -71,7 +71,7 @@ module Yao::Resources
71
71
  role = Yao::Role.get(role_name)
72
72
  user = Yao::User.get(from)
73
73
  tenant = if api_version_v2?
74
- Yao::Tenant.find_by_name(on)
74
+ Yao::Tenant.get(on)
75
75
  else
76
76
  Yao::Project.get(on)
77
77
  end
@@ -53,6 +53,11 @@ module Yao::Resources
53
53
  action(id, {"removeSecurityGroup": {"name": sg_name}})
54
54
  end
55
55
 
56
+ def self.get_vnc_console(id)
57
+ response = action(id, {"os-getVNCConsole": {"type": "novnc"}})
58
+ response.dig("console", "url")
59
+ end
60
+
56
61
  class << self
57
62
  alias :stop :shutoff
58
63
  end
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.4"
3
3
  end
@@ -41,6 +41,6 @@ module RestfullyAccessibleStub
41
41
  end
42
42
 
43
43
  def request_headers
44
- {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"}
44
+ {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"}
45
45
  end
46
46
  end
@@ -80,7 +80,7 @@ class TestHypervisor < TestYaoResource
80
80
 
81
81
  def test_list
82
82
  stub = stub_request(:get, "https://example.com:12345/os-hypervisors/detail")
83
- .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"})
83
+ .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"})
84
84
  .to_return(
85
85
  status: 200,
86
86
  body: <<-JSON,
@@ -105,7 +105,7 @@ class TestHypervisor < TestYaoResource
105
105
 
106
106
  def test_statistics
107
107
  stub = stub_request(:get, "https://example.com:12345/os-hypervisors/statistics")
108
- .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"})
108
+ .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"})
109
109
  .to_return(
110
110
  status: 200,
111
111
  body: <<-JSON,
@@ -137,7 +137,7 @@ class TestHypervisor < TestYaoResource
137
137
 
138
138
  def test_uptime
139
139
  stub = stub_request(:get, "https://example.com:12345/os-hypervisors/1/uptime")
140
- .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"})
140
+ .with(headers: {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"})
141
141
  .to_return(
142
142
  status: 200,
143
143
  body: <<-JSON,
@@ -1,44 +1,142 @@
1
1
  class TestImage < TestYaoResource
2
+ # https://docs.openstack.org/api-ref/compute/?expanded=list-flavors-detail,list-flavors-with-details-detail,list-hosts-detail,show-host-details-detail,list-images-detail,list-images-with-details-detail#list-images-with-details
3
+ @@params = {
4
+ "OS-DCF:diskConfig" => "AUTO",
5
+ "OS-EXT-IMG-SIZE:size" => 74185822,
6
+ "created" => "2011-01-01T01:02:03Z",
7
+ "id" => "70a599e0-31e7-49b7-b260-868f441e862b",
8
+ "links" => [
9
+ {
10
+ "href" => "http://openstack.example.com/v2/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
11
+ "rel" => "self"
12
+ },
13
+ {
14
+ "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
15
+ "rel" => "bookmark"
16
+ },
17
+ {
18
+ "href" => "http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b",
19
+ "rel" => "alternate",
20
+ "type" => "application/vnd.openstack.image"
21
+ }
22
+ ],
23
+ "metadata" => {
24
+ "architecture" => "x86_64",
25
+ "auto_disk_config" => "True",
26
+ "kernel_id" => "nokernel",
27
+ "ramdisk_id" => "nokernel"
28
+ },
29
+ "minDisk" => 0,
30
+ "minRam" => 0,
31
+ "name" => "fakeimage7",
32
+ "progress" => 100,
33
+ "status" => "ACTIVE",
34
+ "updated" => "2011-01-01T01:02:03Z"
35
+ }
2
36
 
3
37
  def test_image
4
38
 
5
- # https://docs.openstack.org/api-ref/compute/?expanded=list-flavors-detail,list-flavors-with-details-detail,list-hosts-detail,show-host-details-detail,list-images-detail,list-images-with-details-detail#list-images-with-details
6
- params = {
39
+ image = Yao::Resources::Image.new(@@params)
40
+ check_image(image)
41
+
42
+ end
43
+
44
+ def test_to_hash
45
+ server = Yao::Resources::Server.new(
7
46
  "OS-DCF:diskConfig" => "AUTO",
8
- "OS-EXT-IMG-SIZE:size" => 74185822,
9
- "created" => "2011-01-01T01:02:03Z",
10
- "id" => "70a599e0-31e7-49b7-b260-868f441e862b",
47
+ "OS-EXT-AZ:availability_zone" => "nova",
48
+ "OS-EXT-SRV-ATTR:host" => "compute",
49
+ "OS-EXT-SRV-ATTR:hostname" => "new-server-test",
50
+ "OS-EXT-SRV-ATTR:hypervisor_hostname" => "fake-mini",
51
+ "OS-EXT-SRV-ATTR:instance_name" => "instance-00000001",
52
+ "OS-EXT-SRV-ATTR:kernel_id" => "",
53
+ "OS-EXT-SRV-ATTR:launch_index" => 0,
54
+ "OS-EXT-SRV-ATTR:ramdisk_id" => "",
55
+ "OS-EXT-SRV-ATTR:reservation_id" => "r-l0i0clt2",
56
+ "OS-EXT-SRV-ATTR:root_device_name" => "/dev/sda",
57
+ "OS-EXT-SRV-ATTR:user_data" => "IyEvYmluL2Jhc2gKL2Jpbi9zdQplY2hvICJJIGFtIGluIHlvdSEiCg==",
58
+ "OS-EXT-STS:power_state" => 1,
59
+ "OS-EXT-STS:task_state" => nil,
60
+ "OS-EXT-STS:vm_state" => "active",
61
+ "OS-SRV-USG:launched_at" => "2019-04-23T15:19:15.317839",
62
+ "OS-SRV-USG:terminated_at" => nil,
63
+ "accessIPv4" => "1.2.3.4",
64
+ "accessIPv6" => "80fe::",
65
+ "addresses" => {
66
+ "private" => [
67
+ {
68
+ "OS-EXT-IPS-MAC:mac_addr" => "aa:bb:cc:dd:ee:ff",
69
+ "OS-EXT-IPS:type" => "fixed",
70
+ "addr" => "192.168.0.3",
71
+ "version" => 4
72
+ }
73
+ ]
74
+ },
75
+ "config_drive" => "",
76
+ "created" => "2019-04-23T15:19:14Z",
77
+ "description" => nil,
78
+ "flavor" => {
79
+ "disk" => 1,
80
+ "ephemeral" => 0,
81
+ "extra_specs" => {},
82
+ "original_name" => "m1.tiny",
83
+ "ram" => 512,
84
+ "swap" => 0,
85
+ "vcpus" => 1
86
+ },
87
+ "hostId" => "2091634baaccdc4c5a1d57069c833e402921df696b7f970791b12ec6",
88
+ "host_status" => "UP",
89
+ "id" => "2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
90
+ "image" => {
91
+ "id" => "70a599e0-31e7-49b7-b260-868f441e862b",
92
+ "links" => [
93
+ {
94
+ "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
95
+ "rel" => "bookmark"
96
+ }
97
+ ]
98
+ },
99
+ "key_name" => nil,
11
100
  "links" => [
12
101
  {
13
- "href" => "http://openstack.example.com/v2/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
102
+ "href" => "http://openstack.example.com/v2.1/6f70656e737461636b20342065766572/servers/2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
14
103
  "rel" => "self"
15
104
  },
16
105
  {
17
- "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
106
+ "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/servers/2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
18
107
  "rel" => "bookmark"
19
- },
20
- {
21
- "href" => "http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b",
22
- "rel" => "alternate",
23
- "type" => "application/vnd.openstack.image"
24
108
  }
25
109
  ],
110
+ "locked" => true,
111
+ "locked_reason" => "I don't want to work",
26
112
  "metadata" => {
27
- "architecture" => "x86_64",
28
- "auto_disk_config" => "True",
29
- "kernel_id" => "nokernel",
30
- "ramdisk_id" => "nokernel"
113
+ "My Server Name" => "Apache1"
31
114
  },
32
- "minDisk" => 0,
33
- "minRam" => 0,
34
- "name" => "fakeimage7",
35
- "progress" => 100,
115
+ "name" => "new-server-test",
116
+ "os-extended-volumes:volumes_attached" => [],
117
+ "progress" => 0,
118
+ "security_groups" => [
119
+ {
120
+ "name" => "default"
121
+ }
122
+ ],
36
123
  "status" => "ACTIVE",
37
- "updated" => "2011-01-01T01:02:03Z"
38
- }
124
+ "tags" => [],
125
+ "tenant_id" => "6f70656e737461636b20342065766572",
126
+ "trusted_image_certificates" => nil,
127
+ "updated" => "2019-04-23T15:19:15Z",
128
+ "user_id" => "fake"
129
+ )
39
130
 
40
- image = Yao::Image.new(params)
131
+ assert_equal(server.image.to_hash, server['image__Yao::Resources::Image'].to_hash)
41
132
 
133
+ image = Yao::Resources::Image.new(@@params)
134
+ assert_equal(image.to_hash, @@params)
135
+ end
136
+
137
+ private
138
+
139
+ def check_image(image)
42
140
  # friendly_attributes
43
141
  assert_equal("fakeimage7", image.name)
44
142
  assert_equal("ACTIVE", image.status)
@@ -60,4 +158,5 @@ class TestImage < TestYaoResource
60
158
  assert_equal(70.74911308288574, image.size('M')) #
61
159
  assert_equal(0.06909093074500561, image.size('G')) #
62
160
  end
161
+
63
162
  end
@@ -66,6 +66,20 @@ class TestRestfullyAccesible < Test::Unit::TestCase
66
66
 
67
67
  assert_equal("OK", Test.get(name))
68
68
  end
69
+
70
+ test 'name (with no item JSON)' do
71
+ Test.return_single_on_querying = false
72
+ name = "dummy2"
73
+ uuid = "00112233-4455-6677-8899-aabbccddeeff"
74
+ body = {@resources_name => []}
75
+
76
+ stub_get_request_not_found([@url, @resources_name, name].join('/'))
77
+ stub_get_request_with_json_response([@url, "#{@resources_name}?name=#{name}"].join('/'), body)
78
+
79
+ assert_raise(Yao::InvalidResponse, "raise proper exception") do
80
+ Test.get(name)
81
+ end
82
+ end
69
83
  end
70
84
 
71
85
  sub_test_case 'get!' do
@@ -60,7 +60,7 @@ class TestRole < TestYaoResource
60
60
  assert_equal("0123456789abcdef0123456789abcdef", roles.first.id)
61
61
  assert_requested(stub)
62
62
  end
63
-
63
+
64
64
  def test_list_for_user
65
65
  stub_user
66
66
  stub_tenant
@@ -77,11 +77,11 @@ class TestRole < TestYaoResource
77
77
  JSON
78
78
  headers: {'Content-Type' => 'application/json'}
79
79
  )
80
-
80
+
81
81
  roles = Yao::Role.list_for_user("test_user", on:"admin")
82
82
  assert_equal("0123456789abcdef0123456789abcdef", roles.first.id)
83
83
  assert_received(Yao::User) { |subject| subject.get("test_user") }
84
- assert_received(Yao::Tenant) { |subject| subject.find_by_name("admin") }
84
+ assert_received(Yao::Tenant) { |subject| subject.get("admin") }
85
85
  assert_requested(stub)
86
86
  end
87
87
 
@@ -99,7 +99,7 @@ class TestRole < TestYaoResource
99
99
  Yao::Role.grant("test_role", to:"test_user", on:"admin")
100
100
  assert_received(Yao::Role) { |subject| subject.get("test_role") }
101
101
  assert_received(Yao::User) { |subject| subject.get("test_user") }
102
- assert_received(Yao::Tenant) { |subject| subject.find_by_name("admin") }
102
+ assert_received(Yao::Tenant) { |subject| subject.get("admin") }
103
103
  assert_requested(stub)
104
104
  end
105
105
 
@@ -117,7 +117,7 @@ class TestRole < TestYaoResource
117
117
  Yao::Role.revoke("test_role", from:"test_user", on:"admin")
118
118
  assert_received(Yao::Role) { |subject| subject.get("test_role") }
119
119
  assert_received(Yao::User) { |subject| subject.get("test_user") }
120
- assert_received(Yao::Tenant) { |subject| subject.find_by_name("admin") }
120
+ assert_received(Yao::Tenant) { |subject| subject.get("admin") }
121
121
  assert_requested(stub)
122
122
  end
123
123
  end
@@ -172,7 +172,7 @@ class TestRole < TestYaoResource
172
172
  assert_equal("0123456789abcdef0123456789abcdef", roles.first.id)
173
173
  assert_requested(stub)
174
174
  end
175
-
175
+
176
176
  def test_list_for_user
177
177
  stub_user
178
178
  stub_project
@@ -189,7 +189,7 @@ class TestRole < TestYaoResource
189
189
  JSON
190
190
  headers: {'Content-Type' => 'application/json'}
191
191
  )
192
-
192
+
193
193
  roles = Yao::Role.list_for_user("test_user", on:"admin")
194
194
  assert_equal("0123456789abcdef0123456789abcdef", roles.first.id)
195
195
  assert_received(Yao::Resources::User) { |subject| subject.get("test_user") }
@@ -249,9 +249,9 @@ class TestRole < TestYaoResource
249
249
  "name" => "test_user",
250
250
  }) }
251
251
  end
252
-
252
+
253
253
  def stub_tenant
254
- stub(Yao::Tenant).find_by_name { Yao::Tenant.new({
254
+ stub(Yao::Tenant).get { Yao::Tenant.new({
255
255
  "id" => "0123456789abcdef0123456789abcdef",
256
256
  "name" => "admin",
257
257
  }) }
@@ -162,6 +162,46 @@ class TestServer < TestYaoResource
162
162
  assert_requested(stub)
163
163
  end
164
164
 
165
+ def test_paging
166
+ stub = stub_request(:get, "https://example.com:12345/servers/detail")
167
+ .to_return(
168
+ status: 200,
169
+ body: <<-JSON,
170
+ {
171
+ "servers_links":[
172
+ {
173
+ "href":"https://example.com:12345/servers/detail",
174
+ "rel":"next"
175
+ }
176
+ ],
177
+ "servers": [{
178
+ "id": "dummy1"
179
+ }]
180
+ }
181
+ JSON
182
+ headers: {'Content-Type' => 'application/json'}
183
+ ).times(1).then
184
+ .to_return(
185
+ status: 200,
186
+ body: <<-JSON,
187
+ {
188
+ "servers": [{
189
+ "id": "dummy2"
190
+ }]
191
+ }
192
+ JSON
193
+ headers: {'Content-Type' => 'application/json'}
194
+ ).times(1)
195
+
196
+ servers = Yao::Server.list
197
+ assert_instance_of(Array, servers)
198
+ assert_instance_of(Yao::Server, servers.first)
199
+ assert_equal('dummy1', servers.first.id)
200
+ assert_equal('dummy2', servers.last.id)
201
+
202
+ assert_requested(stub, times: 2)
203
+ end
204
+
165
205
  def test_list_detail
166
206
  assert_equal(Yao::Server.method(:list), Yao::Server.method(:list_detail))
167
207
  end
@@ -8,27 +8,32 @@ class TestClient < Test::Unit::TestCase
8
8
  cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0")
9
9
  assert { cli.url_prefix.to_s == "http://cool-api.example.com:12345/v3.0" }
10
10
 
11
+ adapter = Faraday::Adapter::NetHttp
12
+ assert { cli.builder.adapter == adapter }
13
+
11
14
  handlers = [
12
15
  Faraday::Request::Accept,
13
16
  Faraday::Request::UrlEncoded,
17
+ Faraday::Request::UserAgent,
14
18
  Faraday::Request::ReadOnly,
15
19
  Faraday::Response::OSErrorDetector,
16
- FaradayMiddleware::ParseJson,
17
- Faraday::Adapter::NetHttp
20
+ FaradayMiddleware::ParseJson
18
21
  ]
19
22
  assert { cli.builder.handlers == handlers }
20
23
  end
21
24
 
22
25
  def test_gen_with_token
23
26
  cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0", token: "deadbeaf")
27
+ adapter = Faraday::Adapter::NetHttp
28
+ assert { cli.builder.adapter == adapter }
24
29
  handlers = [
25
30
  Faraday::Request::Accept,
26
31
  Faraday::Request::UrlEncoded,
32
+ Faraday::Request::UserAgent,
27
33
  Faraday::Request::OSToken,
28
34
  Faraday::Request::ReadOnly,
29
35
  Faraday::Response::OSErrorDetector,
30
- FaradayMiddleware::ParseJson,
31
- Faraday::Adapter::NetHttp
36
+ FaradayMiddleware::ParseJson
32
37
  ]
33
38
  assert { cli.builder.handlers == handlers }
34
39
  end
@@ -37,15 +42,17 @@ class TestClient < Test::Unit::TestCase
37
42
  stub(Yao.config).debug { true }
38
43
 
39
44
  cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0")
45
+ adapter = Faraday::Adapter::NetHttp
46
+ assert { cli.builder.adapter == adapter }
40
47
  handlers = [
41
48
  Faraday::Request::Accept,
42
49
  Faraday::Request::UrlEncoded,
50
+ Faraday::Request::UserAgent,
43
51
  Faraday::Request::ReadOnly,
44
52
  Faraday::Response::OSErrorDetector,
45
53
  FaradayMiddleware::ParseJson,
46
54
  Faraday::Response::Logger,
47
- Faraday::Response::OSDumper,
48
- Faraday::Adapter::NetHttp
55
+ Faraday::Response::OSDumper
49
56
  ]
50
57
  assert { cli.builder.handlers == handlers }
51
58
  end
@@ -57,6 +64,7 @@ class TestClient < Test::Unit::TestCase
57
64
  end
58
65
 
59
66
  def test_cert_key
67
+ stub(Yao.config).ca_cert { File.expand_path("../../fixtures/dummy.pem", __FILE__) }
60
68
  stub(Yao.config).client_cert { File.expand_path("../../fixtures/dummy.pem", __FILE__) }
61
69
  stub(Yao.config).client_key { File.expand_path("../../fixtures/dummy.key", __FILE__) }
62
70
  stub(OpenSSL::X509::Certificate).new { "DummyCert" }
@@ -64,6 +72,7 @@ class TestClient < Test::Unit::TestCase
64
72
 
65
73
  cli = Yao::Client.gen_client("http://cool-api.example.com:12345/v3.0")
66
74
  ssl = cli.ssl
75
+ assert { ssl[:ca_file] == File.expand_path("../../fixtures/dummy.pem", __FILE__) }
67
76
  assert { ssl[:client_cert] == "DummyCert" }
68
77
  assert { ssl[:client_key] == "DummyKey" }
69
78
  end
@@ -1,8 +1,8 @@
1
1
  class TestServerError < Test::Unit::TestCase
2
2
  def test_detects_error_with_env
3
3
  env = Faraday::Env.new
4
- env.body = {"itemNotFound"=>{"message"=>"Image not found.", "code"=>404}}
5
4
  env.status = 404
5
+ env.body = {"itemNotFound"=>{"message"=>"Image not found.", "code"=>404}}
6
6
 
7
7
  error = Yao::ServerError.detect(env)
8
8
  assert { error.is_a? Yao::ItemNotFound }
@@ -13,8 +13,8 @@ class TestServerError < Test::Unit::TestCase
13
13
 
14
14
  def test_anyway_returns_error
15
15
  env = Faraday::Env.new
16
- env.body = "<html>Not found.</html>"
17
16
  env.status = 599
17
+ env.body = "<html>Not found.</html>"
18
18
 
19
19
  error = Yao::ServerError.detect(env)
20
20
  assert { error.is_a? Yao::ServerError }
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "json"
21
- spec.add_dependency "faraday"
21
+ spec.add_dependency "deep_merge"
22
+ spec.add_dependency "faraday", "~> 1.0.1"
22
23
  spec.add_dependency "faraday_middleware"
23
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yao
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio, KONDO
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2020-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday
28
+ name: deep_merge
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: faraday_middleware
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -184,7 +198,7 @@ homepage: https://github.com/yaocloud/yao
184
198
  licenses:
185
199
  - MIT
186
200
  metadata: {}
187
- post_install_message:
201
+ post_install_message:
188
202
  rdoc_options: []
189
203
  require_paths:
190
204
  - lib
@@ -199,8 +213,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
213
  - !ruby/object:Gem::Version
200
214
  version: '0'
201
215
  requirements: []
202
- rubygems_version: 3.1.2
203
- signing_key:
216
+ rubygems_version: 3.0.6
217
+ signing_key:
204
218
  specification_version: 4
205
219
  summary: Yet Another OpenStack API Wrapper that rocks!!
206
220
  test_files: