2019-08-12 10:21:12 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import json
|
|
|
|
|
2020-03-24 08:33:22 +00:00
|
|
|
from tasks.mgr.dashboard.helper import DashboardTestCase
|
2019-08-12 10:21:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
test_data = {
|
|
|
|
'inventory': [
|
|
|
|
{
|
|
|
|
'name': 'test-host0',
|
2020-02-11 15:05:21 +00:00
|
|
|
'addr': '1.2.3.4',
|
2019-08-12 10:21:12 +00:00
|
|
|
'devices': [
|
|
|
|
{
|
2019-10-16 11:07:31 +00:00
|
|
|
'path': '/dev/sda',
|
2019-08-12 10:21:12 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'test-host1',
|
2020-02-11 15:05:21 +00:00
|
|
|
'addr': '1.2.3.5',
|
2019-08-12 10:21:12 +00:00
|
|
|
'devices': [
|
|
|
|
{
|
2019-10-16 11:07:31 +00:00
|
|
|
'path': '/dev/sdb',
|
2019-08-12 10:21:12 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2020-02-17 01:27:46 +00:00
|
|
|
'daemons': [
|
2019-08-12 10:21:12 +00:00
|
|
|
{
|
|
|
|
'nodename': 'test-host0',
|
2020-02-17 01:27:46 +00:00
|
|
|
'daemon_type': 'mon',
|
|
|
|
'daemon_id': 'a'
|
2019-08-12 10:21:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'nodename': 'test-host0',
|
2020-02-17 01:27:46 +00:00
|
|
|
'daemon_type': 'mgr',
|
|
|
|
'daemon_id': 'x'
|
2019-08-12 10:21:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'nodename': 'test-host0',
|
2020-02-17 01:27:46 +00:00
|
|
|
'daemon_type': 'osd',
|
|
|
|
'daemon_id': '0'
|
2019-08-12 10:21:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'nodename': 'test-host1',
|
2020-02-17 01:27:46 +00:00
|
|
|
'daemon_type': 'osd',
|
|
|
|
'daemon_id': '1'
|
2019-08-12 10:21:12 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class OrchestratorControllerTest(DashboardTestCase):
|
|
|
|
|
2019-11-29 08:15:20 +00:00
|
|
|
AUTH_ROLES = ['cluster-manager']
|
2019-08-12 10:21:12 +00:00
|
|
|
|
|
|
|
URL_STATUS = '/api/orchestrator/status'
|
|
|
|
URL_INVENTORY = '/api/orchestrator/inventory'
|
2019-11-29 08:15:20 +00:00
|
|
|
URL_OSD = '/api/orchestrator/osd'
|
2019-08-12 10:21:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
def test_data_inventory(self):
|
|
|
|
return test_data['inventory']
|
|
|
|
|
|
|
|
@property
|
2020-02-17 01:27:46 +00:00
|
|
|
def test_data_daemons(self):
|
|
|
|
return test_data['daemons']
|
2019-08-12 10:21:12 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(OrchestratorControllerTest, cls).setUpClass()
|
|
|
|
cls._load_module('test_orchestrator')
|
2020-02-07 19:20:42 +00:00
|
|
|
cmd = ['orch', 'set', 'backend', 'test_orchestrator']
|
2019-08-12 10:21:12 +00:00
|
|
|
cls.mgr_cluster.mon_manager.raw_cluster_cmd(*cmd)
|
|
|
|
|
|
|
|
cmd = ['test_orchestrator', 'load_data', '-i', '-']
|
|
|
|
cls.mgr_cluster.mon_manager.raw_cluster_cmd_result(*cmd, stdin=json.dumps(test_data))
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
cmd = ['test_orchestrator', 'load_data', '-i', '-']
|
|
|
|
cls.mgr_cluster.mon_manager.raw_cluster_cmd_result(*cmd, stdin='{}')
|
|
|
|
|
|
|
|
def _validate_inventory(self, data, resp_data):
|
|
|
|
self.assertEqual(data['name'], resp_data['name'])
|
|
|
|
self.assertEqual(len(data['devices']), len(resp_data['devices']))
|
|
|
|
|
|
|
|
if not data['devices']:
|
|
|
|
return
|
2019-10-16 11:07:31 +00:00
|
|
|
test_devices = sorted(data['devices'], key=lambda d: d['path'])
|
|
|
|
resp_devices = sorted(resp_data['devices'], key=lambda d: d['path'])
|
2019-08-12 10:21:12 +00:00
|
|
|
|
|
|
|
for test, resp in zip(test_devices, resp_devices):
|
|
|
|
self._validate_device(test, resp)
|
|
|
|
|
|
|
|
def _validate_device(self, data, resp_data):
|
|
|
|
for key, value in data.items():
|
|
|
|
self.assertEqual(value, resp_data[key])
|
|
|
|
|
2020-02-17 01:27:46 +00:00
|
|
|
def _validate_daemon(self, data, resp_data):
|
2019-08-12 10:21:12 +00:00
|
|
|
for key, value in data.items():
|
|
|
|
self.assertEqual(value, resp_data[key])
|
|
|
|
|
|
|
|
@DashboardTestCase.RunAs('test', 'test', ['block-manager'])
|
|
|
|
def test_access_permissions(self):
|
|
|
|
self._get(self.URL_STATUS)
|
|
|
|
self.assertStatus(200)
|
|
|
|
self._get(self.URL_INVENTORY)
|
|
|
|
self.assertStatus(403)
|
|
|
|
|
|
|
|
def test_status_get(self):
|
|
|
|
data = self._get(self.URL_STATUS)
|
|
|
|
self.assertTrue(data['available'])
|
|
|
|
|
2019-10-28 14:57:50 +00:00
|
|
|
def test_inventory_list(self):
|
2019-08-12 10:21:12 +00:00
|
|
|
# get all inventory
|
|
|
|
data = self._get(self.URL_INVENTORY)
|
|
|
|
self.assertStatus(200)
|
|
|
|
|
|
|
|
sorting_key = lambda node: node['name']
|
|
|
|
test_inventory = sorted(self.test_data_inventory, key=sorting_key)
|
|
|
|
resp_inventory = sorted(data, key=sorting_key)
|
|
|
|
self.assertEqual(len(test_inventory), len(resp_inventory))
|
|
|
|
for test, resp in zip(test_inventory, resp_inventory):
|
|
|
|
self._validate_inventory(test, resp)
|
|
|
|
|
|
|
|
# get inventory by hostname
|
|
|
|
node = self.test_data_inventory[-1]
|
|
|
|
data = self._get('{}?hostname={}'.format(self.URL_INVENTORY, node['name']))
|
|
|
|
self.assertStatus(200)
|
|
|
|
self.assertEqual(len(data), 1)
|
|
|
|
self._validate_inventory(node, data[0])
|