~openstack-charmers-next/charms/xenial/nova-compute/trunk

« back to all changes in this revision

Viewing changes to unit_tests/test_nova_compute_hooks.py

  • Committer: Edward Hope-Morley
  • Date: 2016-03-24 11:18:41 UTC
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: edward.hope-morley@canonical.com-20160324111841-99ruo5hjzrpqktlx
Add hardening support

Add charmhelpers.contrib.hardening and calls to install,
config-changed, upgrade-charm and update-status hooks.
Also add new config option to allow one or more hardening
modules to be applied at runtime.

Change-Id: I525c15a14662175f2a68cdcd25a3ab2c92237850

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
import yaml
 
3
 
1
4
from mock import (
2
5
    call,
3
6
    patch,
4
7
    MagicMock
5
8
)
6
 
import yaml
 
9
 
 
10
# python-apt is not installed as part of test-requirements but is imported by
 
11
# some charmhelpers modules so create a fake import.
 
12
sys.modules['apt'] = MagicMock()
 
13
sys.modules['apt_pkg'] = MagicMock()
7
14
 
8
15
from test_utils import CharmTestCase
9
16
 
10
 
with patch("nova_compute_utils.restart_map"):
11
 
    with patch("nova_compute_utils.register_configs"):
12
 
        import nova_compute_hooks as hooks
 
17
with patch('charmhelpers.contrib.hardening.harden.harden') as mock_dec:
 
18
    mock_dec.side_effect = (lambda *dargs, **dkwargs: lambda f:
 
19
                            lambda *args, **kwargs: f(*args, **kwargs))
 
20
    with patch("nova_compute_utils.restart_map"):
 
21
        with patch("nova_compute_utils.register_configs"):
 
22
            import nova_compute_hooks as hooks
13
23
 
14
24
 
15
25
TO_PATCH = [