Ejemplo n.º 1
0
    def test_stat_history(self, *args):
        history_vos = HistoryFactory.build_batch(10, domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), history_vos))

        params = {
            'domain_id': self.domain_id,
            'topic': history_vos[0].topic,
            'query': {
                'aggregate': [{
                    'group': {
                        'keys': [{
                            'key': 'created_at',
                            'name': 'Created At'
                        }],
                        'fields': [{
                            'operator': 'count',
                            'name': 'Count'
                        }]
                    }
                }, {
                    'sort': {
                        'key': 'Count',
                        'desc': True
                    }
                }]
            }
        }

        self.transaction.method = 'stat'
        history_svc = HistoryService(transaction=self.transaction)
        values = history_svc.stat(params)
        StatisticsInfo(values)

        print_data(values, 'test_stat_history')
Ejemplo n.º 2
0
    def test_stat_schedule(self, *args):
        schedule_vos = ScheduleFactory.build_batch(10,
                                                   domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), schedule_vos))

        params = {
            'domain_id': self.domain_id,
            'query': {
                'aggregate': [{
                    'group': {
                        'keys': [{
                            'key': 'schedule_id',
                            'name': 'Id'
                        }],
                        'fields': [{
                            'operator': 'count',
                            'name': 'Count'
                        }]
                    }
                }, {
                    'sort': {
                        'key': 'Count',
                        'desc': True
                    }
                }]
            }
        }

        self.transaction.method = 'stat'
        schedule_svc = ScheduleService(transaction=self.transaction)
        values = schedule_svc.stat(params)
        StatisticsInfo(values)

        print_data(values, 'test_stat_schedule')
Ejemplo n.º 3
0
    def test_resource_stat_distinct(self, mock_stat_resource, *args):
        mock_stat_resource.side_effect = [{
            'results': [
                utils.generate_id('project'),
                utils.generate_id('project'),
                utils.generate_id('project'),
                utils.generate_id('project'),
                utils.generate_id('project')
            ],
            'total_count':
            24
        }]

        params = {
            'resource_type': 'identity.Project',
            'query': {
                'distinct': 'project_id',
                'page': {
                    'start': 5,
                    'limit': 5
                }
            },
            'domain_id': utils.generate_id('domain')
        }

        self.transaction.method = 'stat'
        resource_svc = ResourceService(transaction=self.transaction)
        results = resource_svc.stat(params.copy())

        print_data(results, 'test_resource_stat_distinct')
        StatisticsInfo(results)
Ejemplo n.º 4
0
    def test_resource_stat_index_join_wrong_index(self, mock_stat_resource,
                                                  *args):
        mock_stat_resource.side_effect = [{
            'results': []
        }, {
            'results': [{
                'fail_count': 0
            }]
        }]

        params = {
            'resource_type':
            'inventory.Job',
            'query': {
                'filter': [{
                    'key': 'state',
                    'value': 'SUCCESS',
                    'operator': 'eq'
                }],
                'aggregate': {
                    'count': {
                        'name': 'success_count'
                    }
                }
            },
            'join': [{
                'type': 'OUTER',
                'resource_type': 'inventory.Jon',
                'query': {
                    'filter': [{
                        'key': 'state',
                        'value': 'FAILURE',
                        'operator': 'eq'
                    }],
                    'aggregate': {
                        'count': {
                            'name': 'fail_count'
                        }
                    }
                }
            }],
            'domain_id':
            utils.generate_id('domain')
        }

        self.transaction.method = 'stat'
        resource_svc = ResourceService(transaction=self.transaction)
        results = resource_svc.stat(params.copy())

        print_data(results, 'test_resource_stat_index_join_wrong_index')
        StatisticsInfo(results)
Ejemplo n.º 5
0
    def test_stat_history_distinct(self, *args):
        history_vos = HistoryFactory.build_batch(10, domain_id=self.domain_id)
        list(map(lambda vo: vo.save(), history_vos))

        params = {
            'domain_id': self.domain_id,
            'topic': history_vos[0].topic,
            'query': {
                'distinct': 'topic'
            }
        }

        self.transaction.method = 'stat'
        history_svc = HistoryService(transaction=self.transaction)
        values = history_svc.stat(params)
        StatisticsInfo(values)

        print_data(values, 'test_stat_history_distinct')
