yao 0.8.0 → 0.9.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ubuntu.yml +1 -1
  3. data/lib/yao/client.rb +62 -5
  4. data/lib/yao/plugins/registry.rb +10 -0
  5. data/lib/yao/resources/compute_services.rb +12 -0
  6. data/lib/yao/resources/hypervisor.rb +13 -1
  7. data/lib/yao/resources/restfully_accessible.rb +9 -0
  8. data/lib/yao/version.rb +1 -1
  9. data/test/support/restfully_accesible_stub.rb +10 -0
  10. data/test/yao/resources/test_aggregates.rb +8 -8
  11. data/test/yao/resources/test_base.rb +2 -2
  12. data/test/yao/resources/test_compute_services.rb +31 -19
  13. data/test/yao/resources/test_flavor.rb +13 -13
  14. data/test/yao/resources/test_floating_ip.rb +22 -22
  15. data/test/yao/resources/test_host.rb +3 -3
  16. data/test/yao/resources/test_hypervisor.rb +75 -6
  17. data/test/yao/resources/test_image.rb +12 -12
  18. data/test/yao/resources/test_keypair.rb +4 -4
  19. data/test/yao/resources/test_loadbalancer.rb +9 -9
  20. data/test/yao/resources/test_loadbalancer_healthmonitor.rb +14 -14
  21. data/test/yao/resources/test_loadbalancer_listener.rb +16 -16
  22. data/test/yao/resources/test_loadbalancer_pool.rb +11 -11
  23. data/test/yao/resources/test_loadbalancer_pool_member.rb +11 -11
  24. data/test/yao/resources/test_meter.rb +13 -13
  25. data/test/yao/resources/test_network.rb +12 -12
  26. data/test/yao/resources/test_old_sample.rb +15 -15
  27. data/test/yao/resources/test_port.rb +19 -19
  28. data/test/yao/resources/test_project.rb +7 -7
  29. data/test/yao/resources/test_resource.rb +11 -11
  30. data/test/yao/resources/test_restfully_accessible.rb +29 -8
  31. data/test/yao/resources/test_role.rb +8 -8
  32. data/test/yao/resources/test_role_assignment.rb +4 -4
  33. data/test/yao/resources/test_router.rb +19 -19
  34. data/test/yao/resources/test_sample.rb +13 -13
  35. data/test/yao/resources/test_security_group.rb +4 -4
  36. data/test/yao/resources/test_security_group_rule.rb +5 -5
  37. data/test/yao/resources/test_server.rb +25 -25
  38. data/test/yao/resources/test_subnet.rb +13 -13
  39. data/test/yao/resources/test_user.rb +4 -4
  40. data/test/yao/resources/test_volume.rb +4 -4
  41. data/test/yao/resources/test_volume_type.rb +3 -3
  42. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97e6146fda8345c89f804cb55928c3011e8603999355e27e5416d13eb336e569
4
- data.tar.gz: b47ac5d66e43b08e2482f157c13ff9fa45a335b8ac6992737d6554d08a2c4ca3
3
+ metadata.gz: 5f7b084698d4c47d604863ccbfe4c36b1d5d7815e0b9b011ae1d2f83c8a61895
4
+ data.tar.gz: 00be9619242873d469ce87df87f320e8bb2ce78f8316537f6015023b9c0ac304
5
5
  SHA512:
6
- metadata.gz: f4066fa6911823b55df1b9e61d6796b3efa7719b7dc6afb4858b1daf28153bf16754aed5f4646fdbbbf8a80b540235f2cbf0d763c98e8ec428d1d8de7cb78077
7
- data.tar.gz: 545be1baceecc9ad556b207f19e01dc2658a37321038225707643005f802cbbbfea57f7fba5ba581ad4df1d1a7f2c331d4168ff7ee13c181f2ffb2f7d43056ff
6
+ metadata.gz: ad4a4d532cf894994470e285584ecf54a024591dc7adc43d32cd63aaf32d9bcb7ae4720a96b759b5df8baf38798aa9896332848a0f9dee769f3fa65b6e88c4a5
7
+ data.tar.gz: '099e654bb588b941b5becb906a4b75a7f5c97ce261ed2be093683ee9a39ff9df31ef205252180c72a532b32464d28aa38b59f8e6aeb13a4f79bc00ec9a3790b8'
@@ -13,7 +13,7 @@ jobs:
13
13
  - name: Set up Ruby
