yao 0.15.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) 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/error.rb +1 -1
  6. data/lib/yao/resources/base.rb +17 -5
  7. data/lib/yao/resources/flavor.rb +10 -0
  8. data/lib/yao/resources/floating_ip.rb +26 -5
  9. data/lib/yao/resources/loadbalancer_pool.rb +10 -20
  10. data/lib/yao/resources/meter.rb +1 -1
  11. data/lib/yao/resources/network.rb +1 -1
  12. data/lib/yao/resources/old_sample.rb +1 -1
  13. data/lib/yao/resources/port.rb +17 -1
  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 +11 -6
  17. data/lib/yao/resources/role_assignment.rb +2 -2
  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/volume.rb +2 -0
  23. data/lib/yao/resources.rb +1 -1
  24. data/lib/yao/version.rb +1 -1
  25. data/test/yao/resources/test_base.rb +21 -0
  26. data/test/yao/resources/test_flavor.rb +67 -33
  27. data/test/yao/resources/test_floating_ip.rb +96 -5
  28. data/test/yao/resources/test_loadbalancer_pool.rb +146 -1
  29. data/test/yao/resources/test_meter.rb +5 -5
  30. data/test/yao/resources/test_network.rb +6 -6
  31. data/test/yao/resources/test_port.rb +54 -6
  32. data/test/yao/resources/test_restfully_accessible.rb +87 -5
  33. data/test/yao/resources/test_role_assignment.rb +3 -3
  34. data/test/yao/resources/test_router.rb +33 -12
  35. data/test/yao/resources/test_security_group.rb +5 -5
  36. data/test/yao/resources/test_server.rb +52 -6
  37. data/test/yao/resources/test_subnet.rb +6 -6
  38. data/test/yao/resources/test_volume.rb +21 -0
  39. data/yao.gemspec +1 -1
  40. metadata +6 -6
@@ -82,14 +82,14 @@ class TestFloatingIP < TestYaoResource
82
82
  assert_requested(stub)
83
83
  end
84
84
 
85
- def test_tenant
85
+ def test_project
86
86
 
