Skip to content

Commit

Permalink
Fix component purls empty issue (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchuntao authored May 10, 2023
1 parent 606e2d7 commit 73e4a72
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
7 changes: 5 additions & 2 deletions openlcs/openlcs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,11 @@
EMAIL_REALM = 'REDHAT.COM'

# Give superuser permission to these users.
OPENLCS_ADMIN_LIST = ['jzhao', 'yuwang', 'huiwang', 'qduanmu', 'yulwang',
'chhan', 'wbu', 'axuan']
OPENLCS_ADMIN_LIST = [
'jzhao', 'yuwang', 'huiwang', 'qduanmu', 'yulwang', 'chhan', 'axuan',
'openlcs-dev-worker01', 'openlcs-qe-worker01', 'openlcs-ci-worker01',
'openlcs-stage-worker01', 'openlcs-prod-worker01'
]

# CSRF setting
# https://docs.djangoproject.com/zh-hans/3.2/ref/settings/#csrf-cookie-domain
Expand Down
21 changes: 15 additions & 6 deletions openlcsd/flow/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def get_config(context, engine):
config = resp.json()
except RuntimeError as err:
err_msg = f'Failed to get config data. Reason: {err}'
engine.logger.error(err_msg)
raise RuntimeError(err_msg) from None
# One-time file based logger configuration for each task.
logger_dir = config.get("LOGGER_DIR")
Expand Down Expand Up @@ -972,7 +973,9 @@ def save_scan_result(context, engine):
def sync_result_to_corgi(context, engine):
component = context.get("component")
if not component:
raise RuntimeError("Missing component in request!")
err_msg = "Missing component in request!"
engine.logger.error(err_msg)
raise RuntimeError(err_msg)
client = context['client']
olcs_component_api_url = client.get_abs_url("components")
component_uuid = component["uuid"]
Expand All @@ -984,8 +987,10 @@ def sync_result_to_corgi(context, engine):
# exceptions, the non-existent component makes it impossible to mark
# the sync as failed.
if not results:
raise RuntimeError(f"Failed to sync data to corgi, component "
f"{component_uuid} not found in OpenLCS.")
err_msg = (f"Failed to sync data to corgi, component "
f"{component_uuid} not found in OpenLCS.")
engine.logger.error(err_msg)
raise RuntimeError(err_msg)
olcs_component = results[0]
# Each component has one identical source.
source = olcs_component["source"]
Expand Down Expand Up @@ -1552,13 +1557,17 @@ def populate_subscription_purls(context, engine):
else:
subscription_purl_set.add(component["purl"])
client = context["client"]
client.patch(
resp = client.patch(
f"subscriptions/{subscription_id}",
data={
"component_purls": list(subscription_purl_set),
"missing_components": missings
}
)
if resp.status_code != HTTPStatus.OK:
err_msg = f'Failed to populate subscription purls: {resp.json()}'
engine.logger.error(err_msg)
raise RuntimeError(err_msg) from None
engine.logger.debug(
f"Populated purls for subscription {subscription_id}")

Expand Down Expand Up @@ -1590,15 +1599,15 @@ def trigger_corgi_components_imports(context, engine):
Trigger fork tasks directly using Corgi source.
"""
# set corgi source forked task medium priority
engine.logger.info("Start to trigger Corgi componnet import.")
engine.logger.info("Start to trigger Corgi component import.")
context['priority'] = "medium"
corgi_sources = context.get('corgi_sources')
for corgi_source in corgi_sources:
if parent := corgi_source.get('parent'):
parent_uuid = parent.get('uuid')
else:
parent_uuid = None
# Only fork for components without a openlcs_scan_url
# Only fork for components without an openlcs_scan_url
components = corgi_source.get('components')
scan_components = []
for comp in components:
Expand Down
9 changes: 4 additions & 5 deletions tests/functional/api/test_componentsubscription.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from django.test import TestCase
from django.urls import reverse
from rest_framework import status
import pytest

from packages.models import ComponentSubscription

Expand All @@ -15,6 +12,7 @@ def test_list_subscription(openlcs_client):
assert response["count"] == 2
assert response["results"][0]["name"] == 'ansible_automation_platform:2.2'


def test_create_subscription(openlcs_client):
subscription_name = "mock_subscription"
response = openlcs_client.api_call(
Expand All @@ -30,16 +28,17 @@ def test_create_subscription(openlcs_client):
assert instance.name == subscription_name
assert instance.query_params == {"arch": "src"}


def test_patch_subscription(openlcs_client):
data = dict()
data['name'] = 'test_subscription_updated'
data['active'] = False
response = openlcs_client.api_call(
openlcs_client.api_call(
"/subscriptions/2/",
method="PATCH",
data=data,
expected_code=status.HTTP_200_OK
)
instance = ComponentSubscription.objects.get(pk=2)
assert instance.name == 'test_subscription_updated'
assert instance.active == False
assert instance.active is False

0 comments on commit 73e4a72

Please sign in to comment.