yao 0.14.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +2 -2
  3. data/.github/workflows/ubuntu-rvm.yml +1 -1
  4. data/.github/workflows/ubuntu.yml +2 -2
  5. data/lib/yao/resources/base.rb +17 -5
  6. data/lib/yao/resources/flavor.rb +10 -0
  7. data/lib/yao/resources/floating_ip.rb +1 -7
  8. data/lib/yao/resources/loadbalancer_pool.rb +10 -20
  9. data/lib/yao/resources/meter.rb +1 -1
  10. data/lib/yao/resources/network.rb +1 -1
  11. data/lib/yao/resources/old_sample.rb +1 -1
  12. data/lib/yao/resources/port.rb +1 -1
  13. data/lib/yao/resources/project.rb +5 -0
  14. data/lib/yao/resources/{tenant_associationable.rb → project_associationable.rb} +5 -5
  15. data/lib/yao/resources/resource.rb +1 -1
  16. data/lib/yao/resources/restfully_accessible.rb +3 -2
  17. data/lib/yao/resources/role_assignment.rb +37 -5
  18. data/lib/yao/resources/router.rb +19 -10
  19. data/lib/yao/resources/security_group.rb +1 -1
  20. data/lib/yao/resources/server.rb +6 -1
  21. data/lib/yao/resources/subnet.rb +1 -1
  22. data/lib/yao/resources/tenant.rb +5 -0
  23. data/lib/yao/resources/user.rb +6 -1
  24. data/lib/yao/resources/volume.rb +14 -1
  25. data/lib/yao/resources/volume_action.rb +13 -0
  26. data/lib/yao/resources.rb +1 -1
  27. data/lib/yao/version.rb +1 -1
  28. data/test/yao/resources/test_base.rb +21 -0
  29. data/test/yao/resources/test_flavor.rb +67 -33
  30. data/test/yao/resources/test_floating_ip.rb +5 -5
  31. data/test/yao/resources/test_loadbalancer_pool.rb +146 -1
  32. data/test/yao/resources/test_meter.rb +5 -5
  33. data/test/yao/resources/test_network.rb +6 -6
  34. data/test/yao/resources/test_port.rb +6 -6
  35. data/test/yao/resources/test_project.rb +25 -5
  36. data/test/yao/resources/test_restfully_accessible.rb +46 -4
  37. data/test/yao/resources/test_role_assignment.rb +100 -3
  38. data/test/yao/resources/test_router.rb +33 -12
  39. data/test/yao/resources/test_security_group.rb +5 -5
  40. data/test/yao/resources/test_server.rb +52 -6
  41. data/test/yao/resources/test_subnet.rb +6 -6
  42. data/test/yao/resources/test_user.rb +28 -1
  43. data/test/yao/resources/test_volume.rb +81 -1
  44. data/yao.gemspec +1 -1
  45. metadata +7 -6
@@ -95,12 +95,33 @@ class TestRouter < TestYaoResource
95
95
  assert_equal([], router.availability_zone_hints)
96
96
  assert_equal([ "nova" ], router.availability_zones)
97
97
 
98
- pend 'oops. These are invalid friendly_attributes'
99
- assert_equal( '', router.network_id)
100
- assert_equal('', router.enable_snat)
101
- assert_equal(router.external_fixed_ips '')
102
- assert_equal(router.destination '')
103
- assert_equal(router.nexthop '')
98
+ stub = stub_request(:get, "https://example.com:12345/networks/ae34051f-aa6c-4c75-abf5-50dc9ac99ef3")
99
+ .to_return(
100
+ status: 200,
101
+ body: <<~JSON,
102
+ {
103
+ "network": {
104
+ "id": "ae34051f-aa6c-4c75-abf5-50dc9ac99ef3",
105
+ "name": "example-network"
106
+ }
107
+ }
108
+ JSON
109
+ headers: {'Content-Type' => 'application/json'}
110
+ )
111
+ assert_instance_of(Yao::Network, router.external_network)
112
+ assert_equal("ae34051f-aa6c-4c75-abf5-50dc9ac99ef3", router.external_network.id)
113
+ assert_equal("example-network", router.external_network.name)
114
+ assert_equal(true, router.enable_snat)
115
+ assert_equal([
116
+ {
117
+ "ip_address" => "172.24.4.3",
118
+ "subnet_id" => "b930d7f6-ceb7-40a0-8b81-a425dd994ccf"
119
+ },
120
+ {
121
+ "ip_address" => "2001:db8::c",
122
+ "subnet_id" => "0c56df5d-ace5-46c8-8f4c-45fa4e334d18"
123
+ }
124
+ ], router.external_fixed_ips)
104
125
  end
105
126
 