14
14
  uses: actions/setup-ruby@v1
15
15
  with:
16
- version: ${{ matrix.ruby }}
16
+ ruby-version: ${{ matrix.ruby }}
17
17
  - name: Install dependencies
18
18
  run: |
19
19
  gem install bundler --no-document
data/lib/yao/client.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'yao/config'
2
2
  require 'faraday'
3
+ require 'openssl'
3
4
  require 'yao/plugins/default_client_generator'
4
5
 
5
6
  module Yao
@@ -11,20 +12,50 @@ module Yao
11
12
  @pool = {}
12
13
  @admin_pool = {}
13
14
  end
15
+
16
+ # #pool and #admin_pool returns Hash like below structure
17
+ #
18
+ # {
19
+ # "identity" => #<Faraday::Connection:...>,
20
+ # "image" => #<Faraday::Connection:...>,
21
+ # }
22
+ #
23
+ # @return [Hash { String => Faraday::Connection }]
14
24
  attr_reader :pool, :admin_pool
15
25
 
16
26
  %w(default compute network image metering volume orchestration identity).each do |type|
27
+
28
+ # @return [Faraday::Connection]
17
29
  define_method(type) do
18
30
  self.pool[type]
19
31
  end
20
32
 
33
+ # @return [Faraday::Connection]
21
34
  define_method("#{type}_admin") do
22
35
  self.admin_pool[type]
23
36
  end
24
37
  end
25
38
 
39
+ # endpoints is a Hash like below structure
40
+ #
41
+ # {
42
+ # "identity" => {
43
+ # public_url: "https://example.com/mitaka/keystone/v3",
44
+ # internal_url: "https://example.com/mitaka/keystone/v3",
45
+ # admin_url: "https://example.com/mitaka/admin/keystone/v3"
46
+ # },
47
+ # "image" => {
48
+ # ...
49
+ # },
50
+ # }
51
+ #
52
+ # @param endpoints [Hash{ String => Hash }]
26
53
  def register_endpoints(endpoints, token: nil)
54
+
55
+ # type is String (e.g. network, identity, ... )
56
+ # urls is Hash{ Symbol => String }
27
57
  endpoints.each_pair do |type, urls|
58
+
28
59
  # XXX: neutron just have v2.0 API and endpoint may not have version prefix
29
60
  if type == "network"
30
61
  urls = urls.map {|public_or_admin, url|
@@ -33,39 +64,64 @@ module Yao
33
64
  }.to_h
34
65
  end
35
66
 
67
+ # User can override the public_url and admin_url of endpoints by setting Yao.configure
68
+ # For example.
69
+ #
70
+ # Yao.configure do
71
+ # endpoints identity: { public: "http://override-endpoint.example.com:35357/v3.0" }
72
+ # end
73
+ #
36
74
  force_public_url = Yao.config.endpoints[type.to_sym][:public] rescue nil
37
- force_admin_url = Yao.config.endpoints[type.to_sym][:admin] rescue nil
75
+ force_admin_url = Yao.config.endpoints[type.to_sym][:admin] rescue nil
76
+
77
+ if force_public_url || urls[:public_url]
78
+ self.pool[type] = Yao::Client.gen_client(force_public_url || urls[:public_url], token: token)
79
+ end
38
80
 
39
- self.pool[type] = Yao::Client.gen_client(force_public_url || urls[:public_url], token: token) if force_public_url || urls[:public_url]
40
- self.admin_pool[type] = Yao::Client.gen_client(force_admin_url || urls[:admin_url], token: token) if force_admin_url || urls[:admin_url]
81
+ if force_admin_url || urls[:admin_url]
82
+ self.admin_pool[type] = Yao::Client.gen_client(force_admin_url || urls[:admin_url], token: token)
83
+ end
41
84
  end
