~maas-committers/maas/1.2

« back to all changes in this revision

Viewing changes to src/maasserver/tests/test_node_action.py

[r=julian-edwards][bug=997092][author=julian-edwards] Backport r1489 from trunk: Add stop button in UI

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    NodeAction,
29
29
    RetryCommissioning,
30
30
    StartNode,
 
31
    StopNode,
31
32
    )
32
33
from maasserver.testing.factory import factory
33
34
from maasserver.testing.testcase import TestCase
34
35
from provisioningserver.enum import POWER_TYPE
 
36
from provisioningserver.power.poweraction import PowerAction
35
37
 
36
38
 
37
39
ALL_STATUSES = NODE_STATUS_CHOICES_DICT.keys()
162
164
        action.fake_inhibition = factory.getRandomString()
163
165
        self.assertIsNone(action.inhibition)
164
166
 
 
167
 
 
168
class TestDeleteNodeAction(TestCase):
 
169
 
165
170
    def test_Delete_inhibit_when_node_is_allocated(self):
166
171
        node = factory.make_node(status=NODE_STATUS.ALLOCATED)
167
172
        action = Delete(node, factory.make_admin())
186
191
            reverse('node-delete', args=[node.system_id]),
187
192
            urlparse(unicode(e)).path)
188
193
 
 
194
 
 
195
class TestAcceptAndCommissionNodeAction(TestCase):
 
196
 
189
197
    def test_AcceptAndCommission_starts_commissioning(self):
190
198
        node = factory.make_node(
191
199
            mac=True, status=NODE_STATUS.DECLARED,
197
205
            'provisioningserver.tasks.power_on',
198
206
            self.celery.tasks[0]['task'].name)
199
207
 
 
208
 
 
209
class TestRetryCommissioningNodeAction(TestCase):
 
210
 
200
211
    def test_RetryCommissioning_starts_commissioning(self):
201
212
        node = factory.make_node(
202
213
            mac=True, status=NODE_STATUS.FAILED_TESTS,
208
219
            'provisioningserver.tasks.power_on',
209
220
            self.celery.tasks[0]['task'].name)
210
221
 
 
222
 
 
223
class TestStartNodeNodeAction(TestCase):
 
224
 
211
225
    def test_StartNode_inhibit_allows_user_with_SSH_key(self):
212
226
        user_with_key = factory.make_user()
213
227
        factory.make_sshkey(user_with_key)
232
246
        self.assertEqual(
233
247
            'provisioningserver.tasks.power_on',
234
248
            self.celery.tasks[0]['task'].name)
 
249
 
 
250
 
 
251
class TestStopNodeNodeAction(TestCase):
 
252
 
 
253
    def test_StopNode_stops_and_releases_node(self):
 
254
        self.patch(PowerAction, 'run_shell', lambda *args, **kwargs: ('', ''))
 
255
        user = factory.make_user()
 
256
        params = dict(
 
257
            power_address=factory.getRandomString(),
 
258
            power_user=factory.getRandomString(),
 
259
            power_pass=factory.getRandomString())
 
260
        node = factory.make_node(
 
261
            mac=True, status=NODE_STATUS.ALLOCATED,
 
262
            power_type=POWER_TYPE.IPMI,
 
263
            owner=user, power_parameters=params)
 
264
        StopNode(node, user).execute()
 
265
 
 
266
        self.assertEqual(NODE_STATUS.READY, node.status)
 
267
        self.assertIsNone(node.owner)
 
268
        self.assertEqual(
 
269
            'provisioningserver.tasks.power_off',
 
270
            self.celery.tasks[0]['task'].name)