106
127
  def test_iterfaces
@@ -129,14 +150,14 @@ class TestRouter < TestYaoResource
129
150
  assert_requested(stub)
130
151
  end
131
152
 
132
- def test_tenant
153
+ def test_project
133
154
 
134
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
155
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
135
156
  .to_return(
136
157
  status: 200,
137
158
  body: <<-JSON,
138
159
  {
139
- "tenant": {
160
+ "project": {
140
161
  "id": "0123456789abcdef0123456789abcdef"
141
162
  }
142
163
  }
@@ -144,9 +165,9 @@ class TestRouter < TestYaoResource
144
165
  headers: {'Content-Type' => 'application/json'}
145
166
  )
146
167
 
147
- router = Yao::Router.new('tenant_id' => '0123456789abcdef0123456789abcdef')
148
- assert_instance_of(Yao::Tenant, router.tenant)
149
- assert_equal('0123456789abcdef0123456789abcdef', router.tenant.id)
168
+ router = Yao::Router.new('project_id' => '0123456789abcdef0123456789abcdef')
169
+ assert_instance_of(Yao::Project, router.project)
170
+ assert_equal('0123456789abcdef0123456789abcdef', router.project.id)
150
171
 
151
172
  assert_requested(stub)
152
173
  end
@@ -25,12 +25,12 @@ class TestSecurityGroup < TestYaoResource
25
25
 
26
26
  def test_sg_to_tenant
27
27
 
28
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
28
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
29
29
  .to_return(
30
30
  status: 200,
31
31
  body: <<-JSON,
32
32
  {
33
- "tenant": {
33
+ "project": {
34
34
  "id": "0123456789abcdef0123456789abcdef"
35
35
  }
36
36
  }
@@ -38,9 +38,9 @@ class TestSecurityGroup < TestYaoResource
38
38
  headers: {'Content-Type' => 'application/json'}
39
39
  )
40
40
 
41
- sg = Yao::SecurityGroup.new('tenant_id' => '0123456789abcdef0123456789abcdef')
42
- assert_instance_of(Yao::Tenant, sg.tenant)
43
- assert_equal('0123456789abcdef0123456789abcdef', sg.tenant.id)
41
+ sg = Yao::SecurityGroup.new('project_id' => '0123456789abcdef0123456789abcdef')
42
+ assert_instance_of(Yao::Project, sg.project)
43
+ assert_equal('0123456789abcdef0123456789abcdef', sg.project.id)
44
44
 
45
45
  assert_requested(stub)
46
46
  end
@@ -206,14 +206,14 @@ class TestServer < TestYaoResource
206
206
  assert_equal(Yao::Server.method(:list), Yao::Server.method(:list_detail))
207
207
  end
208
208
 
209
- def test_tenant
209
+ def test_project
210
210
 
211
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
211
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
212
212
  .to_return(
213
213
  status: 200,
214
214
  body: <<-JSON,
215
215
  {
216
- "tenant": {
216
+ "project": {
217
217
  "id": "0123456789abcdef0123456789abcdef"
218
218
  }
219
219
  }
@@ -221,10 +221,56 @@ class TestServer < TestYaoResource
221
221
  headers: {'Content-Type' => 'application/json'}
222
222
  )
223
223
 
224
- server = Yao::Server.new('tenant_id' => '0123456789abcdef0123456789abcdef')
225
- assert_instance_of(Yao::Tenant, server.tenant)
226
- assert_equal('0123456789abcdef0123456789abcdef', server.tenant.id)
224
+ server = Yao::Server.new('project_id' => '0123456789abcdef0123456789abcdef')
225
+ assert_instance_of(Yao::Project, server.project)
226
+ assert_equal('0123456789abcdef0123456789abcdef', server.project.id)
227
227
 
228
228
  assert_requested(stub)
229
229
  end
230
+
231
+ def test_ports
232
+
233
+ stub = stub_request(:get, "https://example.com:12345/ports?device_id")
234
+ .to_return(
235
+ status: 200,
236
+ body: <<-JSON,
237
+ {
238
+ "ports": [{
239
+ "id": "0123456789abcdef0123456789abcdef"
240
+ }]
241
+ }
242
+ JSON
243
+ headers: {'Content-Type' => 'application/json'}
244
+ )
245
+
246
+ server = Yao::Server.new('project_id' => '0123456789abcdef0123456789abcdef')
247
+ ports = server.ports
248
+
249
+ assert_instance_of(Array, ports)
250
+ assert_instance_of(Yao::Port, ports.first)
251
+ assert_equal('0123456789abcdef0123456789abcdef', ports.first.id)
252
+
253
+ assert_requested(stub)
254
+ end
255
+
256
+ def test_ports_empty
257
+
258
+ stub = stub_request(:get, "https://example.com:12345/ports?device_id")
259
+ .to_return(
260
+ status: 200,
261
+ body: <<-JSON,
262
+ {
263
+ "ports": []
264
+ }
265
+ JSON
266
+ headers: {'Content-Type' => 'application/json'}
267
+ )
268
+
269
+ server = Yao::Server.new('project_id' => '0123456789abcdef0123456789abcdef')
270
+ ports = server.ports
271
+
272
+ assert_instance_of(Array, ports)
273
+ assert_equal(0, ports.size)
274
+ assert_requested(stub)
275
+ end
230
276
  end
@@ -76,13 +76,13 @@ class TestSubnet < TestYaoResource
76
76
  assert_requested(stub)
77
77
  end
78
78
 
79
- def test_tenant
80
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
79
+ def test_project
80
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
81
81
  .to_return(
82
82
  status: 200,
83
83
  body: <<-JSON,
84
84
  {
85
- "tenant": {
85
+ "project": {
86
86
  "id": "0123456789abcdef0123456789abcdef"
87
87
  }
88
88
  }
@@ -90,9 +90,9 @@ class TestSubnet < TestYaoResource
90
90
  headers: {'Content-Type' => 'application/json'}
91
91
  )
92
92
 
93
- subnet = Yao::Subnet.new('tenant_id' => '0123456789abcdef0123456789abcdef')
94
- assert_instance_of(Yao::Tenant, subnet.tenant)
95
- assert_equal('0123456789abcdef0123456789abcdef', subnet.tenant.id)
93
+ subnet = Yao::Subnet.new('project_id' => '0123456789abcdef0123456789abcdef')
94
+ assert_instance_of(Yao::Project, subnet.project)
95
+ assert_equal('0123456789abcdef0123456789abcdef', subnet.project.id)
96
96
 
97
97
  assert_requested(stub)
98
98
  end
@@ -1,16 +1,43 @@
1
1
  class TestUser < TestYaoResource
2
- def test_sg_attributes
2
+ def test_user
3
3
  params = {
4
+ "id" => '1234567890',
4
5
  "name" => "test_user",
5
6
  "email" => "test-user@example.com",
6
7
  "password" => "passw0rd"
7
8
  }
8
9
 
9
10
  user = Yao::User.new(params)
11
+ assert_equal("1234567890", user.id)
10
12
  assert_equal("test_user", user.name)
11
13
  assert_equal("test-user@example.com", user.email)
12
14
  end
13
15
 
16
+ def test_role_assignment
17
+ user_id = '123456'
18
+ stub = stub_request(:get, "https://example.com:12345/role_assignments?user.id=#{user_id}").
19
+ to_return(
20
+ status: 200,
21
+ body: <<-JSON,
22
+ {
23
+ "role_assignments": [{
24
+ "scope": {
25
+ "project": {
26
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
27
+ }
28
+ }
29
+ }]
30
+ }
31
+ JSON
32
+ headers: {'Content-Type' => 'application/json'}
33
+ )
34
+
35
+ user = Yao::User.new('id' => user_id)
36
+ role_assignment = user.role_assignment
37
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
38
+ assert_requested(stub)
39
+ end
40
+
14
41
  sub_test_case 'with keystone v2.0' do
15
42
  def setup
16
43
  super
@@ -1,13 +1,35 @@
1
1
  class TestVolume < TestYaoResource
2
2
  def test_volume
3
3
  params = {
4
+ 'attachments' => [],
5
+ 'availability_zone' => 'test',
6
+ 'bootable' => true,
7
+ 'encrypted' => false,
8
+ 'metadata' => {},
9
+ 'multiattach' => false,
4
10
  'name' => 'cinder',
5
- 'size' => 10
11
+ 'replication_status' => 'disabled',
12
+ 'size' => 10,
13
+ 'snapshot_id' => nil,
14
+ 'status' => 'available',
15
+ 'user_id' => 'aaaa166533fd49f3b11b1cdce2430000',
16
+ 'volume_type' => 'test'
6
17
  }
7
18
 
8
19
  volume = Yao::Volume.new(params)
20
+ assert_equal(volume.attachments, [])
21
+ assert_equal(volume.availability_zone, 'test')
22
+ assert_equal(volume.bootable, true)
23
+ assert_equal(volume.encrypted, false)
24
+ assert_equal(volume.metadata, {})
25
+ assert_equal(volume.multiattach, false)
9
26
  assert_equal(volume.name, 'cinder')
27
+ assert_equal(volume.replication_status, 'disabled')
10
28
  assert_equal(volume.size, 10)
29
+ assert_equal(volume.snapshot_id, nil)
30
+ assert_equal(volume.user_id, 'aaaa166533fd49f3b11b1cdce2430000')
31
+ assert_equal(volume.volume_type, 'test')
32
+ assert_equal(volume.type, 'test')
11
33
  end
12
34
 
13
35
  def test_list
@@ -39,4 +61,62 @@ class TestVolume < TestYaoResource
39
61
  def test_list_detail
40
62
  assert_equal(Yao::Volume.method(:list), Yao::Volume.method(:list_detail))
41
63
  end
64
+
65
+ def stub_action_request(id, body)
66
+ # https://docs.openstack.org/api-ref/block-storage/v3/index.html?expanded=list-accessible-volumes-with-details-detail,reset-a-volume-s-statuses-detail#reset-a-volume-s-statuses
67
+ stub_request(:post, "https://example.com:12345/volumes/#{id}/action").
68
+ with(
69
+ body: body,
70
+ headers: {
71
+ 'Accept'=>'application/json',
72
+ 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
73
+ 'Content-Type'=>'application/json',
74
+ 'User-Agent'=>"Yao/#{Yao::VERSION} Faraday/#{Faraday::VERSION}"
75
+ }).
76
+ to_return(
77
+ status: 202,
78
+ body: '',
79
+ headers: {'Content-Type' => 'application/json'}
80
+ )
81
+ end
82
+
83
+ def test_set_status
84
+ volume_id = '00000000-0000-0000-0000-000000000000'
85
+
86
+ stub = stub_action_request(volume_id, {'os-reset_status': {'status': 'error'}})
87
+ Yao::Volume.set_status(volume_id, 'error')
88
+ assert_requested(stub)
89
+ end
90
+
91
+ def test_set_status_on_instance
92
+ volume_id = '00000000-0000-0000-0000-000000000000'
93
+ stub = stub_action_request(volume_id, {'os-reset_status': {'status': 'error'}})
94
+ params = {
95
+ 'id' => volume_id,
96
+ }
97
+ volume = Yao::Volume.new(params)
98
+ volume.status = 'error'
99
+ assert_requested(stub)
100
+ end
101
+
102
+ def test_project
103
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
104
+ .to_return(
105
+ status: 200,
106
+ body: <<-JSON,
107
+ {
108
+ "project": {
109
+ "id": "0123456789abcdef0123456789abcdef"
110
+ }
111
+ }
112
+ JSON
113
+ headers: {'Content-Type' => 'application/json'}
114
+ )
115
+
116
+ volume = Yao::Volume.new('project_id' => '0123456789abcdef0123456789abcdef')
117
+ assert_instance_of(Yao::Project, volume.project)
118
+ assert_equal('0123456789abcdef0123456789abcdef', volume.project.id)
119
+
120
+ assert_requested(stub)
121
+ end
42
122
  end
data/yao.gemspec CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "json"
21
21
  spec.add_dependency "deep_merge"
22
- spec.add_dependency "faraday", "~> 1.8.0"
22
+ spec.add_dependency "faraday", ">= 1.8.0"
23
23
  spec.add_dependency "faraday_middleware"
24
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.14.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio, KONDO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-03 00:00:00.000000000 Z
11
+ date: 2022-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: faraday
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.8.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.8.0
55
55
  - !ruby/object:Gem::Dependency
@@ -122,6 +122,7 @@ files:
122
122
  - lib/yao/resources/port.rb
123
123
  - lib/yao/resources/port_associationable.rb
124
124
  - lib/yao/resources/project.rb
125
+ - lib/yao/resources/project_associationable.rb
125
126
  - lib/yao/resources/resource.rb
126
127
  - lib/yao/resources/restfully_accessible.rb
127
128
  - lib/yao/resources/role.rb
@@ -135,9 +136,9 @@ files:
135
136
  - lib/yao/resources/server_usage_associationable.rb
136
137
  - lib/yao/resources/subnet.rb
137
138
  - lib/yao/resources/tenant.rb
138
- - lib/yao/resources/tenant_associationable.rb
139
139
  - lib/yao/resources/user.rb
140
140
  - lib/yao/resources/volume.rb
141
+ - lib/yao/resources/volume_action.rb
141
142
  - lib/yao/resources/volume_type.rb
142
143
  - lib/yao/setup.rb
143
144
  - lib/yao/token.rb
@@ -215,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
216
  - !ruby/object:Gem::Version
216
217
  version: '0'
217
218
  requirements: []
218
- rubygems_version: 3.2.32
219
+ rubygems_version: 3.3.7
219
220
  signing_key:
220
221
  specification_version: 4
221
222
  summary: Yet Another OpenStack API Wrapper that rocks!!