yao 0.13.4 → 0.16.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +19 -0
  3. data/.github/workflows/ubuntu-rvm.yml +1 -1
  4. data/.github/workflows/ubuntu.yml +2 -2
  5. data/.rubocop.yml +3 -6
  6. data/lib/yao/auth.rb +18 -0
  7. data/lib/yao/client.rb +1 -1
  8. data/lib/yao/config.rb +19 -0
  9. data/lib/yao/faraday_middlewares.rb +37 -3
  10. data/lib/yao/mode.rb +4 -0
  11. data/lib/yao/plugins/default_client_generator.rb +0 -1
  12. data/lib/yao/plugins/registry.rb +2 -1
  13. data/lib/yao/resources/action.rb +7 -0
  14. data/lib/yao/resources/aggregates.rb +1 -0
  15. data/lib/yao/resources/base.rb +39 -6
  16. data/lib/yao/resources/compute_services.rb +8 -1
  17. data/lib/yao/resources/flavor.rb +12 -0
  18. data/lib/yao/resources/floating_ip.rb +2 -6
  19. data/lib/yao/resources/hypervisor.rb +1 -1
  20. data/lib/yao/resources/image.rb +2 -0
  21. data/lib/yao/resources/loadbalancer.rb +4 -0
  22. data/lib/yao/resources/loadbalancer_healthmonitor.rb +3 -0
  23. data/lib/yao/resources/loadbalancer_listener.rb +2 -0
  24. data/lib/yao/resources/loadbalancer_pool.rb +13 -17
  25. data/lib/yao/resources/loadbalancer_pool_member.rb +21 -0
  26. data/lib/yao/resources/metadata_available.rb +21 -0
  27. data/lib/yao/resources/meter.rb +9 -2
  28. data/lib/yao/resources/network.rb +2 -1
  29. data/lib/yao/resources/network_associationable.rb +1 -0
  30. data/lib/yao/resources/old_sample.rb +5 -1
  31. data/lib/yao/resources/port.rb +3 -1
  32. data/lib/yao/resources/port_associationable.rb +1 -0
  33. data/lib/yao/resources/project.rb +11 -0
  34. data/lib/yao/resources/{tenant_associationable.rb → project_associationable.rb} +5 -4
  35. data/lib/yao/resources/resource.rb +9 -3
  36. data/lib/yao/resources/restfully_accessible.rb +18 -2
  37. data/lib/yao/resources/role.rb +6 -4
  38. data/lib/yao/resources/role_assignment.rb +37 -4
  39. data/lib/yao/resources/router.rb +26 -8
  40. data/lib/yao/resources/sample.rb +4 -0
  41. data/lib/yao/resources/security_group.rb +2 -1
  42. data/lib/yao/resources/security_group_rule.rb +10 -0
  43. data/lib/yao/resources/server.rb +21 -1
  44. data/lib/yao/resources/server_group.rb +1 -1
  45. data/lib/yao/resources/server_usage_associationable.rb +12 -0
  46. data/lib/yao/resources/subnet.rb +2 -1
  47. data/lib/yao/resources/tenant.rb +11 -0
  48. data/lib/yao/resources/user.rb +8 -1
  49. data/lib/yao/resources/volume.rb +14 -1
  50. data/lib/yao/resources/volume_action.rb +13 -0
  51. data/lib/yao/resources.rb +4 -1
  52. data/lib/yao/token.rb +1 -0
  53. data/lib/yao/version.rb +1 -1
  54. data/test/yao/resources/test_base.rb +32 -0
  55. data/test/yao/resources/test_flavor.rb +67 -33
  56. data/test/yao/resources/test_floating_ip.rb +5 -5
  57. data/test/yao/resources/test_image.rb +5 -0
  58. data/test/yao/resources/test_loadbalancer_pool.rb +146 -1
  59. data/test/yao/resources/test_meter.rb +5 -5
  60. data/test/yao/resources/test_network.rb +6 -6
  61. data/test/yao/resources/test_port.rb +6 -6
  62. data/test/yao/resources/test_project.rb +45 -6
  63. data/test/yao/resources/test_restfully_accessible.rb +46 -4
  64. data/test/yao/resources/test_role_assignment.rb +100 -3
  65. data/test/yao/resources/test_router.rb +33 -12
  66. data/test/yao/resources/test_security_group.rb +5 -5
  67. data/test/yao/resources/test_server.rb +6 -6
  68. data/test/yao/resources/test_server_group.rb +1 -1
  69. data/test/yao/resources/test_subnet.rb +6 -6
  70. data/test/yao/resources/test_user.rb +28 -1
  71. data/test/yao/resources/test_volume.rb +81 -1
  72. data/test/yao/test_client.rb +0 -1
  73. data/yao.gemspec +1 -1
  74. metadata +11 -8
