示例#1
0
 def test_azure_create_report_with_static_data(self, mock_name):
     """Test the azure report creation method."""
     mock_name.side_effect = self.mock_generate_azure_filename
     now = datetime.datetime.now().replace(microsecond=0,
                                           second=0,
                                           minute=0,
                                           hour=0)
     one_day = datetime.timedelta(days=1)
     yesterday = now - one_day
     static_azure_data = {'generators': [
         {'BandwidthGenerator': {
             'start_date': str(yesterday.date()),
             'end_date': str(now.date()),
             }},
         {'SQLGenerator': { # usage outside current month
             'start_date': str(yesterday.date() + relativedelta(months=-2)),
             'end_date': str(now.date() + relativedelta(months=-2)),
             }},
         {'StorageGenerator': { # usage outside current month
             'start_date': str(yesterday.date() + relativedelta(months=+2)),
             'end_date': str(now.date() + relativedelta(months=+2)),
         }
         }]}
     options = {
         'start_date': yesterday,
         'end_date': now,
         'azure_prefix_name': 'cost_report',
         'azure_report_name': 'report',
         'azure_storage_name': 'cost',
         'static_report_data': static_azure_data
     }
     azure_create_report(options)
     local_path = self.MOCK_AZURE_REPORT_FILENAME
     self.assertTrue(os.path.isfile(local_path))
     os.remove(local_path)
示例#2
0
def run(provider_type, options):
    """Run nise."""
    LOG.info("Creating reports...")
    if provider_type == "aws":
        aws_create_report(options)
    elif provider_type == "azure":
        azure_create_report(options)
    elif provider_type == "ocp":
        ocp_create_report(options)
    elif provider_type == "gcp":
        gcp_create_report(options)
示例#3
0
 def test_azure_create_report(self, mock_name):
     """Test the azure report creation method."""
     mock_name.side_effect = self.mock_generate_azure_filename
     now = datetime.datetime.now().replace(microsecond=0,
                                           second=0,
                                           minute=0,
                                           hour=0)
     one_day = datetime.timedelta(days=1)
     yesterday = now - one_day
     options = {'start_date': yesterday, 'end_date': now}
     azure_create_report(options)
     local_path = self.MOCK_AZURE_REPORT_FILENAME
     self.assertTrue(os.path.isfile(local_path))
     os.remove(local_path)
示例#4
0
 def generate(self):
     """Create data and upload it to the necessary location."""
     options = {
         "start_date": self.start_date,
         "end_date": self.end_date,
         "azure_account_name": self.storage_account,
         "azure_container_name": self.storage_container,
         "azure_prefix_name": self.report_prefix,
         "azure_report_name": self.report_name,
     }
     if self.static_file:
         static_file_data = Source.obtain_static_file_data(
             self.static_file, self.start_date, self.end_date)
         options["static_report_data"] = static_file_data
     azure_create_report(options)
示例#5
0
def run(provider_type, options):
    """Run nise."""
    static_data_bool = _load_static_report_data(options)
    if not options.get("start_date"):
        raise NiseError("'start_date' is required in static files.")
    if not static_data_bool:
        fix_dates(options, provider_type)

    LOG.info("Creating reports...")
    if provider_type == "aws":
        aws_create_report(options)
    elif provider_type == "azure":
        azure_create_report(options)
    elif provider_type == "ocp":
        ocp_create_report(options)
    elif provider_type == "gcp":
        gcp_create_report(options)
示例#6
0
def main():
    """Run data generation program."""
    parser = create_parser()
    args = parser.parse_args()
    options = vars(args)
    _load_static_report_data(options)
    _, provider_type = _validate_provider_inputs(parser, options)
    if not options.get('start_date'):
        parser.error('the following arguments are required: --start-date')
    if provider_type == 'aws':
        aws_create_report(options)
    elif provider_type == 'azure':
        azure_create_report(options)
    elif provider_type == 'ocp':
        ocp_create_report(options)
    elif provider_type == 'gcp':
        gcp_create_report(options)
示例#7
0
 def test_azure_create_report_with_local_dir(self, mock_name):
     """Test the azure report creation method with local directory."""
     mock_name.side_effect = self.mock_generate_azure_filename
     now = datetime.datetime.now().replace(microsecond=0,
                                           second=0,
                                           minute=0,
                                           hour=0)
     one_day = datetime.timedelta(days=1)
     yesterday = now - one_day
     local_storage_path = mkdtemp()
     options = {
         'start_date': yesterday,
         'end_date': now,
         'azure_storage_name': local_storage_path,
         'azure_report_name': 'cur_report'
     }
     azure_create_report(options)
     expected_month_output_file = self.MOCK_AZURE_REPORT_FILENAME
     self.assertTrue(os.path.isfile(expected_month_output_file))
     os.remove(expected_month_output_file)
     shutil.rmtree(local_storage_path)
示例#8
0
 def test_azure_create_report_upload_to_azure(self, mock_name, mock_upload):
     """Test the azure upload is called when environment variable is set."""
     mock_name.side_effect = self.mock_generate_azure_filename
     mock_upload.return_value = True
     now = datetime.datetime.now().replace(microsecond=0,
                                           second=0,
                                           minute=0,
                                           hour=0)
     one_day = datetime.timedelta(days=1)
     yesterday = now - one_day
     local_storage_path = mkdtemp()
     options = {
         'start_date': yesterday,
         'end_date': now,
         'azure_prefic_name': 'prefix',
         'azure_container_name': local_storage_path,
         'azure_report_name': 'cur_report'
     }
     azure_create_report(options)
     mock_upload.assert_called()
     os.remove(self.MOCK_AZURE_REPORT_FILENAME)