yao 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +15 -0
- data/.github/workflows/ubuntu-rvm.yml +29 -0
- data/.github/workflows/ubuntu.yml +22 -0
- data/Gemfile +10 -2
- data/README.md +3 -3
- data/lib/yao/resources.rb +5 -0
- data/lib/yao/resources/action.rb +1 -1
- data/lib/yao/resources/compute_services.rb +46 -0
- data/lib/yao/resources/flavor.rb +1 -10
- data/lib/yao/resources/floating_ip.rb +6 -6
- data/lib/yao/resources/hypervisor.rb +6 -12
- data/lib/yao/resources/keypair.rb +22 -3
- data/lib/yao/resources/meter.rb +6 -7
- data/lib/yao/resources/network.rb +3 -1
- data/lib/yao/resources/network_associationable.rb +14 -0
- data/lib/yao/resources/old_sample.rb +5 -7
- data/lib/yao/resources/port.rb +6 -6
- data/lib/yao/resources/port_associationable.rb +14 -0
- data/lib/yao/resources/project.rb +16 -0
- data/lib/yao/resources/resource.rb +12 -7
- data/lib/yao/resources/restfully_accessible.rb +72 -35
- data/lib/yao/resources/role.rb +73 -18
- data/lib/yao/resources/router.rb +3 -1
- data/lib/yao/resources/sample.rb +1 -5
- data/lib/yao/resources/security_group.rb +3 -1
- data/lib/yao/resources/server.rb +4 -9
- data/lib/yao/resources/subnet.rb +5 -5
- data/lib/yao/resources/tenant.rb +1 -1
- data/lib/yao/resources/tenant_associationable.rb +17 -0
- data/lib/yao/resources/user.rb +15 -4
- data/lib/yao/resources/volume.rb +1 -10
- data/lib/yao/version.rb +1 -1
- data/test/config.rb +1 -0
- data/test/support/auth_stub.rb +1 -0
- data/test/support/test_yao_resource.rb +49 -0
- data/test/yao/resources/test_aggregates.rb +1 -4
- data/test/yao/resources/test_base.rb +1 -1
- data/test/yao/resources/test_compute_services.rb +118 -0
- data/test/yao/resources/test_flavor.rb +15 -9
- data/test/yao/resources/test_floating_ip.rb +24 -19
- data/test/yao/resources/test_host.rb +1 -1
- data/test/yao/resources/test_hypervisor.rb +17 -10
- data/test/yao/resources/test_image.rb +1 -1
- data/test/yao/resources/test_keypair.rb +3 -6
- data/test/yao/resources/test_loadbalancer.rb +1 -3
- data/test/yao/resources/test_loadbalancer_healthmonitor.rb +1 -3
- data/test/yao/resources/test_loadbalancer_listener.rb +1 -5
- data/test/yao/resources/test_loadbalancer_pool.rb +1 -3
- data/test/yao/resources/test_loadbalancer_pool_member.rb +1 -3
- data/test/yao/resources/test_meter.rb +13 -14
- data/test/yao/resources/test_network.rb +28 -1
- data/test/yao/resources/test_old_sample.rb +86 -0
- data/test/yao/resources/test_port.rb +29 -7
- data/test/yao/resources/test_project.rb +32 -0
- data/test/yao/resources/test_resource.rb +56 -0
- data/test/yao/resources/test_role.rb +255 -1
- data/test/yao/resources/test_role_assignment.rb +4 -6
- data/test/yao/resources/test_router.rb +26 -6
- data/test/yao/resources/test_sample.rb +61 -0
- data/test/yao/resources/test_security_group.rb +23 -1
- data/test/yao/resources/test_security_group_rule.rb +1 -1
- data/test/yao/resources/test_server.rb +34 -8
- data/test/yao/resources/test_subnet.rb +25 -6
- data/test/yao/resources/test_user.rb +73 -1
- data/test/yao/resources/test_volume.rb +31 -1
- data/test/yao/resources/test_volume_type.rb +1 -1
- data/test/yao/test_config.rb +21 -8
- data/test/yao/test_read_only.rb +3 -3
- data/yao.gemspec +0 -8
- metadata +22 -101
- data/.travis.yml +0 -28
data/lib/yao/resources/subnet.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Yao::Resources
|
2
2
|
class Subnet < Base
|
3
|
-
|
3
|
+
|
4
|
+
include NetworkAssociationable
|
5
|
+
include TenantAssociationable
|
6
|
+
|
7
|
+
friendly_attributes :name, :cidr, :gateway_ip, :network_id, :ip_version,
|
4
8
|
:dns_nameservers, :host_routes, :enable_dhcp
|
5
9
|
|
6
10
|
def allocation_pools
|
@@ -9,10 +13,6 @@ module Yao::Resources
|
|
9
13
|
end
|
10
14
|
end
|
11
15
|
|
12
|
-
def network
|
13
|
-
Yao::Network.find network_id
|
14
|
-
end
|
15
|
-
|
16
16
|
alias dhcp_enabled? enable_dhcp
|
17
17
|
|
18
18
|
self.service = "network"
|
data/lib/yao/resources/tenant.rb
CHANGED
@@ -9,7 +9,7 @@ module Yao::Resources
|
|
9
9
|
self.return_single_on_querying = true
|
10
10
|
|
11
11
|
def servers
|
12
|
-
@servers ||= Yao::Server.
|
12
|
+
@servers ||= Yao::Server.list(all_tenants: 1).select{|s| s.tenant_id == id }
|
13
13
|
end
|
14
14
|
|
15
15
|
def meters
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Yao
|
2
|
+
module Resources
|
3
|
+
module TenantAssociationable
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.friendly_attributes :project_id
|
7
|
+
base.friendly_attributes :tenant_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def tenant
|
11
|
+
@tenant ||= Yao::Tenant.find(project_id || tenant_id)
|
12
|
+
end
|
13
|
+
|
14
|
+
alias :project :tenant
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/yao/resources/user.rb
CHANGED
@@ -8,13 +8,24 @@ module Yao::Resources
|
|
8
8
|
self.resource_name = "user"
|
9
9
|
self.resources_name = "users"
|
10
10
|
self.admin = true
|
11
|
-
self.return_single_on_querying = true
|
12
11
|
|
13
12
|
class << self
|
14
|
-
def
|
15
|
-
|
13
|
+
def find_by_name(name, query={})
|
14
|
+
if api_verion_v2?
|
15
|
+
[super]
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def return_single_on_querying
|
22
|
+
api_verion_v2?
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def api_verion_v2?
|
27
|
+
client.url_prefix.to_s.match?(/v2\.0/)
|
16
28
|
end
|
17
|
-
alias find_by_name get_by_name
|
18
29
|
end
|
19
30
|
end
|
20
31
|
end
|
data/lib/yao/resources/volume.rb
CHANGED
@@ -7,15 +7,6 @@ module Yao::Resources
|
|
7
7
|
self.service = "volumev3"
|
8
8
|
self.resource_name = "volume"
|
9
9
|
self.resources_name = "volumes"
|
10
|
-
|
11
|
-
class << self
|
12
|
-
def list_detail(query={})
|
13
|
-
return_resources(
|
14
|
-
resources_from_json(
|
15
|
-
GET([resources_path, "detail"].join("/"), query).body
|
16
|
-
)
|
17
|
-
)
|
18
|
-
end
|
19
|
-
end
|
10
|
+
self.resources_detail_available = true
|
20
11
|
end
|
21
12
|
end
|
data/lib/yao/version.rb
CHANGED
data/test/config.rb
CHANGED
data/test/support/auth_stub.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
class TestYaoResource < Test::Unit::TestCase
|
2
|
+
include AuthStub
|
3
|
+
|
4
|
+
def setup
|
5
|
+
initialize_test_client!
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
reset_test_client!
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
# Yao::Resources::* のテストで Yao.default.pool の設定を都度都度 記述しなくていいよういするヘルパー
|
15
|
+
# endpoint の URL がマチマチだとテストを記述するのが面倒なので example.com で統一している
|
16
|
+
def initialize_test_client!
|
17
|
+
auth_url = "http://example.com:12345"
|
18
|
+
username = "yao"
|
19
|
+
tenant = "default"
|
20
|
+
password = "password"
|
21
|
+
|
22
|
+
stub_auth_request(auth_url, username, password, tenant)
|
23
|
+
|
24
|
+
Yao.config.set :auth_url, auth_url
|
25
|
+
Yao::Auth.new(tenant_name: tenant, username: username, password: password)
|
26
|
+
|
27
|
+
client = Yao::Client.gen_client("https://example.com:12345")
|
28
|
+
Yao.default_client.admin_pool["identity"] = client
|
29
|
+
Yao.default_client.pool["network"] = client
|
30
|
+
Yao.default_client.pool["compute"] = client
|
31
|
+
Yao.default_client.pool["metering"] = client
|
32
|
+
Yao.default_client.pool["volumev3"] = client
|
33
|
+
end
|
34
|
+
|
35
|
+
# 他のテストで副作用を出さないように Yao::Client.default_client, Yao::Conig を nil でリセットしておきます
|
36
|
+
def reset_test_client!
|
37
|
+
Yao::Client.default_client = nil
|
38
|
+
|
39
|
+
Yao::Config::HOOK_RENEW_CLIENT_KEYS.each do |key|
|
40
|
+
Yao.configure do
|
41
|
+
set key, nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# https://github.com/bblimke/webmock/wiki/Clear-stubs-and-request-history
|
46
|
+
# 他のテストに作用しないように stub_request を reset する
|
47
|
+
WebMock.reset!
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
class TestComputeServices < TestYaoResource
|
2
|
+
|
3
|
+
def test_compute_services
|
4
|
+
|
5
|
+
# https://docs.openstack.org/api-ref/compute/?expanded=update-forced-down-detail,update-compute-service-detail,list-compute-services-detail#compute-services-os-services
|
6
|
+
params = {
|
7
|
+
"id" => 1,
|
8
|
+
"binary" => "nova-scheduler",
|
9
|
+
"disabled_reason" => "test1",
|
10
|
+
"host" => "host1",
|
11
|
+
"state" => "up",
|
12
|
+
"status" => "disabled",
|
13
|
+
"updated_at" => "2012-10-29T13:42:02.000000",
|
14
|
+
"forced_down" => false,
|
15
|
+
"zone" => "internal"
|
16
|
+
}
|
17
|
+
compute_service = Yao::ComputeServices.new(params)
|
18
|
+
|
19
|
+
assert_equal(compute_service.id, 1)
|
20
|
+
assert_equal(compute_service.binary, "nova-scheduler")
|
21
|
+
assert_equal(compute_service.disabled_reason, "test1")
|
22
|
+
assert_equal(compute_service.host, "host1")
|
23
|
+
assert_equal(compute_service.state, "up")
|
24
|
+
assert_equal(compute_service.status, "disabled")
|
25
|
+
assert_equal(compute_service.updated, Time.mktime(2012,10,29,13,42,2))
|
26
|
+
assert_equal(compute_service.forced_down, false)
|
27
|
+
assert_equal(compute_service.zone, "internal")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_enable
|
31
|
+
stub = stub_request(:put, "https://example.com:12345/os-services/enable").
|
32
|
+
with(
|
33
|
+
body: <<~JSON.chomp
|
34
|
+
{"host":"host1","binary":"nova-compute"}
|
35
|
+
JSON
|
36
|
+
).to_return(
|
37
|
+
status: 200,
|
38
|
+
body: <<-JSON,
|
39
|
+
{
|
40
|
+
"service": {
|
41
|
+
"binary": "nova-compute",
|
42
|
+
"host": "host1",
|
43
|
+
"status": "enabled"
|
44
|
+
}
|
45
|
+
}
|
46
|
+
JSON
|
47
|
+
headers: {'Content-Type' => 'application/json'}
|
48
|
+
)
|
49
|
+
|
50
|
+
compute_service = Yao::ComputeServices.enable('host1', 'nova-compute')
|
51
|
+
|
52
|
+
assert_equal(compute_service.host, "host1")
|
53
|
+
assert_equal(compute_service.binary, "nova-compute")
|
54
|
+
assert_equal(compute_service.status, "enabled")
|
55
|
+
|
56
|
+
assert_requested stub
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_disable
|
60
|
+
stub = stub_request(:put, "https://example.com:12345/os-services/disable").
|
61
|
+
with(
|
62
|
+
body: <<~JSON.chomp
|
63
|
+
{"host":"host1","binary":"nova-compute"}
|
64
|
+
JSON
|
65
|
+
).to_return(
|
66
|
+
status: 200,
|
67
|
+
body: <<-JSON,
|
68
|
+
{
|
69
|
+
"service": {
|
70
|
+
"binary": "nova-compute",
|
71
|
+
"host": "host1",
|
72
|
+
"status": "disabled"
|
73
|
+
}
|
74
|
+
}
|
75
|
+
JSON
|
76
|
+
headers: {'Content-Type' => 'application/json'}
|
77
|
+
)
|
78
|
+
|
79
|
+
compute_service = Yao::ComputeServices.disable('host1', 'nova-compute')
|
80
|
+
|
81
|
+
assert_equal(compute_service.host, "host1")
|
82
|
+
assert_equal(compute_service.binary, "nova-compute")
|
83
|
+
assert_equal(compute_service.status, "disabled")
|
84
|
+
|
85
|
+
assert_requested stub
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_disable_with_reason
|
89
|
+
stub = stub_request(:put, "https://example.com:12345/os-services/disable-log-reason").
|
90
|
+
with(
|
91
|
+
body: <<~JSON.chomp
|
92
|
+
{"host":"host1","binary":"nova-compute","disabled_reason":"test2"}
|
93
|
+
JSON
|
94
|
+
).to_return(
|
95
|
+
status: 200,
|
96
|
+
body: <<-JSON,
|
97
|
+
{
|
98
|
+
"service": {
|
99
|
+
"binary": "nova-compute",
|
100
|
+
"disabled_reason": "test2",
|
101
|
+
"host": "host1",
|
102
|
+
"status": "disabled"
|
103
|
+
}
|
104
|
+
}
|
105
|
+
JSON
|
106
|
+
headers: {'Content-Type' => 'application/json'}
|
107
|
+
)
|
108
|
+
|
109
|
+
compute_service = Yao::ComputeServices.disable('host1', 'nova-compute', 'test2')
|
110
|
+
|
111
|
+
assert_equal(compute_service.host, "host1")
|
112
|
+
assert_equal(compute_service.binary, "nova-compute")
|
113
|
+
assert_equal(compute_service.status, "disabled")
|
114
|
+
assert_equal(compute_service.disabled_reason, "test2")
|
115
|
+
|
116
|
+
assert_requested stub
|
117
|
+
end
|
118
|
+
end
|
@@ -1,8 +1,4 @@
|
|
1
|
-
class TestFlavor <
|
2
|
-
|
3
|
-
def setup
|
4
|
-
Yao.default_client.pool["compute"] = Yao::Client.gen_client("https://example.com:12345")
|
5
|
-
end
|
1
|
+
class TestFlavor < TestYaoResource
|
6
2
|
|
7
3
|
def test_flavor
|
8
4
|
# https://docs.openstack.org/api-ref/compute/?expanded=list-flavors-detail,list-flavors-with-details-detail#list-flavors-with-details
|
@@ -50,8 +46,8 @@ class TestFlavor < Test::Unit::TestCase
|
|
50
46
|
assert_equal(flavor.memory, 512)
|
51
47
|
end
|
52
48
|
|
53
|
-
def
|
54
|
-
stub_request(:get, "https://example.com:12345/flavors/detail").
|
49
|
+
def test_list
|
50
|
+
stub = stub_request(:get, "https://example.com:12345/flavors/detail").
|
55
51
|
to_return(
|
56
52
|
status: 200,
|
57
53
|
body: <<-JSON,
|
@@ -87,8 +83,18 @@ class TestFlavor < Test::Unit::TestCase
|
|
87
83
|
headers: {'Content-Type' => 'application/json'}
|
88
84
|
)
|
89
85
|
|
90
|
-
|
91
|
-
|
86
|
+
assert(Yao::Flavor.resources_detail_available)
|
87
|
+
|
88
|
+
flavors = Yao::Flavor.list
|
89
|
+
assert_instance_of(Yao::Flavor, flavors.first)
|
92
90
|
assert_equal(flavors.first.name, "m1.tiny")
|
91
|
+
|
92
|
+
assert_requested(stub)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_list_detail
|
96
|
+
# Yao::Flavor.list_detail と Yao::Flavor.list が alias にあることをテストする
|
97
|
+
# see also: https://stackoverflow.com/questions/25883618/how-to-test-method-alias-ruby
|
98
|
+
assert_equal(Yao::Flavor.method(:list_detail), Yao::Flavor.method(:list))
|
93
99
|
end
|
94
100
|
end
|
@@ -1,10 +1,4 @@
|
|
1
|
-
class TestFloatingIP <
|
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
|
1
|
+
class TestFloatingIP < TestYaoResource
|
8
2
|
|
9
3
|
def test_floating_ip
|
10
4
|
params = {
|
@@ -67,33 +61,37 @@ class TestFloatingIP < Test::Unit::TestCase
|
|
67
61
|
|
68
62
|
def test_floating_ip_to_router
|
69
63
|
|
70
|
-
stub_request(:get, "https://example.com:12345/routers/00000000-0000-0000-0000-000000000000")
|
64
|
+
stub = stub_request(:get, "https://example.com:12345/routers/00000000-0000-0000-0000-000000000000")
|
71
65
|
.to_return(
|
72
66
|
status: 200,
|
73
67
|
body: <<-JSON,
|
74
68
|
{
|
75
|
-
"
|
76
|
-
"id": "
|
77
|
-
}
|
69
|
+
"router": {
|
70
|
+
"id": "00000000-0000-0000-0000-000000000000"
|
71
|
+
}
|
78
72
|
}
|
79
73
|
JSON
|
80
74
|
headers: {'Content-Type' => 'application/json'}
|
81
75
|
)
|
82
76
|
|
83
77
|
fip = Yao::FloatingIP.new("router_id" => "00000000-0000-0000-0000-000000000000")
|
78
|
+
|
84
79
|
assert_instance_of(Yao::Router, fip.router)
|
80
|
+
assert_equal(fip.router.id, "00000000-0000-0000-0000-000000000000")
|
81
|
+
|
82
|
+
assert_requested(stub)
|
85
83
|
end
|
86
84
|
|
87
|
-
def
|
85
|
+
def test_tenant
|
88
86
|
|
89
|
-
stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
|
87
|
+
stub = stub_request(:get, "https://example.com:12345/tenants/0123456789abcdef0123456789abcdef")
|
90
88
|
.to_return(
|
91
89
|
status: 200,
|
92
90
|
body: <<-JSON,
|
93
91
|
{
|
94
|
-
"
|
92
|
+
"tenant": {
|
95
93
|
"id": "0123456789abcdef0123456789abcdef"
|
96
|
-
}
|
94
|
+
}
|
97
95
|
}
|
98
96
|
JSON
|
99
97
|
headers: {'Content-Type' => 'application/json'}
|
@@ -106,24 +104,31 @@ class TestFloatingIP < Test::Unit::TestCase
|
|
106
104
|
|
107
105
|
assert_instance_of(Yao::Tenant, fip.tenant)
|
108
106
|
assert_instance_of(Yao::Tenant, fip.project)
|
107
|
+
assert_equal(fip.tenant.id, '0123456789abcdef0123456789abcdef')
|
108
|
+
|
109
|
+
assert_requested(stub)
|
109
110
|
end
|
110
111
|
|
111
112
|
def test_floating_ip_to_port
|
112
113
|
|
113
|
-
stub_request(:get, "https://example.com:12345/ports/00000000-0000-0000-0000-000000000000")
|
114
|
+
stub = stub_request(:get, "https://example.com:12345/ports/00000000-0000-0000-0000-000000000000")
|
114
115
|
.to_return(
|
115
116
|
status: 200,
|
116
117
|
body: <<-JSON,
|
117
118
|
{
|
118
|
-
"
|
119
|
-
"id": "
|
120
|
-
}
|
119
|
+
"port": {
|
120
|
+
"id": "00000000-0000-0000-0000-000000000000"
|
121
|
+
}
|
121
122
|
}
|
122
123
|
JSON
|
123
124
|
headers: {'Content-Type' => 'application/json'}
|
124
125
|
)
|
125
126
|
|
126
127
|
fip = Yao::FloatingIP.new("port_id" => "00000000-0000-0000-0000-000000000000")
|
128
|
+
|
127
129
|
assert_instance_of(Yao::Port, fip.port)
|
130
|
+
assert_equal(fip.port.id, "00000000-0000-0000-0000-000000000000")
|
131
|
+
|
132
|
+
assert_requested(stub)
|
128
133
|
end
|
129
134
|
end
|