@@ -88,13 +88,13 @@ class TestMeter < TestYaoResource
88
88
  assert_requested(stub)
89
89
  end
90
90
 
91
- def test_tenant
92
- stub = stub_request(:get, "https://example.com:12345/tenants/00000000-0000-0000-0000-000000000000")
91
+ def test_project
92
+ stub = stub_request(:get, "https://example.com:12345/projects/00000000-0000-0000-0000-000000000000")
93
93
  .to_return(
94
94
  status: 200,
95
95
  body: <<-JSON,
96
96
  {
97
- "tenant": {
97
+ "project": {
98
98
  "id": "00000000-0000-0000-0000-000000000000"
99
99
  }
100
100
  }
@@ -107,8 +107,8 @@ class TestMeter < TestYaoResource
107
107
  }
108
108
 
109
109
  meter = Yao::Meter.new(params)
110
- assert_instance_of(Yao::Tenant, meter.tenant)
111
- assert_equal("00000000-0000-0000-0000-000000000000", meter.tenant.id)
110
+ assert_instance_of(Yao::Project, meter.project)
111
+ assert_equal("00000000-0000-0000-0000-000000000000", meter.project.id)
112
112
 
113
113
  assert_requested(stub)
114
114
  end
@@ -37,14 +37,14 @@ class TestNetwork < TestYaoResource
37
37
  assert_equal(1000, network.segmentation_id)
38
38
  end
39
39
 
40
- def test_tenant
40
+ def test_project
41
41
 
42
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
42
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
43
43
  .to_return(
44
44
  status: 200,
45
45
  body: <<-JSON,
46
46
  {
47
- "tenant": {
47
+ "project": {
48
48
  "id": "0123456789abcdef0123456789abcdef"
49
49
  }
50
50
  }
@@ -57,9 +57,9 @@ class TestNetwork < TestYaoResource
57
57
  "tenant_id" => "0123456789abcdef0123456789abcdef",
58
58
  )
59
59
 
60
- assert_instance_of(Yao::Tenant, network.tenant)
61
- assert_instance_of(Yao::Tenant, network.project)
62
- assert_equal('0123456789abcdef0123456789abcdef', network.tenant.id)
60
+ assert_instance_of(Yao::Project, network.tenant)
61
+ assert_instance_of(Yao::Project, network.project)
62
+ assert_equal('0123456789abcdef0123456789abcdef', network.project.id)
63
63
 
64
64
  assert_requested(stub)
65
65
  end
@@ -77,14 +77,14 @@ class TestPort < TestYaoResource
77
77
  assert_equal("10.0.0.1", port.primary_ip)
78
78
  end
79
79
 
80
- def test_tenant
80
+ def test_project
81
81
 
82
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
82
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
83
83
  .to_return(
84
84
  status: 200,
85
85
  body: <<-JSON,
86
86
  {
87
- "tenant": {
87
+ "project": {
88
88
  "id": "0123456789abcdef0123456789abcdef"
89
89
  }
90
90
  }
@@ -92,9 +92,9 @@ class TestPort < TestYaoResource
92
92
  headers: {'Content-Type' => 'application/json'}
93
93
  )
94
94
 
95
- port = Yao::Port.new('tenant_id' => '0123456789abcdef0123456789abcdef')
96
- assert_instance_of(Yao::Tenant, port.tenant)
97
- assert_equal('0123456789abcdef0123456789abcdef', port.tenant.id)
95
+ port = Yao::Port.new('project_id' => '0123456789abcdef0123456789abcdef')
96
+ assert_instance_of(Yao::Project, port.project)
97
+ assert_equal('0123456789abcdef0123456789abcdef', port.project.id)
98
98
 
99
99
  assert_requested(stub)
100
100
  end
@@ -1,9 +1,4 @@
1
1
  class TestProject < TestYaoResource
2
- def setup
3
- super
4
- Yao.default_client.admin_pool["identity"] = Yao::Client.gen_client("https://example.com:12345/v2.0")
5
- end
6
-
7
2
  # https://docs.openstack.org/api-ref/identity/v3/?expanded=list-projects-detail#projects
8
3
  def test_project
9
4
  params = {
@@ -254,4 +249,48 @@ class TestProject < TestYaoResource
254
249
  assert_instance_of(Array, project.servers)
255
250
  assert_requested(stub)
256
251
  end
257
- end
252
+
253
+ def test_server_usage
254
+ stub = stub_request(:get, "https://example.com:12345/os-simple-tenant-usage/0123456789abcdef0123456789abcdef")
255
+ .to_return(
256
+ status: 200,
257
+ body: <<-JSON,
258
+ {
259
+ "tenant_usage": {
260
+ "total_memory_mb_usage": 1024
261
+ }
262
+ }
263
+ JSON
264
+ headers: {'Content-Type' => 'application/json'}
265
+ )
266
+
267
+ project = Yao::Project::new("id" => "0123456789abcdef0123456789abcdef")
268
+ usage = project.server_usage
269
+ assert_equal(1024, usage["total_memory_mb_usage"])
270
+ end
271
+
272
+ def test_role_assignment
273
+ project_id = 'aaaa166533fd49f3b11b1cdce2430000'
274
+ stub = stub_request(:get, "https://example.com:12345/role_assignments?scope.project.id=#{project_id}").
275
+ to_return(
276
+ status: 200,
277
+ body: <<-JSON,
278
+ {
279
+ "role_assignments": [{
280
+ "scope": {
281
+ "project": {
282
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
283
+ }
284
+ }
285
+ }]
286
+ }
287
+ JSON
288
+ headers: {'Content-Type' => 'application/json'}
289
+ )
290
+
291
+ project = Yao::Project.new('id' => project_id)
292
+ role_assignment = project.role_assignment
293
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
294
+ assert_requested(stub)
295
+ end
296
+ end
@@ -1,6 +1,18 @@
1
1
  class TestRestfullyAccesible < Test::Unit::TestCase
2
2
  include RestfullyAccessibleStub
3
3
  class Test
4
+ def initialize(data_via_json)
5
+ @data = data_via_json
6
+ end
7
+
8
+ def id
9
+ @data['id']
10
+ end
11
+
12
+ def name
13
+ @data['name']
14
+ end
15
+
4
16
  class << self
5
17
  attr_accessor :client
6
18
  end
@@ -45,7 +57,7 @@ class TestRestfullyAccesible < Test::Unit::TestCase
45
57
 
46
58
  stub_get_request_not_found([@url, @resources_name, name].join('/'))
47
59
  stub_get_request([@url, "#{@resources_name}?name=dummy"].join('/'), @resources_name)
48
- mock(Test).new("dummy_resource") { Struct.new(:id).new(uuid) }
60
+ mock(Test).new("dummy_resource") { Struct.new(:id, :name).new(uuid, name) }
49
61
  stub_get_request([@url, @resources_name, uuid].join('/'), @resources_name)
50
62
  mock(Test).new("dummy_resource") { "OK" }
51
63
 
@@ -60,7 +72,7 @@ class TestRestfullyAccesible < Test::Unit::TestCase
60
72
 
61
73
  stub_get_request_not_found([@url, @resources_name, name].join('/'))
62
74
  stub_get_request_with_json_response([@url, "#{@resources_name}?name=dummy"].join('/'), body)
63
- mock(Test).new("dummy_resources") { Struct.new(:id).new(uuid) }
75
+ mock(Test).new("dummy_resources") { Struct.new(:id, :name).new(uuid, name) }
64
76
  stub_get_request([@url, @resources_name, uuid].join('/'), @resource_name)
65
77
  mock(Test).new("dummy_resource") { "OK" }
66
78
 
@@ -84,8 +96,17 @@ class TestRestfullyAccesible < Test::Unit::TestCase
84
96
 
85
97
  sub_test_case 'get!' do
86
98
  test 'not found' do
87
- stub_get_request_not_found("https://example.com/dummy_resource")
88
- assert_equal(nil, Test.get!("https://example.com/dummy_resource"))
99
+ Test.return_single_on_querying = false
100
+ name = "dummy"
101
+ uuid = "00112233-4455-6677-8899-aabbccddeeff"
102
+ body = {@resources_name => []}
103
+
104
+ stub1 = stub_get_request_not_found([@url, @resources_name, name].join('/'))
105
+ stub2 = stub_get_request_with_json_response([@url, "#{@resources_name}?name=#{name}"].join('/'), body)
106
+
107
+ assert_equal(nil, Test.get!(name))
108
+ assert_requested(stub1)
109
+ assert_requested(stub2)
89
110
  end
90
111
 
91
112
  test 'found' do
@@ -103,6 +124,23 @@ class TestRestfullyAccesible < Test::Unit::TestCase
103
124
  end
104
125
  end
105
126
 
127
+ sub_test_case 'get_by_name' do
128
+ test 'multiple found' do
129
+ name = 'dummy'
130
+ uuid = '00112233-4455-6677-8899-aabbccddeeff'
131
+ list_body = { @resources_name => [
132
+ { 'name' => 'dummy', 'id' => uuid },
133
+ { 'name' => 'dummy2', 'id' => '308cb410-9c84-40ec-a3eb-583001aaa7fd' }
134
+ ]}
135
+ get_body = { @resource_name => { 'name' => 'dummy', 'id' => uuid } }
136
+ stub1 = stub_get_request_not_found([@url, @resources_name, name].join('/'))
137
+ stub2 = stub_get_request_with_json_response([@url, "#{@resources_name}?name=#{name}"].join('/'), list_body)
138
+ stub3 = stub_get_request_with_json_response([@url, @resources_name, name].join('/'), get_body)
139
+
140
+ assert_equal(uuid, Test.send(:get_by_name, 'dummy').body[@resource_name]['id'])
141
+ end
142
+ end
143
+
106
144
  def test_find_by_name
107
145
  mock(Test).list({"name" => "dummy"}) { "dummy" }
108
146
 
@@ -116,4 +154,8 @@ class TestRestfullyAccesible < Test::Unit::TestCase
116
154
  assert_equal(false, Test.send(:uuid?, "dummy resource"))
117
155
  assert_equal(false, Test.send(:uuid?, "00112233445566778899aabbccddeeff"))
118
156
  end
157
+
158
+ def test_delete
159
+ assert_equal(Test.method(:delete), Test.method(:destroy))
160
+ end
119
161
  end
@@ -32,13 +32,110 @@ class TestRoleAssignment < TestYaoResource
32
32
  assert_equal("313233", role_assignment.user.id)
33
33
  end
34
34
 
35
+ def test_list
36
+ stub = stub_request(:get, "https://example.com:12345/role_assignments").
37
+ to_return(
38
+ status: 200,
39
+ body: <<-JSON,
40
+ {
41
+ "role_assignments": [{
42
+ "scope": {
43
+ "project": {
44
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
45
+ }
46
+ }
47
+ }]
48
+ }
49
+ JSON
50
+ headers: {'Content-Type' => 'application/json'}
51
+ )
52
+ role_assignment = Yao::RoleAssignment.list
53
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
54
+ assert_requested(stub)
55
+ end
56
+
57
+ def test_get_user
58
+ user_id = '123456'
59
+ stub = stub_request(:get, "https://example.com:12345/role_assignments?user.id=#{user_id}").
60
+ to_return(
61
+ status: 200,
62
+ body: <<-JSON,
63
+ {
64
+ "role_assignments": [{
65
+ "scope": {
66
+ "project": {
67
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
68
+ }
69
+ }
70
+ }]
71
+ }
72
+ JSON
73
+ headers: {'Content-Type' => 'application/json'}
74
+ )
75
+
76
+ user = Yao::User.new('id' => user_id)
77
+ role_assignment = Yao::RoleAssignment.get(user: user)
78
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
79
+ assert_requested(stub)
80
+ end
81
+
82
+ def test_get_project
83
+ project_id = 'aaaa166533fd49f3b11b1cdce2430000'
84
+ stub = stub_request(:get, "https://example.com:12345/role_assignments?scope.project.id=#{project_id}").
85
+ to_return(
86
+ status: 200,
87
+ body: <<-JSON,
88
+ {
89
+ "role_assignments": [{
90
+ "scope": {
91
+ "project": {
92
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
93
+ }
94
+ }
95
+ }]
96
+ }
97
+ JSON
98
+ headers: {'Content-Type' => 'application/json'}
99
+ )
100
+
101
+ project = Yao::Project.new('id' => project_id)
102
+ role_assignment = Yao::RoleAssignment.get(project: project)
103
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
104
+ assert_requested(stub)
105
+ end
106
+
107
+ def test_get_tenant
108
+ tenant_id = 'aaaa166533fd49f3b11b1cdce2430000'
109
+ stub = stub_request(:get, "https://example.com:12345/role_assignments?scope.project.id=#{tenant_id}").
110
+ to_return(
111
+ status: 200,
112
+ body: <<-JSON,
113
+ {
114
+ "role_assignments": [{
115
+ "scope": {
116
+ "project": {
117
+ "id": "aaaa166533fd49f3b11b1cdce2430000"
118
+ }
119
+ }
120
+ }]
121
+ }
122
+ JSON
123
+ headers: {'Content-Type' => 'application/json'}
124
+ )
125
+
126
+ tenant = Yao::Project.new('id' => tenant_id)
127
+ role_assignment = Yao::RoleAssignment.get(tenant: tenant)
128
+ assert_equal('aaaa166533fd49f3b11b1cdce2430000', role_assignment.first.scope['project']['id'])
129
+ assert_requested(stub)
130
+ end
131
+
35
132
  def test_project
36
- stub = stub_request(:get, "http://example.com:12345/tenants/456789").
133
+ stub = stub_request(:get, "https://example.com:12345/projects/456789").
37
134
  to_return(
38
135
  status: 200,
39
136
  body: <<-JSON,
40
137
  {
41
- "tenant": {
138
+ "project": {
42
139
  "id": "456789"
43
140
  }
44
141
  }
@@ -55,7 +152,7 @@ class TestRoleAssignment < TestYaoResource
55
152
  }
56
153
 
57
154
  role_assignment = Yao::RoleAssignment.new(params)
58
- assert_instance_of(Yao::Resources::Tenant, role_assignment.project)
155
+ assert_instance_of(Yao::Project, role_assignment.project)
59
156
  assert_equal("456789", role_assignment.project.id)
60
157
 
61
158
  assert_requested(stub)
@@ -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,9 +221,9 @@ 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
@@ -20,4 +20,4 @@ class TestServerGroup < TestYaoResource
20
20
  assert_equal("6f70656e737461636b20342065766572", sg.project_id)
21
21
  assert_equal("fake", sg.user_id)
22
22
  end
23
- end
23
+ 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