← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~andreserl/maas/maas_power_off into lp:maas

 

Andres Rodriguez has proposed merging lp:~andreserl/maas/maas_power_off into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~andreserl/maas/maas_power_off/+merge/115809
-- 
https://code.launchpad.net/~andreserl/maas/maas_power_off/+merge/115809
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~andreserl/maas/maas_power_off into lp:maas.
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py	2012-07-16 12:33:43 +0000
+++ src/maasserver/models/node.py	2012-07-19 18:47:31 +0000
@@ -57,7 +57,7 @@
     POWER_TYPE,
     POWER_TYPE_CHOICES,
     )
-from provisioningserver.tasks import power_on
+from provisioningserver.tasks import power_on, power_off
 
 
 def generate_node_system_id():
@@ -274,8 +274,15 @@
         :rtype: list
         """
         nodes = self.get_nodes(by_user, NODE_PERMISSION.EDIT, ids=ids)
-        get_papi().stop_nodes([node.system_id for node in nodes])
-        return nodes
+        processed_nodes = []
+        for node in nodes:
+            power_params = node.get_effective_power_parameters()
+            node_power_type = node.get_effective_power_type()
+            # WAKE_ON_LAN does not support poweroff.
+            if node_power_type != POWER_TYPE.WAKE_ON_LAN:
+                power_off.delay(node_power_type, **power_params)
+            processed_nodes.append(node)
+        return processed_nodes
 
     def start_nodes(self, ids, by_user, user_data=None):
         """Request on given user's behalf that the given nodes be started up.

=== modified file 'src/maasserver/tests/test_node.py'
--- src/maasserver/tests/test_node.py	2012-06-22 07:15:27 +0000
+++ src/maasserver/tests/test_node.py	2012-07-19 18:47:31 +0000
@@ -607,13 +607,22 @@
                 user, {'name': factory.getRandomString()}))
 
     def test_stop_nodes_stops_nodes(self):
+        # We don't actually want to fire off power events, but we'll go
+        # through the motions right up to the point where we'd normally
+        # run shell commands.
+        self.patch(PowerAction, 'run_shell', lambda *args, **kwargs: ('', ''))
         user = factory.make_user()
-        node = self.make_node(user)
+        node, mac = self.make_node_with_mac(
+                user, power_type=POWER_TYPE.VIRSH)
         output = Node.objects.stop_nodes([node.system_id], user)
 
         self.assertItemsEqual([node], output)
-        power_status = get_provisioning_api_proxy().power_status
-        self.assertEqual('stop', power_status[node.system_id])
+        self.assertEqual(
+            (1, 'provisioningserver.tasks.power_off'),
+            (
+                len(self.celery.tasks),
+                self.celery.tasks[0]['task'].name,
+            ))
 
     def test_stop_nodes_ignores_uneditable_nodes(self):
         nodes = [