87
- stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
87
+ stub = stub_request(:get, "https://example.com:12345/projects/0123456789abcdef0123456789abcdef")
88
88
  .to_return(
89
89
  status: 200,
90
90
  body: <<-JSON,
91
91
  {
92
- "tenant": {
92
+ "project": {
93
93
  "id": "0123456789abcdef0123456789abcdef"
94
94
  }
95
95
  }
@@ -102,8 +102,8 @@ class TestFloatingIP < TestYaoResource
102
102
  "tenant_id" => "0123456789abcdef0123456789abcdef",
103
103
  )
104
104
 
105
- assert_instance_of(Yao::Tenant, fip.tenant)
106
- assert_instance_of(Yao::Tenant, fip.project)
105
+ assert_instance_of(Yao::Project, fip.tenant)
106
+ assert_instance_of(Yao::Project, fip.project)
107
107
  assert_equal('0123456789abcdef0123456789abcdef', fip.tenant.id)
108
108
 
109
109
  assert_requested(stub)
@@ -131,4 +131,95 @@ class TestFloatingIP < TestYaoResource
131
131
 
132
132
  assert_requested(stub)
133
133
  end
134
+
135
+ def test_associate_port
136
+
137
+ floating_ip = Yao::FloatingIP.new("id" => "00000000-0000-0000-0000-000000000000")
138
+ port = Yao::Port.new("id" => "01234567-0123-0123-0123-0123456789ab")
139
+
140
+ stub = stub_request(:put, "https://example.com:12345/floatingips/00000000-0000-0000-0000-000000000000").
141
+ with(
142
+ body: '{"floatingip":{"port_id":"01234567-0123-0123-0123-0123456789ab"}}'
143
+ )
144
+ .to_return(
145
+ status: 200,
146
+ body: <<-JSON,
147
+ {
148
+ "floatingip": {
149
+ "id": "00000000-0000-0000-0000-000000000000"
150
+ }
151
+ }
152
+ JSON
153
+ headers: {'Content-Type' => 'application/json'}
154
+ )
155
+
156
+ resource = Yao::FloatingIP.associate_port(floating_ip.id, port.id)
157
+ assert_instance_of(Yao::FloatingIP, resource)
158
+ assert_equal("00000000-0000-0000-0000-000000000000", resource.id)
159
+
160
+ assert_requested(stub)
161
+ end
162
+
163
+ sub_test_case 'Yao::FloatingIP#associate_port' do
164
+
165
+ def setup
166
+ stub(Yao::Resources::FloatingIP).associate_port {}
167
+ end
168
+
169
+ def test_associate_port
170
+ floating_ip = Yao::FloatingIP.new("id" => "00000000-0000-0000-0000-000000000000")
171
+ port = Yao::Port.new("id" => "01234567-0123-0123-0123-0123456789ab")
172
+
173
+ floating_ip.associate_port(port)
174
+
175
+ assert_received(Yao::Resources::FloatingIP) { |subject|
176
+ subject.associate_port(floating_ip.id, port.id)
177
+ }
178
+ end
179
+ end
180
+
181
+ def test_disassociate_port
182
+
183
+ stub = stub_request(:put, "https://example.com:12345/floatingips/00000000-0000-0000-0000-000000000000").
184
+ with(
185
+ body: '{"floatingip":{"port_id":null}}'
186
+ )
187
+ .to_return(
188
+ status: 200,
189
+ body: <<-JSON,
190
+ {
191
+ "floatingip": {
192
+ "id": "00000000-0000-0000-0000-000000000000"
193
+ }
194
+ }
195
+ JSON
196
+ headers: {'Content-Type' => 'application/json'}
197
+ )
198
+
199
+ floating_ip = Yao::FloatingIP.new("id" => "00000000-0000-0000-0000-000000000000")
200
+
201
+ resource = Yao::FloatingIP.disassociate_port(floating_ip.id)
202
+ assert_instance_of(Yao::FloatingIP, resource)
203
+ assert_equal("00000000-0000-0000-0000-000000000000", resource.id)
204
+
205
+ assert_requested(stub)
206
+ end
207
+
208
+ sub_test_case 'Yao::FloatingIP#disassociate_port' do
209
+
210
+ def setup
211
+ stub(Yao::Resources::FloatingIP).disassociate_port {}
212
+ end
213
+
214
+ def test_associate_port
215
+ floating_ip = Yao::FloatingIP.new("id" => "00000000-0000-0000-0000-000000000000")
216
+ port = Yao::Port.new("id" => "01234567-0123-0123-0123-0123456789ab")
217
+
218
+ floating_ip.disassociate_port
219
+
220
+ assert_received(Yao::Resources::FloatingIP) { |subject|
221
+ subject.disassociate_port(floating_ip.id)
222
+ }
223
+ end
224
+ end
134
225
  end
@@ -13,7 +13,14 @@ class TestLoadBalancerPool < TestYaoResource
13
13
  "type" => "SOURCE_IP"
14
14
  },
15
15
  "operating_status" => "ONLINE",
16
- "name" => "round_robin_pool"
16
+ "name" => "round_robin_pool",
17
+ "members" => [
18
+ {"id" => "957a1ace-1bd2-449b-8455-820b6e4b63f3"},
19
+ ],
20
+ "listeners" => [
21
+ {"id" => "023f2e34-7806-443b-bfae-16c324569a3d"}
22
+ ],
23
+ "healthmonitor_id" => "8ed3c5ac-6efa-420c-bedb-99ba14e58db5",
17
24
  }
18
25
 
19
26
  pool = Yao::Resources::LoadBalancerPool.new(params)
@@ -30,5 +37,143 @@ class TestLoadBalancerPool < TestYaoResource
30
37
  }, pool.session_persistence)
31
38
  assert_equal("ONLINE", pool.operating_status)
32
39
  assert_equal("round_robin_pool", pool.name)
