Пример #1
0
    def test_event_get_all_project_safe(self):
        self.ctx.project = 'project_1'
        cluster1 = shared.create_cluster(self.ctx, self.profile,
                                         name='cluster1')
        self.create_event(self.ctx, entity=cluster1)
        self.ctx.project = 'project_2'
        cluster2 = shared.create_cluster(self.ctx, self.profile,
                                         name='cluster2')
        self.create_event(self.ctx, entity=cluster2, action='CLUSTER_CREATE')
        self.create_event(self.ctx, entity=cluster2, action='CLUSTER_DELETE')

        # Default project_safe to true, only the last two events are visible
        events = db_api.event_get_all(self.ctx)
        self.assertEqual(2, len(events))

        oids = [event.oid for event in events]
        onames = [event.oname for event in events]
        self.assertNotIn(cluster1.id, oids)
        self.assertNotIn(cluster1.name, onames)
        self.assertIn(cluster2.id, oids)
        self.assertIn(cluster2.name, onames)

        # Set project_safe to false, we should get all three events
        events = db_api.event_get_all(self.ctx, project_safe=False)
        self.assertEqual(3, len(events))

        oids = [event.oid for event in events]
        onames = [event.oname for event in events]
        self.assertIn(cluster1.id, oids)
        self.assertIn(cluster1.name, onames)
        self.assertIn(cluster2.id, oids)
        self.assertIn(cluster2.name, onames)
Пример #2
0
    def test_event_get_all_with_limit_and_marker(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)

        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster1)

        events_all = db_api.event_get_all(self.ctx)
        self.assertEqual(3, len(events_all))

        marker = events_all[0].id
        event1_id = events_all[1].id
        event2_id = events_all[2].id
        events = db_api.event_get_all(self.ctx, limit=1, marker=marker)
        self.assertEqual(1, len(events))
        self.assertEqual(event1_id, events[0].id)

        events = db_api.event_get_all(self.ctx, limit=2, marker=marker)
        self.assertEqual(2, len(events))
        self.assertEqual(event1_id, events[0].id)
        self.assertEqual(event2_id, events[1].id)

        marker = event1_id
        events = db_api.event_get_all(self.ctx, limit=1, marker=marker)
        self.assertEqual(1, len(events))
        self.assertEqual(event2_id, events[0].id)
Пример #3
0
    def test_event_get_all_with_sorting(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)

        event1 = self.create_event(self.ctx, entity=cluster1,
                                   timestamp=tu.utcnow(True),
                                   action='action2')
        event2 = self.create_event(self.ctx, entity=cluster1,
                                   timestamp=tu.utcnow(True),
                                   action='action3')
        event3 = self.create_event(self.ctx, entity=cluster1,
                                   timestamp=tu.utcnow(True),
                                   action='action1')

        events = db_api.event_get_all(self.ctx, sort='timestamp')
        self.assertEqual(event1.id, events[0].id)
        self.assertEqual(event2.id, events[1].id)
        self.assertEqual(event3.id, events[2].id)

        events = db_api.event_get_all(self.ctx, sort='timestamp:desc')
        self.assertEqual(event1.id, events[2].id)
        self.assertEqual(event2.id, events[1].id)
        self.assertEqual(event3.id, events[0].id)

        events = db_api.event_get_all(self.ctx, sort='action')
        self.assertEqual(event1.id, events[1].id)
        self.assertEqual(event2.id, events[2].id)
        self.assertEqual(event3.id, events[0].id)

        events = db_api.event_get_all(self.ctx, sort='action:desc')
        self.assertEqual(event1.id, events[1].id)
        self.assertEqual(event2.id, events[0].id)
        self.assertEqual(event3.id, events[2].id)