42
85
  end
43
86
  end
44
87
 
45
88
  class << self
89
+
90
+ # @return [Yao::Client::ClientSet]
46
91
  attr_accessor :default_client
47
92
 
93
+ # @return [Yao::Plugins::DefaultClientGenerator]
48
94
  def client_generator
49
95
  Plugins::Registry.instance[:client_generator][Yao.config.client_generator].new
50
96
  end
51
97
 
98
+ # @param endpoint [String]
99
+ # @param token [String]
100
+ # @return [Faraday::Connection]
52
101
  def gen_client(endpoint, token: nil)
53
102
  Faraday.new( endpoint, client_options ) do |f|
54
103
  client_generator.call(f, token)
55
104
  end
56
105
  end
57
106
 
107
+ # @param [String]
58
108
  def reset_client(new_endpoint=nil)
59
109
  set = ClientSet.new
60
110
  set.register_endpoints("default" => {public_url: new_endpoint || Yao.config.endpoint})
61
111
  self.default_client = set
62
112
  end
63
113
 
114
+ # generate Hash options for Faraday.new
115
+ # @return [Hash]
64
116
  def client_options
65
117
  opt = {}
66
- opt.merge!({ request: { timeout: Yao.config.timeout }}) if Yao.config.timeout
118
+
119
+ if Yao.config.timeout
120
+ opt.merge!({ request: { timeout: Yao.config.timeout }})
121
+ end
122
+
123
+ # Client Certificate Authentication
67
124
  if Yao.config.client_cert && Yao.config.client_key
68
- require 'openssl'
69
125
  cert = OpenSSL::X509::Certificate.new(File.read(Yao.config.client_cert))
70
126
  key = OpenSSL::PKey.read(File.read(Yao.config.client_key))