40
+
41
+ # https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=show-member-details-detail#show-member-details
42
+ stub = stub_request(:get, "http://endpoint.example.com:9876/v2.0/lbaas/pools//members/957a1ace-1bd2-449b-8455-820b6e4b63f3")
43
+ .to_return(
44
+ status: 200,
45
+ body: <<-JSON,
46
+ {
47
+ "member": {
48
+ "monitor_port": 8080,
49
+ "project_id": "e3cd678b11784734bc366148aa37580e",
50
+ "name": "web-server-1",
51
+ "weight": 20,
52
+ "backup": false,
53
+ "admin_state_up": true,
54
+ "subnet_id": "bbb35f84-35cc-4b2f-84c2-a6a29bba68aa",
55
+ "created_at": "2017-05-11T17:21:34",
56
+ "provisioning_status": "ACTIVE",
57
+ "monitor_address": null,
58
+ "updated_at": "2017-05-11T17:21:37",
59
+ "address": "192.0.2.16",
60
+ "protocol_port": 80,
61
+ "id": "957a1ace-1bd2-449b-8455-820b6e4b63f3",
62
+ "operating_status": "NO_MONITOR",
63
+ "tags": ["test_tag"]
64
+ }
65
+ }
66
+ JSON
67
+ headers: {'Content-Type' => 'application/json'}
68
+ )
69
+
70
+ assert_instance_of(Yao::LoadBalancerPoolMember, pool.members.first)
71
+ assert_equal("957a1ace-1bd2-449b-8455-820b6e4b63f3", pool.members.first.id)
72
+ assert_equal("web-server-1", pool.members.first.name)
73
+ assert_requested(stub)
74
+
75
+ # https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=show-member-details-detail,show-listener-details-detail,show-pool-details-detail#show-listener-details
76
+ stub = stub_request(:get, "http://endpoint.example.com:9876/v2.0/lbaas/listeners/023f2e34-7806-443b-bfae-16c324569a3d")
77
+ .to_return(
78
+ status: 200,
79
+ body: <<-JSON,
80
+ {
81
+ "listener": {
82
+ "description": "A great TLS listener",
83
+ "admin_state_up": true,
84
+ "project_id": "e3cd678b11784734bc366148aa37580e",
85
+ "protocol": "TERMINATED_HTTPS",
86
+ "protocol_port": 443,
87
+ "provisioning_status": "ACTIVE",
88
+ "default_tls_container_ref": "http://198.51.100.10:9311/v1/containers/a570068c-d295-4780-91d4-3046a325db51",
89
+ "loadbalancers": [
90
+ {
91
+ "id": "607226db-27ef-4d41-ae89-f2a800e9c2db"
92
+ }
93
+ ],
94
+ "insert_headers": {
95
+ "X-Forwarded-Port": "true",
96
+ "X-Forwarded-For": "true"
97
+ },
98
+ "created_at": "2017-02-28T00:42:44",
99
+ "updated_at": "2017-02-28T00:44:30",
100
+ "id": "023f2e34-7806-443b-bfae-16c324569a3d",
101
+ "operating_status": "ONLINE",
102
+ "default_pool_id": "ddb2b28f-89e9-45d3-a329-a359c3e39e4a",
103
+ "sni_container_refs": [
104
+ "http://198.51.100.10:9311/v1/containers/a570068c-d295-4780-91d4-3046a325db51",
105
+ "http://198.51.100.10:9311/v1/containers/aaebb31e-7761-4826-8cb4-2b829caca3ee"
106
+ ],
107
+ "l7policies": [
108
+ {
109
+ "id": "5e618272-339d-4a80-8d14-dbc093091bb1"
110
+ }
111
+ ],
112
+ "name": "great_tls_listener",
113
+ "timeout_client_data": 50000,
114
+ "timeout_member_connect": 5000,
115
+ "timeout_member_data": 50000,
116
+ "timeout_tcp_inspect": 0,
117
+ "tags": ["test_tag"],
118
+ "client_ca_tls_container_ref": "http://198.51.100.10:9311/v1/containers/35649991-49f3-4625-81ce-2465fe8932e5",
119
+ "client_authentication": "MANDATORY",
120
+ "client_crl_container_ref": "http://198.51.100.10:9311/v1/containers/e222b065-b93b-4e2a-9a02-804b7a118c3c",
121
+ "allowed_cidrs": [
122
+ "192.0.2.0/24",
123
+ "198.51.100.0/24"
124
+ ],
125
+ "tls_ciphers": "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256",
126
+ "tls_versions": ["TLSv1.2", "TLSv1.3"],
127
+ "alpn_protocols": ["http/1.1", "http/1.0"]
128
+ }
129
+ }
130
+ JSON
131
+ headers: {'Content-Type' => 'application/json'}
132
+ )
133
+ assert_instance_of(Yao::LoadBalancerListener, pool.listeners.first)
134
+ assert_equal("023f2e34-7806-443b-bfae-16c324569a3d", pool.listeners.first.id)
135
+ assert_equal("great_tls_listener", pool.listeners.first.name)
136
+ assert_requested(stub)
137
+
138
+ # https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=show-member-details-detail,show-listener-details-detail,show-pool-details-detail,show-health-monitor-details-detail#show-health-monitor-details
139
+ stub = stub_request(:get, "http://endpoint.example.com:9876/v2.0/lbaas/healthmonitors/8ed3c5ac-6efa-420c-bedb-99ba14e58db5")
140
+ .to_return(
141
+ status: 200,
142
+ body: <<-JSON,
143
+ {
144
+ "healthmonitor": {
145
+ "project_id": "e3cd678b11784734bc366148aa37580e",
146
+ "name": "super-pool-health-monitor",
147
+ "admin_state_up": true,
148
+ "pools": [
149
+ {
150
+ "id": "4029d267-3983-4224-a3d0-afb3fe16a2cd"
151
+ }
152
+ ],
153
+ "created_at": "2017-05-11T23:53:47",
154
+ "provisioning_status": "ACTIVE",
155
+ "updated_at": "2017-05-11T23:53:47",
156
+ "delay": 10,
157
+ "expected_codes": "200",
158
+ "max_retries": 1,
159
+ "http_method": "GET",
160
+ "timeout": 5,
161
+ "max_retries_down": 3,
162
+ "url_path": "/",
163
+ "type": "HTTP",
164
+ "id": "8ed3c5ac-6efa-420c-bedb-99ba14e58db5",
165
+ "operating_status": "ONLINE",
166
+ "tags": ["test_tag"],
167
+ "http_version": 1.0,
168
+ "domain_name": null
169
+ }
170
+ }
171
+ JSON
172
+ headers: {'Content-Type' => 'application/json'}
173
+ )
174
+ assert_instance_of(Yao::LoadBalancerHealthMonitor, pool.healthmonitor)
175
+ assert_equal("8ed3c5ac-6efa-420c-bedb-99ba14e58db5", pool.healthmonitor.id)
176
+ assert_equal("super-pool-health-monitor", pool.healthmonitor.name)
177
+ assert_requested(stub)
33
178
  end