Ejemplo n.º 6
0
    def test_resource_stat_join_and_formula(self, mock_stat_resource, *args):
        mock_stat_resource.side_effect = [
            {
                'results': [{
                    'project_id': 'project-123',
                    'project_name': 'ncsoft'
                }, {
                    'project_id': 'project-456',
                    'project_name': 'nexon'
                }, {
                    'project_id': 'project-789',
                    'project_name': 'netmarble'
                }]
            }, {
                'results': [{
                    'project_id': 'project-123',
                    'server_count': 100
                }, {
                    'project_id': 'project-456',
                    'server_count': 65
                }, {
                    'project_id': 'project-789',
                    'server_count': 77
                }]
            }, {
                'results': [{
                    'project_id': 'project-123',
                    'cloud_service_count': 45
                }, {
                    'project_id': 'project-456',
                    'cloud_service_count': 87
                }, {
                    'project_id': 'project-789',
                    'cloud_service_count': 104
                }]
            }
        ]

        params = {
            'aggregate': [
                {
                    'query': {
                        'resource_type': 'identity.Project',
                        'query': {
                            'aggregate': [
                                {
                                    'group': {
                                        'keys': [
                                            {
                                                'key': 'project_id',
                                                'name': 'project_id'
                                            },
                                            {
                                                'key': 'name',
                                                'name': 'project_name'
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                },
                {
                    'join': {
                        'resource_type': 'inventory.Server',
                        'type': 'LEFT',
                        'keys': ['project_id'],
                        'query': {
                            'aggregate': [
                                {
                                    'group': {
                                        'keys': [
                                            {
                                                'key': 'project_id',
                                                'name': 'project_id'
                                            }
                                        ],
                                        'fields': [
                                            {
                                                'operator': 'count',
                                                'name': 'server_count'
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                },
                {
                    'join': {
                        'resource_type': 'inventory.CloudService',
                        'type': 'LEFT',
                        'keys': ['project_id'],
                        'query': {
                            'aggregate': [
                                {
                                    'group': {
                                        'keys': [
                                            {
                                                'key': 'project_id',
                                                'name': 'project_id'
                                            }
                                        ],
                                        'fields': [
                                            {
                                                'operator': 'count',
                                                'name': 'cloud_service_count'
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                },
                {
                    'formula': {
                        'eval': 'resource_count = server_count + cloud_service_count'
                    }
                },
                {
                    'sort': {
                        'key': 'resource_count',
                        'desc': True
                    }
                }
            ],
            'page': {
                'limit': 5
            },
            'domain_id': utils.generate_id('domain')
        }

        self.transaction.method = 'stat'
        resource_svc = ResourceService(transaction=self.transaction)
        results = resource_svc.stat(params.copy())

        print_data(results, 'test_resource_stat_join_and_formula')
        StatisticsInfo(results)
Ejemplo n.º 7
0
    def test_resource_stat_empty_join(self, mock_stat_resource, *args):
        mock_stat_resource.side_effect = [
            {
                'results': [{
                    'project_id': 'project-123',
                    'project_name': 'ncsoft',
                    'project_group_name': 'game'
                }, {
                    'project_id': 'project-456',
                    'project_name': 'nexon',
                    'project_group_name': 'game'
                }, {
                    'project_id': 'project-789',
                    'project_name': 'netmarble',
                    'project_group_name': 'game'
                }]
            }, {
                'results': []
            }
        ]

        params = {
            'aggregate': [
                {
                    'query': {
                        'resource_type': 'identity.Project',
                        'query': {
                            'aggregate': [
                                {
                                    'group': {
                                        'keys': [
                                            {
                                                'key': 'project_id',
                                                'name': 'project_id'
                                            },
                                            {
                                                'key': 'name',
                                                'name': 'project_name'
                                            }
                                        ],
                                        'fields': []
                                    }
                                }
                            ]
                        }
                    }
                },
                {
                    'join': {
                        'resource_type': 'inventory.Server',
                        'keys': ['project_id'],
                        'query': {
                            'aggregate': [
                                {
                                    'group': {
                                        'keys': [
                                            {
                                                'key': 'project_id',
                                                'name': 'project_id'
                                            }
                                        ],
                                        'fields': [
                                            {
                                                'operator': 'count',
                                                'name': 'server_count'
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                }
            ],
            'page': {
                'start': 2,
                'limit': 1
            },
            'domain_id': utils.generate_id('domain')
        }

        self.transaction.method = 'stat'
        resource_svc = ResourceService(transaction=self.transaction)
        results = resource_svc.stat(params.copy())

        print_data(results, 'test_resource_stat_empty_join')
        StatisticsInfo(results)