def test_deletion_task_called(self, mdeletion_execute):
        cluster = self.env.create_cluster()
        cluster_id = cluster['id']
        node_db = self.env.create_node(
            api=False,
            cluster_id=cluster['id'],
            pending_addition=False,
            pending_deletion=True,
            status=NODE_STATUSES.ready,
            roles=['controller'])

        manager_ = manager.ApplyChangesTaskManager(cluster_id)
        manager_.execute()

        self.assertEqual(mdeletion_execute.call_count, 1)
        task, nodes = mdeletion_execute.call_args[0]
        # unfortunately assertItemsEqual does not recurse into dicts
        self.assertItemsEqual(
            nodes['nodes_to_delete'],
            DeletionTask.prepare_nodes_for_task([node_db])['nodes_to_delete']
        )
        self.assertItemsEqual(
            nodes['nodes_to_restore'],
            DeletionTask.prepare_nodes_for_task([node_db])['nodes_to_restore']
        )
    def test_undeployed_node_called(
            self,
            mremove_undeployed_nodes_from_db,
            mmake_astute_message,
            mrpc):
        self.add_node(consts.NODE_STATUSES.discover)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)

        self.assertEqual(len(nodes['nodes_to_delete']), 1)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)

        task = models.Task(
            name=consts.TASK_NAMES.cluster_deletion,
            cluster=self.cluster_db
        )
        db().add(task)
        db().commit()

        mremove_undeployed_nodes_from_db.return_value = []
        DeletionTask.execute(task, nodes=nodes)

        mremove_undeployed_nodes_from_db.assert_called_once_with(
            nodes['nodes_to_delete'])
        self.assertEqual(mmake_astute_message.call_count, 1)
        self.assertEqual(mrpc.cast.call_count, 1)
Exemple #3
0
    def test_astute_message_creation(self, mmake_astute_message, mrpc):
        # 'discover' node is not deployed yet -- it will be removed
        # immediately
        n_discover = self.add_node(consts.NODE_STATUSES.discover)
        # 'ready' node is deployed -- astute will take care of it
        self.add_node(consts.NODE_STATUSES.ready)
        # 'offline' node will also be passed to astute
        self.add_node(consts.NODE_STATUSES.ready, online=False)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)
        astute_nodes = [
            node for node in nodes['nodes_to_delete']
            if node['id'] != n_discover.id
        ]

        self.assertEqual(len(nodes['nodes_to_delete']), 3)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)

        task = models.Task(name=consts.TASK_NAMES.cluster_deletion,
                           cluster=self.cluster_db)
        db().add(task)
        db().commit()

        DeletionTask.execute(task, nodes=nodes)

        self.assertEqual(mmake_astute_message.call_count, 1)
        message = mmake_astute_message.call_args[0][3]

        self.assertIn('nodes', message)
        self.assertItemsEqual(message['nodes'], astute_nodes)

        self.assertEqual(mrpc.cast.call_count, 1)
    def test_astute_message_creation(self, mmake_astute_message, mrpc):
        # 'discover' node is not deployed yet -- it will be removed
        # immediately
        n_discover = self.add_node(consts.NODE_STATUSES.discover)
        # 'ready' node is deployed -- astute will take care of it
        self.add_node(consts.NODE_STATUSES.ready)
        # 'offline' node will also be passed to astute
        self.add_node(consts.NODE_STATUSES.ready, online=False)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)
        astute_nodes = [node for node in nodes['nodes_to_delete']
                        if node['id'] != n_discover.id]

        self.assertEqual(len(nodes['nodes_to_delete']), 3)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)

        task = models.Task(
            name=consts.TASK_NAMES.cluster_deletion,
            cluster=self.cluster_db
        )
        db().add(task)
        db().commit()

        DeletionTask.execute(task, nodes=nodes)

        self.assertEqual(mmake_astute_message.call_count, 1)
        message = mmake_astute_message.call_args[0][3]

        self.assertIn('nodes', message)
        self.assertItemsEqual(message['nodes'], astute_nodes)

        self.assertEqual(mrpc.cast.call_count, 1)
    def test_undeployed_node_called(
            self,
            mremove_undeployed_nodes_from_db,
            mmake_astute_message,
            mrpc):
        self.add_node(consts.NODE_STATUSES.discover)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)

        self.assertEqual(len(nodes['nodes_to_delete']), 1)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)

        task = models.Task(
            name=consts.TASK_NAMES.cluster_deletion,
            cluster=self.cluster_db
        )
        db().add(task)
        db().commit()

        mremove_undeployed_nodes_from_db.return_value = []
        DeletionTask.execute(task, nodes=nodes)

        mremove_undeployed_nodes_from_db.assert_called_once_with(
            nodes['nodes_to_delete'])
        self.assertEqual(mmake_astute_message.call_count, 1)
        self.assertEqual(mrpc.cast.call_count, 1)
    def test_get_task_nodes(self):
        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)

        self.assertEqual(len(nodes['nodes_to_delete']), 0)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)

        self.add_node(consts.NODE_STATUSES.ready)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)

        self.assertEqual(len(nodes['nodes_to_delete']), 1)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)