71
127
  opt.merge!(ssl: {
@@ -84,6 +140,7 @@ module Yao
84
140
  end
85
141
  end
86
142
 
143
+ # @return [Yao::Client::ClientSet]
87
144
  def self.default_client
88
145
  Yao::Client.default_client
89
146
  end
@@ -1,5 +1,7 @@
1
1
  require 'singleton'
2
2
 
3
+ # Regstiry Pattern - https://www.martinfowler.com/eaaCatalog/registry.html
4
+ # A well-known object that other objects can use to find common objects and services.
3
5
  module Yao::Plugins
4
6
  class Registry
5
7
  include Singleton
@@ -8,10 +10,15 @@ module Yao::Plugins
8
10
  @types = {}
9
11
  end
10
12
 
13
+ # @type type [Symbol]
14
+ # @return [Object]
11
15
  def [](type)
12
16
  @types[type]
13
17
  end
14
18
 
19
+ # @param klass [*]
20
+ # @param type [Symbol]
21
+ # @param name [Symbol]
15
22
  def register(klass, type: nil, name: :default)
16
23
  raise("Plugin registration requires both type and name.") if !type or !name
17
24
  @types[type] ||= {}
@@ -19,6 +26,9 @@ module Yao::Plugins
19
26
  end
20
27
  end
21
28
 
29
+ # @param [*]
30
+ # @param [Symbol]
31
+ # @param [Symbol]
22
32
  def self.register(*a)
23
33
  Registry.instance.register(*a)
24
34
  end
@@ -6,6 +6,18 @@ module Yao::Resources
6
6
  self.resource_name = "service"
7
7
  self.resources_name = "os-services"
8
8
 
9
+ # return true if ComputeServices is enabled
10
+ # @return [Bool]
11
+ def enabled?
12
+ status == 'enabled'
13
+ end
14
+
15
+ # return true if ComputeServices is disabled
16
+ # @return [Bool]
17
+ def disabled?
18
+ status == 'disabled'
19
+ end
20
+
9
21
  class << self
10
22
  def enable(host, binary)
11
23
  params = {
@@ -7,16 +7,28 @@ module Yao::Resources
7
7
  :memory_mb, :memory_mb_used, :free_disk_gb,
8
8
  :local_gb, :local_gb_used, :free_disk_gb, :status
9
9
 
10
+ # @return [Hash]
10
11
  def cpu_info
11
12
  JSON.parse self["cpu_info"]
12
13
  end
13
14
 
15
+ # @return [Bool]
14
16
  def enabled?
15
17
  self['status'] == 'enabled'
16
18
  end
17
19
 
20
+ # @return [Bool]
21
+ def disabled?
22
+ self['status'] == 'disabled'
23
+ end
24
+
25
+ # @return [Yao::ComputeServices]
26
+ def service
27
+ Yao::ComputeServices.new(self['service'])
28
+ end
29
+
18
30
  alias hostname hypervisor_hostname
19
- alias type hypervisor_hostname
31
+ alias type hypervisor_type
20
32
  alias version hypervisor_version
21
33
 
22
34
  self.service = "compute"
@@ -115,6 +115,15 @@ module Yao::Resources
115
115
  end
116
116
  alias find get
117
117
 
118
+ # @param id_or_name_or_permalink [Stirng]
119
+ # @param query [Hash]
120
+ # @return [Yao::Resources::*]
121
+ def get!(id_or_name_or_permalink, query={})
122
+ get(id_or_name_or_permalink, query)
123
+ rescue Yao::ItemNotFound, Yao::NotFound
124
+ nil
125
+ end
126
+
118
127
  def find_by_name(name, query={})
119
128
  list(query.merge({"name" => name}))
120
129
  end
data/lib/yao/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -19,6 +19,16 @@ module RestfullAccessibleStub
19
19
  )
20
20
  end
21
21
 
22
+ def stub_get_request_unauthorized(url)
23
+ stub_request(:get, url)
24
+ .with(
25
+ headers: request_headers
26
+ ).to_return(
27
+ status: 401,
28
+ body: "unauthorized"
29
+ )
30
+ end
31
+
22
32
  def request_headers
23
33
  {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"}
24
34
  end
@@ -12,13 +12,13 @@ class TestAggregates < TestYaoResource
12
12
  }
13
13
 
14
14
  aggregates = Yao::Aggregates.new(params)
15
- assert_equal(aggregates.availability_zone, "nova")
16
- assert_equal(aggregates.deleted, false)
17
- assert_equal(aggregates.hosts, ["host1", "host2"])
18
- assert_equal(aggregates.metadata, {"foo" => "bar"})
19
- assert_equal(aggregates.name, "nova")
20
- assert_equal(aggregates.created, Time.parse("2015-08-27T09:49:58-05:00"))
21
- assert_equal(aggregates.updated, Time.parse("2015-08-27T09:49:58-05:00"))
22
- assert_equal(aggregates.deleted_at, Date.parse("2015-08-27T09:49:58-05:00"))
15
+ assert_equal("nova", aggregates.availability_zone)
16
+ assert_equal(false, aggregates.deleted)
17
+ assert_equal(["host1", "host2"], aggregates.hosts)
18
+ assert_equal({"foo" => "bar"}, aggregates.metadata)
19
+ assert_equal("nova", aggregates.name)
20
+ assert_equal(Time.parse("2015-08-27T09:49:58-05:00"), aggregates.created)
21
+ assert_equal(Time.parse("2015-08-27T09:49:58-05:00"), aggregates.updated)
22
+ assert_equal(Date.parse("2015-08-27T09:49:58-05:00"), aggregates.deleted_at)
23
23
  end
24
24
  end
@@ -6,10 +6,10 @@ class TestResourceBase < TestYaoResource
6
6
  def test_friendly_attributes
7
7
  base = Yao::Resources::Base.new({"id" => "foor"})
8
8
  base.class.friendly_attributes(:name)
9
- assert_equal(base.name, "bar")
9
+ assert_equal("bar", base.name)
10
10
 
11
11
  base = Yao::Resources::Base.new({"name" => "bar"})
12
12
  base.class.friendly_attributes(:name)
13
- assert_equal(base.name, "bar")
13
+ assert_equal("bar", base.name)
14
14
  end
15
15
  end
@@ -16,15 +16,27 @@ class TestComputeServices < TestYaoResource
16
16
  }
17
17
  compute_service = Yao::ComputeServices.new(params)
18
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")
19
+ assert_equal(1, compute_service.id)
20
+ assert_equal("nova-scheduler", compute_service.binary)
21
+ assert_equal("test1", compute_service.disabled_reason)
22
+ assert_equal("host1", compute_service.host)
23
+ assert_equal("up", compute_service.state)
24
+ assert_equal("disabled", compute_service.status)
25
+ assert_equal(Time.mktime(2012,10,29,13,42,2), compute_service.updated)
26
+ assert_equal(false, compute_service.forced_down)
27
+ assert_equal("internal", compute_service.zone)
28
+ end
29
+
30
+ def test_enabled?
31
+ compute_service = Yao::ComputeServices.new( 'status' => 'enabled' )
32
+ assert_true compute_service.enabled?
33
+ assert_false compute_service.disabled?
34
+ end
35
+
36
+ def test_disabled?
37
+ compute_service = Yao::ComputeServices.new( 'status' => 'disabled' )
38
+ assert_false compute_service.enabled?
39
+ assert_true compute_service.disabled?
28
40
  end
29
41
 
30
42
  def test_enable
@@ -49,9 +61,9 @@ class TestComputeServices < TestYaoResource
49
61
 
50
62
  compute_service = Yao::ComputeServices.enable('host1', 'nova-compute')
51
63
 
52
- assert_equal(compute_service.host, "host1")
53
- assert_equal(compute_service.binary, "nova-compute")
54
- assert_equal(compute_service.status, "enabled")
64
+ assert_equal("host1", compute_service.host)
65
+ assert_equal("nova-compute", compute_service.binary)
66
+ assert_equal("enabled", compute_service.status)
55
67
 
56
68
  assert_requested stub
57
69
  end
@@ -78,9 +90,9 @@ class TestComputeServices < TestYaoResource
78
90
 
79
91
  compute_service = Yao::ComputeServices.disable('host1', 'nova-compute')
80
92
 
81
- assert_equal(compute_service.host, "host1")
82
- assert_equal(compute_service.binary, "nova-compute")
83
- assert_equal(compute_service.status, "disabled")
93
+ assert_equal("host1", compute_service.host)
94
+ assert_equal("nova-compute", compute_service.binary)
95
+ assert_equal("disabled", compute_service.status)
84
96
 
85
97
  assert_requested stub
86
98
  end
@@ -108,10 +120,10 @@ class TestComputeServices < TestYaoResource
108
120
 
109
121
  compute_service = Yao::ComputeServices.disable('host1', 'nova-compute', 'test2')
110
122
 
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")
123
+ assert_equal("host1", compute_service.host)
124
+ assert_equal("nova-compute", compute_service.binary)
125
+ assert_equal("disabled", compute_service.status)
126
+ assert_equal("test2", compute_service.disabled_reason)
115
127
 
116
128
  assert_requested stub
117
129
  end
@@ -30,20 +30,20 @@ class TestFlavor < TestYaoResource
30
30
  flavor = Yao::Flavor.new(params)
31
31
 
32
32
  # friendly_attributes
33
- assert_equal(flavor.id, "1")
34
- assert_equal(flavor.name, "m1.tiny")
35
- assert_equal(flavor.vcpus, 1)
36
- assert_equal(flavor.disk, 1)
37
- assert_equal(flavor.swap, "")
33
+ assert_equal("1", flavor.id)
34
+ assert_equal("m1.tiny", flavor.name)
35
+ assert_equal(1, flavor.vcpus)
36
+ assert_equal(1, flavor.disk)
37
+ assert_equal("", flavor.swap)
38
38
 
39
39
  # map_attribute_to_attribute
40
- assert_equal(flavor.public?, true)
41
- assert_equal(flavor.disabled?, false)
40
+ assert_equal(true, flavor.public?)
41
+ assert_equal(false, flavor.disabled?)
42
42
 
43
- assert_equal(flavor.ram, 512)
44
- assert_equal(flavor.ram('M'), 512)
45
- assert_equal(flavor.ram('G'), 0.5)
46
- assert_equal(flavor.memory, 512)
43
+ assert_equal(512, flavor.ram)
44
+ assert_equal(512, flavor.ram('M'))
45
+ assert_equal(0.5, flavor.ram('G'))
46
+ assert_equal(512, flavor.memory)
47
47
  end
48
48
 
49
49
  def test_list
@@ -87,7 +87,7 @@ class TestFlavor < TestYaoResource
87
87
 
88
88
  flavors = Yao::Flavor.list
89
89
  assert_instance_of(Yao::Flavor, flavors.first)
90
- assert_equal(flavors.first.name, "m1.tiny")
90
+ assert_equal("m1.tiny", flavors.first.name)
91
91
 
92
92
  assert_requested(stub)
93
93
  end
@@ -95,6 +95,6 @@ class TestFlavor < TestYaoResource
95
95
  def test_list_detail
96
96
  # Yao::Flavor.list_detail と Yao::Flavor.list が alias にあることをテストする
97
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))
98
+ assert_equal(Yao::Flavor.method(:list), Yao::Flavor.method(:list_detail))
99
99
  end