Пример #4
0
    def test_event_get_all_with_sorting(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)

        event1 = self.create_event(self.ctx, entity=cluster1,
                                   timestamp=tu.utcnow(True),
                                   action='action2')
        event2 = self.create_event(self.ctx, entity=cluster1,
                                   timestamp=tu.utcnow(True),
                                   action='action3')
        event3 = self.create_event(self.ctx, entity=cluster1,
                                   timestamp=tu.utcnow(True),
                                   action='action1')

        events = db_api.event_get_all(self.ctx, sort='timestamp')
        self.assertEqual(event1.id, events[0].id)
        self.assertEqual(event2.id, events[1].id)
        self.assertEqual(event3.id, events[2].id)

        events = db_api.event_get_all(self.ctx, sort='timestamp:desc')
        self.assertEqual(event1.id, events[2].id)
        self.assertEqual(event2.id, events[1].id)
        self.assertEqual(event3.id, events[0].id)

        events = db_api.event_get_all(self.ctx, sort='action')
        self.assertEqual(event1.id, events[1].id)
        self.assertEqual(event2.id, events[2].id)
        self.assertEqual(event3.id, events[0].id)

        events = db_api.event_get_all(self.ctx, sort='action:desc')
        self.assertEqual(event1.id, events[1].id)
        self.assertEqual(event2.id, events[0].id)
        self.assertEqual(event3.id, events[2].id)
Пример #5
0
    def test_event_get_all_project_safe(self):
        self.ctx.project = 'project_1'
        cluster1 = shared.create_cluster(self.ctx, self.profile,
                                         name='cluster1')
        self.create_event(self.ctx, entity=cluster1)
        self.ctx.project = 'project_2'
        cluster2 = shared.create_cluster(self.ctx, self.profile,
                                         name='cluster2')
        self.create_event(self.ctx, entity=cluster2, action='CLUSTER_CREATE')
        self.create_event(self.ctx, entity=cluster2, action='CLUSTER_DELETE')

        # Default project_safe to true, only the last two events are visible
        events = db_api.event_get_all(self.ctx)
        self.assertEqual(2, len(events))

        oids = [event.oid for event in events]
        onames = [event.oname for event in events]
        self.assertNotIn(cluster1.id, oids)
        self.assertNotIn(cluster1.name, onames)
        self.assertIn(cluster2.id, oids)
        self.assertIn(cluster2.name, onames)

        # Set project_safe to false, we should get all three events
        events = db_api.event_get_all(self.ctx, project_safe=False)
        self.assertEqual(3, len(events))

        oids = [event.oid for event in events]
        onames = [event.oname for event in events]
        self.assertIn(cluster1.id, oids)
        self.assertIn(cluster1.name, onames)
        self.assertIn(cluster2.id, oids)
        self.assertIn(cluster2.name, onames)
Пример #6
0
    def test_event_get_all_with_limit_and_marker(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)

        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster1)

        events_all = db_api.event_get_all(self.ctx)
        self.assertEqual(3, len(events_all))

        marker = events_all[0].id
        event1_id = events_all[1].id
        event2_id = events_all[2].id
        events = db_api.event_get_all(self.ctx, limit=1, marker=marker)
        self.assertEqual(1, len(events))
        self.assertEqual(event1_id, events[0].id)

        events = db_api.event_get_all(self.ctx, limit=2, marker=marker)
        self.assertEqual(2, len(events))
        self.assertEqual(event1_id, events[0].id)
        self.assertEqual(event2_id, events[1].id)

        marker = event1_id
        events = db_api.event_get_all(self.ctx, limit=1, marker=marker)
        self.assertEqual(1, len(events))
        self.assertEqual(event2_id, events[0].id)
Пример #7
0
    def test_event_get_all_with_sort_keys_and_dir(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)

        event1 = self.create_event(self.ctx, entity=cluster1,
                                   timestamp=tu.utcnow(),
                                   action='action2')
        event2 = self.create_event(self.ctx, entity=cluster1,
                                   timestamp=tu.utcnow(),
                                   action='action3')
        event3 = self.create_event(self.ctx, entity=cluster1,
                                   timestamp=tu.utcnow(),
                                   action='action1')

        events = db_api.event_get_all(self.ctx, sort_keys=['timestamp'])
        self.assertEqual(event1.id, events[0].id)
        self.assertEqual(event2.id, events[1].id)
        self.assertEqual(event3.id, events[2].id)

        events = db_api.event_get_all(self.ctx, sort_keys=['timestamp'],
                                      sort_dir='desc')
        self.assertEqual(event1.id, events[2].id)
        self.assertEqual(event2.id, events[1].id)
        self.assertEqual(event3.id, events[0].id)

        events = db_api.event_get_all(self.ctx, sort_keys=['action'])
        self.assertEqual(event1.id, events[1].id)
        self.assertEqual(event2.id, events[2].id)
        self.assertEqual(event3.id, events[0].id)

        events = db_api.event_get_all(self.ctx, sort_keys=['action'],
                                      sort_dir='desc')
        self.assertEqual(event1.id, events[1].id)
        self.assertEqual(event2.id, events[0].id)
        self.assertEqual(event3.id, events[2].id)