34
179
  end
@@ -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
@@ -170,4 +170,52 @@ class TestPort < TestYaoResource
170
170
 
171
171
  assert_requested(stub)
172
172
  end
173
+
174
+ def test_floating_ip
175
+
176
+ stub = stub_request(:get, "https://example.com:12345/floatingips?port_id")
177
+ .to_return(
178
+ status: 200,
179
+ body: <<-JSON,
180
+ {
181
+ "floatingips": [{
182
+ "id": "00000000-0000-0000-0000-000000000000"
183
+ }]
184
+ }
185
+ JSON
186
+ headers: {'Content-Type' => 'application/json'}
187
+ )
188
+
189
+ params = {
190
+ "port_id" => "00000000-0000-0000-0000-000000000000",
191
+ }
192
+
193
+ port = Yao::Port.new(params)
194
+ assert_instance_of(Yao::FloatingIP, port.floating_ip)
195
+ assert_true(port.has_floating_ip?)
196
+ assert_requested(stub)
197
+ end
198
+
199
+ def test_floating_ip_empty
200
+
201
+ stub = stub_request(:get, "https://example.com:12345/floatingips?port_id")
202
+ .to_return(
203
+ status: 200,
204
+ body: <<-JSON,
205
+ {
206
+ "floatingips": []
207
+ }
208
+ JSON
209
+ headers: {'Content-Type' => 'application/json'}
210
+ )
211
+
212
+ params = {
213
+ "port_id" => "00000000-0000-0000-0000-000000000000",
214
+ }
215
+
216
+ port = Yao::Port.new(params)
217
+ assert_nil(port.floating_ip)
218
+ assert_false(port.has_floating_ip?)
219
+ assert_requested(stub)
220
+ end
173
221
  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
 