100
100
  end
@@ -31,23 +31,23 @@ class TestFloatingIP < TestYaoResource
31
31
  }
32
32
 
33
33
  fip = Yao::Resources::FloatingIP.new(params)
34
- assert_equal(fip.router_id, "d23abc8d-2991-4a55-ba98-2aaea84cc72f")
35
- assert_equal(fip.description, "for test")
36
- assert_equal(fip.dns_domain, "my-domain.org.")
37
- assert_equal(fip.dns_name, "myfip")
38
- assert_equal(fip.created, Time.parse("2016-12-21T10:55:50Z"))
39
- assert_equal(fip.updated, Time.parse("2016-12-21T10:55:53Z"))
40
- assert_equal(fip.revision_number, 1)
41
- assert_equal(fip.project_id, "4969c491a3c74ee4af974e6d800c62de")
42
- assert_equal(fip.tenant_id, "4969c491a3c74ee4af974e6d800c62de")
43
- assert_equal(fip.floating_network_id, "376da547-b977-4cfe-9cba-275c80debf57")
44
- assert_equal(fip.fixed_ip_address, "10.0.0.3")
45
- assert_equal(fip.floating_ip_address, "172.24.4.228")
46
- assert_equal(fip.port_id, "ce705c24-c1ef-408a-bda3-7bbd946164ab")
47
- assert_equal(fip.id, "2f245a7b-796b-4f26-9cf9-9e82d248fda7")
48
- assert_equal(fip.status, "ACTIVE")
49
- assert_equal(fip.tags, ["tag1,tag2"])
50
- assert_equal(fip.port_details, {
34
+ assert_equal("d23abc8d-2991-4a55-ba98-2aaea84cc72f", fip.router_id)
35
+ assert_equal("for test", fip.description)
36
+ assert_equal("my-domain.org.", fip.dns_domain)
37
+ assert_equal("myfip", fip.dns_name)
38
+ assert_equal(Time.parse("2016-12-21T10:55:50Z"), fip.created)
39
+ assert_equal(Time.parse("2016-12-21T10:55:53Z"), fip.updated)
40
+ assert_equal(1, fip.revision_number)
41
+ assert_equal("4969c491a3c74ee4af974e6d800c62de", fip.project_id)
42
+ assert_equal("4969c491a3c74ee4af974e6d800c62de", fip.tenant_id)
43
+ assert_equal("376da547-b977-4cfe-9cba-275c80debf57", fip.floating_network_id)
44
+ assert_equal("10.0.0.3", fip.fixed_ip_address)
45
+ assert_equal("172.24.4.228", fip.floating_ip_address)
46
+ assert_equal("ce705c24-c1ef-408a-bda3-7bbd946164ab", fip.port_id)
47
+ assert_equal("2f245a7b-796b-4f26-9cf9-9e82d248fda7", fip.id)
48
+ assert_equal("ACTIVE", fip.status)
49
+ assert_equal(["tag1,tag2"], fip.tags)
50
+ assert_equal({
51
51
  "status" => "ACTIVE",
52
52
  "name" => "",
53
53
  "admin_state_up" => true,
@@ -55,8 +55,8 @@ class TestFloatingIP < TestYaoResource
55
55
  "device_owner" => "compute:nova",
56
56
  "mac_address" => "fa:16:3e:b1:3b:30",
57
57
  "device_id" => "8e3941b4-a6e9-499f-a1ac-2a4662025cba"
58
- })
59
- assert_equal(fip.port_forwardings, [])
58
+ },fip.port_details)
59
+ assert_equal([], fip.port_forwardings)
60
60
  end
