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

« back to all changes in this revision

Viewing changes to unit_tests/test_actions_pause_resume.py

  • Committer: Gerrit Code Review
  • Author(s): Jenkins
  • Date: 2016-04-06 06:43:55 UTC
  • mfrom: (211.1.1 trunk)
  • Revision ID: review@openstack.org-20160406064355-hhfnwzmint2jmju2
Merge "Enhanced pause/resume for maintenance mode"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import mock
 
2
from mock import patch
 
3
 
 
4
from test_utils import CharmTestCase
 
5
 
 
6
with patch('nova_compute_utils.register_configs') as configs:
 
7
    configs.return_value = 'test-config'
 
8
    import pause_resume as actions
 
9
 
 
10
 
 
11
class PauseTestCase(CharmTestCase):
 
12
 
 
13
    def setUp(self):
 
14
        super(PauseTestCase, self).setUp(
 
15
            actions, ["pause_unit_helper"])
 
16
 
 
17
    def test_pauses_services(self):
 
18
        actions.pause([])
 
19
        self.pause_unit_helper.assert_called_once_with('test-config')
 
20
 
 
21
 
 
22
class ResumeTestCase(CharmTestCase):
 
23
 
 
24
    def setUp(self):
 
25
        super(ResumeTestCase, self).setUp(
 
26
            actions, ["resume_unit_helper"])
 
27
 
 
28
    def test_pauses_services(self):
 
29
        actions.resume([])
 
30
        self.resume_unit_helper.assert_called_once_with('test-config')
 
31
 
 
32
 
 
33
class MainTestCase(CharmTestCase):
 
34
 
 
35
    def setUp(self):
 
36
        super(MainTestCase, self).setUp(actions, ["action_fail"])
 
37
 
 
38
    def test_invokes_action(self):
 
39
        dummy_calls = []
 
40
 
 
41
        def dummy_action(args):
 
42
            dummy_calls.append(True)
 
43
 
 
44
        with mock.patch.dict(actions.ACTIONS, {"foo": dummy_action}):
 
45
            actions.main(["foo"])
 
46
        self.assertEqual(dummy_calls, [True])
 
47
 
 
48
    def test_unknown_action(self):
 
49
        """Unknown actions aren't a traceback."""
 
50
        exit_string = actions.main(["foo"])
 
51
        self.assertEqual("Action foo undefined", exit_string)
 
52
 
 
53
    def test_failing_action(self):
 
54
        """Actions which traceback trigger action_fail() calls."""
 
55
        dummy_calls = []
 
56
 
 
57
        self.action_fail.side_effect = dummy_calls.append
 
58
 
 
59
        def dummy_action(args):
 
60
            raise ValueError("uh oh")
 
61
 
 
62
        with mock.patch.dict(actions.ACTIONS, {"foo": dummy_action}):
 
63
            actions.main(["foo"])
 
64
        self.assertEqual(dummy_calls, ["Action foo failed: uh oh"])