diff --git a/hooks/neutron_utils.py b/hooks/neutron_utils.py index 87ed652a..273ee020 100644 --- a/hooks/neutron_utils.py +++ b/hooks/neutron_utils.py @@ -1542,5 +1542,10 @@ def _pause_resume_helper(f, configs): def configure_apparmor(): '''Configure all apparmor profiles for the local unit''' - for profile in APPARMOR_PROFILES: + profiles = deepcopy(APPARMOR_PROFILES) + cmp_os_source = CompareOpenStackReleases(os_release('neutron-common')) + if cmp_os_source >= 'newton': + profiles.remove(NEUTRON_LBAAS_AA_PROFILE) + profiles.append(NEUTRON_LBAASV2_AA_PROFILE) + for profile in profiles: context.AppArmorContext(profile).setup_aa_profile() diff --git a/unit_tests/test_neutron_hooks.py b/unit_tests/test_neutron_hooks.py index 969b79f8..53b8f0cc 100644 --- a/unit_tests/test_neutron_hooks.py +++ b/unit_tests/test_neutron_hooks.py @@ -58,6 +58,7 @@ TO_PATCH = [ 'service_restart', 'is_unit_paused_set', 'install_systemd_override', + 'configure_apparmor', ] @@ -164,6 +165,7 @@ class TestQuantumHooks(CharmTestCase): self.assertTrue(_amqp_nova_joined.called) self.assertTrue(_zmq_joined.called) self.assertTrue(self.create_sysctl.called) + self.configure_apparmor.assert_called_with() @patch.object(hooks, 'git_install_requested') def test_config_changed_upgrade(self, git_requested): diff --git a/unit_tests/test_neutron_utils.py b/unit_tests/test_neutron_utils.py index 3bb7ef2d..48217dd2 100644 --- a/unit_tests/test_neutron_utils.py +++ b/unit_tests/test_neutron_utils.py @@ -1537,3 +1537,21 @@ class TestNeutronAgentReallocation(CharmTestCase): _subprocess.check_call.assert_called_with( ['systemctl', 'daemon-reload'] ) + + @patch.object(neutron_utils, 'context') + def test_configure_apparmor_mitaka(self, context): + self.os_release.return_value = 'mitaka' + context.AppArmorContext = MagicMock() + neutron_utils.configure_apparmor() + context.AppArmorContext.assert_any_call( + neutron_utils.NEUTRON_LBAAS_AA_PROFILE + ) + + @patch.object(neutron_utils, 'context') + def test_configure_apparmor_newton(self, context): + self.os_release.return_value = 'newton' + context.AppArmorContext = MagicMock() + neutron_utils.configure_apparmor() + context.AppArmorContext.assert_any_call( + neutron_utils.NEUTRON_LBAASV2_AA_PROFILE + )