Use service list instead of hypervisor list

the host names in them are not necessarily the same,
and Masakari service itself validates the input against
the nova service list, not hypervisor list,
since change I9c591d33f17a8d5950bdb1fc2d686e2301fc6d95 in Masakari.

Closes-Bug: #1944679
Change-Id: Id017b91c59aff54435c35d410fcb56a086a732ef
(cherry picked from commit 021d1c184e)
(cherry picked from commit fae46199bb)
This commit is contained in:
Pavlo Shchelokovskyy 2021-09-21 17:15:35 +03:00 committed by Radosław Piliszek
parent b14c036daa
commit a879b6bbfb
6 changed files with 42 additions and 29 deletions

View File

@ -46,8 +46,8 @@ def openstack_connection(request, version=None):
return conn.instance_ha return conn.instance_ha
def get_hypervisor_list(request): def get_compute_service_list(request):
return nova_api.hypervisor_list(request) return nova_api.service_list(request, binary="nova-compute")
@handle_errors(_("Unable to retrieve segments"), []) @handle_errors(_("Unable to retrieve segments"), [])

View File

@ -40,7 +40,7 @@ class HostTest(test.TestCase):
def test_create_post(self): def test_create_post(self):
segment = self.masakari_segment.list() segment = self.masakari_segment.list()
host = self.masakari_host.list()[0] host = self.masakari_host.list()[0]
hypervisors = self.hypervisors.list() compute_services = self.compute_services.list()
create_url = reverse('horizon:masakaridashboard:segments:addhost', create_url = reverse('horizon:masakaridashboard:segments:addhost',
args=[segment[0].uuid]) args=[segment[0].uuid])
form_data = { form_data = {
@ -56,8 +56,8 @@ class HostTest(test.TestCase):
return_value=segment), mock.patch( return_value=segment), mock.patch(
'masakaridashboard.api.api.get_host_list', 'masakaridashboard.api.api.get_host_list',
return_value=[]), mock.patch( return_value=[]), mock.patch(
'masakaridashboard.api.api.get_hypervisor_list', 'masakaridashboard.api.api.get_compute_service_list',
return_value=hypervisors), mock.patch( return_value=compute_services), mock.patch(
'masakaridashboard.api.api.get_segment', 'masakaridashboard.api.api.get_segment',
return_value=segment[0]), mock.patch( return_value=segment[0]), mock.patch(
'masakaridashboard.api.api.create_host', 'masakaridashboard.api.api.create_host',

View File

@ -160,19 +160,22 @@ class AddHostForm(forms.SelfHandlingForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(AddHostForm, self).__init__(*args, **kwargs) super(AddHostForm, self).__init__(*args, **kwargs)
# Populate hypervisor name choices # Populate candidate name choices
hypervisor_list = kwargs.get('initial', {}).get("hypervisor_list", []) available_host_list = kwargs.get('initial', {}).get(
hypervisor_name_list = [] "available_host_list", [])
for hypervisor in hypervisor_list: host_candidate_list = []
hypervisor_name_list.append( # NOTE(pas-ha) available_host_list contains
(hypervisor.hypervisor_hostname, '%(name)s (%(id)s)' # novaclient v2 Service objects
% {"name": hypervisor.hypervisor_hostname, for service in available_host_list:
"id": hypervisor.id})) host_candidate_list.append(
if hypervisor_name_list: (service.host, '%(name)s (%(id)s)'
hypervisor_name_list.insert(0, ("", _("Select a host"))) % {"name": service.host,
"id": service.id}))
if host_candidate_list:
host_candidate_list.insert(0, ("", _("Select a host")))
else: else:
hypervisor_name_list.insert(0, ("", _("No host available"))) host_candidate_list.insert(0, ("", _("No host available")))
self.fields['name'].choices = hypervisor_name_list self.fields['name'].choices = host_candidate_list
def handle(self, request, data): def handle(self, request, data):
try: try:

View File

@ -202,10 +202,10 @@ class AddHostView(forms.ModalFormView):
host_list.append(item.name) host_list.append(item.name)
try: try:
available_host_list = [] available_host_list = []
hypervisor_list = api.get_hypervisor_list(self.request) service_list = api.get_compute_service_list(self.request)
for hypervisor in hypervisor_list: for service in service_list:
if hypervisor.hypervisor_hostname not in host_list: if service.host not in host_list:
available_host_list.append(hypervisor) available_host_list.append(service)
return available_host_list return available_host_list
except Exception: except Exception:
msg = _('Unable to retrieve host list.') msg = _('Unable to retrieve host list.')
@ -222,12 +222,12 @@ class AddHostView(forms.ModalFormView):
return context return context
def get_initial(self): def get_initial(self):
hypervisor_list = self.get_object() available_host_list = self.get_object()
segment_name = api.get_segment( segment_name = api.get_segment(
self.request, self.kwargs['segment_id']).name self.request, self.kwargs['segment_id']).name
initial = {'segment_id': self.kwargs['segment_id'], initial = {'segment_id': self.kwargs['segment_id'],
'segment_name': segment_name, 'segment_name': segment_name,
'hypervisor_list': hypervisor_list, 'available_host_list': available_host_list,
'reserved': self.kwargs.get('reserved'), 'reserved': self.kwargs.get('reserved'),
'type': self.kwargs.get('service_type'), 'type': self.kwargs.get('service_type'),
'control_attributes': self.kwargs.get('control_attributes'), 'control_attributes': self.kwargs.get('control_attributes'),

View File

@ -22,8 +22,8 @@ from openstack.instance_ha.v1 import segment
from openstack_dashboard.test.test_data import utils as test_data_utils from openstack_dashboard.test.test_data import utils as test_data_utils
from masakaridashboard.test import uuidsentinel from masakaridashboard.test import uuidsentinel
from novaclient.v2.hypervisors import Hypervisor from novaclient.v2.services import Service
from novaclient.v2.hypervisors import HypervisorManager from novaclient.v2.services import ServiceManager
NOW = timeutils.utcnow().replace(microsecond=0) NOW = timeutils.utcnow().replace(microsecond=0)
@ -71,12 +71,15 @@ def data(TEST):
TEST.masakari_host.add(host1) TEST.masakari_host.add(host1)
TEST.hypervisors = test_data_utils.TestDataContainer() TEST.compute_services = test_data_utils.TestDataContainer()
hypervisor1 = Hypervisor( service1 = Service(
HypervisorManager, {'id': '1', 'hypervisor_hostname': "test"}) ServiceManager, {
"id": 1, "host": "test",
}
)
TEST.hypervisors.add(hypervisor1) TEST.compute_services.add(service1)
TEST.masakari_notification = test_data_utils.TestDataContainer() TEST.masakari_notification = test_data_utils.TestDataContainer()
notification1 = notification.Notification( notification1 = notification.Notification(

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixed an issue with retreiving candidates for hosts.
Now they are retreived using compute service list API,
the same as used during host validation in Masakari itself.
`LP#1944679 <https://launchpad.net/bugs/1944679>`__