]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/tests/test_host.py
import ceph quincy 17.2.6
[ceph.git] / ceph / src / pybind / mgr / dashboard / tests / test_host.py
index 0f55ce52247c117fea36972700a8daace03f60be..a41d33e713c600d19c759de85fbef24532f05e4f 100644 (file)
@@ -1,7 +1,7 @@
 import unittest
 from unittest import mock
 
-from orchestrator import HostSpec
+from orchestrator import DaemonDescription, HostSpec
 
 from .. import mgr
 from ..controllers._version import APIVersion
@@ -123,14 +123,14 @@ class HostControllerTest(ControllerTestCase):
             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
@@ -152,7 +152,7 @@ class HostControllerTest(ControllerTestCase):
             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):
@@ -163,7 +163,10 @@ class HostControllerTest(ControllerTestCase):
             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))
@@ -182,6 +185,87 @@ class HostControllerTest(ControllerTestCase):
             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):
@@ -375,9 +459,11 @@ class HostUiControllerTest(ControllerTestCase):
 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']),
@@ -499,11 +585,15 @@ class TestHosts(unittest.TestCase):
             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])