yao 0.7.0 → 0.8.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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +15 -0
  3. data/.github/workflows/ubuntu-rvm.yml +29 -0
  4. data/.github/workflows/ubuntu.yml +22 -0
  5. data/Gemfile +10 -2
  6. data/README.md +3 -3
  7. data/lib/yao/resources.rb +5 -0
  8. data/lib/yao/resources/action.rb +1 -1
  9. data/lib/yao/resources/compute_services.rb +46 -0
  10. data/lib/yao/resources/flavor.rb +1 -10
  11. data/lib/yao/resources/floating_ip.rb +6 -6
  12. data/lib/yao/resources/hypervisor.rb +6 -12
  13. data/lib/yao/resources/keypair.rb +22 -3
  14. data/lib/yao/resources/meter.rb +6 -7
  15. data/lib/yao/resources/network.rb +3 -1
  16. data/lib/yao/resources/network_associationable.rb +14 -0
  17. data/lib/yao/resources/old_sample.rb +5 -7
  18. data/lib/yao/resources/port.rb +6 -6
  19. data/lib/yao/resources/port_associationable.rb +14 -0
  20. data/lib/yao/resources/project.rb +16 -0
  21. data/lib/yao/resources/resource.rb +12 -7
  22. data/lib/yao/resources/restfully_accessible.rb +72 -35
  23. data/lib/yao/resources/role.rb +73 -18
  24. data/lib/yao/resources/router.rb +3 -1
  25. data/lib/yao/resources/sample.rb +1 -5
  26. data/lib/yao/resources/security_group.rb +3 -1
  27. data/lib/yao/resources/server.rb +4 -9
  28. data/lib/yao/resources/subnet.rb +5 -5
  29. data/lib/yao/resources/tenant.rb +1 -1
  30. data/lib/yao/resources/tenant_associationable.rb +17 -0
  31. data/lib/yao/resources/user.rb +15 -4
  32. data/lib/yao/resources/volume.rb +1 -10
  33. data/lib/yao/version.rb +1 -1
  34. data/test/config.rb +1 -0
  35. data/test/support/auth_stub.rb +1 -0
  36. data/test/support/test_yao_resource.rb +49 -0
  37. data/test/yao/resources/test_aggregates.rb +1 -4
  38. data/test/yao/resources/test_base.rb +1 -1
  39. data/test/yao/resources/test_compute_services.rb +118 -0
  40. data/test/yao/resources/test_flavor.rb +15 -9
  41. data/test/yao/resources/test_floating_ip.rb +24 -19
  42. data/test/yao/resources/test_host.rb +1 -1
  43. data/test/yao/resources/test_hypervisor.rb +17 -10
  44. data/test/yao/resources/test_image.rb +1 -1
  45. data/test/yao/resources/test_keypair.rb +3 -6
  46. data/test/yao/resources/test_loadbalancer.rb +1 -3
  47. data/test/yao/resources/test_loadbalancer_healthmonitor.rb +1 -3
  48. data/test/yao/resources/test_loadbalancer_listener.rb +1 -5
  49. data/test/yao/resources/test_loadbalancer_pool.rb +1 -3
  50. data/test/yao/resources/test_loadbalancer_pool_member.rb +1 -3
  51. data/test/yao/resources/test_meter.rb +13 -14
  52. data/test/yao/resources/test_network.rb +28 -1
  53. data/test/yao/resources/test_old_sample.rb +86 -0
  54. data/test/yao/resources/test_port.rb +29 -7
  55. data/test/yao/resources/test_project.rb +32 -0
  56. data/test/yao/resources/test_resource.rb +56 -0
  57. data/test/yao/resources/test_role.rb +255 -1
  58. data/test/yao/resources/test_role_assignment.rb +4 -6
  59. data/test/yao/resources/test_router.rb +26 -6
  60. data/test/yao/resources/test_sample.rb +61 -0
  61. data/test/yao/resources/test_security_group.rb +23 -1
  62. data/test/yao/resources/test_security_group_rule.rb +1 -1
  63. data/test/yao/resources/test_server.rb +34 -8
  64. data/test/yao/resources/test_subnet.rb +25 -6
  65. data/test/yao/resources/test_user.rb +73 -1
  66. data/test/yao/resources/test_volume.rb +31 -1
  67. data/test/yao/resources/test_volume_type.rb +1 -1
  68. data/test/yao/test_config.rb +21 -8
  69. data/test/yao/test_read_only.rb +3 -3
  70. data/yao.gemspec +0 -8
  71. metadata +22 -101
  72. data/.travis.yml +0 -28
