~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/tests/drivers/test_base.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-03-30 11:14:57 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20150330111457-kr4ju3guf22m4vbz
Tags: 2015.1~b3-0ubuntu1
* New upstream release.
  + d/control: 
    - Align with upstream dependencies.
    - Add dh-python to build-dependencies.
    - Add psmisc as a dependency. (LP: #1358820)
  + d/p/fix-requirements.patch: Rediffed.
  + d/ironic-conductor.init.in: Fixed typos in LSB headers,
    thanks to JJ Asghar. (LP: #1429962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    def noexception(self):
30
30
        return "Fake"
31
31
 
 
32
    @driver_base.driver_passthru(['POST'])
 
33
    def driver_noexception(self):
 
34
        return "Fake"
 
35
 
32
36
    @driver_base.passthru(['POST'])
33
37
    def ironicexception(self):
34
38
        raise exception.IronicException("Fake!")
67
71
        driver_base.LOG.exception.assert_called_with(
68
72
            mock.ANY, 'normalexception')
69
73
 
 
74
    def test_passthru_check_func_references(self):
 
75
        inst1 = FakeVendorInterface()
 
76
        inst2 = FakeVendorInterface()
 
77
 
 
78
        self.assertNotEqual(inst1.vendor_routes['noexception']['func'],
 
79
                            inst2.vendor_routes['noexception']['func'])
 
80
        self.assertNotEqual(inst1.driver_routes['driver_noexception']['func'],
 
81
                            inst2.driver_routes['driver_noexception']['func'])
 
82
 
70
83
 
71
84
@mock.patch.object(eventlet.greenthread, 'spawn_n',
72
85
                   side_effect=lambda func, *args, **kw: func(*args, **kw))
98
111
        function()
99
112
        function_mock.assert_called_once_with()
100
113
        self.assertEqual(1, spawn_mock.call_count)
 
114
 
 
115
 
 
116
class CleanStepTestCase(base.TestCase):
 
117
    def test_get_and_execute_clean_steps(self):
 
118
        # Create a fake Driver class, create some clean steps, make sure
 
119
        # they are listed correctly, and attempt to execute one of them
 
120
 
 
121
        method_mock = mock.Mock()
 
122
        task_mock = mock.Mock()
 
123
 
 
124
        class TestClass(driver_base.BaseInterface):
 
125
            interface_type = 'test'
 
126
 
 
127
            @driver_base.clean_step(priority=0)
 
128
            def zap_method(self, task):
 
129
                pass
 
130
 
 
131
            @driver_base.clean_step(priority=10)
 
132
            def clean_method(self, task):
 
133
                method_mock(task)
 
134
 
 
135
            def not_clean_method(self, task):
 
136
                pass
 
137
 
 
138
        class TestClass2(driver_base.BaseInterface):
 
139
            interface_type = 'test2'
 
140
 
 
141
            @driver_base.clean_step(priority=0)
 
142
            def zap_method2(self, task):
 
143
                pass
 
144
 
 
145
            @driver_base.clean_step(priority=20)
 
146
            def clean_method2(self, task):
 
147
                method_mock(task)
 
148
 
 
149
            def not_clean_method2(self, task):
 
150
                pass
 
151
 
 
152
        obj = TestClass()
 
153
        obj2 = TestClass2()
 
154
 
 
155
        self.assertEqual(2, len(obj.get_clean_steps(task_mock)))
 
156
        # Ensure the steps look correct
 
157
        self.assertEqual(10, obj.get_clean_steps(task_mock)[0]['priority'])
 
158
        self.assertEqual('test', obj.get_clean_steps(
 
159
            task_mock)[0]['interface'])
 
160
        self.assertEqual('clean_method', obj.get_clean_steps(
 
161
            task_mock)[0]['step'])
 
162
        self.assertEqual(0, obj.get_clean_steps(task_mock)[1]['priority'])
 
163
        self.assertEqual('test', obj.get_clean_steps(
 
164
            task_mock)[1]['interface'])
 
165
        self.assertEqual('zap_method', obj.get_clean_steps(
 
166
            task_mock)[1]['step'])
 
167
 
 
168
        # Ensure the second obj get different clean steps
 
169
        self.assertEqual(2, len(obj2.get_clean_steps(task_mock)))
 
170
        # Ensure the steps look correct
 
171
        self.assertEqual(20, obj2.get_clean_steps(task_mock)[0]['priority'])
 
172
        self.assertEqual('test2', obj2.get_clean_steps(
 
173
            task_mock)[0]['interface'])
 
174
        self.assertEqual('clean_method2', obj2.get_clean_steps(
 
175
            task_mock)[0]['step'])
 
176
        self.assertEqual(0, obj2.get_clean_steps(task_mock)[1]['priority'])
 
177
        self.assertEqual('test2', obj2.get_clean_steps(
 
178
            task_mock)[1]['interface'])
 
179
        self.assertEqual('zap_method2', obj2.get_clean_steps(
 
180
            task_mock)[1]['step'])
 
181
 
 
182
        # Ensure we can execute the function.
 
183
        obj.execute_clean_step(task_mock, obj.get_clean_steps(task_mock)[0])
 
184
        method_mock.assert_called_once_with(task_mock)