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 `__