Merge lp:~james-page/charm-helpers/add-profile-name-to-params into lp:charm-helpers

Proposed by James Page
Status: Merged
Merged at revision: 638
Proposed branch: lp:~james-page/charm-helpers/add-profile-name-to-params
Merge into: lp:charm-helpers
Diff against target: 76 lines (+7/-19)
2 files modified
charmhelpers/contrib/openstack/context.py (+4/-2)
tests/contrib/openstack/test_os_contexts.py (+3/-17)
To merge this branch: bzr merge lp:~james-page/charm-helpers/add-profile-name-to-params
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+307032@code.launchpad.net

Description of the change

Refactor AppArmorContext

The current design of the AppArmorContext class results in alot of
boilerplate configuration being written:

class NeutronMetadataAppArmorContext(AppArmorContext):

    def __init__(self):
        super(NeutronMetadataAppArmorContext, self).__init__()
        self.aa_profile = NEUTRON_METADATA_AA_PROFILE

    def __call__(self):
        super(NeutronMetadataAppArmorContext, self).__call__()
        if not self.ctxt:
            return self.ctxt
        self._ctxt.update({'aa_profile': self.aa_profile})
        return self.ctxt

this might be better done as:

 n_metadata = AppArmorContext(profile_name=NEUTRON_METADATA_AA_PROFILE)

thus avoid creating a specific class when not really required.

To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

LGTM, thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/context.py'
2--- charmhelpers/contrib/openstack/context.py 2016-07-12 23:01:31 +0000
3+++ charmhelpers/contrib/openstack/context.py 2016-09-28 13:59:55 +0000
4@@ -1421,9 +1421,9 @@
5 class AppArmorContext(OSContextGenerator):
6 """Base class for apparmor contexts."""
7
8- def __init__(self):
9+ def __init__(self, profile_name=None):
10 self._ctxt = None
11- self.aa_profile = None
12+ self.aa_profile = profile_name
13 self.aa_utils_packages = ['apparmor-utils']
14
15 @property
16@@ -1442,6 +1442,8 @@
17 if config('aa-profile-mode') in ['disable', 'enforce', 'complain']:
18 ctxt = {'aa_profile_mode': config('aa-profile-mode'),
19 'ubuntu_release': lsb_release()['DISTRIB_RELEASE']}
20+ if self.aa_profile:
21+ ctxt['aa_profile'] = self.aa_profile
22 else:
23 ctxt = None
24 return ctxt
25
26=== modified file 'tests/contrib/openstack/test_os_contexts.py'
27--- tests/contrib/openstack/test_os_contexts.py 2016-07-12 23:01:31 +0000
28+++ tests/contrib/openstack/test_os_contexts.py 2016-09-28 13:59:55 +0000
29@@ -85,20 +85,6 @@
30 return sorted(self.relation_data[relation_id].keys())
31
32
33-class FakeAppArmorContext(context.AppArmorContext):
34-
35- def __init__(self):
36- super(FakeAppArmorContext, self).__init__()
37- self.aa_profile = 'fake-aa-profile'
38-
39- def __call__(self):
40- super(FakeAppArmorContext, self).__call__()
41- if not self.ctxt:
42- return self.ctxt
43- self._ctxt.update({'aa_profile': self.aa_profile})
44- return self.ctxt
45-
46-
47 SHARED_DB_RELATION = {
48 'db_host': 'dbserver.local',
49 'password': 'foo'
50@@ -2973,7 +2959,7 @@
51
52 def test_apparmor_setup_complain(self):
53 ''' Tests for the apparmor setup'''
54- AA = FakeAppArmorContext()
55+ AA = context.AppArmorContext(profile_name='fake-aa-profile')
56 AA.install_aa_utils = MagicMock()
57 AA.manually_disable_aa_profile = MagicMock()
58 # Test complain mode
59@@ -2985,7 +2971,7 @@
60
61 def test_apparmor_setup_enforce(self):
62 ''' Tests for the apparmor setup'''
63- AA = FakeAppArmorContext()
64+ AA = context.AppArmorContext(profile_name='fake-aa-profile')
65 AA.install_aa_utils = MagicMock()
66 AA.manually_disable_aa_profile = MagicMock()
67 # Test enforce mode
68@@ -2996,7 +2982,7 @@
69
70 def test_apparmor_setup_disable(self):
71 ''' Tests for the apparmor setup'''
72- AA = FakeAppArmorContext()
73+ AA = context.AppArmorContext(profile_name='fake-aa-profile')
74 AA.install_aa_utils = MagicMock()
75 AA.manually_disable_aa_profile = MagicMock()
76 # Test disable mode

Subscribers

People subscribed via source and target branches