Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAP-39220 : Run ccspv2 build_report outside awx #51

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions metrics_utility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def manage():
sys.path.append(awx_path)
spec = importlib.util.find_spec('awx')
if spec is None:
sys.stderr.write(f"Automation Controller modules not found in {awx_path}\n")
exit(1)
sys.stderr.write(f"Automation Controller modules not found in {awx_path} (AWX_PATH). Using mock and continuing.\n")
sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'mock_awx')))

import django
from awx import prepare_env
Expand Down
17 changes: 13 additions & 4 deletions metrics_utility/automation_controller_billing/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import json
import logging

import importlib.util

import insights_analytics_collector as base
from awx.main.utils import datetime_hook
from awx.main.utils.pglock import advisory_lock
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
from django.db import connection
Expand All @@ -13,8 +13,17 @@
# from awx.main.models import Job
# from awx.main.access import access_registry
# from rest_framework.exceptions import PermissionDenied
from metrics_utility.automation_controller_billing.package.factory import \
Factory as PackageFactory

from metrics_utility.automation_controller_billing.package.factory import Factory as PackageFactory

from awx.main.utils import datetime_hook

if importlib.util.find_spec('ansible_base') is None:
# 2.4
from awx.main.utils.pglock import advisory_lock
else:
# 2.5
from ansible_base.lib.utils.db import advisory_lock

logger = logging.getLogger('metrics_utility.collector')

Expand Down
4 changes: 4 additions & 0 deletions mock_awx/awx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

def prepare_env():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
19 changes: 19 additions & 0 deletions mock_awx/awx/main/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.utils.dateparse import parse_datetime

def get_awx_version():
"24.6.123"

def get_awx_http_client_headers():
return {
'Content-Type': 'application/json',
'User-Agent': '{} {} ({})'.format('Red Hat Ansible Automation Platform', get_awx_version(), 'UNLICENSED'),
}

def datetime_hook(d):
new_d = {}
for key, value in d.items():
try:
new_d[key] = parse_datetime(value)
except TypeError:
new_d[key] = value
return new_d
Empty file added mock_awx/settings/__init__.py
Empty file.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies = [
"botocore==1.35.96",
"distro==1.9.0",
"django==4.2.16",
"django-ansible-base>=2025.1.3",
"insights-analytics-collector==0.3.2",
"openpyxl==3.1.2",
"pandas==2.2.1",
Expand Down
23 changes: 23 additions & 0 deletions run-ccsp2-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
set -e

export METRICS_UTILITY_PRICE_PER_NODE=11.55 # in USD
export METRICS_UTILITY_REPORT_COMPANY_NAME="Partner A"
export METRICS_UTILITY_REPORT_EMAIL="[email protected]"
export METRICS_UTILITY_REPORT_END_USER_CITY="Springfield"
export METRICS_UTILITY_REPORT_END_USER_COMPANY_NAME="Customer A"
export METRICS_UTILITY_REPORT_END_USER_COUNTRY="US"
export METRICS_UTILITY_REPORT_END_USER_STATE="TX"
export METRICS_UTILITY_REPORT_H1_HEADING="CCSP NA Direct Reporting Template"
export METRICS_UTILITY_REPORT_PO_NUMBER="123"
export METRICS_UTILITY_REPORT_RHN_LOGIN="test_login"
export METRICS_UTILITY_REPORT_SKU="MCT3752MO"
export METRICS_UTILITY_REPORT_SKU_DESCRIPTION="EX: Red Hat Ansible Automation Platform, Full Support (1 Managed Node, Dedicated, Monthly)"
export METRICS_UTILITY_REPORT_TYPE="CCSPv2"
export METRICS_UTILITY_SHIP_PATH=./metrics_utility/test/test_data/
export METRICS_UTILITY_SHIP_TARGET=directory

uv run ./manage.py build_report --month=2024-04 --force "$@"

set -x
ls -l metrics_utility/test/test_data/reports/2024/04/
147 changes: 147 additions & 0 deletions uv.lock

Large diffs are not rendered by default.