~registry/charms/trusty/neutron-api/next

« back to all changes in this revision

Viewing changes to unit_tests/test_actions_git_reinstall.py

Deploy from source

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mock import patch
 
2
 
 
3
with patch('charmhelpers.core.hookenv.config') as config:
 
4
    config.return_value = 'neutron'
 
5
    import neutron_api_utils as utils  # noqa
 
6
 
 
7
import git_reinstall
 
8
 
 
9
from test_utils import (
 
10
    CharmTestCase
 
11
)
 
12
 
 
13
TO_PATCH = [
 
14
    'config',
 
15
]
 
16
 
 
17
 
 
18
openstack_origin_git = \
 
19
    """repositories:
 
20
         - {name: requirements,
 
21
            repository: 'git://git.openstack.org/openstack/requirements',
 
22
            branch: stable/juno}
 
23
         - {name: neutron,
 
24
            repository: 'git://git.openstack.org/openstack/neutron',
 
25
            branch: stable/juno}"""
 
26
 
 
27
 
 
28
class TestNeutronAPIActions(CharmTestCase):
 
29
 
 
30
    def setUp(self):
 
31
        super(TestNeutronAPIActions, self).setUp(git_reinstall, TO_PATCH)
 
32
        self.config.side_effect = self.test_config.get
 
33
 
 
34
    @patch.object(git_reinstall, 'action_set')
 
35
    @patch.object(git_reinstall, 'action_fail')
 
36
    @patch.object(git_reinstall, 'git_install')
 
37
    def test_git_reinstall(self, git_install, action_fail, action_set):
 
38
        self.test_config.set('openstack-origin-git', openstack_origin_git)
 
39
 
 
40
        git_reinstall.git_reinstall()
 
41
 
 
42
        git_install.assert_called_with(openstack_origin_git)
 
43
        self.assertTrue(git_install.called)
 
44
        self.assertFalse(action_set.called)
 
45
        self.assertFalse(action_fail.called)
 
46
 
 
47
    @patch.object(git_reinstall, 'action_set')
 
48
    @patch.object(git_reinstall, 'action_fail')
 
49
    @patch.object(git_reinstall, 'git_install')
 
50
    @patch('charmhelpers.contrib.openstack.utils.config')
 
51
    def test_git_reinstall_not_configured(self, _config, git_install,
 
52
                                          action_fail, action_set):
 
53
        _config.return_value = None
 
54
 
 
55
        git_reinstall.git_reinstall()
 
56
 
 
57
        msg = 'openstack-origin-git is not configured'
 
58
        action_fail.assert_called_with(msg)
 
59
        self.assertFalse(git_install.called)
 
60
        self.assertFalse(action_set.called)
 
61
 
 
62
    @patch.object(git_reinstall, 'action_set')
 
63
    @patch.object(git_reinstall, 'action_fail')
 
64
    @patch.object(git_reinstall, 'git_install')
 
65
    @patch('charmhelpers.contrib.openstack.utils.config')
 
66
    def test_git_reinstall_exception(self, _config, git_install,
 
67
                                     action_fail, action_set):
 
68
        _config.return_value = openstack_origin_git
 
69
        e = OSError('something bad happened')
 
70
        git_install.side_effect = e
 
71
        traceback = (
 
72
            "Traceback (most recent call last):\n"
 
73
            "  File \"actions/git_reinstall.py\", line 33, in git_reinstall\n"
 
74
            "    git_install(config(\'openstack-origin-git\'))\n"
 
75
            "  File \"/usr/lib/python2.7/dist-packages/mock.py\", line 964, in __call__\n"  # noqa
 
76
            "    return _mock_self._mock_call(*args, **kwargs)\n"
 
77
            "  File \"/usr/lib/python2.7/dist-packages/mock.py\", line 1019, in _mock_call\n"  # noqa
 
78
            "    raise effect\n"
 
79
            "OSError: something bad happened\n")
 
80
 
 
81
        git_reinstall.git_reinstall()
 
82
 
 
83
        msg = 'git-reinstall resulted in an unexpected error'
 
84
        action_fail.assert_called_with(msg)
 
85
        action_set.assert_called_with({'traceback': traceback})