コード例 #1
0
ファイル: test_lock_api.py プロジェクト: tomas-mazak/senlin
    def test_cluster_lock_cluster_lock_first(self):
        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID1, -1)
        self.assertIn(UUID1, observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID2, -1)
        self.assertNotIn(UUID2, observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID2, -1)
        self.assertFalse(observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID3, 1)
        self.assertNotIn(UUID3, observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID3, 1)
        self.assertFalse(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID1, -1)
        self.assertTrue(observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID2, -1)
        self.assertIn(UUID2, observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID2, -1)
        self.assertTrue(observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID3, 1)
        self.assertIn(UUID3, observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID3, 1)
        self.assertTrue(observed)
コード例 #2
0
ファイル: test_lock_api.py プロジェクト: tomas-mazak/senlin
    def test_cluster_lock_node_scope(self):
        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID1, 1)
        self.assertIn(UUID1, observed)
        self.assertNotIn(UUID2, observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID2, 1)
        self.assertIn(UUID1, observed)
        self.assertIn(UUID2, observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID2, 1)
        self.assertIn(UUID1, observed)
        self.assertIn(UUID2, observed)
        self.assertEqual(2, len(observed))

        observed = db_api.cluster_lock_release(self.cluster.id, UUID1, 1)
        self.assertTrue(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID1, 1)
        self.assertFalse(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID3, 1)
        self.assertFalse(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID2, 1)
        self.assertTrue(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID2, 1)
        self.assertFalse(observed)
コード例 #3
0
ファイル: test_lock_api.py プロジェクト: tomas-mazak/senlin
    def test_delete_cluster_lock_and_node_lock_1(self):
        # Test the case that an action is about node that also locked a
        # cluster and the cluster lock can be released
        #
        #  (dead-engine) --> Action      --> NodeLock
        #                    |action|owner|  |node |action|
        #                    | A1   | E1  |  |N1   |A1    |
        #                                --> ClusterLock
        #                                    |cluster|action|scope|
        #                                    |C1     |[A1]  |1    |
        # preparation
        engine_id = UUID1
        action = shared.create_action(self.ctx, target=self.node.id,
                                      status='RUNNING', owner=engine_id,
                                      project=self.ctx.project_id)
        db_api.cluster_lock_acquire(self.cluster.id, action.id, 1)
        db_api.node_lock_acquire(self.cluster.id, action.id)

        # do it
        db_api.dummy_gc(engine_id)

        # assertion
        # even a read lock is okay now
        observed = db_api.cluster_lock_acquire(self.node.id, UUID2, 1)
        self.assertIn(UUID2, observed)
        self.assertNotIn(action.id, observed)

        # node can be locked again
        observed = db_api.node_lock_acquire(self.node.id, UUID2)
        self.assertEqual(UUID2, observed)

        new_action = db_api.action_get(self.ctx, action.id)
        self.assertEqual('FAILED', new_action.status)
        self.assertEqual("Engine failure", new_action.status_reason)
コード例 #4
0
ファイル: test_lock_api.py プロジェクト: tomas-mazak/senlin
    def test_delete_cluster_lock(self):
        # Test the case that a single cluster-scope clock can be released
        #
        #  (dead-engine) --> Action      --> ClusterLock
        #                    |action|owner|  |cluster|action|scope|
        #                    | A1   | E1  |  |C1     |[A1]  |-1   |

        # preparation
        engine_id = UUID1
        action = shared.create_action(self.ctx, target=self.cluster.id,
                                      status='RUNNING', owner=engine_id,
                                      project=self.ctx.project_id)
        db_api.cluster_lock_acquire(self.cluster.id, action.id, -1)

        # do it
        db_api.dummy_gc(engine_id)

        # assertion
        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID2, -1)
        self.assertIn(UUID2, observed)
        self.assertNotIn(action.id, observed)

        new_action = db_api.action_get(self.ctx, action.id)
        self.assertEqual('FAILED', new_action.status)
        self.assertEqual("Engine failure", new_action.status_reason)
コード例 #5
0
ファイル: test_lock_api.py プロジェクト: KongJustin/senlin
    def test_cluster_lock_cluster_lock_first(self):
        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID1, -1)
        self.assertIn(UUID1, observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID2, -1)
        self.assertNotIn(UUID2, observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID2, -1)
        self.assertFalse(observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID3, 1)
        self.assertNotIn(UUID3, observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID3, 1)
        self.assertFalse(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID1, -1)
        self.assertTrue(observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID2, -1)
        self.assertIn(UUID2, observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID2, -1)
        self.assertTrue(observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID3, 1)
        self.assertIn(UUID3, observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID3, 1)
        self.assertTrue(observed)