61
61
 
62
62
  def test_floating_ip_to_router
@@ -77,7 +77,7 @@ class TestFloatingIP < TestYaoResource
77
77
  fip = Yao::FloatingIP.new("router_id" => "00000000-0000-0000-0000-000000000000")
78
78
 
79
79
  assert_instance_of(Yao::Router, fip.router)
80
- assert_equal(fip.router.id, "00000000-0000-0000-0000-000000000000")
80
+ assert_equal("00000000-0000-0000-0000-000000000000", fip.router.id)
81
81
 
82
82
  assert_requested(stub)
83
83
  end
@@ -104,7 +104,7 @@ class TestFloatingIP < TestYaoResource
104
104
 
105
105
  assert_instance_of(Yao::Tenant, fip.tenant)
106
106
  assert_instance_of(Yao::Tenant, fip.project)
107
- assert_equal(fip.tenant.id, '0123456789abcdef0123456789abcdef')
107
+ assert_equal('0123456789abcdef0123456789abcdef', fip.tenant.id)
108
108
 
109
109
  assert_requested(stub)
110
110
  end
@@ -127,7 +127,7 @@ class TestFloatingIP < TestYaoResource
127
127
  fip = Yao::FloatingIP.new("port_id" => "00000000-0000-0000-0000-000000000000")
