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 +4 -4
- data/lib/yao/faraday_middlewares.rb +4 -3
- data/lib/yao/resources/floating_ip.rb +21 -4
- data/lib/yao/resources/tenant.rb +0 -5
- data/lib/yao/version.rb +1 -1
- data/test/yao/resources/test_aggregates.rb +1 -1
- data/test/yao/resources/test_flavor.rb +94 -0
- data/test/yao/resources/test_floating_ip.rb +129 -0
- data/test/yao/resources/test_host.rb +18 -0
- data/test/yao/resources/test_image.rb +63 -0
- data/test/yao/resources/test_keypair.rb +54 -0
- data/test/yao/resources/test_loadbalancer.rb +1 -1
- data/test/yao/resources/test_loadbalancer_healthmonitor.rb +1 -1
- data/test/yao/resources/test_loadbalancer_listener.rb +1 -1
- data/test/yao/resources/test_loadbalancer_pool.rb +1 -1
- data/test/yao/resources/test_loadbalancer_pool_member.rb +1 -1
- data/test/yao/resources/test_meter.rb +105 -0
- data/test/yao/resources/test_network.rb +38 -0
- data/test/yao/resources/test_port.rb +151 -0
- data/test/yao/resources/test_role_assignment.rb +65 -0
- data/test/yao/resources/test_router.rb +133 -0
- data/test/yao/resources/test_server.rb +164 -0
- data/test/yao/resources/test_subnet.rb +80 -0
- data/test/yao/resources/test_volume.rb +1 -1
- data/test/yao/resources/test_volume_type.rb +1 -1
- metadata +27 -4
@@ -0,0 +1,151 @@
|
|
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
|
6
|
+
|
7
|
+
def test_port
|
8
|
+
|
9
|
+
# https://docs.openstack.org/api-ref/network/v2/?expanded=list-floating-ips-detail,show-port-details-detail#ports
|
10
|
+
params = {
|
11
|
+
"admin_state_up" => true,
|
12
|
+
"allowed_address_pairs" => [],
|
13
|
+
"created_at" => "2016-03-08T20:19:41",
|
14
|
+
"data_plane_status" => "ACTIVE",
|
15
|
+
"description" => "",
|
16
|
+
"device_id" => "5e3898d7-11be-483e-9732-b2f5eccd2b2e",
|
17
|
+
"device_owner" => "network:router_interface",
|
18
|
+
"dns_assignment" => {
|
19
|
+
"hostname" => "myport",
|
20
|
+
"ip_address" => "10.0.0.1",
|
21
|
+
"fqdn" => "myport.my-domain.org"
|
22
|
+
},
|
23
|
+
"dns_domain" => "my-domain.org.",
|
24
|
+
"dns_name" => "myport",
|
25
|
+
"extra_dhcp_opts" => [
|
26
|
+
{
|
27
|
+
"opt_value" => "pxelinux.0",
|
28
|
+
"ip_version" => 4,
|
29
|
+
"opt_name" => "bootfile-name"
|
30
|
+
}
|
31
|
+
],
|
32
|
+
"fixed_ips" => [
|
33
|
+
{
|
34
|
+
"ip_address" => "10.0.0.1",
|
35
|
+
"subnet_id" => "a0304c3a-4f08-4c43-88af-d796509c97d2"
|
36
|
+
}
|
37
|
+
],
|
38
|
+
"id" => "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2",
|
39
|
+
"ip_allocation" => "immediate",
|
40
|
+
"mac_address" => "fa:16:3e:23:fd:d7",
|
41
|
+
"name" => "foobar",
|
42
|
+
"network_id" => "a87cc70a-3e15-4acf-8205-9b711a3531b7",
|
43
|
+
"port_security_enabled" => false,
|
44
|
+
"project_id" => "7e02058126cc4950b75f9970368ba177",
|
45
|
+
"revision_number" => 1,
|
46
|
+
"security_groups" => [],
|
47
|
+
"status" => "ACTIVE",
|
48
|
+
"tags" => ["tag1,tag2"],
|
49
|
+
"tenant_id" => "7e02058126cc4950b75f9970368ba177",
|
50
|
+
"updated_at" => "2016-03-08T20:19:41",
|
51
|
+
"qos_policy_id" => "29d5e02e-d5ab-4929-bee4-4a9fc12e22ae",
|
52
|
+
"uplink_status_propagation" => false,
|
53
|
+
"binding:host_id" => "compute-000",
|
54
|
+
}
|
55
|
+
|
56
|
+
port = Yao::Port.new(params)
|
57
|
+
assert_equal(port.id, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2")
|
58
|
+
|
59
|
+
# friendly_attributes
|
60
|
+
assert_equal(port.name, "foobar")
|
61
|
+
assert_equal(port.mac_address, "fa:16:3e:23:fd:d7")
|
62
|
+
assert_equal(port.status, "ACTIVE")
|
63
|
+
assert_equal(port.allowed_address_pairs, [])
|
64
|
+
assert_equal(port.device_owner, "network:router_interface")
|
65
|
+
assert_equal(port.fixed_ips, [
|
66
|
+
{
|
67
|
+
"ip_address" => "10.0.0.1",
|
68
|
+
"subnet_id" => "a0304c3a-4f08-4c43-88af-d796509c97d2"
|
69
|
+
}
|
70
|
+
])
|
71
|
+
assert_equal(port.security_groups, [])
|
72
|
+
assert_equal(port.device_id, "5e3898d7-11be-483e-9732-b2f5eccd2b2e")
|
73
|
+
assert_equal(port.network_id, "a87cc70a-3e15-4acf-8205-9b711a3531b7")
|
74
|
+
assert_equal(port.tenant_id, "7e02058126cc4950b75f9970368ba177")
|
75
|
+
assert_equal(port.admin_state_up, true)
|
76
|
+
|
77
|
+
# map_attribute_to_attribute
|
78
|
+
assert_equal(port.host_id, "compute-000")
|
79
|
+
|
80
|
+
# primary_ip
|
81
|
+
assert_equal(port.primary_ip, "10.0.0.1")
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_primary_ip
|
85
|
+
|
86
|
+
params = {
|
87
|
+
"fixed_ips" => [
|
88
|
+
{
|
89
|
+
"ip_address" => "10.0.0.1",
|
90
|
+
"subnet_id" => "a0304c3a-4f08-4c43-88af-d796509c97d2"
|
91
|
+
}
|
92
|
+
],
|
93
|
+
}
|
94
|
+
|
95
|
+
port = Yao::Port.new(params)
|
96
|
+
assert_equal(port.primary_ip, "10.0.0.1")
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_primary_subnet
|
100
|
+
|
101
|
+
stub_request(:get, "https://example.com:12345/subnets/00000000-0000-0000-0000-000000000000")
|
102
|
+
.to_return(
|
103
|
+
status: 200,
|
104
|
+
body: <<-JSON,
|
105
|
+
{
|
106
|
+
"subnet": {
|
107
|
+
"id": "00000000-0000-0000-0000-000000000000"
|
108
|
+
}
|
109
|
+
}
|
110
|
+
JSON
|
111
|
+
headers: {'Content-Type' => 'application/json'}
|
112
|
+
)
|
113
|
+
|
114
|
+
params = {
|
115
|
+
"fixed_ips" => [
|
116
|
+
{
|
117
|
+
"ip_address" => "10.0.0.1",
|
118
|
+
"subnet_id" => "00000000-0000-0000-0000-000000000000"
|
119
|
+
}
|
120
|
+
],
|
121
|
+
}
|
122
|
+
|
123
|
+
port = Yao::Port.new(params)
|
124
|
+
assert{ port.primary_subnet.instance_of?(Yao::Subnet) }
|
125
|
+
assert_equal(port.primary_subnet.id, "00000000-0000-0000-0000-000000000000")
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_network
|
129
|
+
|
130
|
+
stub_request(:get, "https://example.com:12345/networks/00000000-0000-0000-0000-000000000000")
|
131
|
+
.to_return(
|
132
|
+
status: 200,
|
133
|
+
body: <<-JSON,
|
134
|
+
{
|
135
|
+
"network": {
|
136
|
+
"id": "00000000-0000-0000-0000-000000000000"
|
137
|
+
}
|
138
|
+
}
|
139
|
+
JSON
|
140
|
+
headers: {'Content-Type' => 'application/json'}
|
141
|
+
)
|
142
|
+
|
143
|
+
params = {
|
144
|
+
"network_id" => "00000000-0000-0000-0000-000000000000",
|
145
|
+
}
|
146
|
+
|
147
|
+
port = Yao::Port.new(params)
|
148
|
+
assert_instance_of(Yao::Network, port.network)
|
149
|
+
assert_equal(port.network.id, "00000000-0000-0000-0000-000000000000")
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class TestRoleAssignment < 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_role_assignment
|
8
|
+
|
9
|
+
# https://docs.openstack.org/api-ref/identity/v3/?expanded=validate-and-show-information-for-token-detail,list-role-assignments-detail#list-role-assignments
|
10
|
+
params = {
|
11
|
+
"links" => {
|
12
|
+
"assignment" => "http://example.com/identity/v3/domains/161718/users/313233/roles/123456"
|
13
|
+
},
|
14
|
+
"role" => {
|
15
|
+
"id" => "123456"
|
16
|
+
},
|
17
|
+
"scope" => {
|
18
|
+
"project" => {
|
19
|
+
"id" => "456789"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"user" => {
|
23
|
+
"id" => "313233"
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
role_assignment = Yao::RoleAssignment.new(params)
|
28
|
+
assert_equal(role_assignment.scope, { "project" => { "id" => "456789" } })
|
29
|
+
|
30
|
+
# map_attribute_to_resource
|
31
|
+
assert_instance_of(Yao::Resources::Role, role_assignment.role)
|
32
|
+
assert_equal(role_assignment.role.id, "123456")
|
33
|
+
|
34
|
+
# map_attribute_to_resource
|
35
|
+
assert_instance_of(Yao::Resources::User, role_assignment.user)
|
36
|
+
assert_equal(role_assignment.user.id, "313233")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_project
|
40
|
+
stub_request(:get, "http://endpoint.example.com:12345/tenants/456789").
|
41
|
+
to_return(
|
42
|
+
status: 200,
|
43
|
+
body: <<-JSON,
|
44
|
+
{
|
45
|
+
"tenant": {
|
46
|
+
"id": "456789"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
JSON
|
50
|
+
headers: {'Content-Type' => 'application/json'}
|
51
|
+
)
|
52
|
+
|
53
|
+
params = {
|
54
|
+
"scope" => {
|
55
|
+
"project" => {
|
56
|
+
"id" => "456789"
|
57
|
+
}
|
58
|
+
},
|
59
|
+
}
|
60
|
+
|
61
|
+
role_assignment = Yao::RoleAssignment.new(params)
|
62
|
+
assert_instance_of(Yao::Resources::Tenant, role_assignment.project)
|
63
|
+
assert_equal(role_assignment.project.id, "456789")
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
class TestRouter < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def setup
|
4
|
+
Yao.default_client.pool["network"] = Yao::Client.gen_client("https://example.com:12345")
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_router
|
8
|
+
|
9
|
+
# https://docs.openstack.org/api-ref/network/v2/?expanded=list-subnets-detail,list-routers-detail#list-routers
|
10
|
+
params = {
|
11
|
+
"admin_state_up" => true,
|
12
|
+
"availability_zone_hints" => [],
|
13
|
+
"availability_zones" => [
|
14
|
+
"nova"
|
15
|
+
],
|
16
|
+
"created_at" => "2018-03-19T19:17:04Z",
|
17
|
+
"description" => "",
|
18
|
+
"distributed" => false,
|
19
|
+
"external_gateway_info" => {
|
20
|
+
"enable_snat" => true,
|
21
|
+
"external_fixed_ips" => [
|
22
|
+
{
|
23
|
+
"ip_address" => "172.24.4.3",
|
24
|
+
"subnet_id" => "b930d7f6-ceb7-40a0-8b81-a425dd994ccf"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"ip_address" => "2001:db8::c",
|
28
|
+
"subnet_id" => "0c56df5d-ace5-46c8-8f4c-45fa4e334d18"
|
29
|
+
}
|
30
|
+
],
|
31
|
+
"network_id" => "ae34051f-aa6c-4c75-abf5-50dc9ac99ef3"
|
32
|
+
},
|
33
|
+
"flavor_id" => "f7b14d9a-b0dc-4fbe-bb14-a0f4970a69e0",
|
34
|
+
"ha" => false,
|
35
|
+
"id" => "915a14a6-867b-4af7-83d1-70efceb146f9",
|
36
|
+
"name" => "router2",
|
37
|
+
"revision_number" => 1,
|
38
|
+
"routes" => [
|
39
|
+
{
|
40
|
+
"destination" => "179.24.1.0/24",
|
41
|
+
"nexthop" => "172.24.3.99"
|
42
|
+
}
|
43
|
+
],
|
44
|
+
"status" => "ACTIVE",
|
45
|
+
"updated_at" => "2018-03-19T19:17:22Z",
|
46
|
+
"project_id" => "0bd18306d801447bb457a46252d82d13",
|
47
|
+
"tenant_id" => "0bd18306d801447bb457a46252d82d13",
|
48
|
+
"service_type_id" => nil,
|
49
|
+
"tags" => ["tag1,tag2"],
|
50
|
+
"conntrack_helpers" => [
|
51
|
+
{
|
52
|
+
"protocol" => "udp",
|
53
|
+
"helper" => "tftp",
|
54
|
+
"port" => 69
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"protocol" => "tcp",
|
58
|
+
"helper" => "ftp",
|
59
|
+
"port" => 21
|
60
|
+
}
|
61
|
+
]
|
62
|
+
}
|
63
|
+
|
64
|
+
router = Yao::Router.new(params)
|
65
|
+
|
66
|
+
assert_equal(router.id, "915a14a6-867b-4af7-83d1-70efceb146f9")
|
67
|
+
|
68
|
+
# friendly_attributes
|
69
|
+
assert_equal(router.tenant_id, "0bd18306d801447bb457a46252d82d13")
|
70
|
+
assert_equal(router.project_id, "0bd18306d801447bb457a46252d82d13")
|
71
|
+
assert_equal(router.name, "router2")
|
72
|
+
assert_equal(router.description, "")
|
73
|
+
assert_equal(router.admin_state_up, true)
|
74
|
+
assert_equal(router.status, "ACTIVE")
|
75
|
+
assert_equal(router.external_gateway_info, {
|
76
|
+
"enable_snat" => true,
|
77
|
+
"external_fixed_ips" => [
|
78
|
+
{
|
79
|
+
"ip_address" => "172.24.4.3",
|
80
|
+
"subnet_id" => "b930d7f6-ceb7-40a0-8b81-a425dd994ccf"
|
81
|
+
},
|
82
|
+
{
|
83
|
+
"ip_address" => "2001:db8::c",
|
84
|
+
"subnet_id" => "0c56df5d-ace5-46c8-8f4c-45fa4e334d18"
|
85
|
+
}
|
86
|
+
],
|
87
|
+
"network_id" => "ae34051f-aa6c-4c75-abf5-50dc9ac99ef3"
|
88
|
+
})
|
89
|
+
|
90
|
+
assert_equal(router.routes, [
|
91
|
+
{
|
92
|
+
"destination" => "179.24.1.0/24",
|
93
|
+
"nexthop" => "172.24.3.99"
|
94
|
+
}
|
95
|
+
])
|
96
|
+
|
97
|
+
assert_equal(router.distributed, false)
|
98
|
+
assert_equal(router.ha, false)
|
99
|
+
assert_equal(router.availability_zone_hints, [])
|
100
|
+
assert_equal(router.availability_zones, [ "nova" ])
|
101
|
+
|
102
|
+
pend 'oops. These are invalid friendly_attributes'
|
103
|
+
assert_equal(router.network_id, '')
|
104
|
+
assert_equal(router.enable_snat, '')
|
105
|
+
assert_equal(router.external_fixed_ips '')
|
106
|
+
assert_equal(router.destination '')
|
107
|
+
assert_equal(router.nexthop '')
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_iterfaces
|
111
|
+
stub_request(:get, "https://example.com:12345/ports?device_id=00000000-0000-0000-0000-000000000000")
|
112
|
+
.to_return(
|
113
|
+
status: 200,
|
114
|
+
body: <<-JSON,
|
115
|
+
{
|
116
|
+
"ports": [{
|
117
|
+
"id": "00000000-0000-0000-0000-000000000000"
|
118
|
+
}]
|
119
|
+
}
|
120
|
+
JSON
|
121
|
+
headers: {'Content-Type' => 'application/json'}
|
122
|
+
)
|
123
|
+
|
124
|
+
params = {
|
125
|
+
"id" => "00000000-0000-0000-0000-000000000000",
|
126
|
+
}
|
127
|
+
|
128
|
+
router = Yao::Router.new(params)
|
129
|
+
port = router.interfaces.first
|
130
|
+
assert_instance_of(Yao::Port, port)
|
131
|
+
assert_equal(port.id, "00000000-0000-0000-0000-000000000000")
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
class TestServer < 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_server
|
8
|
+
|
9
|
+
# https://docs.openstack.org/api-ref/compute/?expanded=list-servers-detail,list-servers-detailed-detail#list-servers
|
10
|
+
params = {
|
11
|
+
"OS-DCF:diskConfig" => "AUTO",
|
12
|
+
"OS-EXT-AZ:availability_zone" => "nova",
|
13
|
+
"OS-EXT-SRV-ATTR:host" => "compute",
|
14
|
+
"OS-EXT-SRV-ATTR:hostname" => "new-server-test",
|
15
|
+
"OS-EXT-SRV-ATTR:hypervisor_hostname" => "fake-mini",
|
16
|
+
"OS-EXT-SRV-ATTR:instance_name" => "instance-00000001",
|
17
|
+
"OS-EXT-SRV-ATTR:kernel_id" => "",
|
18
|
+
"OS-EXT-SRV-ATTR:launch_index" => 0,
|
19
|
+
"OS-EXT-SRV-ATTR:ramdisk_id" => "",
|
20
|
+
"OS-EXT-SRV-ATTR:reservation_id" => "r-l0i0clt2",
|
21
|
+
"OS-EXT-SRV-ATTR:root_device_name" => "/dev/sda",
|
22
|
+
"OS-EXT-SRV-ATTR:user_data" => "IyEvYmluL2Jhc2gKL2Jpbi9zdQplY2hvICJJIGFtIGluIHlvdSEiCg==",
|
23
|
+
"OS-EXT-STS:power_state" => 1,
|
24
|
+
"OS-EXT-STS:task_state" => nil,
|
25
|
+
"OS-EXT-STS:vm_state" => "active",
|
26
|
+
"OS-SRV-USG:launched_at" => "2019-04-23T15:19:15.317839",
|
27
|
+
"OS-SRV-USG:terminated_at" => nil,
|
28
|
+
"accessIPv4" => "1.2.3.4",
|
29
|
+
"accessIPv6" => "80fe::",
|
30
|
+
"addresses" => {
|
31
|
+
"private" => [
|
32
|
+
{
|
33
|
+
"OS-EXT-IPS-MAC:mac_addr" => "aa:bb:cc:dd:ee:ff",
|
34
|
+
"OS-EXT-IPS:type" => "fixed",
|
35
|
+
"addr" => "192.168.0.3",
|
36
|
+
"version" => 4
|
37
|
+
}
|
38
|
+
]
|
39
|
+
},
|
40
|
+
"config_drive" => "",
|
41
|
+
"created" => "2019-04-23T15:19:14Z",
|
42
|
+
"description" => nil,
|
43
|
+
"flavor" => {
|
44
|
+
"disk" => 1,
|
45
|
+
"ephemeral" => 0,
|
46
|
+
"extra_specs" => {},
|
47
|
+
"original_name" => "m1.tiny",
|
48
|
+
"ram" => 512,
|
49
|
+
"swap" => 0,
|
50
|
+
"vcpus" => 1
|
51
|
+
},
|
52
|
+
"hostId" => "2091634baaccdc4c5a1d57069c833e402921df696b7f970791b12ec6",
|
53
|
+
"host_status" => "UP",
|
54
|
+
"id" => "2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
|
55
|
+
"image" => {
|
56
|
+
"id" => "70a599e0-31e7-49b7-b260-868f441e862b",
|
57
|
+
"links" => [
|
58
|
+
{
|
59
|
+
"href" => "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
|
60
|
+
"rel" => "bookmark"
|
61
|
+
}
|
62
|
+
]
|
63
|
+
},
|
64
|
+
"key_name" => nil,
|
65
|
+
"links" => [
|
66
|
+
{
|
67
|
+
"href" => "http://openstack.example.com/v2.1/6f70656e737461636b20342065766572/servers/2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
|
68
|
+
"rel" => "self"
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"href" => "http://openstack.example.com/6f70656e737461636b20342065766572/servers/2ce4c5b3-2866-4972-93ce-77a2ea46a7f9",
|
72
|
+
"rel" => "bookmark"
|
73
|
+
}
|
74
|
+
],
|
75
|
+
"locked" => true,
|
76
|
+
"locked_reason" => "I don't want to work",
|
77
|
+
"metadata" => {
|
78
|
+
"My Server Name" => "Apache1"
|
79
|
+
},
|
80
|
+
"name" => "new-server-test",
|
81
|
+
"os-extended-volumes:volumes_attached" => [],
|
82
|
+
"progress" => 0,
|
83
|
+
"security_groups" => [
|
84
|
+
{
|
85
|
+
"name" => "default"
|
86
|
+
}
|
87
|
+
],
|
88
|
+
"status" => "ACTIVE",
|
89
|
+
"tags" => [],
|
90
|
+
"tenant_id" => "6f70656e737461636b20342065766572",
|
91
|
+
"trusted_image_certificates" => nil,
|
92
|
+
"updated" => "2019-04-23T15:19:15Z",
|
93
|
+
"user_id" => "fake"
|
94
|
+
}
|
95
|
+
|
96
|
+
server = Yao::Server.new(params)
|
97
|
+
|
98
|
+
# friendly_attributes
|
99
|
+
assert_equal(server.id, "2ce4c5b3-2866-4972-93ce-77a2ea46a7f9")
|
100
|
+
assert_equal(server.addresses, {
|
101
|
+
"private" => [
|
102
|
+
{
|
103
|
+
"OS-EXT-IPS-MAC:mac_addr" => "aa:bb:cc:dd:ee:ff",
|
104
|
+
"OS-EXT-IPS:type" => "fixed",
|
105
|
+
"addr" => "192.168.0.3",
|
106
|
+
"version" => 4
|
107
|
+
}
|
108
|
+
]
|
109
|
+
})
|
110
|
+
assert_equal(server.metadata, { "My Server Name" => "Apache1" })
|
111
|
+
assert_equal(server.name, "new-server-test")
|
112
|
+
assert_equal(server.progress, 0)
|
113
|
+
assert_equal(server.status, "ACTIVE")
|
114
|
+
assert_equal(server.tenant_id, "6f70656e737461636b20342065766572")
|
115
|
+
assert_equal(server.user_id, "fake")
|
116
|
+
assert_equal(server.key_name, nil)
|
117
|
+
|
118
|
+
# map_attribute_to_attribute
|
119
|
+
assert_equal(server.host_id, "2091634baaccdc4c5a1d57069c833e402921df696b7f970791b12ec6")
|
120
|
+
|
121
|
+
# map_attribute_to_resource - flavor
|
122
|
+
assert_instance_of(Yao::Resources::Flavor, server.flavor)
|
123
|
+
assert_equal(server.flavor.disk, 1)
|
124
|
+
|
125
|
+
# map_attribute_to_resource - image
|
126
|
+
assert_instance_of(Yao::Resources::Image, server.image)
|
127
|
+
assert_equal(server.image.id, "70a599e0-31e7-49b7-b260-868f441e862b")
|
128
|
+
|
129
|
+
# map_attribute_to_resource - security_groups
|
130
|
+
assert_instance_of(Array, server.security_groups)
|
131
|
+
assert_instance_of(Yao::Resources::SecurityGroup, server.security_groups.first)
|
132
|
+
assert_equal(server.security_groups.first.name, "default")
|
133
|
+
|
134
|
+
# map_attribute_to_attribute
|
135
|
+
assert_equal(server.availability_zone, "nova")
|
136
|
+
assert_equal(server.dcf_disk_config, "AUTO")
|
137
|
+
assert_equal(server.ext_srv_attr_host, "compute")
|
138
|
+
assert_equal(server.ext_srv_attr_hypervisor_hostname, "fake-mini")
|
139
|
+
assert_equal(server.ext_srv_attr_instance_name, "instance-00000001")
|
140
|
+
assert_equal(server.ext_sts_power_state, 1)
|
141
|
+
assert_equal(server.ext_sts_task_state, nil)
|
142
|
+
assert_equal(server.ext_sts_vm_state, "active")
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_list_detail
|
146
|
+
stub_request(:get, "https://example.com:12345/servers/detail")
|
147
|
+
.to_return(
|
148
|
+
status: 200,
|
149
|
+
body: <<-JSON,
|
150
|
+
{
|
151
|
+
"servers": [{
|
152
|
+
"id": "dummy"
|
153
|
+
}]
|
154
|
+
}
|
155
|
+
JSON
|
156
|
+
headers: {'Content-Type' => 'application/json'}
|
157
|
+
)
|
158
|
+
|
159
|
+
servers = Yao::Server.list_detail
|
160
|
+
assert_instance_of(Array, servers)
|
161
|
+
assert_instance_of(Yao::Server, servers.first)
|
162
|
+
assert_equal(servers.first.id, 'dummy')
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class TestSubnet < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def setup
|
4
|
+
Yao.default_client.pool["network"] = Yao::Client.gen_client("https://example.com:12345")
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_subnet
|
8
|
+
# https://docs.openstack.org/api-ref/network/v2/#subnets
|
9
|
+
params = {
|
10
|
+
"name" => "private-subnet",
|
11
|
+
"enable_dhcp" => true,
|
12
|
+
"network_id" => "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
|
13
|
+
"segment_id" => nil,
|
14
|
+
"project_id" => "26a7980765d0414dbc1fc1f88cdb7e6e",
|
15
|
+
"tenant_id" => "26a7980765d0414dbc1fc1f88cdb7e6e",
|
16
|
+
"dns_nameservers" => [],
|
17
|
+
"dns_publish_fixed_ip" => false,
|
18
|
+
"allocation_pools" => [
|
19
|
+
{
|
20
|
+
"start" => "10.0.0.2",
|
21
|
+
"end" => "10.0.0.254"
|
22
|
+
}
|
23
|
+
],
|
24
|
+
"host_routes" => [],
|
25
|
+
"ip_version" => 4,
|
26
|
+
"gateway_ip" => "10.0.0.1",
|
27
|
+
"cidr" => "10.0.0.0/24",
|
28
|
+
"id" => "08eae331-0402-425a-923c-34f7cfe39c1b",
|
29
|
+
"created_at" => "2016-10-10T14:35:34Z",
|
30
|
+
"description" => "",
|
31
|
+
"ipv6_address_mode" => nil,
|
32
|
+
"ipv6_ra_mode" => nil,
|
33
|
+
"revision_number" => 2,
|
34
|
+
"service_types" => [],
|
35
|
+
"subnetpool_id" => nil,
|
36
|
+
"tags" => ["tag1,tag2"],
|
37
|
+
"updated_at" => "2016-10-10T14:35:34Z"
|
38
|
+
}
|
39
|
+
|
40
|
+
subnet = Yao::Subnet.new(params)
|
41
|
+
|
42
|
+
# friendly_attributes
|
43
|
+
assert_equal(subnet.name, "private-subnet")
|
44
|
+
assert_equal(subnet.cidr, "10.0.0.0/24")
|
45
|
+
assert_equal(subnet.gateway_ip, "10.0.0.1")
|
46
|
+
assert_equal(subnet.network_id, "db193ab3-96e3-4cb3-8fc5-05f4296d0324")
|
47
|
+
assert_equal(subnet.tenant_id, "26a7980765d0414dbc1fc1f88cdb7e6e")
|
48
|
+
assert_equal(subnet.ip_version, 4)
|
49
|
+
assert_equal(subnet.dns_nameservers, [])
|
50
|
+
assert_equal(subnet.host_routes, [])
|
51
|
+
assert_equal(subnet.enable_dhcp, true)
|
52
|
+
assert_equal(subnet.dhcp_enabled?, true) # alias
|
53
|
+
|
54
|
+
# #allocation_pools
|
55
|
+
assert_equal(subnet.allocation_pools, ["10.0.0.2".."10.0.0.254"])
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_network
|
59
|
+
stub_request(:get, "https://example.com:12345/networks/00000000-0000-0000-0000-000000000000").
|
60
|
+
to_return(
|
61
|
+
status: 200,
|
62
|
+
body: <<-JSON,
|
63
|
+
{
|
64
|
+
"network": {
|
65
|
+
"id": "00000000-0000-0000-0000-000000000000"
|
66
|
+
}
|
67
|
+
}
|
68
|
+
JSON
|
69
|
+
headers: {'Content-Type' => 'application/json'}
|
70
|
+
)
|
71
|
+
|
72
|
+
params = {
|
73
|
+
"network_id" => "00000000-0000-0000-0000-000000000000",
|
74
|
+
}
|
75
|
+
|
76
|
+
subnet = Yao::Subnet.new(params)
|
77
|
+
assert_instance_of(Yao::Resources::Network, subnet.network)
|
78
|
+
assert_equal(subnet.network.id, "00000000-0000-0000-0000-000000000000")
|
79
|
+
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yao
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uchio, KONDO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -223,16 +223,28 @@ files:
|
|
223
223
|
- test/support/restfully_accesible_stub.rb
|
224
224
|
- test/yao/resources/test_aggregates.rb
|
225
225
|
- test/yao/resources/test_base.rb
|
226
|
+
- test/yao/resources/test_flavor.rb
|
227
|
+
- test/yao/resources/test_floating_ip.rb
|
228
|
+
- test/yao/resources/test_host.rb
|
226
229
|
- test/yao/resources/test_hypervisor.rb
|
230
|
+
- test/yao/resources/test_image.rb
|
231
|
+
- test/yao/resources/test_keypair.rb
|
227
232
|
- test/yao/resources/test_loadbalancer.rb
|
228
233
|
- test/yao/resources/test_loadbalancer_healthmonitor.rb
|
229
234
|
- test/yao/resources/test_loadbalancer_listener.rb
|
230
235
|
- test/yao/resources/test_loadbalancer_pool.rb
|
231
236
|
- test/yao/resources/test_loadbalancer_pool_member.rb
|
237
|
+
- test/yao/resources/test_meter.rb
|
238
|
+
- test/yao/resources/test_network.rb
|
239
|
+
- test/yao/resources/test_port.rb
|
232
240
|
- test/yao/resources/test_restfully_accessible.rb
|
233
241
|
- test/yao/resources/test_role.rb
|
242
|
+
- test/yao/resources/test_role_assignment.rb
|
243
|
+
- test/yao/resources/test_router.rb
|
234
244
|
- test/yao/resources/test_security_group.rb
|
235
245
|
- test/yao/resources/test_security_group_rule.rb
|
246
|
+
- test/yao/resources/test_server.rb
|
247
|
+
- test/yao/resources/test_subnet.rb
|
236
248
|
- test/yao/resources/test_user.rb
|
237
249
|
- test/yao/resources/test_volume.rb
|
238
250
|
- test/yao/resources/test_volume_type.rb
|
@@ -266,8 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
278
|
- !ruby/object:Gem::Version
|
267
279
|
version: '0'
|
268
280
|
requirements: []
|
269
|
-
|
270
|
-
rubygems_version: 2.7.6
|
281
|
+
rubygems_version: 3.0.3
|
271
282
|
signing_key:
|
272
283
|
specification_version: 4
|
273
284
|
summary: Yet Another OpenStack API Wrapper that rocks!!
|
@@ -280,16 +291,28 @@ test_files:
|
|
280
291
|
- test/support/restfully_accesible_stub.rb
|
281
292
|
- test/yao/resources/test_aggregates.rb
|
282
293
|
- test/yao/resources/test_base.rb
|
294
|
+
- test/yao/resources/test_flavor.rb
|
295
|
+
- test/yao/resources/test_floating_ip.rb
|
296
|
+
- test/yao/resources/test_host.rb
|
283
297
|
- test/yao/resources/test_hypervisor.rb
|
298
|
+
- test/yao/resources/test_image.rb
|
299
|
+
- test/yao/resources/test_keypair.rb
|
284
300
|
- test/yao/resources/test_loadbalancer.rb
|
285
301
|
- test/yao/resources/test_loadbalancer_healthmonitor.rb
|
286
302
|
- test/yao/resources/test_loadbalancer_listener.rb
|
287
303
|
- test/yao/resources/test_loadbalancer_pool.rb
|
288
304
|
- test/yao/resources/test_loadbalancer_pool_member.rb
|
305
|
+
- test/yao/resources/test_meter.rb
|
306
|
+
- test/yao/resources/test_network.rb
|
307
|
+
- test/yao/resources/test_port.rb
|
289
308
|
- test/yao/resources/test_restfully_accessible.rb
|
290
309
|
- test/yao/resources/test_role.rb
|
310
|
+
- test/yao/resources/test_role_assignment.rb
|
311
|
+
- test/yao/resources/test_router.rb
|
291
312
|
- test/yao/resources/test_security_group.rb
|
292
313
|
- test/yao/resources/test_security_group_rule.rb
|
314
|
+
- test/yao/resources/test_server.rb
|
315
|
+
- test/yao/resources/test_subnet.rb
|
293
316
|
- test/yao/resources/test_user.rb
|
294
317
|
- test/yao/resources/test_volume.rb
|
295
318
|
- test/yao/resources/test_volume_type.rb
|