コード例 #6
0
ファイル: test_lock_api.py プロジェクト: KongJustin/senlin
    def test_cluster_lock_node_scope(self):
        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID1, 1)
        self.assertIn(UUID1, observed)
        self.assertNotIn(UUID2, observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID2, 1)
        self.assertIn(UUID1, observed)
        self.assertIn(UUID2, observed)

        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID2, 1)
        self.assertIn(UUID1, observed)
        self.assertIn(UUID2, observed)
        self.assertEqual(2, len(observed))

        observed = db_api.cluster_lock_release(self.cluster.id, UUID1, 1)
        self.assertTrue(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID1, 1)
        self.assertFalse(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID3, 1)
        self.assertFalse(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID2, 1)
        self.assertTrue(observed)

        observed = db_api.cluster_lock_release(self.cluster.id, UUID2, 1)
        self.assertFalse(observed)
コード例 #7
0
ファイル: test_lock_api.py プロジェクト: tomas-mazak/senlin
    def test_cluster_is_locked(self):
        # newly created cluster should not be locked
        observed = db_api.cluster_is_locked(self.cluster.id)
        self.assertFalse(observed)

        # lock cluster
        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID1, -1)
        self.assertIn(UUID1, observed)

        # cluster should be locked
        observed = db_api.cluster_is_locked(self.cluster.id)
        self.assertTrue(observed)

        # release cluster lock
        observed = db_api.cluster_lock_release(self.cluster.id, UUID1, -1)
        self.assertTrue(observed)

        # cluster should not be locked anymore
        observed = db_api.cluster_is_locked(self.cluster.id)
        self.assertFalse(observed)
コード例 #8
0
ファイル: test_lock_api.py プロジェクト: tomas-mazak/senlin
    def test_mult_engine_keep_node_scope_lock(self):
        engine1 = UUID1
        engine2 = UUID2

        node2 = shared.create_node(self.ctx, self.cluster, self.profile)

        c_action = shared.create_action(self.ctx, target=self.cluster.id,
                                        status='WAITING', owner=engine1,
                                        project=self.ctx.project_id)

        n_action_1 = shared.create_action(self.ctx, target=self.node.id,
                                          status='RUNNING', owner=engine1,
                                          project=self.ctx.project_id)

        n_action_2 = shared.create_action(self.ctx, target=node2.id,
                                          status='RUNNING', owner=engine2,
                                          project=self.ctx.project_id)

        db_api.dependency_add(self.ctx, [n_action_1.id, n_action_2.id],
                              c_action.id)

        db_api.cluster_lock_acquire(self.cluster.id, c_action.id, -1)
        db_api.cluster_lock_acquire(self.cluster.id, n_action_1.id, 1)
        db_api.cluster_lock_acquire(self.cluster.id, n_action_2.id, 1)
        db_api.node_lock_acquire(self.node.id, n_action_1.id)
        db_api.node_lock_acquire(node2.id, n_action_2.id)

        # do it
        db_api.dummy_gc(engine1)

        # try to acquire cluster scope lock
        observed = db_api.cluster_lock_acquire(self.cluster.id, UUID3, -1)
        self.assertIn(UUID3, observed)
        self.assertEqual(1, len(observed))

        # try to acquire node scope lock
        UUID4 = uuidutils.generate_uuid()
        observed = db_api.cluster_lock_acquire(self.node.id, UUID4, 1)
        self.assertIn(UUID4, observed)
        self.assertEqual(1, len(observed))

        # node scope lock will be also released
        UUID5 = uuidutils.generate_uuid()
        observed = db_api.cluster_lock_acquire(node2.id, UUID5, 1)
        self.assertIn(UUID5, observed)
        self.assertEqual(1, len(observed))

        # try to acquire node lock
        UUID6 = uuidutils.generate_uuid()
        observed = db_api.node_lock_acquire(self.node.id, UUID6)
        self.assertEqual(UUID6, observed)

        # node locks for actions owned by other engines are still there
        UUID7 = uuidutils.generate_uuid()
        observed = db_api.node_lock_acquire(node2.id, UUID7)
        self.assertNotEqual(UUID7, observed)
        self.assertEqual(n_action_2.id, observed)

        # check dependency
        dependents = db_api.dependency_get_depended(self.ctx, c_action.id)
        self.assertEqual(0, len(dependents))

        # check action status
        new_c_action = db_api.action_get(self.ctx, c_action.id)
        self.assertEqual('FAILED', new_c_action.status)
        self.assertIsNone(new_c_action.owner)

        new_n_action_1 = db_api.action_get(self.ctx, n_action_1.id)
        self.assertEqual('FAILED', new_n_action_1.status)
        self.assertIsNone(new_n_action_1.owner)

        new_n_action_2 = db_api.action_get(self.ctx, n_action_2.id)
        self.assertEqual('FAILED', new_n_action_2.status)
        self.assertIsNone(new_n_action_2.owner)