Exemplo n.º 1
0
    def _check_dependency_add_dependent_list(self):
        specs = [
            {'name': 'A01', 'target': 'cluster_001'},
            {'name': 'A02', 'target': 'node_001'},
            {'name': 'A03', 'target': 'node_002'},
            {'name': 'A04', 'target': 'node_003'},
        ]

        id_of = {}
        for spec in specs:
            action = _create_action(self.ctx, **spec)
            id_of[spec['name']] = action.id

        db_api.dependency_add(self.ctx,
                              id_of['A01'],
                              [id_of['A02'], id_of['A03'], id_of['A04']])

        res = db_api.dependency_get_dependents(self.ctx, id_of['A01'])
        self.assertEqual(3, len(res))
        self.assertIn(id_of['A02'], res)
        self.assertIn(id_of['A03'], res)
        self.assertIn(id_of['A04'], res)
        res = db_api.dependency_get_depended(self.ctx, id_of['A01'])
        self.assertEqual(0, len(res))

        for aid in [id_of['A02'], id_of['A03'], id_of['A04']]:
            res = db_api.dependency_get_depended(self.ctx, aid)
            self.assertEqual(1, len(res))
            self.assertIn(id_of['A01'], res)
            res = db_api.dependency_get_dependents(self.ctx, aid)
            self.assertEqual(0, len(res))
            action = db_api.action_get(self.ctx, aid)
            self.assertEqual(action.status, consts.ACTION_WAITING)

        return id_of
Exemplo n.º 2
0
    def test_engine_mark_failed_without_depended(self):
        timestamp = time.time()
        id_of = self._prepare_action_mark_failed_cancel()
        with db_api.session_for_write() as session:
            db_api._mark_engine_failed(session, id_of['A02'],
                                       timestamp, 'BOOM')

        for aid in [id_of['A03'], id_of['A04']]:
            action = db_api.action_get(self.ctx, aid)
            self.assertEqual(consts.ACTION_INIT, action.status)
            self.assertNotEqual('BOOM', action.status_reason)
            self.assertIsNone(action.end_time)

        action = db_api.action_get(self.ctx, id_of['A01'])
        self.assertEqual(consts.ACTION_WAITING, action.status)
        self.assertNotEqual('BOOM', action.status_reason)
        self.assertIsNone(action.end_time)

        action_d = db_api.action_get(self.ctx, id_of['A02'])
        self.assertEqual(consts.ACTION_FAILED, action_d.status)
        self.assertEqual('BOOM', action_d.status_reason)
        self.assertEqual(round(timestamp, 6), float(action_d.end_time))

        for aid in [id_of['A03'], id_of['A04']]:
            result = db_api.dependency_get_dependents(self.ctx, aid)
            self.assertEqual(1, len(result))
        result = db_api.dependency_get_dependents(self.ctx, id_of['A02'])
        self.assertEqual(0, len(result))
Exemplo n.º 3
0
    def _check_dependency_add_dependent_list(self):
        specs = [
            {'name': 'A01', 'target': 'cluster_001'},
            {'name': 'A02', 'target': 'node_001'},
            {'name': 'A03', 'target': 'node_002'},
            {'name': 'A04', 'target': 'node_003'},
        ]

        id_of = {}
        for spec in specs:
            action = _create_action(self.ctx, **spec)
            id_of[spec['name']] = action.id

        db_api.dependency_add(self.ctx,
                              id_of['A01'],
                              [id_of['A02'], id_of['A03'], id_of['A04']])

        res = db_api.dependency_get_dependents(self.ctx, id_of['A01'])
        self.assertEqual(3, len(res))
        self.assertIn(id_of['A02'], res)
        self.assertIn(id_of['A03'], res)
        self.assertIn(id_of['A04'], res)
        res = db_api.dependency_get_depended(self.ctx, id_of['A01'])
        self.assertEqual(0, len(res))

        for aid in [id_of['A02'], id_of['A03'], id_of['A04']]:
            res = db_api.dependency_get_depended(self.ctx, aid)
            self.assertEqual(1, len(res))
            self.assertIn(id_of['A01'], res)
            res = db_api.dependency_get_dependents(self.ctx, aid)
            self.assertEqual(0, len(res))
            action = db_api.action_get(self.ctx, aid)
            self.assertEqual(action.status, consts.ACTION_WAITING)

        return id_of
