Пример #1
0
def signal_update_power_state_of_node(instance, old_values, **kwargs):
    """Updates the power state of a node, when its status changes."""
    node = instance
    [old_status] = old_values

    # Only check the power state if it's an interesting transition.
    if old_status in QUERY_TRANSITIONS:
        if node.status in QUERY_TRANSITIONS[old_status]:
            post_commit().addCallback(callOut, update_power_state_of_node_soon,
                                      node.system_id)
Пример #2
0
    def test_Abort_aborts_testing(self):
        """Makes sure a TESTING node is returned to previous status after an
        abort.
        """
        status = random.choice(list(NODE_TESTING_RESET_READY_TRANSITIONS))
        with transaction.atomic():
            node = factory.make_Node(interface=True,
                                     previous_status=status,
                                     status=NODE_STATUS.TESTING,
                                     power_type='virsh')
            admin = factory.make_admin()

        node_stop = self.patch_autospec(node, '_stop')
        # Return a post-commit hook from Node.stop().
        node_stop.side_effect = lambda user: post_commit()

        with post_commit_hooks:
            with transaction.atomic():
                Abort(node, admin).execute()

        # Allow abortion of auto testing into ready state.
        if status == NODE_STATUS.COMMISSIONING:
            status = NODE_STATUS.READY

        with transaction.atomic():
            node = reload_object(node)
            self.assertEqual(status, node.status)

        self.assertThat(node_stop, MockCalledOnceWith(admin))
Пример #3
0
 def test_Commission_starts_commissioning(self):
     node = factory.make_Node(
         interface=True, status=self.status,
         power_type='manual', power_state=POWER_STATE.OFF)
     node_start = self.patch(node, '_start')
     node_start.side_effect = (
         lambda user, user_data, old_status, allow_power_cycle: (
             post_commit()))
     admin = factory.make_admin()
     action = Commission(node, admin)
     with post_commit_hooks:
         action.execute()
     self.assertEqual(NODE_STATUS.COMMISSIONING, node.status)
     self.assertThat(
         node_start,
         MockCalledOnceWith(admin, ANY, ANY, allow_power_cycle=True))
Пример #4
0
    def test_Abort_aborts_disk_erasing(self):
        self.useFixture(SignalsDisabled("power"))
        with transaction.atomic():
            owner = factory.make_User()
            node = factory.make_Node(status=NODE_STATUS.DISK_ERASING,
                                     owner=owner)

        node_stop = self.patch_autospec(node, '_stop')
        # Return a post-commit hook from Node.stop().
        node_stop.side_effect = lambda user: post_commit()

        with post_commit_hooks:
            with transaction.atomic():
                Abort(node, owner).execute()

        with transaction.atomic():
            node = reload_object(node)
            self.assertEqual(NODE_STATUS.FAILED_DISK_ERASING, node.status)

        self.assertThat(node_stop, MockCalledOnceWith(owner))
Пример #5
0
    def test_Abort_aborts_deployment(self):
        """Makes sure a DEPLOYING node is returned to ALLOCATED status after an
        abort.
        """
        with transaction.atomic():
            node = factory.make_Node(interface=True,
                                     status=NODE_STATUS.DEPLOYING,
                                     power_type='virsh')
            admin = factory.make_admin()

        node_stop = self.patch_autospec(node, '_stop')
        # Return a post-commit hook from Node.stop().
        node_stop.side_effect = lambda user: post_commit()

        with post_commit_hooks:
            with transaction.atomic():
                Abort(node, admin).execute()

        with transaction.atomic():
            node = reload_object(node)
            self.assertEqual(NODE_STATUS.ALLOCATED, node.status)

        self.assertThat(node_stop, MockCalledOnceWith(admin))