@@ -1,4 +1,5 @@
1
- class TestHypervisor < Test::Unit::TestCase
1
+ class TestHypervisor < TestYaoResource
2
+
2
3
  def test_hypervisor
3
4
  params = {
4
5
  "status" => "enabled"
@@ -8,12 +9,8 @@ class TestHypervisor < Test::Unit::TestCase
8
9
  assert_equal(host.enabled?, true)
9
10
  end
10
11
 
11
- def setup
12
- Yao.default_client.pool["compute"] = Yao::Client.gen_client("https://example.com:12345")
13
- end
14
-
15
- def test_list_detail
16
- stub_request(:get, "https://example.com:12345/os-hypervisors/detail")
12
+ def test_list
13
+ stub = stub_request(:get, "https://example.com:12345/os-hypervisors/detail")
17
14
  .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}"})
18
15
  .to_return(
19
16
  status: 200,
@@ -27,12 +24,18 @@ class TestHypervisor < Test::Unit::TestCase
27
24
  headers: {'Content-Type' => 'application/json'}
28
25
  )
29
26
 
30
- h = Yao::Resources::Hypervisor.list_detail
27
+ h = Yao::Resources::Hypervisor.list
31
28
  assert_equal(h.first.id, "dummy")
29
+
30
+ assert_requested(stub)
31
+ end
32
+
33
+ def test_list_detail
34
+ assert_equal(Yao::Hypervisor.method(:list_detail), Yao::Hypervisor.method(:list))
32
35
  end
33
36
 
34
37
  def test_statistics
35
- stub_request(:get, "https://example.com:12345/os-hypervisors/statistics")
38
+ stub = stub_request(:get, "https://example.com:12345/os-hypervisors/statistics")
36
39
  .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}"})
37
40
  .to_return(
38
41
  status: 200,
@@ -59,10 +62,12 @@ class TestHypervisor < Test::Unit::TestCase
59
62
 
60
63
  s = Yao::Resources::Hypervisor.statistics
61
64
  assert_equal(s.count, 1)
65
+
66
+ assert_requested(stub)
62
67
  end
63
68
 
64
69
  def test_uptime
65
- stub_request(:get, "https://example.com:12345/os-hypervisors/1/uptime")
70
+ stub = stub_request(:get, "https://example.com:12345/os-hypervisors/1/uptime")
66
71
  .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}"})