Exemplo n.º 4
0
    def _prepare_action_mark_failed_cancel(self):
        specs = [
            {'name': 'A01', 'status': 'INIT', 'target': 'cluster_001'},
            {'name': 'A02', 'status': 'INIT', 'target': 'node_001'},
            {'name': 'A03', 'status': 'INIT', 'target': 'node_002'},
            {'name': 'A04', 'status': 'INIT', 'target': 'node_003'},
            {'name': 'A05', 'status': 'INIT', 'target': 'cluster_002'},
            {'name': 'A06', 'status': 'INIT', 'target': 'cluster_003'},
            {'name': 'A07', 'status': 'INIT', 'target': 'cluster_004'},
        ]

        id_of = {}
        for spec in specs:
            action = _create_action(self.ctx, **spec)
            id_of[spec['name']] = action.id

        db_api.dependency_add(self.ctx,
                              [id_of['A02'], id_of['A03'], id_of['A04']],
                              id_of['A01'])

        db_api.dependency_add(self.ctx,
                              id_of['A01'],
                              [id_of['A05'], id_of['A06'], id_of['A07']])

        res = db_api.dependency_get_depended(self.ctx, id_of['A01'])
        self.assertEqual(3, len(res))
        self.assertIn(id_of['A02'], res)
        self.assertIn(id_of['A03'], res)
        self.assertIn(id_of['A04'], res)

        action = db_api.action_get(self.ctx, id_of['A01'])
        self.assertEqual(consts.ACTION_WAITING, action.status)

        for aid in [id_of['A02'], id_of['A03'], id_of['A04']]:
            res = db_api.dependency_get_dependents(self.ctx, aid)
            self.assertEqual(1, len(res))
            self.assertIn(id_of['A01'], res)
            res = db_api.dependency_get_depended(self.ctx, aid)
            self.assertEqual(0, len(res))

        res = db_api.dependency_get_dependents(self.ctx, id_of['A01'])
        self.assertEqual(3, len(res))
        self.assertIn(id_of['A05'], res)
        self.assertIn(id_of['A06'], res)
        self.assertIn(id_of['A07'], res)

        for aid in [id_of['A05'], id_of['A06'], id_of['A07']]:
            res = db_api.dependency_get_depended(self.ctx, aid)
            self.assertEqual(1, len(res))
            self.assertIn(id_of['A01'], res)

            res = db_api.dependency_get_dependents(self.ctx, aid)
            self.assertEqual(0, len(res))

            action = db_api.action_get(self.ctx, aid)
            self.assertEqual(consts.ACTION_WAITING, action.status)

        return id_of
Exemplo n.º 5
0
    def _prepare_action_mark_failed_cancel(self):
        specs = [
            {'name': 'A01', 'status': 'INIT', 'target': 'cluster_001'},
            {'name': 'A02', 'status': 'INIT', 'target': 'node_001'},
            {'name': 'A03', 'status': 'INIT', 'target': 'node_002'},
            {'name': 'A04', 'status': 'INIT', 'target': 'node_003'},
            {'name': 'A05', 'status': 'INIT', 'target': 'cluster_002'},
            {'name': 'A06', 'status': 'INIT', 'target': 'cluster_003'},
            {'name': 'A07', 'status': 'INIT', 'target': 'cluster_004'},
        ]

        id_of = {}
        for spec in specs:
            action = _create_action(self.ctx, **spec)
            id_of[spec['name']] = action.id

        db_api.dependency_add(self.ctx,
                              [id_of['A02'], id_of['A03'], id_of['A04']],
                              id_of['A01'])

        db_api.dependency_add(self.ctx,
                              id_of['A01'],
                              [id_of['A05'], id_of['A06'], id_of['A07']])

        res = db_api.dependency_get_depended(self.ctx, id_of['A01'])
        self.assertEqual(3, len(res))
        self.assertIn(id_of['A02'], res)
        self.assertIn(id_of['A03'], res)
        self.assertIn(id_of['A04'], res)

        action = db_api.action_get(self.ctx, id_of['A01'])
        self.assertEqual(consts.ACTION_WAITING, action.status)

        for aid in [id_of['A02'], id_of['A03'], id_of['A04']]:
            res = db_api.dependency_get_dependents(self.ctx, aid)
            self.assertEqual(1, len(res))
            self.assertIn(id_of['A01'], res)
            res = db_api.dependency_get_depended(self.ctx, aid)
            self.assertEqual(0, len(res))

        res = db_api.dependency_get_dependents(self.ctx, id_of['A01'])
        self.assertEqual(3, len(res))
        self.assertIn(id_of['A05'], res)
        self.assertIn(id_of['A06'], res)
        self.assertIn(id_of['A07'], res)

        for aid in [id_of['A05'], id_of['A06'], id_of['A07']]:
            res = db_api.dependency_get_depended(self.ctx, aid)
            self.assertEqual(1, len(res))
            self.assertIn(id_of['A01'], res)

            res = db_api.dependency_get_dependents(self.ctx, aid)
            self.assertEqual(0, len(res))

            action = db_api.action_get(self.ctx, aid)
            self.assertEqual(consts.ACTION_WAITING, action.status)

        return id_of
