Exemple #1
0
    def test_changing_status_of_node_emits_event(self):
        self.addCleanup(node_query.signals.enable)
        node_query.signals.disable()

        old_status = NODE_STATUS.COMMISSIONING
        node = factory.make_Node(status=old_status)
        node.status = get_failed_status(old_status)
        node.save()

        latest_event = Event.objects.filter(node=node).last()
        description = "From '%s' to '%s'" % (
            NODE_STATUS_CHOICES_DICT[old_status],
            NODE_STATUS_CHOICES_DICT[node.status],
        )
        self.assertEqual(
            (
                EVENT_TYPES.NODE_CHANGED_STATUS,
                EVENT_DETAILS[EVENT_TYPES.NODE_CHANGED_STATUS].description,
                description,
            ),
            (
                latest_event.type.name,
                latest_event.type.description,
                latest_event.description,
            ),
        )
Exemple #2
0
    def test_changing_status_of_node_emits_event(self):
        self.patch_autospec(power, 'update_power_state_of_node_soon')
        old_status = NODE_STATUS.COMMISSIONING
        node = factory.make_Node(status=old_status, power_type='virsh')
        node.status = get_failed_status(old_status)

        with post_commit_hooks:
            node.save()
            # update_power_state_of_node_soon is registered as a post-commit
            # task, so it's not called immediately.
            self.expectThat(power.update_power_state_of_node_soon,
                            MockNotCalled())

        # One post-commit hooks have been fired, then it's called.
        post_commit_hooks.fire()
        self.assertThat(power.update_power_state_of_node_soon,
                        MockCalledOnceWith(node.system_id))