128
128
 
129
129
  assert_instance_of(Yao::Port, fip.port)
130
- assert_equal(fip.port.id, "00000000-0000-0000-0000-000000000000")
130
+ assert_equal("00000000-0000-0000-0000-000000000000", fip.port.id)
131
131
 
132
132
  assert_requested(stub)
133
133
  end
@@ -11,8 +11,8 @@ class TestHost < TestYaoResource
11
11
  host = Yao::Host.new(params)
12
12
 
13
13
  # friendly_attributes
14
- assert_equal(host.host_name, "b6e4adbc193d428ea923899d07fb001e")
15
- assert_equal(host.service, "conductor")
16
- assert_equal(host.zone, "internal")
14
+ assert_equal("b6e4adbc193d428ea923899d07fb001e", host.host_name)
15
+ assert_equal("conductor", host.service)
16
+ assert_equal("internal", host.zone)
17
17
  end
18
18
  end
@@ -2,11 +2,80 @@ class TestHypervisor < TestYaoResource
2
2
 
3
3
  def test_hypervisor
4
4
  params = {
5
- "status" => "enabled"
5
+ "current_workload" => 0,
6
+ "status" => "enabled",
7
+ "state" => "up",
8
+ "disk_available_least" => 0,
9
+ "host_ip" => "1.1.1.1",
10
+ "free_disk_gb" => 1028,
11
+ "free_ram_mb" => 7680,
12
+ "hypervisor_hostname" => "host1",
13
+ "hypervisor_type" => "fake",
14
+ "hypervisor_version" => 1000,
15
+ "id" => 2,
16
+ "local_gb" => 1028,
17
+ "local_gb_used" => 0,
18
+ "memory_mb" => 8192,
19
+ "memory_mb_used" => 512,
20
+ "running_vms" => 0,
21
+ "service" => {
22
+ "host" => "host1",
23
+ "id" => 6,
24
+ "disabled_reason" => nil,
25
+ },
26
+ "vcpus" => 2,
27
+ "vcpus_used" => 0
6
28
  }
