From 021d1c184e5d87b5b4df5e067954f6f1cb46b6c4 Mon Sep 17 00:00:00 2001 From: Pavlo Shchelokovskyy Date: Tue, 21 Sep 2021 17:15:35 +0300 Subject: [PATCH] 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 --- masakaridashboard/api/api.py | 4 +-- masakaridashboard/hosts/tests.py | 6 ++--- masakaridashboard/segments/forms.py | 27 ++++++++++--------- masakaridashboard/segments/views.py | 12 ++++----- .../test/test_data/masakari_data.py | 15 ++++++----- .../notes/bug-1944679-0df043f17a8bbaff.yaml | 7 +++++ 6 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 releasenotes/notes/bug-1944679-0df043f17a8bbaff.yaml diff --git a/masakaridashboard/api/api.py b/masakaridashboard/api/api.py index 703392c..2ec4af5 100644 --- a/masakaridashboard/api/api.py +++ b/masakaridashboard/api/api.py @@ -46,8 +46,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"), []) diff --git a/masakaridashboard/hosts/tests.py b/masakaridashboard/hosts/tests.py index 0ec91d6..5d37113 100644 --- a/masakaridashboard/hosts/tests.py +++ b/masakaridashboard/hosts/tests.py @@ -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', diff --git a/masakaridashboard/segments/forms.py b/masakaridashboard/segments/forms.py index c747ff4..54e7748 100644 --- a/masakaridashboard/segments/forms.py +++ b/masakaridashboard/segments/forms.py @@ -160,19 +160,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: diff --git a/masakaridashboard/segments/views.py b/masakaridashboard/segments/views.py index b0db0cb..7126330 100644 --- a/masakaridashboard/segments/views.py +++ b/masakaridashboard/segments/views.py @@ -202,10 +202,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.') @@ -222,12 +222,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'), diff --git a/masakaridashboard/test/test_data/masakari_data.py b/masakaridashboard/test/test_data/masakari_data.py index 2f996af..e3132ba 100644 --- a/masakaridashboard/test/test_data/masakari_data.py +++ b/masakaridashboard/test/test_data/masakari_data.py @@ -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) @@ -71,12 +71,15 @@ def data(TEST): TEST.masakari_host.add(host1) - TEST.hypervisors = test_data_utils.TestDataContainer() + TEST.compute_services = test_data_utils.TestDataContainer() - hypervisor1 = Hypervisor( - HypervisorManager, {'id': '1', 'hypervisor_hostname': "test"}) + service1 = Service( + ServiceManager, { + "id": 1, "host": "test", + } + ) - TEST.hypervisors.add(hypervisor1) + TEST.compute_services.add(service1) TEST.masakari_notification = test_data_utils.TestDataContainer() notification1 = notification.Notification( diff --git a/releasenotes/notes/bug-1944679-0df043f17a8bbaff.yaml b/releasenotes/notes/bug-1944679-0df043f17a8bbaff.yaml new file mode 100644 index 0000000..0e1b86b --- /dev/null +++ b/releasenotes/notes/bug-1944679-0df043f17a8bbaff.yaml @@ -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 `__