Exemplo n.º 6
0
    def test_action_mark_cancelled_parent_status_update_not_needed(self):
        timestamp = time.time()
        id_of = self._prepare_action_mark_failed_cancel()
        db_api.action_mark_cancelled(self.ctx, id_of['A03'], timestamp)

        action = db_api.action_get(self.ctx, id_of['A01'])
        self.assertEqual(consts.ACTION_WAITING, action.status)
        self.assertIsNone(action.end_time)

        result = db_api.dependency_get_dependents(self.ctx, id_of['A01'])
        self.assertEqual(3, len(result))
Exemplo n.º 7
0
    def test_action_mark_cancelled_parent_status_update_needed(self):
        timestamp = time.time()
        id_of = self._prepare_action_mark_failed_cancel()
        db_api.action_mark_cancelled(self.ctx, id_of['A04'], timestamp)

        action = db_api.action_get(self.ctx, id_of['A01'])
        self.assertEqual(consts.ACTION_CANCELLED, action.status)
        self.assertEqual(round(timestamp, 6), float(action.end_time))

        result = db_api.dependency_get_dependents(self.ctx, id_of['A01'])
        self.assertEqual(0, len(result))
Exemplo n.º 8
0
    def test_action_mark_cancelled(self):
        timestamp = time.time()
        id_of = self._prepare_action_mark_failed_cancel()
        db_api.action_mark_cancelled(self.ctx, id_of['A01'], timestamp)

        for aid in [id_of['A05'], id_of['A06'], id_of['A07']]:
            action = db_api.action_get(self.ctx, aid)
            self.assertEqual(consts.ACTION_CANCELLED, action.status)
            self.assertEqual(timestamp, action.end_time)

        result = db_api.dependency_get_dependents(self.ctx, id_of['A01'])
        self.assertEqual(0, len(result))
Exemplo n.º 9
0
    def test_action_mark_failed(self):
        timestamp = time.time()
        id_of = self._prepare_action_mark_failed_cancel()
        db_api.action_mark_failed(self.ctx, id_of['A01'], timestamp)

        for aid in [id_of['A05'], id_of['A06'], id_of['A07']]:
            action = db_api.action_get(self.ctx, aid)
            self.assertEqual(consts.ACTION_FAILED, action.status)
            self.assertEqual(round(timestamp, 6), float(action.end_time))

        result = db_api.dependency_get_dependents(self.ctx, id_of['A01'])
        self.assertEqual(0, len(result))
Exemplo n.º 10
0
    def test_action_mark_succeeded(self):
        timestamp = time.time()
        id_of = self._check_dependency_add_dependent_list()

        db_api.action_mark_succeeded(self.ctx, id_of['A01'], timestamp)

        res = db_api.dependency_get_depended(self.ctx, id_of['A01'])
        self.assertEqual(0, len(res))

        action = db_api.action_get(self.ctx, id_of['A01'])
        self.assertEqual(consts.ACTION_SUCCEEDED, action.status)
        self.assertEqual(timestamp, action.end_time)

        for aid in [id_of['A02'], id_of['A03'], id_of['A04']]:
            res = db_api.dependency_get_dependents(self.ctx, aid)
            self.assertEqual(0, len(res))
Exemplo n.º 11
0
    def test_action_mark_succeeded(self):
        timestamp = time.time()
        id_of = self._check_dependency_add_dependent_list()

        db_api.action_mark_succeeded(self.ctx, id_of['A01'], timestamp)

        res = db_api.dependency_get_depended(self.ctx, id_of['A01'])
        self.assertEqual(0, len(res))

        action = db_api.action_get(self.ctx, id_of['A01'])
        self.assertEqual(consts.ACTION_SUCCEEDED, action.status)
        self.assertEqual(round(timestamp, 6), float(action.end_time))

        for aid in [id_of['A02'], id_of['A03'], id_of['A04']]:
            res = db_api.dependency_get_dependents(self.ctx, aid)
            self.assertEqual(0, len(res))