Пример #1
0
 def test_ocp_create_report_with_local_dir(self):
     """Test the ocp report creation method with local directory."""
     now = datetime.datetime.now().replace(microsecond=0,
                                           second=0,
                                           minute=0,
                                           hour=0)
     one_day = datetime.timedelta(days=1)
     yesterday = now - one_day
     local_insights_upload = mkdtemp()
     cluster_id = '11112222'
     options = {
         'start_date': yesterday,
         'end_date': now,
         'insights_upload': local_insights_upload,
         'ocp_cluster_id': cluster_id
     }
     ocp_create_report(options)
     for report_type in OCP_REPORT_TYPE_TO_COLS.keys():
         month_output_file_name = '{}-{}-{}-{}'.format(
             calendar.month_name[now.month], now.year, cluster_id,
             report_type)
         expected_month_output_file = '{}/{}.csv'.format(
             os.getcwd(), month_output_file_name)
         self.assertTrue(os.path.isfile(expected_month_output_file))
         os.remove(expected_month_output_file)
     shutil.rmtree(local_insights_upload)
Пример #2
0
    def test_ocp_create_report_with_local_dir_static_generation_with_dates(
            self):
        """Test the ocp report creation method with local directory and static generation with usage dates."""
        now = datetime.datetime.now().replace(microsecond=0,
                                              second=0,
                                              minute=0)
        one_day = datetime.timedelta(days=1)
        yesterday = now - one_day
        local_insights_upload = mkdtemp()
        cluster_id = '11112222'
        static_ocp_data = {
            'generators': [{
                'OCPGenerator': {
                    'start_date':
                    str(yesterday.date()),
                    'end_date':
                    str(now.date()),
                    'nodes': [{
                        'node': None,
                        'node_name': 'alpha',
                        'cpu_cores': 2,
                        'memory_gig': 4,
                        'start_date': str(now),
                        'end_date': str(now),
                        'namespaces': {
                            'namespace_ci': {
                                'pods': [{
                                    'pod': None,
                                    'pod_name': 'pod_name1',
                                    'cpu_request': 5,
                                    'mem_request_gig': 2,
                                    'cpu_limit': 5,
                                    'mem_limit_gig': 2,
                                    'pod_seconds': 3600
                                }, {
                                    'pod': None,
                                    'pod_name': 'pod_name2',
                                    'cpu_request': 10,
                                    'mem_request_gig': 4,
                                    'cpu_limit': 10,
                                    'mem_limit_gig': 4
                                }],
                                'volumes': [{
                                    'volume':
                                    None,
                                    'volume_name':
                                    'pvc-1234',
                                    'storage_class':
                                    'gp2',
                                    'volume_request_gig':
                                    20,
                                    'volume_claims': [{
                                        'volume_claim_name': 'pod1_data',
                                        'pod_name': 'pod_name1',
                                        'capacity_gig': 5
                                    }]
                                }]
                            }
                        }
                    }]
                }
            }]
        }
        options = {
            'start_date': yesterday,
            'end_date': now,
            'insights_upload': local_insights_upload,
            'ocp_cluster_id': cluster_id,
            'static_report_data': static_ocp_data
        }
        ocp_create_report(options)

        for report_type in OCP_REPORT_TYPE_TO_COLS.keys():
            month_output_file_name = '{}-{}-{}-{}'.format(
                calendar.month_name[now.month], now.year, cluster_id,
                report_type)
            expected_month_output_file = '{}/{}.csv'.format(
                os.getcwd(), month_output_file_name)
            self.assertTrue(os.path.isfile(expected_month_output_file))
            os.remove(expected_month_output_file)

        shutil.rmtree(local_insights_upload)