7
29
 
30
+ # ooooooooooooooopsssssssssssss
31
+ params['cpu_info'] = {
32
+ "arch" => "x86_64",
33
+ "model" => "Nehalem",
34
+ "vendor" => "Intel",
35
+ "features" => [
36
+ "pge",
37
+ "clflush"
38
+ ],
39
+ "topology" => {
40
+ "cores" => 1,
41
+ "threads" => 1,
42
+ "sockets" => 4
43
+ }
44
+ }.to_json
45
+
8
46
  host = Yao::Hypervisor.new(params)
9
- assert_equal(host.enabled?, true)
47
+
48
+ assert_equal("host1", host.hypervisor_hostname)
49
+ assert_equal("host1", host.hostname)
50
+
51
+ assert_equal("fake", host.hypervisor_type)
52
+ assert_equal("fake", host.type)
53
+
54
+ assert_equal(1000, host.hypervisor_version)
55
+ assert_equal(1000, host.version)
56
+
57
+ assert_equal(0, host.running_vms)
58
+ assert_equal(0, host.current_workload)
59
+ assert_equal(2, host.vcpus)
60
+ assert_equal(0, host.vcpus_used)
61
+ assert_equal(8192, host.memory_mb)
62
+ assert_equal(512, host.memory_mb_used)
63
+ assert_equal(1028, host.free_disk_gb)
64
+ assert_equal(1028, host.local_gb)
65
+ assert_equal(0, host.local_gb_used)
66
+ assert_equal(1028, host.free_disk_gb)
67
+ assert_equal('enabled', host.status)
68
+
69
+ # #cpu_info
70
+ assert_equal('x86_64', host.cpu_info["arch"])
71
+
72
+ # #enabled?
73
+ assert_true(host.enabled?)
74
+ assert_false(host.disabled?)
75
+
76
+ # #service
77
+ assert_instance_of(Yao::ComputeServices, host.service)
78
+ assert_equal(6, host.service.id)
10
79
  end
11
80
 
12
81
  def test_list
@@ -25,13 +94,13 @@ class TestHypervisor < TestYaoResource
25
94
  )
26
95
 
27
96
  h = Yao::Resources::Hypervisor.list
28
- assert_equal(h.first.id, "dummy")
97
+ assert_equal("dummy", h.first.id)
29
98
 
30
99
  assert_requested(stub)
31
100
  end
32
101
 
33
102
  def test_list_detail
34
- assert_equal(Yao::Hypervisor.method(:list_detail), Yao::Hypervisor.method(:list))
103
+ assert_equal(Yao::Hypervisor.method(:list), Yao::Hypervisor.method(:list_detail))
35
104
  end
36
105
 
37
106
  def test_statistics
@@ -61,7 +130,7 @@ class TestHypervisor < TestYaoResource
61
130
  )
62
131
 
63
132
  s = Yao::Resources::Hypervisor.statistics
64
- assert_equal(s.count, 1)
133
+ assert_equal(1, s.count)
65
134
 
66
135
  assert_requested(stub)
67
136
  end
@@ -86,7 +155,7 @@ class TestHypervisor < TestYaoResource
86
155
  )
87
156
 
88
157
  u = Yao::Resources::Hypervisor.uptime(1)
89
- assert_equal(u.uptime, " 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14")
158
+ assert_equal(" 08:32:11 up 93 days, 18:25, 12 users, load average: 0.20, 0.12, 0.14", u.uptime)
90
159
 
91
160
  assert_requested(stub)
92
161
  end