67
72
  .to_return(
68
73
  status: 200,
@@ -82,5 +87,7 @@ class TestHypervisor < Test::Unit::TestCase
82
87
 
83
88
  u = Yao::Resources::Hypervisor.uptime(1)
84
89
  assert_equal(u.uptime, " 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14")
90
+
91
+ assert_requested(stub)
85
92
  end
86
93
  end
@@ -1,4 +1,4 @@
1
- class TestImage < Test::Unit::TestCase
1
+ class TestImage < TestYaoResource
2
2
 
3
3
  def test_image
4
4
 
@@ -1,8 +1,4 @@
1
- class TestKeypair < Test::Unit::TestCase
2
-
3
- def setup
4
- Yao.default_client.pool["compute"] = Yao::Client.gen_client("https://example.com:12345")
5
- end
1
+ class TestKeypair < TestYaoResource
6
2
 
7
3
  def test_keypair
8
4
  # https://docs.openstack.org/api-ref/compute/?expanded=list-keypairs-detail#list-keypairs
@@ -24,7 +20,7 @@ EOS
24
20
  end
25
21
 
26
22
  def test_list
27
- stub_request(:get, "https://example.com:12345/os-keypairs")
23
+ stub = stub_request(:get, "https://example.com:12345/os-keypairs")
28
24
  .to_return(
29
25
  status: 200,
30
26
  body: <<-JSON,
@@ -50,5 +46,6 @@ EOS
50
46
 
51
47
  keypairs = Yao::Keypair.list
52
48
  assert_equal(keypairs.first.fingerprint, "7e:eb:ab:24:ba:d1:e1:88:ae:9a:fb:66:53:df:d3:bd")
49
+ assert_requested(stub)
53
50
  end
54
51
  end
@@ -1,6 +1,4 @@
1
- require "time"
2
-
3
- class TestLoadBalancer < Test::Unit::TestCase
1
+ class TestLoadBalancer < TestYaoResource
4
2
  def test_loadbalancer
5
3
  params = {
6
4
  "provider" => "octavia",
@@ -1,6 +1,4 @@
1
- require "time"
2
-
3
- class TestLoadBalancerHealthMonitor < Test::Unit::TestCase
1
+ class TestLoadBalancerHealthMonitor < TestYaoResource
4
2
  def test_loadbalancer_healtchmonitor
5
3
  params = {
6
4
  "name" => "super-pool-health-monitor",
@@ -1,6 +1,4 @@
1
- require "time"
2
-
3
- class TestLoadBalancerListener < Test::Unit::TestCase
1
+ class TestLoadBalancerListener < TestYaoResource
4
2
  def test_loadbalancer_listener
5
3
  params = {
6
4
  "description" => "A great TLS listener",
@@ -22,7 +20,6 @@ class TestLoadBalancerListener < Test::Unit::TestCase
22
20
  ],
23
21
  "l7policies" => [
24
22
  {
25
- "id" => "58284ac9-673e-47ff-9dcb-09871a1956c4",
26
23
  "id" => "5e618272-339d-4a80-8d14-dbc093091bb1"
27
24
  }
28
25
  ],
@@ -49,7 +46,6 @@ class TestLoadBalancerListener < Test::Unit::TestCase
49
46
  ])
50
47
  assert_equal(listener.l7policies, [
51
48
  {
52
- "id" => "58284ac9-673e-47ff-9dcb-09871a1956c4",
53
49
  "id" => "5e618272-339d-4a80-8d14-dbc093091bb1"
54
50
  }
55
51
  ])
@@ -1,6 +1,4 @@
1
- require "time"
2
-
3
- class TestLoadBalancerPool < Test::Unit::TestCase
1
+ class TestLoadBalancerPool < TestYaoResource
4
2
  def test_loadbalancer_pool
5
3
  params = {
6
4
  "lb_algorithm" => "ROUND_ROBIN",
@@ -1,6 +1,4 @@
1
- require "time"
2
-
3
- class TestLoadBalancerPoolMember < Test::Unit::TestCase
1
+ class TestLoadBalancerPoolMember < TestYaoResource
4
2
  def test_loadbalancer_pool_member
5
3
  params = {
6
4
  "monitor_port" => 8080,
@@ -1,10 +1,4 @@
1
- class TestMeter < Test::Unit::TestCase
2
-
3
- def setup
4
- Yao.default_client.pool["metering"] = Yao::Client.gen_client("https://example.com:12345")
5
- # notice: admin_pool を指定するあたりでハマったので注意
6
- Yao.default_client.admin_pool["identity"] = Yao::Client.gen_client("https://example.com:12345")
7
- end
1
+ class TestMeter < TestYaoResource
8
2
 
9
3
  def test_meter
10
4
  # https://docs.openstack.org/ceilometer/pike/webapi/v2.html
@@ -34,9 +28,8 @@ class TestMeter < Test::Unit::TestCase
34
28
  end
35
29
 
36
30
  def test_resource
37
-
38
31
  # https://docs.openstack.org/ceilometer/pike/webapi/v2.html
39
- stub_request(:get, "https://example.com:12345/v2/resources/00000000-0000-0000-0000-000000000000")
32
+ stub = stub_request(:get, "https://example.com:12345/v2/resources/00000000-0000-0000-0000-000000000000")
40
33
  .to_return(
41
34
  status: 200,
42
35
  body: <<-JSON,
@@ -52,13 +45,15 @@ class TestMeter < Test::Unit::TestCase
52
45
  }
53
46
 
54
47
  meter = Yao::Meter.new(params)
55
- resource = meter.resource
56
- assert_instance_of(Yao::Resource, resource)
57
- assert_equal(resource.resource_id, "00000000-0000-0000-0000-000000000000")
48
+ assert_instance_of(Yao::Resource, meter.resource)
49
+ assert_equal(meter.resource.resource_id, "00000000-0000-0000-0000-000000000000")
50
+ assert_equal(meter.resource.id, "00000000-0000-0000-0000-000000000000")
51
+
52
+ assert_requested(stub)
58
53
  end
59
54
 
60
55
  def test_tenant
61
- stub_request(:get, "https://example.com:12345/tenants/00000000-0000-0000-0000-000000000000")
56
+ stub = stub_request(:get, "https://example.com:12345/tenants/00000000-0000-0000-0000-000000000000")
62
57
  .to_return(
63
58
  status: 200,
64
59
  body: <<-JSON,
@@ -78,10 +73,12 @@ class TestMeter < Test::Unit::TestCase
78
73
  meter = Yao::Meter.new(params)
79
74
  assert_instance_of(Yao::Tenant, meter.tenant)
80
75
  assert_equal(meter.tenant.id, "00000000-0000-0000-0000-000000000000")
76
+
77
+ assert_requested(stub)
81
78
  end
82
79
 
83
80
  def test_user
84
- stub_request(:get, "https://example.com:12345/users/00000000-0000-0000-0000-000000000000")
81
+ stub = stub_request(:get, "https://example.com:12345/users/00000000-0000-0000-0000-000000000000")
85
82
  .to_return(
86
83
  status: 200,
87
84
  body: <<-JSON,
@@ -101,5 +98,7 @@ class TestMeter < Test::Unit::TestCase
101
98
  meter = Yao::Meter.new(params)
102
99
  assert_instance_of(Yao::User, meter.user)
103
100
  assert_equal(meter.user.id, "00000000-0000-0000-0000-000000000000")
101
+
102
+ assert_requested(stub)
104
103
  end
105
104
  end
@@ -1,4 +1,4 @@
1
- class TestNetwork < Test::Unit::TestCase
1
+ class TestNetwork < TestYaoResource
2
2
 
3
3
  def test_network
4
4
 
@@ -35,4 +35,31 @@ class TestNetwork < Test::Unit::TestCase
35
35
  assert_equal(network.type, "vlan")
36
36
  assert_equal(network.segmentation_id, 1000)
37
37
  end
38
+
39
+ def test_tenant
40
+
41
+ stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
42
+ .to_return(
43
+ status: 200,
44
+ body: <<-JSON,
45
+ {
46
+ "tenant": {
47
+ "id": "0123456789abcdef0123456789abcdef"
48
+ }
49
+ }
50
+ JSON
51
+ headers: {'Content-Type' => 'application/json'}
52
+ )
53
+
54
+ network = Yao::Network.new(
55
+ "project_id" => "0123456789abcdef0123456789abcdef",
56
+ "tenant_id" => "0123456789abcdef0123456789abcdef",
57
+ )
58
+
59
+ assert_instance_of(Yao::Tenant, network.tenant)
60
+ assert_instance_of(Yao::Tenant, network.project)
61
+ assert_equal(network.tenant.id, '0123456789abcdef0123456789abcdef')
62
+
63
+ assert_requested(stub)
64
+ end
38
65
  end
@@ -0,0 +1,86 @@
1
+ class TestOldSample < TestYaoResource
2
+
3
+ def test_old_sample
4
+
5
+ # https://docs.openstack.org/ceilometer/pike/webapi/v2.html#Sample
6
+ params = {
7
+ "counter_name" => "instance",
8
+ "counter_type" => "gauge",
9
+ "counter_unit" => "instance",
10
+ "counter_volume" => 1.0,
11
+ "message_id" => "5460acce-4fd6-480d-ab18-9735ec7b1996",
12
+ "project_id" => "35b17138-b364-4e6a-a131-8f3099c5be68",
13
+ "recorded_at" => "2015-01-01T12:00:00",
14
+ "resource_id" => "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
15
+ "resource_metadata" => {
16
+ "name1" => "value1",
17
+ "name2" => "value2"
18
+ },
19
+ "source" => "openstack",
20
+ "timestamp" => "2015-01-01T12:00:00",
21
+ "user_id" => "efd87807-12d2-4b38-9c70-5f5c2ac427ff"
22
+ }
23
+
24
+ sample = Yao::Resources::OldSample.new(params)
25
+
26
+ assert_equal(sample.id, "5460acce-4fd6-480d-ab18-9735ec7b1996")
27
+ assert_equal(sample.message_id, "5460acce-4fd6-480d-ab18-9735ec7b1996")
28
+
29
+ assert_equal(sample.counter_name, "instance")
30
+ assert_equal(sample.counter_type, "gauge")
31
+ assert_equal(sample.counter_unit, "instance")
32
+ assert_equal(sample.counter_volume, 1.0)
33
+ assert_equal(sample.resource_id, "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36")
34
+ assert_equal(sample.timestamp, Time.parse("2015-01-01T12:00:00"))
35
+ assert_equal(sample.resource_metadata, {
36
+ "name1" => "value1",
37
+ "name2" => "value2"
38
+ })
39
+ assert_equal(sample.user_id, "efd87807-12d2-4b38-9c70-5f5c2ac427ff")
40
+ assert_equal(sample.source, "openstack")
41
+ assert_equal(sample.recorded_at, Time.parse("2015-01-01T12:00:00"))
42
+ end
43
+
44
+ def test_resource
45
+ # https://docs.openstack.org/ceilometer/pike/webapi/v2.html
46
+ stub = stub_request(:get, "https://example.com:12345/v2/resources/00000000-0000-0000-0000-000000000000")
47
+ .to_return(
48
+ status: 200,
49
+ body: <<-JSON,
50
+ {
51
+ "resource_id": "00000000-0000-0000-0000-000000000000"
52
+ }
53
+ JSON
54
+ headers: {'Content-Type' => 'application/json'}
55
+ )
56
+
57
+ sample = Yao::Resources::OldSample.new( 'resource_id' => '00000000-0000-0000-0000-000000000000' )
58
+
59
+ assert_instance_of(Yao::Resources::Resource, sample.resource)
60
+ assert_equal(sample.resource.id, "00000000-0000-0000-0000-000000000000")
61
+
62
+ assert_requested(stub)
63
+ end
64
+
65
+ def test_user
66
+
67
+ stub = stub_request(:get, "https://example.com:12345/users/00000000-0000-0000-0000-000000000000")
68
+ .to_return(
69
+ status: 200,
70
+ body: <<-JSON,
71
+ {
72
+ "user": {
73
+ "id": "00000000-0000-0000-0000-000000000000"
74
+ }
75
+ }
76
+ JSON
77
+ headers: {'Content-Type' => 'application/json'}
78
+ )
79
+
80
+ meter = Yao::OldSample.new( "user_id" => "00000000-0000-0000-0000-000000000000" )
81
+ assert_instance_of(Yao::User, meter.user)
82
+ assert_equal(meter.user.id, "00000000-0000-0000-0000-000000000000")
83
+
84
+ assert_requested(stub)
85
+ end
86
+ end
@@ -1,8 +1,4 @@
1
- class TestPort < Test::Unit::TestCase
2
-
3
- def setup
4
- Yao.default_client.pool["network"] = Yao::Client.gen_client("https://example.com:12345")
5
- end
1
+ class TestPort < TestYaoResource
6
2
 
7
3
  def test_port
8
4
 
@@ -81,6 +77,28 @@ class TestPort < Test::Unit::TestCase
81
77
  assert_equal(port.primary_ip, "10.0.0.1")
82
78
  end
83
79
 
80
+ def test_tenant
81
+
82
+ stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
83
+ .to_return(
84
+ status: 200,
85
+ body: <<-JSON,
86
+ {
87
+ "tenant": {
88
+ "id": "0123456789abcdef0123456789abcdef"
89
+ }
90
+ }
91
+ JSON
92
+ headers: {'Content-Type' => 'application/json'}
93
+ )
94
+
95
+ port = Yao::Port.new('tenant_id' => '0123456789abcdef0123456789abcdef')
96
+ assert_instance_of(Yao::Tenant, port.tenant)
97
+ assert_equal(port.tenant.id, '0123456789abcdef0123456789abcdef')
98
+
99
+ assert_requested(stub)
100
+ end
101
+
84
102
  def test_primary_ip
85
103
 
86
104
  params = {
@@ -98,7 +116,7 @@ class TestPort < Test::Unit::TestCase
98
116
 
99
117
  def test_primary_subnet
100
118
 
101
- stub_request(:get, "https://example.com:12345/subnets/00000000-0000-0000-0000-000000000000")
119
+ stub = stub_request(:get, "https://example.com:12345/subnets/00000000-0000-0000-0000-000000000000")
102
120
  .to_return(
103
121
  status: 200,
104
122
  body: <<-JSON,
@@ -123,11 +141,13 @@ class TestPort < Test::Unit::TestCase
123
141
  port = Yao::Port.new(params)
124
142
  assert{ port.primary_subnet.instance_of?(Yao::Subnet) }
125
143
  assert_equal(port.primary_subnet.id, "00000000-0000-0000-0000-000000000000")
144
+
145
+ assert_requested(stub)
126
146
  end
127
147
 
128
148
  def test_network
129
149
 
130
- stub_request(:get, "https://example.com:12345/networks/00000000-0000-0000-0000-000000000000")
150
+ stub = stub_request(:get, "https://example.com:12345/networks/00000000-0000-0000-0000-000000000000")
131
151
  .to_return(
132
152
  status: 200,
133
153
  body: <<-JSON,
@@ -147,5 +167,7 @@ class TestPort < Test::Unit::TestCase
147
167
  port = Yao::Port.new(params)
148
168
  assert_instance_of(Yao::Network, port.network)
149
169
  assert_equal(port.network.id, "00000000-0000-0000-0000-000000000000")
170
+
171
+ assert_requested(stub)
150
172
  end
151
173
  end
@@ -0,0 +1,32 @@
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
+ # https://docs.openstack.org/api-ref/identity/v3/?expanded=list-projects-detail#projects
8
+ def test_project
9
+ params = {
10
+ "is_domain" => false,
11
+ "description" => nil,
12
+ "domain_id" => "default",
13
+ "enabled" => true,
14
+ "id" => "0c4e939acacf4376bdcd1129f1a054ad",
15
+ "links" => {
16
+ "self" => "http://example.com/identity/v3/projects/0c4e939acacf4376bdcd1129f1a054ad"
17
+ },
18
+ "name" => "admin",
19
+ "parent_id" => nil,
20
+ "tags" => []
21
+ }
22
+
23
+ project = Yao::Project.new(params)
24
+ assert_equal(project.domain?, false)
25
+ assert_equal(project.description, nil)
26
+ assert_equal(project.domain_id, "default")
27
+ assert_equal(project.enabled?, true)
28
+ assert_equal(project.id, "0c4e939acacf4376bdcd1129f1a054ad")
29
+ assert_equal(project.name, "admin")
30
+ assert_equal(project.parent_id, nil)
31
+ end
32
+ end
@@ -0,0 +1,56 @@
1
+ class TestResource < TestYaoResource
2
+
3
+ def test_resource
4
+
5
+ # https://docs.openstack.org/ceilometer/pike/webapi/v2.html#Resource
6
+ params = {
7
+ "links" =>[
8
+ {
9
+ "href" => "http://localhost:8777/v2/resources/bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
10
+ "rel" => "self"
11
+ },
12
+ {
13
+ "href" => "http://localhost:8777/v2/meters/volume?q.field=resource_id&q.value=bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
14
+ "rel" => "volume"
15
+ }
16
+ ],
17
+ "metadata" => {
18
+ "name1" =>"value1",
19
+ "name2" =>"value2"
20
+ },
21
+ "project_id" => "35b17138-b364-4e6a-a131-8f3099c5be68",
22
+ "resource_id" => "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
23
+ "source" => "openstack",
24
+ "user_id" => "efd87807-12d2-4b38-9c70-5f5c2ac427ff",
25
+ # uncodumented
26
+ "last_sample_timestamp" => "2019-08-29T08:41:22.555000",
27
+ "first_sample_timestamp" => "2019-03-19T08:41:21.383000",
28
+ }
29
+
30
+ resource = Yao::Resources::Resource.new(params)
31
+
32
+ assert_equal(resource.last_sample_timestamp, "2019-08-29T08:41:22.555000")
33
+ assert_equal(resource.last_sampled_at, Time.parse("2019-08-29T08:41:22.555000"))
34
+
35
+ assert_equal(resource.first_sample_timestamp, "2019-03-19T08:41:21.383000")
36
+ assert_equal(resource.first_sampled_at, Time.parse("2019-03-19T08:41:21.383000"))
37
+
38
+ assert_equal(resource.id, "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36")
39
+ assert_equal(resource.resource_id, "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36")
40
+ assert_equal(resource.user_id, "efd87807-12d2-4b38-9c70-5f5c2ac427ff")
41
+ assert_equal(resource.metadata, {
42
+ "name1" =>"value1",
43
+ "name2" =>"value2"
44
+ })
45
+ assert_equal(resource.links, [
46
+ {
47
+ "href" => "http://localhost:8777/v2/resources/bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
48
+ "rel" => "self"
49
+ },
50
+ {
51
+ "href" => "http://localhost:8777/v2/meters/volume?q.field=resource_id&q.value=bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
52
+ "rel" => "volume"
53
+ }
54
+ ])
55
+ end
56
+ end