@@ -76,7 +88,7 @@ class TestRestfullyAccesible < Test::Unit::TestCase
76
88
  stub_get_request_not_found([@url, @resources_name, name].join('/'))
77
89
  stub_get_request_with_json_response([@url, "#{@resources_name}?name=#{name}"].join('/'), body)
78
90
 
79
- assert_raise(Yao::InvalidResponse, "raise proper exception") do
91
+ assert_raise(Yao::ItemNotFound, "raise proper exception") do
80
92
  Test.get(name)
81
93
  end
82
94
  end
@@ -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,63 @@ 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
+
143
+ test 'multiple same name found' do
144
+ name = 'dummy'
145
+ uuid = '00112233-4455-6677-8899-aabbccddeeff'
146
+ list_body = { @resources_name => [
147
+ { 'name' => 'dummy', 'id' => uuid },
148
+ { 'name' => 'dummy', 'id' => '308cb410-9c84-40ec-a3eb-583001aaa7fd' }
149
+ ]}
150
+ stub1 = stub_get_request_not_found([@url, @resources_name, name].join('/'))
151
+ stub2 = stub_get_request_with_json_response([@url, "#{@resources_name}?name=#{name}"].join('/'), list_body)
152
+
153
+ assert_raise(Yao::TooManyItemFonud, "More than one resource exists with the name '#{name}'") do
154
+ Test.send(:get_by_name, name)
155
+ end
156
+ end
157
+
158
+ test 'empty name' do
159
+ assert_raise(Yao::InvalidRequest, "Invalid requeset with empty name or nil") do
160
+ Test.send(:get_by_name, '')
161
+ end
162
+ end
163
+
164
+ test 'nil' do
165
+ assert_raise(Yao::InvalidRequest, "Invalid requeset with empty name or nil") do
166
+ Test.send(:get_by_name, nil)
167
+ end
168
+ end
169
+
170
+ test 'not found' do
171
+ name = "dummy"
172
+ uuid = "00112233-4455-6677-8899-aabbccddeeff"
173
+ body = {@resources_name => []}
174
+
175
+ stub1 = stub_get_request_not_found([@url, @resources_name, name].join('/'))
176
+ stub2 = stub_get_request_with_json_response([@url, "#{@resources_name}?name=#{name}"].join('/'), body)
177
+
178
+ assert_raise(Yao::ItemNotFound) do
179
+ Test.send(:get_by_name, name)
180
+ end
181
+ end
182
+ end
183
+
106
184
  def test_find_by_name
107
185
  mock(Test).list({"name" => "dummy"}) { "dummy" }
108
186
 
@@ -116,4 +194,8 @@ class TestRestfullyAccesible < Test::Unit::TestCase
116
194
  assert_equal(false, Test.send(:uuid?, "dummy resource"))
117
195
  assert_equal(false, Test.send(:uuid?, "00112233445566778899aabbccddeeff"))
118
196
  end
197
+
198
+ def test_delete
199
+ assert_equal(Test.method(:delete), Test.method(:destroy))
200
+ end
119
201
  end
@@ -130,12 +130,12 @@ class TestRoleAssignment < TestYaoResource
130
130
  end
131
131
 
132
132
  def test_project
133
- stub = stub_request(:get, "https://example.com:12345/tenants/456789").
133
+ stub = stub_request(:get, "https://example.com:12345/projects/456789").
134
134
  to_return(
135
135
  status: 200,
136
136
  body: <<-JSON,
137
137
  {
138
- "tenant": {
138
+ "project": {
139
139
  "id": "456789"
140
140
  }
141
141
  }
@@ -152,7 +152,7 @@ class TestRoleAssignment < TestYaoResource
152
152
  }
153
153
 
154
154
  role_assignment = Yao::RoleAssignment.new(params)
155
- assert_instance_of(Yao::Resources::Tenant, role_assignment.project)
155
+ assert_instance_of(Yao::Project, role_assignment.project)
156
156
  assert_equal("456789", role_assignment.project.id)
157
157
 
158
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