From 5724990df9b4705693b4baca04a6550fa36fba20 Mon Sep 17 00:00:00 2001 From: David Sullivan Date: Wed, 2 Oct 2019 12:09:16 -0400 Subject: [PATCH] Allow CPU profiles with isolated cores Update CPU profile rules to work with the constraints for isolated cores. CPU edits/profiles are only permitted on worker nodes. Change-Id: If6b0cf7d87291eb76bb28e7a42015d05d57a8e55 Story: 2006565 Task: 36899 Signed-off-by: David Sullivan --- .../admin/inventory/cpu_functions/tables.py | 9 ++- .../admin/inventory/cpu_functions/utils.py | 26 +------ .../dashboards/admin/inventory/workflows.py | 70 +++++++++---------- 3 files changed, 40 insertions(+), 65 deletions(-) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/tables.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/tables.py index 45d76a8f..87f0da9d 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/tables.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/tables.py @@ -31,7 +31,9 @@ class EditCpuFunctions(tables.LinkAction): def allowed(self, request, cpufunction=None): host = self.table.kwargs['host'] - return host._administrative == 'locked' + allowed = host._administrative == 'locked' and \ + 'worker' in host.subfunctions + return allowed class CreateCpuProfile(tables.LinkAction): @@ -45,7 +47,10 @@ class CreateCpuProfile(tables.LinkAction): return reverse(self.url, args=(host_id,)) def allowed(self, request, cpufunction=None): - return not stx_api.sysinv.is_system_mode_simplex(request) + host = self.table.kwargs['host'] + allowed = not stx_api.sysinv.is_system_mode_simplex(request) and \ + 'worker' in host.subfunctions + return allowed def get_function_name(datum): diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/utils.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/utils.py index a4c5f42d..06a67313 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/utils.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/cpu_functions/utils.py @@ -126,34 +126,10 @@ class HostCpuProfile(CpuProfile): def profile_applicable(self, profile): if self.number_of_cpu == profile.number_of_cpu and \ self.cores_per_cpu == profile.cores_per_cpu: - return self.check_profile_core_functions(profile) + return True else: return False - return not True - - def check_profile_core_functions(self, profile): - platform_cores = 0 - vswitch_cores = 0 - shared_cores = 0 - vm_cores = 0 - isolated_cores = 0 - for cpu in profile.processors: - platform_cores += cpu.platform - vswitch_cores += cpu.vswitch - shared_cores += cpu.shared - vm_cores += cpu.vms - isolated_cores += cpu.isolated - - result = True - if platform_cores == 0: - result = False - elif 'worker' in self.personality and vswitch_cores == 0: - result = False - elif 'worker' in self.personality and vm_cores == 0: - result = False - return result - def compress_range(c_list): c_list.append(999) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/workflows.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/workflows.py index 42576361..9053f248 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/workflows.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/workflows.py @@ -70,17 +70,6 @@ def ifprofile_applicable(request, host, profile): return True -def cpuprofile_applicable(host, profile): - if (host.sockets == profile.sockets and - host.physical_cores == profile.physical_cores and - host.hyperthreading == profile.hyperthreading): - errorstring = icpu_utils.check_core_functions(host.subfunctions, - profile.cpus) - if not errorstring: - return True - return False - - def diskprofile_applicable(host, diskprofile): # if host contain sufficient number of disks for diskprofile if not len(host.disks) >= len(diskprofile.disks): @@ -324,6 +313,7 @@ class UpdateHostInfoAction(workflows.Action): personality = self.initial['personality'] mem_profile_configurable = False + cpu_profile_configurable = False if personality and self.system_mode != constants.SYSTEM_MODE_SIMPLEX: self.fields['personality'].widget.attrs['disabled'] = 'disabled' @@ -338,38 +328,13 @@ class UpdateHostInfoAction(workflows.Action): if 'worker' in host.subfunctions: mem_profile_configurable = True + cpu_profile_configurable = True host.memory = stx_api.sysinv.host_memory_list( self.request, host.uuid) else: del self.fields['memoryProfile'] if host.nodes and host.cpus and host.ports: - # Populate Available Cpu Profile Choices - try: - avail_cpu_profile_list = \ - stx_api.sysinv.host_cpuprofile_list(self.request) - - host_profile = icpu_utils.HostCpuProfile( - host.subfunctions, - host.cpus, host.nodes) - - cpu_profile_tuple_list = [ - ('', _("Copy from an available cpu profile."))] - for ip in avail_cpu_profile_list: - nodes = stx_api.sysinv.host_node_list(self.request, - ip.uuid) - cpu_profile = icpu_utils.CpuProfile(ip.cpus, nodes) - if host_profile.profile_applicable(cpu_profile): - cpu_profile_tuple_list.append( - (ip.profilename, ip.profilename)) - - except Exception: - exceptions.handle(self.request, _( - 'Unable to retrieve list of cpu profiles.')) - cpu_profile_tuple_list = [] - - self.fields['cpuProfile'].choices = cpu_profile_tuple_list - # Populate Available Interface Profile Choices try: avail_interface_profile_list = \ @@ -390,7 +355,6 @@ class UpdateHostInfoAction(workflows.Action): self.fields[ 'interfaceProfile'].choices = interface_profile_tuple_list else: - self.fields['cpuProfile'].widget = forms.widgets.HiddenInput() self.fields[ 'interfaceProfile'].widget = forms.widgets.HiddenInput() @@ -420,6 +384,36 @@ class UpdateHostInfoAction(workflows.Action): else: self.fields['diskProfile'].widget = forms.widgets.HiddenInput() + # Populate Available Cpu Profile Choices + if cpu_profile_configurable and host.nodes and host.memory: + try: + avail_cpu_profile_list = \ + stx_api.sysinv.host_cpuprofile_list(self.request) + + host_profile = icpu_utils.HostCpuProfile( + host.subfunctions, + host.cpus, host.nodes) + + cpu_profile_tuple_list = [ + ('', _("Copy from an available cpu profile."))] + for ip in avail_cpu_profile_list: + nodes = stx_api.sysinv.host_node_list(self.request, + ip.uuid) + cpu_profile = icpu_utils.CpuProfile(ip.cpus, nodes) + if host_profile.profile_applicable(cpu_profile): + cpu_profile_tuple_list.append( + (ip.profilename, ip.profilename)) + + except Exception: + exceptions.handle(self.request, _( + 'Unable to retrieve list of cpu profiles.')) + cpu_profile_tuple_list = [] + + self.fields['cpuProfile'].choices = cpu_profile_tuple_list + + else: + self.fields['cpuProfile'].widget = forms.widgets.HiddenInput() + if mem_profile_configurable and host.nodes and host.memory: # Populate Available Memory Profile Choices try: