import unittest
from unittest import mock
-from orchestrator import HostSpec
+from orchestrator import DaemonDescription, HostSpec
from .. import mgr
from ..controllers._version import APIVersion
self._get('{}?facts=true'.format(self.URL_HOST), version=APIVersion(1, 1))
self.assertStatus(200)
self.assertHeader('Content-Type',
- 'application/vnd.ceph.api.v1.1+json')
+ APIVersion(1, 2).to_mime_type())
self.assertJsonBody(hosts_with_facts)
# test with ?facts=false
self._get('{}?facts=false'.format(self.URL_HOST), version=APIVersion(1, 1))
self.assertStatus(200)
self.assertHeader('Content-Type',
- 'application/vnd.ceph.api.v1.1+json')
+ APIVersion(1, 2).to_mime_type())
self.assertJsonBody(hosts_without_facts)
# test with orchestrator available but orch backend!=cephadm
self._get('{}?facts=false'.format(self.URL_HOST), version=APIVersion(1, 1))
self.assertStatus(200)
self.assertHeader('Content-Type',
- 'application/vnd.ceph.api.v1.1+json')
+ APIVersion(1, 2).to_mime_type())
self.assertJsonBody(hosts_without_facts)
def test_get_1(self):
self.assertStatus(404)
def test_get_2(self):
- mgr.list_servers.return_value = [{'hostname': 'node1'}]
+ mgr.list_servers.return_value = [{
+ 'hostname': 'node1',
+ 'services': []
+ }]
with patch_orch(False):
self._get('{}/node1'.format(self.URL_HOST))
self.assertIn('status', self.json_body())
self.assertIn('addr', self.json_body())
+ def test_populate_service_instances(self):
+ mgr.list_servers.return_value = []
+
+ node1_daemons = [
+ DaemonDescription(
+ hostname='node1',
+ daemon_type='mon',
+ daemon_id='a'
+ ),
+ DaemonDescription(
+ hostname='node1',
+ daemon_type='mon',
+ daemon_id='b'
+ )
+ ]
+
+ node2_daemons = [
+ DaemonDescription(
+ hostname='node2',
+ daemon_type='mgr',
+ daemon_id='x'
+ ),
+ DaemonDescription(
+ hostname='node2',
+ daemon_type='mon',
+ daemon_id='c'
+ )
+ ]
+
+ node1_instances = [{
+ 'type': 'mon',
+ 'count': 2
+ }]
+
+ node2_instances = [{
+ 'type': 'mgr',
+ 'count': 1
+ }, {
+ 'type': 'mon',
+ 'count': 1
+ }]
+
+ # test with orchestrator available
+ with patch_orch(True,
+ hosts=[HostSpec('node1'), HostSpec('node2')]) as fake_client:
+ fake_client.services.list_daemons.return_value = node1_daemons
+ self._get('{}/node1'.format(self.URL_HOST))
+ self.assertStatus(200)
+ self.assertIn('service_instances', self.json_body())
+ self.assertEqual(self.json_body()['service_instances'], node1_instances)
+
+ fake_client.services.list_daemons.return_value = node2_daemons
+ self._get('{}/node2'.format(self.URL_HOST))
+ self.assertStatus(200)
+ self.assertIn('service_instances', self.json_body())
+ self.assertEqual(self.json_body()['service_instances'], node2_instances)
+
+ # test with no orchestrator available
+ with patch_orch(False):
+ mgr.list_servers.return_value = [{
+ 'hostname': 'node1',
+ 'services': [{
+ 'type': 'mon',
+ 'id': 'a'
+ }, {
+ 'type': 'mgr',
+ 'id': 'b'
+ }]
+ }]
+ self._get('{}/node1'.format(self.URL_HOST))
+ self.assertStatus(200)
+ self.assertIn('service_instances', self.json_body())
+ self.assertEqual(self.json_body()['service_instances'],
+ [{
+ 'type': 'mon',
+ 'count': 1
+ }, {
+ 'type': 'mgr',
+ 'count': 1
+ }])
+
@mock.patch('dashboard.controllers.host.add_host')
def test_add_host(self, mock_add_host):
with patch_orch(True):
class TestHosts(unittest.TestCase):
def test_get_hosts(self):
mgr.list_servers.return_value = [{
- 'hostname': 'node1'
+ 'hostname': 'node1',
+ 'services': []
}, {
- 'hostname': 'localhost'
+ 'hostname': 'localhost',
+ 'services': []
}]
orch_hosts = [
HostSpec('node1', labels=['foo', 'bar']),
host0 = inventories[0]
self.assertEqual(host0['name'], 'host-0')
self.assertEqual(host0['addr'], '1.2.3.4')
- self.assertEqual(host0['devices'][0]['osd_ids'], [1, 2])
- self.assertEqual(host0['devices'][1]['osd_ids'], [1])
- self.assertEqual(host0['devices'][2]['osd_ids'], [2])
+ # devices should be sorted by path name, so
+ # /dev/sdb, /dev/sdc, nvme0n1
+ self.assertEqual(host0['devices'][0]['osd_ids'], [1])
+ self.assertEqual(host0['devices'][1]['osd_ids'], [2])
+ self.assertEqual(host0['devices'][2]['osd_ids'], [1, 2])
host1 = inventories[1]
self.assertEqual(host1['name'], 'host-1')
self.assertEqual(host1['addr'], '1.2.3.5')
+ # devices should be sorted by path name, so
+ # /dev/sda, sdb
self.assertEqual(host1['devices'][0]['osd_ids'], [])
self.assertEqual(host1['devices'][1]['osd_ids'], [3])