From adbbfc3fa56f132dc1fc689e7e9ff17ba96384f2 Mon Sep 17 00:00:00 2001 From: Enzo Candotti Date: Wed, 1 Feb 2023 14:31:24 -0300 Subject: [PATCH] Add "Apparmor Module" on Edit Host modal This change adds a dropdown menu in order to enable or disable the apparmor module when updating a host. By default, apparmor will be disabled on creation and this value can be modified using the Edit Host button, or system host-update command. Test Plan: PASS: Build and install starlingx-dashboard package. Verify that the changes are applied. PASS: Edit a locked host in order to change the apparmor value. Verify that the change impacts when running system host-show command. PASS: Edit a unlocked host by changing the apparmor value. Verify that an error message is shown since the host has to be locked. PASS: Verify that the correct apparmor value is shown in "Host Detail" page. Story: 2010310 Task: 47249 Signed-off-by: Enzo Candotti Change-Id: I814896806479e141ce86961cc08b48da5600afed --- .../starlingx_dashboard/api/sysinv.py | 19 +++++++++++++++++-- .../templates/inventory/_detail_overview.html | 2 ++ .../dashboards/admin/inventory/views.py | 3 ++- .../dashboards/admin/inventory/workflows.py | 12 +++++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py index 3ccdc9ff..3761cdf0 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py @@ -32,6 +32,9 @@ import sysinv.common.constants as constants SYSTEM_TYPE_STANDARD = constants.TIS_STD_BUILD SYSTEM_TYPE_AIO = constants.TIS_AIO_BUILD +APPARMOR_STATE_ENABLED = constants.APPARMOR_STATE_ENABLED +APPARMOR_STATE_DISABLED = constants.APPARMOR_STATE_DISABLED + PERSONALITY_CONTROLLER = 'controller' PERSONALITY_WORKER = 'worker' PERSONALITY_NETWORK = 'network' @@ -841,8 +844,8 @@ class Host(base.APIResourceWrapper): _attrs = ['id', 'uuid', 'hostname', 'personality', 'subfunctions', 'subfunction_oper', 'subfunction_avail', - 'location', 'serialid', 'operational', 'administrative', - 'invprovision', 'peers', + 'apparmor', 'location', 'serialid', 'operational', + 'administrative', 'invprovision', 'peers', 'availability', 'uptime', 'task', 'capabilities', 'created_at', 'updated_at', 'mgmt_mac', 'mgmt_ip', 'bm_ip', 'bm_type', 'bm_username', @@ -867,6 +870,12 @@ class Host(base.APIResourceWrapper): ('disabled', _("Disabled")), ('enabled', _("Enabled")), ) + + APPARMOR_DISPLAY_CHOICES = ( + (APPARMOR_STATE_ENABLED, _("enabled")), + (APPARMOR_STATE_DISABLED, _("disabled")), + ) + AVAIL_DISPLAY_CHOICES = ( ('available', _("Available")), ('intest', _("In-Test")), @@ -909,6 +918,7 @@ class Host(base.APIResourceWrapper): self._subfunctions = self.subfunctions self._subfunction_oper = self.subfunction_oper self._subfunction_avail = self.subfunction_avail + self._apparmor = self.apparmor self._location = self.location self._peers = self.peers self._bm_type = self.bm_type @@ -968,6 +978,11 @@ class Host(base.APIResourceWrapper): return self._get_display_value(self.AVAIL_DISPLAY_CHOICES, self._subfunction_avail) + @property + def apparmor(self): + return self._get_display_value(self.APPARMOR_DISPLAY_CHOICES, + self._apparmor) + @property def config_required(self): return self.config_status == 'config required' diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/templates/inventory/_detail_overview.html b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/templates/inventory/_detail_overview.html index e8feb21a..ae4ceffa 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/templates/inventory/_detail_overview.html +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/templates/inventory/_detail_overview.html @@ -30,6 +30,8 @@
{{ host.serialid }}
{% trans "Location" %}
{{ host.location|default:_("Not Specified") }}
+
{% trans "AppArmor Module" %}
+
{{ host.apparmor }}
{% trans "Serial Line Carrier Detect" %}
{{ host.ttys_dcd }}
{% trans "Clock Synchronization" %}
diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/views.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/views.py index 9b723780..0a6d856c 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/views.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/inventory/views.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2021 Wind River Systems, Inc. +# Copyright (c) 2013-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -75,6 +75,7 @@ class UpdateView(workflows.WorkflowView): 'hostname': host.hostname, 'personality': host._personality, 'subfunctions': host._subfunctions, + 'apparmor': host.apparmor, 'location': host.location, 'bm_type': host.bm_type, 'bm_ip': host.bm_ip, 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 929f4e29..101d0d42 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 @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2022 Wind River Systems, Inc. +# Copyright (c) 2013-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -219,6 +219,11 @@ class UpdateHostInfoAction(workflows.Action): "port revoke any active session and a new login " "process is initiated when a new connection is detected.")) + apparmor = forms.ChoiceField( + label=_("AppArmor Module"), + required=False, + choices=stx_api.sysinv.Host.APPARMOR_DISPLAY_CHOICES) + class Meta(object): name = _("Host Info") help_text = _( @@ -334,6 +339,7 @@ class UpdateHostInfo(workflows.Step): contributes = ("host_id", "personality", "subfunctions", + "apparmor", "hostname", "location", "ttys_dcd", @@ -636,6 +642,10 @@ class UpdateHost(workflows.Workflow): if host.clock_synchronization == data['clock_synchronization']: data.pop('clock_synchronization') + # if not trying to change apparmor choice, skip check + if host.apparmor == data['apparmor']: + data.pop('apparmor') + host = stx_api.sysinv.host_update(request, **data) return True if host else False