yao 0.6.3 → 0.7.0

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: 4bf740bcd6b85eca63564301bd0973aa28a0a3b0b23b54f3b6ab0e97f07dc9a1
4
- data.tar.gz: 5eedb044d0dcc2ba116ffcb8f7682877ae5bf474ff248eb365eaea3153f6c319
3
+ metadata.gz: 74b1d157a6a9fbf7bb533bf9bf95755c44fc29f76a412c71a492ca849310fefb
4
+ data.tar.gz: 93fe712c7e19d8a007c29258d9c3f619df4765bf6934e10937121fec77afcdb6
5
5
  SHA512:
6
- metadata.gz: caee46b46e10040bcd80c37c9fd27993a4b1108f765e12352252bca33780f8b7ab4924c87da301f67f753911f8cd7ac79ebcf196ce9fdf081b581fbf2ad6c6db
7
- data.tar.gz: 1e6d1450e4c8c0d890908a0df085afcc735ecfc9a95451338097c7325dd19b751dbc80ca67afefa0ca649043835e4404ee62f6fef9063950db5a41be2408e8c9
6
+ metadata.gz: 449ee882dafffefe8839b0fd39d857e15801967e4c73b650e39412d14c0121d833a3b11ff1c875b6de5ecd94d4da1a33424e5bf19a36ea58a7a4e8e639251cb5
7
+ data.tar.gz: 443e2353eadf6df3c5f6b357d46f7c23d8fa4a87ff493f11f0e82c14d47562e9a5670cf88d2f6043992a64c7d5e8368eb15525ee6c57b1890f9464f6ff1822c7
@@ -106,9 +106,10 @@ Faraday::Response.register_middleware os_dumper: -> { Faraday::Response::OSDumpe
106
106
 
107
107
  class Faraday::Response::OSResponseRecorder < Faraday::Response::Middleware
108
108
  def on_complete(env)
109
- require 'pathname'
110
- root = Pathname.new(File.expand_path('../../../tmp', __FILE__))
111
- Dir.mkdir(root) unless File.exist?(root)
109
+ require 'tmpdir'
110
+
111
+ @@tmpdir ||= Dir.mktmpdir('yao-')
112
+ root = Pathname.new(@@tmpdir)
112
113
 
113
114
  path = [env.method.to_s.upcase, env.url.path.gsub('/', '-')].join("-") + ".json"
114
115
 
@@ -1,9 +1,26 @@
1
1
  module Yao::Resources
2
2
  class FloatingIP < Base
3
- friendly_attributes :fixed_ip, :instance_id, :ip, :pool
3
+ friendly_attributes :router_id, :description, :dns_domain, :dns_name,
4
+ :revision_number, :project_id, :tenant_id,
5
+ :floating_network_id, :fixed_ip_address,
6
+ :floating_ip_address, :port_id,
7
+ :status, :port_details, :tags, :port_forwardings
4
8
 
5
- self.service = "compute"
6
- self.resource_name = "os-floating-ip"
7
- self.resources_name = "os-floating-ips"
9
+ self.service = "network"
10
+ self.resource_name = "floatingip"
11
+ self.resources_name = "floatingips"
12
+
13
+ def router
14
+ @router ||= Yao::Router.get(router_id)
15
+ end
16
+
17
+ def project
18
+ @project ||= Yao::Tenant.get(project_id)
19
+ end
20
+ alias :tenant :project
21
+
22
+ def port
23
+ @port ||= Yao::Port.find(port_id)
24
+ end
8
25
  end
9
26
  end
@@ -25,11 +25,6 @@ module Yao::Resources
25
25
  end
26
26
 
27
27
  class << self
28
- def get_by_name(name)
29
- self.list(name: name)
30
- end
31
- alias find_by_name get_by_name
32
-
33
28
  def accessible
34
29
  as_member { self.list }
35
30
  end
data/lib/yao/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.6.3"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require "time"
2
2
  require "date"
3
3
 
4
- class TestRole < Test::Unit::TestCase
4
+ class TestAggregates < Test::Unit::TestCase
5
5
  def test_server_aggregates
6
6
  params = {
7
7
  "availability_zone" => "nova",
@@ -0,0 +1,94 @@
1
+ class TestFlavor < Test::Unit::TestCase
2
+
3
+ def setup
4
+ Yao.default_client.pool["compute"] = Yao::Client.gen_client("https://example.com:12345")
5
+ end
6
+
7
+ def test_flavor
8
+ # https://docs.openstack.org/api-ref/compute/?expanded=list-flavors-detail,list-flavors-with-details-detail#list-flavors-with-details
9
+ params = {
10
+ "OS-FLV-DISABLED:disabled" => false,
11
+ "disk" => 1,
12
+ "OS-FLV-EXT-DATA:ephemeral" => 0,
13
+ "os-flavor-access:is_public" => true,
14
+ "id" => "1",
15
+ "links" => [
16
+ {
17
+ "href" => "http://openstack.example.com/v2/6f70656e737461636b20342065766572/flavors/1",
18
+ "rel" => "self"
19
+ },
20
+ {
21
+ "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/flavors/1",
22
+ "rel" => "bookmark"
23
+ }
24
+ ],
25
+ "name" => "m1.tiny",
26
+ "ram" => 512,
27
+ "swap" => "",
28
+ "vcpus" => 1,
29
+ "rxtx_factor" => 1.0,
30
+ "description" => nil,
31
+ "extra_specs" => {}
32
+ }
33
+
34
+ flavor = Yao::Flavor.new(params)
35
+
36
+ # friendly_attributes
37
+ assert_equal(flavor.id, "1")
38
+ assert_equal(flavor.name, "m1.tiny")
39
+ assert_equal(flavor.vcpus, 1)
40
+ assert_equal(flavor.disk, 1)
41
+ assert_equal(flavor.swap, "")
42
+
43
+ # map_attribute_to_attribute
44
+ assert_equal(flavor.public?, true)
45
+ assert_equal(flavor.disabled?, false)
46
+
47
+ assert_equal(flavor.ram, 512)
48
+ assert_equal(flavor.ram('M'), 512)
49
+ assert_equal(flavor.ram('G'), 0.5)
50
+ assert_equal(flavor.memory, 512)
51
+ end
52
+
53
+ def test_list_detail
54
+ stub_request(:get, "https://example.com:12345/flavors/detail").
55
+ to_return(
56
+ status: 200,
57
+ body: <<-JSON,
58
+ {
59
+ "flavors": [
60
+ {
61
+ "OS-FLV-DISABLED:disabled": false,
62
+ "disk": 1,
63
+ "OS-FLV-EXT-DATA:ephemeral": 0,
64
+ "os-flavor-access:is_public": true,
65
+ "id": "1",
66
+ "links": [
67
+ {
68
+ "href": "http://openstack.example.com/v2/6f70656e737461636b20342065766572/flavors/1",
69
+ "rel": "self"
70
+ },
71
+ {
72
+ "href": "http://openstack.example.com/6f70656e737461636b20342065766572/flavors/1",
73
+ "rel": "bookmark"
74
+ }
75
+ ],
76
+ "name": "m1.tiny",
77
+ "ram": 512,
78
+ "swap": "",
79
+ "vcpus": 1,
80
+ "rxtx_factor": 1.0,
81
+ "description": null,
82
+ "extra_specs": {}
83
+ }
84
+ ]
85
+ }
86
+ JSON
87
+ headers: {'Content-Type' => 'application/json'}
88
+ )
89
+
90
+ flavors = Yao::Flavor.list_detail
91
+ assert { flavors.first.instance_of? Yao::Flavor }
92
+ assert_equal(flavors.first.name, "m1.tiny")
93
+ end
94
+ end
@@ -0,0 +1,129 @@
1
+ class TestFloatingIP < Test::Unit::TestCase
2
+
3
+ def setup
4
+ Yao.default_client.admin_pool["identity"] = Yao::Client.gen_client("https://example.com:12345")
5
+ Yao.default_client.pool["network"] = Yao::Client.gen_client("https://example.com:12345")
6
+ Yao.default_client.pool["compute"] = Yao::Client.gen_client("https://example.com:12345")
7
+ end
8
+
9
+ def test_floating_ip
10
+ params = {
11
+ "router_id" => "d23abc8d-2991-4a55-ba98-2aaea84cc72f",
12
+ "description" => "for test",
13
+ "dns_domain" => "my-domain.org.",
14
+ "dns_name" => "myfip",
15
+ "created_at" => "2016-12-21T10:55:50Z",
16
+ "updated_at" => "2016-12-21T10:55:53Z",
17
+ "revision_number" => 1,
18
+ "project_id" => "4969c491a3c74ee4af974e6d800c62de",
19
+ "tenant_id" => "4969c491a3c74ee4af974e6d800c62de",
20
+ "floating_network_id" => "376da547-b977-4cfe-9cba-275c80debf57",
21
+ "fixed_ip_address" => "10.0.0.3",
22
+ "floating_ip_address" => "172.24.4.228",
23
+ "port_id" => "ce705c24-c1ef-408a-bda3-7bbd946164ab",
24
+ "id" => "2f245a7b-796b-4f26-9cf9-9e82d248fda7",
25
+ "status" => "ACTIVE",
26
+ "port_details" => {
27
+ "status" => "ACTIVE",
28
+ "name" => "",
29
+ "admin_state_up" => true,
30
+ "network_id" => "02dd8479-ef26-4398-a102-d19d0a7b3a1f",
31
+ "device_owner" => "compute:nova",
32
+ "mac_address" => "fa:16:3e:b1:3b:30",
33
+ "device_id" => "8e3941b4-a6e9-499f-a1ac-2a4662025cba"
34
+ },
35
+ "tags" => ["tag1,tag2"],
36
+ "port_forwardings" => []
37
+ }
38
+
39
+ fip = Yao::Resources::FloatingIP.new(params)
40
+ assert_equal(fip.router_id, "d23abc8d-2991-4a55-ba98-2aaea84cc72f")
41
+ assert_equal(fip.description, "for test")
42
+ assert_equal(fip.dns_domain, "my-domain.org.")
43
+ assert_equal(fip.dns_name, "myfip")
44
+ assert_equal(fip.created, Time.parse("2016-12-21T10:55:50Z"))
45
+ assert_equal(fip.updated, Time.parse("2016-12-21T10:55:53Z"))
46
+ assert_equal(fip.revision_number, 1)
47
+ assert_equal(fip.project_id, "4969c491a3c74ee4af974e6d800c62de")
48
+ assert_equal(fip.tenant_id, "4969c491a3c74ee4af974e6d800c62de")
49
+ assert_equal(fip.floating_network_id, "376da547-b977-4cfe-9cba-275c80debf57")
50
+ assert_equal(fip.fixed_ip_address, "10.0.0.3")
51
+ assert_equal(fip.floating_ip_address, "172.24.4.228")
52
+ assert_equal(fip.port_id, "ce705c24-c1ef-408a-bda3-7bbd946164ab")
53
+ assert_equal(fip.id, "2f245a7b-796b-4f26-9cf9-9e82d248fda7")
54
+ assert_equal(fip.status, "ACTIVE")
55
+ assert_equal(fip.tags, ["tag1,tag2"])
56
+ assert_equal(fip.port_details, {
57
+ "status" => "ACTIVE",
58
+ "name" => "",
59
+ "admin_state_up" => true,
60
+ "network_id" => "02dd8479-ef26-4398-a102-d19d0a7b3a1f",
61
+ "device_owner" => "compute:nova",
62
+ "mac_address" => "fa:16:3e:b1:3b:30",
63
+ "device_id" => "8e3941b4-a6e9-499f-a1ac-2a4662025cba"
64
+ })
65
+ assert_equal(fip.port_forwardings, [])
66
+ end
67
+
68
+ def test_floating_ip_to_router
69
+
70
+ stub_request(:get, "https://example.com:12345/routers/00000000-0000-0000-0000-000000000000")
71
+ .to_return(
72
+ status: 200,
73
+ body: <<-JSON,
74
+ {
75
+ "routers": [{
76
+ "id": "0123456789abcdef0123456789abcdef"
77
+ }]
78
+ }
79
+ JSON
80
+ headers: {'Content-Type' => 'application/json'}
81
+ )
82
+
83
+ fip = Yao::FloatingIP.new("router_id" => "00000000-0000-0000-0000-000000000000")
84
+ assert_instance_of(Yao::Router, fip.router)
85
+ end
86
+
87
+ def test_floating_to_tenant
88
+
89
+ stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
90
+ .to_return(
91
+ status: 200,
92
+ body: <<-JSON,
93
+ {
94
+ "tenants": [{
95
+ "id": "0123456789abcdef0123456789abcdef"
96
+ }]
97
+ }
98
+ JSON
99
+ headers: {'Content-Type' => 'application/json'}
100
+ )
101
+
102
+ fip = Yao::FloatingIP.new(
103
+ "project_id" => "0123456789abcdef0123456789abcdef",
104
+ "tenant_id" => "0123456789abcdef0123456789abcdef",
105
+ )
106
+
107
+ assert_instance_of(Yao::Tenant, fip.tenant)
108
+ assert_instance_of(Yao::Tenant, fip.project)
109
+ end
110
+
111
+ def test_floating_ip_to_port
112
+
113
+ stub_request(:get, "https://example.com:12345/ports/00000000-0000-0000-0000-000000000000")
114
+ .to_return(
115
+ status: 200,
116
+ body: <<-JSON,
117
+ {
118
+ "ports": [{
119
+ "id": "0123456789abcdef0123456789abcdef"
120
+ }]
121
+ }
122
+ JSON
123
+ headers: {'Content-Type' => 'application/json'}
124
+ )
125
+
126
+ fip = Yao::FloatingIP.new("port_id" => "00000000-0000-0000-0000-000000000000")
127
+ assert_instance_of(Yao::Port, fip.port)
128
+ end
129
+ end
@@ -0,0 +1,18 @@
1
+ class TestHost < Test::Unit::TestCase
2
+
3
+ def test_host
4
+ # https://docs.openstack.org/api-ref/compute/?expanded=list-flavors-detail,list-flavors-with-details-detail,list-hosts-detail#hosts-os-hosts-deprecated
5
+ params = {
6
+ "host_name" => "b6e4adbc193d428ea923899d07fb001e",
7
+ "service" => "conductor",
8
+ "zone" => "internal"
9
+ }
10
+
11
+ host = Yao::Host.new(params)
12
+
13
+ # friendly_attributes
14
+ assert_equal(host.host_name, "b6e4adbc193d428ea923899d07fb001e")
15
+ assert_equal(host.service, "conductor")
16
+ assert_equal(host.zone, "internal")
17
+ end
18
+ end
@@ -0,0 +1,63 @@
1
+ class TestImage < Test::Unit::TestCase
2
+
3
+ def test_image
4
+
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 = {
7
+ "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",
11
+ "links" => [
12
+ {
13
+ "href" => "http://openstack.example.com/v2/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
14
+ "rel" => "self"
15
+ },
16
+ {
17
+ "href" => "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
18
+ "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
+ }
25
+ ],
26
+ "metadata" => {
27
+ "architecture" => "x86_64",
28
+ "auto_disk_config" => "True",
29
+ "kernel_id" => "nokernel",
30
+ "ramdisk_id" => "nokernel"
31
+ },
32
+ "minDisk" => 0,
33
+ "minRam" => 0,
34
+ "name" => "fakeimage7",
35
+ "progress" => 100,
36
+ "status" => "ACTIVE",
37
+ "updated" => "2011-01-01T01:02:03Z"
38
+ }
39
+
40
+ image = Yao::Image.new(params)
41
+
42
+ # friendly_attributes
43
+ assert_equal(image.name, "fakeimage7")
44
+ assert_equal(image.status, "ACTIVE")
45
+ assert_equal(image.progress, 100)
46
+ assert_equal(image.metadata, {
47
+ "architecture" => "x86_64",
48
+ "auto_disk_config" => "True",
49
+ "kernel_id" => "nokernel",
50
+ "ramdisk_id" => "nokernel"
51
+ })
52
+
53
+ # map_attribute_to_attribute
54
+ assert_equal(image.min_disk, 0)
55
+ assert_equal(image.min_ram, 0)
56
+
57
+ assert_equal(image.size, image["OS-EXT-IMG-SIZE:size"])
58
+ assert_equal(image.size, 74185822)
59
+ assert_equal(image.size('K'), 72447.091796875) # oops
60
+ assert_equal(image.size('M'), 70.74911308288574) #
61
+ assert_equal(image.size('G'), 0.06909093074500561) #
62
+ end
63
+ end
@@ -0,0 +1,54 @@
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
6
+
7
+ def test_keypair
8
+ # https://docs.openstack.org/api-ref/compute/?expanded=list-keypairs-detail#list-keypairs
9
+ params = {
10
+ "fingerprint" => "7e:eb:ab:24:ba:d1:e1:88:ae:9a:fb:66:53:df:d3:bd",
11
+ "name" => "keypair-5d935425-31d5-48a7-a0f1-e76e9813f2c3",
12
+ "type" => "ssh",
13
+ "public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCkF3MX59OrlBs3dH5CU7lNmvpbrgZxSpyGjlnE8Flkirnc/Up22lpjznoxqeoTAwTW034k7Dz6aYIrZGmQwe2TkE084yqvlj45Dkyoj95fW/sZacm0cZNuL69EObEGHdprfGJQajrpz22NQoCD8TFB8Wv+8om9NH9Le6s+WPe98WC77KLw8qgfQsbIey+JawPWl4O67ZdL5xrypuRjfIPWjgy/VH85IXg/Z/GONZ2nxHgSShMkwqSFECAC5L3PHB+0+/12M/iikdatFSVGjpuHvkLOs3oe7m6HlOfluSJ85BzLWBbvva93qkGmLg4ZAc8rPh2O+YIsBUHNLLMM/oQp Generated-by-Nova\n"
14
+ }
15
+
16
+ keypair = Yao::Keypair.new(params)
17
+
18
+ # friendly_attributes
19
+ assert_equal(keypair.name, "keypair-5d935425-31d5-48a7-a0f1-e76e9813f2c3")
20
+ assert_equal(keypair.fingerprint, "7e:eb:ab:24:ba:d1:e1:88:ae:9a:fb:66:53:df:d3:bd")
21
+ assert_equal(keypair.public_key, <<EOS)
22
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCkF3MX59OrlBs3dH5CU7lNmvpbrgZxSpyGjlnE8Flkirnc/Up22lpjznoxqeoTAwTW034k7Dz6aYIrZGmQwe2TkE084yqvlj45Dkyoj95fW/sZacm0cZNuL69EObEGHdprfGJQajrpz22NQoCD8TFB8Wv+8om9NH9Le6s+WPe98WC77KLw8qgfQsbIey+JawPWl4O67ZdL5xrypuRjfIPWjgy/VH85IXg/Z/GONZ2nxHgSShMkwqSFECAC5L3PHB+0+/12M/iikdatFSVGjpuHvkLOs3oe7m6HlOfluSJ85BzLWBbvva93qkGmLg4ZAc8rPh2O+YIsBUHNLLMM/oQp Generated-by-Nova
23
+ EOS
24
+ end
25
+
26
+ def test_list
27
+ stub_request(:get, "https://example.com:12345/os-keypairs")
28
+ .to_return(
29
+ status: 200,
30
+ body: <<-JSON,
31
+ {
32
+ "keypairs": [
33
+ {
34
+ "keypair": {
35
+ "fingerprint": "7e:eb:ab:24:ba:d1:e1:88:ae:9a:fb:66:53:df:d3:bd",
36
+ "name": "keypair-5d935425-31d5-48a7-a0f1-e76e9813f2c3",
37
+ "type": "ssh",
38
+ "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCkF3MX59OrlBs3dH5CU7lNmvpbrgZxSpyGjlnE8Flkirnc/Up22lpjznoxqeoTAwTW034k7Dz6aYIrZGmQwe2TkE084yqvlj45Dkyoj95fW/sZacm0cZNuL69EObEGHdprfGJQajrpz22NQoCD8TFB8Wv+8om9NH9Le6s+WPe98WC77KLw8qgfQsbIey+JawPWl4O67ZdL5xrypuRjfIPWjgy/VH85IXg/Z/GONZ2nxHgSShMkwqSFECAC5L3PHB+0+/12M/iikdatFSVGjpuHvkLOs3oe7m6HlOfluSJ85BzLWBbvva93qkGmLg4ZAc8rPh2O+YIsBUHNLLMM/oQp Generated-by-Nova\\n"
39
+ }
40
+ }
41
+ ],
42
+ "keypairs_links": [
43
+ {
44
+ }
45
+ ]
46
+ }
47
+ JSON
48
+ headers: {'Content-Type' => 'application/json'}
49
+ )
50
+
51
+ keypairs = Yao::Keypair.list
52
+ assert_equal(keypairs.first.fingerprint, "7e:eb:ab:24:ba:d1:e1:88:ae:9a:fb:66:53:df:d3:bd")
53
+ end
54
+ end
@@ -1,6 +1,6 @@
1
1
  require "time"
2
2
 
3
- class TestRole < Test::Unit::TestCase
3
+ class TestLoadBalancer < Test::Unit::TestCase
4
4
  def test_loadbalancer
5
5
  params = {
6
6
  "provider" => "octavia",
@@ -1,6 +1,6 @@
1
1
  require "time"
2
2
 
3
- class TestRole < Test::Unit::TestCase
3
+ class TestLoadBalancerHealthMonitor < Test::Unit::TestCase
4
4
  def test_loadbalancer_healtchmonitor
5
5
  params = {
6
6
  "name" => "super-pool-health-monitor",
@@ -1,6 +1,6 @@
1
1
  require "time"
2
2
 
3
- class TestRole < Test::Unit::TestCase
3
+ class TestLoadBalancerListener < Test::Unit::TestCase
4
4
  def test_loadbalancer_listener
5
5
  params = {
6
6
  "description" => "A great TLS listener",
@@ -1,6 +1,6 @@
1
1
  require "time"
2
2
 
3
- class TestRole < Test::Unit::TestCase
3
+ class TestLoadBalancerPool < Test::Unit::TestCase
4
4
  def test_loadbalancer_pool
5
5
  params = {
6
6
  "lb_algorithm" => "ROUND_ROBIN",
@@ -1,6 +1,6 @@
1
1
  require "time"
2
2
 
3
- class TestRole < Test::Unit::TestCase
3
+ class TestLoadBalancerPoolMember < Test::Unit::TestCase
4
4
  def test_loadbalancer_pool_member
5
5
  params = {
6
6
  "monitor_port" => 8080,
@@ -0,0 +1,105 @@
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
8
+
9
+ def test_meter
10
+ # https://docs.openstack.org/ceilometer/pike/webapi/v2.html
11
+ params = {
12
+ "meter_id" => "YmQ5NDMxYzEtOGQ2OS00YWQzLTgwM2EtOGQ0YTZiODlmZDM2K2luc3RhbmNl",
13
+ "name" => "instance",
14
+ "project_id" => "35b17138-b364-4e6a-a131-8f3099c5be68",
15
+ "resource_id" => "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36",
16
+ "source" => "openstack",
17
+ "type" => "gauge",
18
+ "unit" => "instance",
19
+ "user_id" => "efd87807-12d2-4b38-9c70-5f5c2ac427ff"
20
+ }
21
+
22
+ meter = Yao::Meter.new(params)
23
+
24
+ # friendly_attributes
25
+ assert_equal(meter.meter_id, "YmQ5NDMxYzEtOGQ2OS00YWQzLTgwM2EtOGQ0YTZiODlmZDM2K2luc3RhbmNl")
26
+ assert_equal(meter.meter_id, meter.id)
27
+ assert_equal(meter.name, "instance")
28
+ assert_equal(meter.project_id, "35b17138-b364-4e6a-a131-8f3099c5be68")
29
+ assert_equal(meter.resource_id, "bd9431c1-8d69-4ad3-803a-8d4a6b89fd36")
30
+ assert_equal(meter.source, "openstack")
31
+ assert_equal(meter.type, "gauge")
32
+ assert_equal(meter.unit, "instance")
33
+ assert_equal(meter.user_id, "efd87807-12d2-4b38-9c70-5f5c2ac427ff")
34
+ end
35
+
36
+ def test_resource
37
+
38
+ # https://docs.openstack.org/ceilometer/pike/webapi/v2.html
39
+ stub_request(:get, "https://example.com:12345/v2/resources/00000000-0000-0000-0000-000000000000")
40
+ .to_return(
41
+ status: 200,
42
+ body: <<-JSON,
43
+ {
44
+ "resource_id": "00000000-0000-0000-0000-000000000000"
45
+ }
46
+ JSON
47
+ headers: {'Content-Type' => 'application/json'}
48
+ )
49
+
50
+ params = {
51
+ "resource_id" => "00000000-0000-0000-0000-000000000000",
52
+ }
53
+
54
+ 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")
58
+ end
59
+
60
+ def test_tenant
61
+ stub_request(:get, "https://example.com:12345/tenants/00000000-0000-0000-0000-000000000000")
62
+ .to_return(
63
+ status: 200,
64
+ body: <<-JSON,
65
+ {
66
+ "tenant": {
67
+ "id": "00000000-0000-0000-0000-000000000000"
68
+ }
69
+ }
70
+ JSON
71
+ headers: {'Content-Type' => 'application/json'}
72
+ )
73
+
74
+ params = {
75
+ "project_id" => "00000000-0000-0000-0000-000000000000",
76
+ }
77
+
78
+ meter = Yao::Meter.new(params)
79
+ assert_instance_of(Yao::Tenant, meter.tenant)
80
+ assert_equal(meter.tenant.id, "00000000-0000-0000-0000-000000000000")
81
+ end
82
+
83
+ def test_user
84
+ stub_request(:get, "https://example.com:12345/users/00000000-0000-0000-0000-000000000000")
85
+ .to_return(
86
+ status: 200,
87
+ body: <<-JSON,
88
+ {
89
+ "user": {
90
+ "id": "00000000-0000-0000-0000-000000000000"
91
+ }
92
+ }
93
+ JSON
94
+ headers: {'Content-Type' => 'application/json'}
95
+ )
96
+
97
+ params = {
98
+ "user_id" => "00000000-0000-0000-0000-000000000000",
99
+ }
100
+
101
+ meter = Yao::Meter.new(params)
102
+ assert_instance_of(Yao::User, meter.user)
103
+ assert_equal(meter.user.id, "00000000-0000-0000-0000-000000000000")
104
+ end
105
+ end
@@ -0,0 +1,38 @@
1
+ class TestNetwork < Test::Unit::TestCase
2
+
3
+ def test_network
4
+
5
+ # https://docs.openstack.org/api-ref/network/v2/#networks
6
+ params = {
7
+ "admin_state_up" => true,
8
+ "id" => "b3680498-03da-4691-896f-ef9ee1d856a7",
9
+ "name" => "net1",
10
+ "provider:network_type" => "vlan",
11
+ "provider:physical_network" => "physnet1",
12
+ "provider:segmentation_id" => 1000,
13
+ "router:external" => false,
14
+ "shared" => false,
15
+ "status" => "ACTIVE",
16
+ "subnets" => [],
17
+ "tenant_id" => "c05140b3dc7c4555afff9fab6b58edc2",
18
+ "project_id" => "c05140b3dc7c4555afff9fab6b58edc2",
19
+ }
20
+
21
+ network = Yao::Network.new(params)
22
+
23
+ # friendly_attributes
24
+ assert_equal(network.id, "b3680498-03da-4691-896f-ef9ee1d856a7")
25
+ assert_equal(network.name, "net1")
26
+ assert_equal(network.status, "ACTIVE")
27
+ assert_equal(network.shared, false)
28
+ assert_equal(network.shared?, false)
29
+ assert_equal(network.tenant_id, "c05140b3dc7c4555afff9fab6b58edc2")
30
+ assert_equal(network.subnets, [])
31
+ assert_equal(network.admin_state_up, true)
32
+
33
+ #map_attribute_to_attribute
34
+ assert_equal(network.physical_network, "physnet1")
35
+ assert_equal(network.type, "vlan")
36
+ assert_equal(network.segmentation_id, 1000)
37
+ end
38
+ end