Пример #8
0
    def test_event_get_all_with_limit(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)

        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster1)

        events = db_api.event_get_all(self.ctx)
        self.assertEqual(3, len(events))

        events = db_api.event_get_all(self.ctx, limit=1)
        self.assertEqual(1, len(events))

        events = db_api.event_get_all(self.ctx, limit=2)
        self.assertEqual(2, len(events))
Пример #9
0
    def test_event_get_all_with_limit(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)

        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster1)

        events = db_api.event_get_all(self.ctx)
        self.assertEqual(3, len(events))

        events = db_api.event_get_all(self.ctx, limit=1)
        self.assertEqual(1, len(events))

        events = db_api.event_get_all(self.ctx, limit=2)
        self.assertEqual(2, len(events))
Пример #10
0
    def test_event_get_all_show_deleted(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)
        cluster2 = shared.create_cluster(self.ctx, self.profile)

        # Simulate deleted events by setting 'deleted_time' to not-None
        now = tu.utcnow()
        self.create_event(self.ctx, entity=cluster1, deleted_time=now)
        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster2, deleted_time=now)

        # Default show_deleted is False
        events = db_api.event_get_all(self.ctx)
        self.assertEqual(1, len(events))

        events = db_api.event_get_all(self.ctx, show_deleted=True)
        self.assertEqual(3, len(events))
Пример #11
0
    def test_event_get_all_admin_context(self):
        self.ctx.project = 'project_1'
        cluster1 = shared.create_cluster(self.ctx, self.profile,
                                         name='cluster1')
        self.create_event(self.ctx, entity=cluster1)
        self.ctx.project = 'project_2'
        cluster2 = shared.create_cluster(self.ctx, self.profile,
                                         name='cluster2')
        self.create_event(self.ctx, entity=cluster2, action='CLUSTER_CREATE')
        self.create_event(self.ctx, entity=cluster2, action='CLUSTER_DELETE')

        admin_ctx = utils.dummy_context(project='another-project',
                                        is_admin=True)
        events = db_api.event_get_all(admin_ctx, project_safe=True)
        self.assertEqual(0, len(events))
        events = db_api.event_get_all(admin_ctx, project_safe=False)
        self.assertEqual(3, len(events))
Пример #12
0
    def test_event_get_all(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)
        cluster2 = shared.create_cluster(self.ctx, self.profile)

        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster1)
        self.create_event(self.ctx, entity=cluster2)

        # Default project_safe
        events = db_api.event_get_all(self.ctx)
        self.assertEqual(3, len(events))

        cluster_ids = [event.obj_id for event in events]
        obj_names = [event.obj_name for event in events]

        self.assertIn(cluster1.id, cluster_ids)
        self.assertIn(cluster1.name, obj_names)
        self.assertIn(cluster2.id, cluster_ids)
        self.assertIn(cluster2.name, obj_names)

        # Set project_safe to false
        events = db_api.event_get_all(self.ctx, project_safe=False)
        self.assertEqual(3, len(events))
Пример #13
0
    def test_event_get_all_admin_context(self):
        self.ctx.project = 'project_1'
        cluster1 = shared.create_cluster(self.ctx, self.profile,
                                         name='cluster1')
        self.create_event(self.ctx, entity=cluster1)
        self.ctx.project = 'project_2'
        cluster2 = shared.create_cluster(self.ctx, self.profile,
                                         name='cluster2')
        self.create_event(self.ctx, entity=cluster2, action='CLUSTER_CREATE')
        self.create_event(self.ctx, entity=cluster2, action='CLUSTER_DELETE')

        admin_ctx = utils.dummy_context(project='another-project',
                                        is_admin=True)
        events = db_api.event_get_all(admin_ctx, project_safe=True)
        self.assertEqual(3, len(events))