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)
(cherry picked from commit a879b6bbfb)
(cherry picked from commit 57610fce4b)
This commit is contained in:
Pavlo Shchelokovskyy 2021-09-21 17:15:35 +03:00 committed by Radosław Piliszek
parent d5c42e7e1a
commit b216633941
6 changed files with 45 additions and 27 deletions

View File

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

View File

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

View File

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

View File

@ -199,10 +199,10 @@ class AddHostView(forms.ModalFormView):
host_list.append(item.name)
try:
available_host_list = []
hypervisor_list = api.get_hypervisor_list(self.request)
for hypervisor in hypervisor_list:
if hypervisor.hypervisor_hostname not in host_list:
available_host_list.append(hypervisor)
service_list = api.get_compute_service_list(self.request)
for service in service_list:
if service.host not in host_list:
available_host_list.append(service)
return available_host_list
except Exception:
msg = _('Unable to retrieve host list.')
@ -219,12 +219,12 @@ class AddHostView(forms.ModalFormView):
return context
def get_initial(self):
hypervisor_list = self.get_object()
available_host_list = self.get_object()
segment_name = api.get_segment(
self.request, self.kwargs['segment_id']).name
initial = {'segment_id': self.kwargs['segment_id'],
'segment_name': segment_name,
'hypervisor_list': hypervisor_list,
'available_host_list': available_host_list,
'reserved': self.kwargs.get('reserved'),
'type': self.kwargs.get('service_type'),
'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 masakaridashboard.test import uuidsentinel
from novaclient.v2.hypervisors import Hypervisor
from novaclient.v2.hypervisors import HypervisorManager
from novaclient.v2.services import Service
from novaclient.v2.services import ServiceManager
NOW = timeutils.utcnow().replace(microsecond=0)
@ -56,12 +56,20 @@ def data(TEST):
TEST.masakari_host.add(host1)
TEST.hypervisors = test_data_utils.TestDataContainer()
TEST.compute_services = test_data_utils.TestDataContainer()
<<<<<<< HEAD (d5c42e Merge "Add OPENSTACK_ENDPOINT_TYPE to the connection" into s)
hypervisor1 = Hypervisor(
HypervisorManager, {'id': '1', 'hypervisor_hostname': "test"})
=======
service1 = Service(
ServiceManager, {
"id": 1, "host": "test",
}
)
>>>>>>> CHANGE (57610f Use service list instead of hypervisor list)
TEST.hypervisors.add(hypervisor1)
TEST.compute_services.add(service1)
TEST.masakari_notification = test_data_utils.TestDataContainer()
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>`__