~openstack-charmers-archive/charms/trusty/glance/next

« back to all changes in this revision

Viewing changes to unit_tests/test_actions_git_reinstall.py

  • Committer: james.page at ubuntu
  • Date: 2015-04-16 19:53:49 UTC
  • mfrom: (102.2.11 glance)
  • Revision ID: james.page@ubuntu.com-20150416195349-o031tx0ad7elcekx
[coreycb,r=james-page] Add deploy from source support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mock import patch
 
2
import os
 
3
 
 
4
os.environ['JUJU_UNIT_NAME'] = 'glance'
 
5
 
 
6
with patch('glance_utils.register_configs') as register_configs:
 
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: glance,
 
24
            repository: 'git://git.openstack.org/openstack/glance',
 
25
            branch: stable/juno}"""
 
26
 
 
27
 
 
28
class TestGlanceActions(CharmTestCase):
 
29
 
 
30
    def setUp(self):
 
31
        super(TestGlanceActions, 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
    @patch.object(git_reinstall, 'config_changed')
 
38
    @patch('charmhelpers.contrib.openstack.utils.config')
 
39
    def test_git_reinstall(self, _config, config_changed, git_install,
 
40
                           action_fail, action_set):
 
41
        _config.return_value = openstack_origin_git
 
42
        self.test_config.set('openstack-origin-git', openstack_origin_git)
 
43
 
 
44
        git_reinstall.git_reinstall()
 
45
 
 
46
        git_install.assert_called_with(openstack_origin_git)
 
47
        self.assertTrue(git_install.called)
 
48
        self.assertTrue(config_changed.called)
 
49
        self.assertFalse(action_set.called)
 
50
        self.assertFalse(action_fail.called)
 
51
 
 
52
    @patch.object(git_reinstall, 'action_set')
 
53
    @patch.object(git_reinstall, 'action_fail')
 
54
    @patch.object(git_reinstall, 'git_install')
 
55
    @patch.object(git_reinstall, 'config_changed')
 
56
    @patch('charmhelpers.contrib.openstack.utils.config')
 
57
    def test_git_reinstall_not_configured(self, _config, config_changed,
 
58
                                          git_install, action_fail,
 
59
                                          action_set):
 
60
        _config.return_value = None
 
61
 
 
62
        git_reinstall.git_reinstall()
 
63
 
 
64
        msg = 'openstack-origin-git is not configured'
 
65
        action_fail.assert_called_with(msg)
 
66
        self.assertFalse(git_install.called)
 
67
        self.assertFalse(action_set.called)
 
68
 
 
69
    @patch.object(git_reinstall, 'action_set')
 
70
    @patch.object(git_reinstall, 'action_fail')
 
71
    @patch.object(git_reinstall, 'git_install')
 
72
    @patch.object(git_reinstall, 'config_changed')
 
73
    @patch('traceback.format_exc')
 
74
    @patch('charmhelpers.contrib.openstack.utils.config')
 
75
    def test_git_reinstall_exception(self, _config, format_exc,
 
76
                                     config_changed, git_install, action_fail,
 
77
                                     action_set):
 
78
        _config.return_value = openstack_origin_git
 
79
        e = OSError('something bad happened')
 
80
        git_install.side_effect = e
 
81
        traceback = (
 
82
            "Traceback (most recent call last):\n"
 
83
            "  File \"actions/git_reinstall.py\", line 37, in git_reinstall\n"
 
84
            "    git_install(config(\'openstack-origin-git\'))\n"
 
85
            "  File \"/usr/lib/python2.7/dist-packages/mock.py\", line 964, in __call__\n"  # noqa
 
86
            "    return _mock_self._mock_call(*args, **kwargs)\n"
 
87
            "  File \"/usr/lib/python2.7/dist-packages/mock.py\", line 1019, in _mock_call\n"  # noqa
 
88
            "    raise effect\n"
 
89
            "OSError: something bad happened\n")
 
90
        format_exc.return_value = traceback
 
91
 
 
92
        git_reinstall.git_reinstall()
 
93
 
 
94
        msg = 'git-reinstall resulted in an unexpected error'
 
95
        action_fail.assert_called_with(msg)
 
96
        action_set.assert_called_with({'traceback': traceback})