Exemple #7
0
    def test_get_task_nodes(self):
        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)

        self.assertEqual(len(nodes['nodes_to_delete']), 0)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)

        self.add_node(consts.NODE_STATUSES.ready)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)

        self.assertEqual(len(nodes['nodes_to_delete']), 1)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)
Exemple #8
0
    def test_undeployed_node_removal(self):
        self.add_node(consts.NODE_STATUSES.discover)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)

        self.assertEqual(len(nodes['nodes_to_delete']), 1)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)

        ret = DeletionTask.remove_undeployed_nodes_from_db(
            nodes['nodes_to_delete'])

        self.assertEqual(len(self.cluster_db.nodes), 0)
        self.assertEqual(len(ret), 0)
    def test_undeployed_node_removal(self):
        self.add_node(consts.NODE_STATUSES.discover)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)

        self.assertEqual(len(nodes['nodes_to_delete']), 1)
        self.assertEqual(len(nodes['nodes_to_restore']), 0)

        ret = DeletionTask.remove_undeployed_nodes_from_db(
            nodes['nodes_to_delete']
        )

        self.assertEqual(len(self.cluster_db.nodes), 0)
        self.assertEqual(len(ret), 0)
Exemple #10
0
    def test_execute_with_zabbix_node(self, mock_zabbix_manager,
                                      mmake_astute_message, mrpc):
        self.add_node(consts.NODE_STATUSES.ready)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)
        self.assertEqual(len(nodes['nodes_to_delete']), 1)

        task = models.Task(name=consts.TASK_NAMES.cluster_deletion,
                           cluster=self.cluster_db)
        db().add(task)
        db().commit()

        DeletionTask.execute(task, nodes=nodes)
        self.assertEqual(mock_zabbix_manager.get_zabbix_node.called, False)
    def test_execute_with_zabbix_node(
            self,
            mock_zabbix_manager,
            mmake_astute_message,
            mrpc):
        self.add_node(consts.NODE_STATUSES.ready)

        nodes = DeletionTask.get_task_nodes_for_cluster(self.cluster_db)
        self.assertEqual(len(nodes['nodes_to_delete']), 1)

        task = models.Task(
            name=consts.TASK_NAMES.cluster_deletion,
            cluster=self.cluster_db
        )
        db().add(task)
        db().commit()

        DeletionTask.execute(task, nodes=nodes)
        self.assertEqual(mock_zabbix_manager.get_zabbix_node.called, False)
Exemple #12
0
    def test_deletion_task_called(self, mdeletion_execute):
        cluster = self.env.create_cluster()
        cluster_id = cluster['id']
        node_db = self.env.create_node(api=False,
                                       cluster_id=cluster['id'],
                                       pending_addition=False,
                                       pending_deletion=True,
                                       status=NODE_STATUSES.ready,
                                       roles=['controller'])

        manager_ = manager.ApplyChangesTaskManager(cluster_id)
        manager_.execute()

        self.assertEqual(mdeletion_execute.call_count, 1)
        task, nodes = mdeletion_execute.call_args[0]
        # unfortunately assertItemsEqual does not recurse into dicts
        self.assertItemsEqual(
            nodes['nodes_to_delete'],
            DeletionTask.prepare_nodes_for_task([node_db])['nodes_to_delete'])
        self.assertItemsEqual(
            nodes['nodes_to_restore'],
            DeletionTask.prepare_nodes_for_task([node_db])['nodes_to_restore'])