~openstack-charmers-next/charms/vivid/rabbitmq-server/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/context.py

  • Committer: James Page
  • Date: 2016-07-06 15:43:20 UTC
  • Revision ID: james.page@ubuntu.com-20160706154320-b493t8fv10dvt99t
Resync charmhelpers for licensing change

The charm-helpers project have re-licensed to Apache 2.0
inline with the agreed licensing approach to intefaces,
layers and charms generally.

Resync helpers to bring charmhelpers inline with charm
codebase.

Change-Id: I4999da180d6bb9d3763367c488469f6fb936f6f2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright 2014-2015 Canonical Limited.
2
2
#
3
 
# This file is part of charm-helpers.
4
 
#
5
 
# charm-helpers is free software: you can redistribute it and/or modify
6
 
# it under the terms of the GNU Lesser General Public License version 3 as
7
 
# published by the Free Software Foundation.
8
 
#
9
 
# charm-helpers is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU Lesser General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU Lesser General Public License
15
 
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
 
3
# Licensed under the Apache License, Version 2.0 (the "License");
 
4
# you may not use this file except in compliance with the License.
 
5
# You may obtain a copy of the License at
 
6
#
 
7
#  http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
# Unless required by applicable law or agreed to in writing, software
 
10
# distributed under the License is distributed on an "AS IS" BASIS,
 
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
12
# See the License for the specific language governing permissions and
 
13
# limitations under the License.
16
14
 
17
15
import glob
18
16
import json
1438
1436
        :return ctxt: Dictionary of the apparmor profile or None
1439
1437
        """
1440
1438
        if config('aa-profile-mode') in ['disable', 'enforce', 'complain']:
1441
 
            ctxt = {'aa-profile-mode': config('aa-profile-mode')}
 
1439
            ctxt = {'aa_profile_mode': config('aa-profile-mode')}
1442
1440
        else:
1443
1441
            ctxt = None
1444
1442
        return ctxt
1482
1480
            log("Not enabling apparmor Profile")
1483
1481
            return
1484
1482
        self.install_aa_utils()
1485
 
        cmd = ['aa-{}'.format(self.ctxt['aa-profile-mode'])]
1486
 
        cmd.append(self.ctxt['aa-profile'])
 
1483
        cmd = ['aa-{}'.format(self.ctxt['aa_profile_mode'])]
 
1484
        cmd.append(self.ctxt['aa_profile'])
1487
1485
        log("Setting up the apparmor profile for {} in {} mode."
1488
 
            "".format(self.ctxt['aa-profile'], self.ctxt['aa-profile-mode']))
 
1486
            "".format(self.ctxt['aa_profile'], self.ctxt['aa_profile_mode']))
1489
1487
        try:
1490
1488
            check_call(cmd)
1491
1489
        except CalledProcessError as e:
1494
1492
            # apparmor is yet unaware of the profile and aa-disable aa-profile
1495
1493
            # fails. If aa-disable learns to read profile files first this can
1496
1494
            # be removed.
1497
 
            if self.ctxt['aa-profile-mode'] == 'disable':
 
1495
            if self.ctxt['aa_profile_mode'] == 'disable':
1498
1496
                log("Manually disabling the apparmor profile for {}."
1499
 
                    "".format(self.ctxt['aa-profile']))
 
1497
                    "".format(self.ctxt['aa_profile']))
1500
1498
                self.manually_disable_aa_profile()
1501
1499
                return
1502
1500
            status_set('blocked', "Apparmor profile {} failed to be set to {}."
1503
 
                                  "".format(self.ctxt['aa-profile'],
1504
 
                                            self.ctxt['aa-profile-mode']))
 
1501
                                  "".format(self.ctxt['aa_profile'],
 
1502
                                            self.ctxt['aa_profile_mode']))
1505
1503
            raise e