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

Use an artifact server for hosting the logo images. #2111

Closed
wants to merge 13 commits into from
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions galaxy_ng/app/api/v3/serializers/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def create(self, validated_data):

instance.links.set(new_links)

dispatch_create_pulp_namespace_metadata(instance, True)
taskid = dispatch_create_pulp_namespace_metadata(instance, True)
print(f'DISPATCHED [create] create pulp namespace metadata as {taskid.pulp_id}')
return instance

@transaction.atomic
Expand All @@ -156,7 +157,8 @@ def update(self, instance, validated_data):

instance = super().update(instance, validated_data)
instance.save()
dispatch_create_pulp_namespace_metadata(instance, download_logo)
taskid = dispatch_create_pulp_namespace_metadata(instance, download_logo)
print(f'DISPATCHED [update] create pulp namespace metadata as {taskid.pulp_id}')
return instance


Expand Down
37 changes: 33 additions & 4 deletions galaxy_ng/app/tasks/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from pulpcore.plugin.download import HttpDownloader

from pulp_ansible.app.models import AnsibleNamespaceMetadata, AnsibleNamespace
from pulp_ansible.app.models import AnsibleNamespaceMetadata, AnsibleNamespace, AnsibleRepository
from pulpcore.plugin.tasking import add_and_remove, dispatch
from pulpcore.plugin.models import RepositoryContent, Artifact, ContentArtifact

Expand All @@ -22,7 +22,9 @@

def dispatch_create_pulp_namespace_metadata(galaxy_ns, download_logo):

dispatch(
#raise Exception('FUCK YOU')

return dispatch(
_create_pulp_namespace,
kwargs={
"galaxy_ns_pk": galaxy_ns.pk,
Expand Down Expand Up @@ -84,12 +86,19 @@ def _download_avatar(url, namespace_name):


def _create_pulp_namespace(galaxy_ns_pk, download_logo):

print('*' * 100)
print(f'CREATE PULP NAMESPACE START')
print('*' * 100)
#raise Exception('FUCK YOU')

# get metadata values
galaxy_ns = Namespace.objects.get(pk=galaxy_ns_pk)
links = {x.name: x.url for x in galaxy_ns.links.all()}

avatar_artifact = None

print(f'call _download_avatar')
if download_logo:
avatar_artifact = _download_avatar(galaxy_ns._avatar_url, galaxy_ns.name)

Expand All @@ -108,20 +117,25 @@ def _create_pulp_namespace(galaxy_ns_pk, download_logo):
}

namespace_data["name"] = galaxy_ns.name
print('get or create ansiblenamespace')
namespace, created = AnsibleNamespace.objects.get_or_create(name=namespace_data["name"])
metadata = AnsibleNamespaceMetadata(namespace=namespace, **namespace_data)
print('calculate sha256')
metadata.calculate_metadata_sha256()
print('filter for matching metadata objects')
content = AnsibleNamespaceMetadata.objects.filter(
metadata_sha256=metadata.metadata_sha256
).first()

# If the metadata already exists, don't do anything
if content:
print(f'skip altering namespace')
content.touch()
galaxy_ns.last_created_pulp_metadata = content
galaxy_ns.save()

else:
print('create contentartifact')
with transaction.atomic():
metadata.save()
ContentArtifact.objects.create(
Expand Down Expand Up @@ -149,21 +163,36 @@ def _create_pulp_namespace(galaxy_ns_pk, download_logo):
)

repos = [x.repository for x in repo_content_qs]
if not repos:
repos.append(AnsibleRepository.objects.filter(name='published').first())

return dispatch(
'''
print(f'DISPATCH _add_namespace_metadata_to_repos ...')
dtask = dispatch(
_add_namespace_metadata_to_repos,
kwargs={
"namespace_pk": metadata.pk,
"repo_list": [x.pk for x in repos],
},
exclusive_resources=repos
)
print(f'DISPATCHED _add_namespace_metadata_to_repos as {dtask.pulp_id}')
return dtask
'''

_add_namespace_metadata_to_repos(metadata.pk, [x.pk for x in repos])


def _add_namespace_metadata_to_repos(namespace_pk, repo_list):

print('*' * 100)
print(f'ADD NAMESPACE METADATA TO REPOS START {repo_list}')
print('*' * 100)

for pk in repo_list:
add_and_remove(
dtask = add_and_remove(
pk,
add_content_units=[namespace_pk, ],
remove_content_units=[]
)
print(f'CALLED ADD_AND_REMOVE ON repo:{pk} ns:{namespace_pk} AS {dtask}')
47 changes: 41 additions & 6 deletions galaxy_ng/tests/integration/api/test_namespace_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from time import sleep

import pytest
import socket

from galaxykit.namespaces import get_namespace, get_namespace_collections
from galaxykit.repositories import search_collection
Expand Down Expand Up @@ -147,36 +148,70 @@ def test_namespace_edit_with_user(galaxy_client, user_property):
@pytest.mark.all
@pytest.mark.min_hub_version("4.9dev")
def test_namespace_edit_logo(galaxy_client):

# short hostnames don't pass serializer validation
# dns resoultion with aiohttp is wonky so we need to use the IP
artifacts_ip = socket.gethostbyname("artifacts")
artifacts_baseurl = f'http://{artifacts_ip}'

gc = galaxy_client("admin")
new_namespace = f"ns_test_{generate_random_string()}"
payload = {
'name': new_namespace,
}
my_namespace = gc.post("_ui/v1/my-namespaces/", body=payload)

wait_for_all_tasks_gk(gc)
# print('sleep 60')
sleep(60)
wait_for_all_tasks_gk(gc)

for x in range(0, 100):
my_namespace = gc.get(f'_ui/v1/my-namespaces/{new_namespace}/')
if my_namespace["avatar_url"] == "":
break
sleep(5)

assert my_namespace["avatar_url"] == ''
# import epdb; epdb.st()

namespaces = gc.get('_ui/v1/my-namespaces/')
name = my_namespace["name"]

payload = {
"name": name,
# "avatar_url": "http://placekitten.com/400/400"
"avatar_url": "https://avatars.githubusercontent.com/u/1869705?v=4"
"avatar_url": f"{artifacts_baseurl}/images/pexels-daniel-nettesheim-1162361.jpg"
}
gc.put(f"_ui/v1/my-namespaces/{name}/", body=payload)
# sleep(60)
wait_for_all_tasks_gk(gc)
sleep(60)
wait_for_all_tasks_gk(gc)
updated_namespace = gc.get(f'_ui/v1/my-namespaces/{name}/')

for x in range(0, 100):
updated_namespace = gc.get(f'_ui/v1/my-namespaces/{name}/')
if updated_namespace["avatar_url"] != "":
break
sleep(5)

assert updated_namespace["avatar_url"] != ""

payload = {
"name": name,
# "avatar_url": "http://placekitten.com/123/456"
"avatar_url": "https://avatars.githubusercontent.com/u/481677?v=4"
"avatar_url": f"{artifacts_baseurl}/images/pexels-viktoria-goda-1107495.jpg"
}
gc.put(f"_ui/v1/my-namespaces/{name}/", body=payload)
wait_for_all_tasks_gk(gc)
updated_again_namespace = gc.get(f"_ui/v1/my-namespaces/{name}/")
sleep(60)
wait_for_all_tasks_gk(gc)

for x in range(0, 20):
updated_again_namespace = gc.get(f"_ui/v1/my-namespaces/{name}/")
if updated_namespace["avatar_url"] != updated_again_namespace["avatar_url"] and \
updated_namespace["avatar_sha256"] is not None:
break
sleep(5)

assert updated_namespace["avatar_url"] != updated_again_namespace["avatar_url"]
assert updated_namespace["avatar_sha256"] is not None

Expand Down
16 changes: 16 additions & 0 deletions galaxy_ng/tests/integration/utils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ def wait_for_all_tasks_gk(gc, timeout=300):
while not ready:
if wait_until < time.time():
raise TaskWaitingTimeout()

next_url = "pulp/api/v3/tasks/"
while next_url:
resp = gc.get(next_url)

for res in resp['results']:
if res['state'] != 'completed':
print(f"{res['pulp_href']} {res['state']}")

if not resp['next']:
break

next_url = resp['next']
ix = next_url.index("pulp/api/v3/tasks/")
next_url = next_url[ix:]

running_count = gc.get("pulp/api/v3/tasks/?state=running")["count"]
waiting_count = gc.get("pulp/api/v3/tasks/?state=waiting")["count"]
ready = running_count == 0 and waiting_count == 0
Expand Down
7 changes: 7 additions & 0 deletions profiles/base/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ services:
image: "localhost/oci_env/galaxy_ng:base"
entrypoint: "/bin/true"

artifacts:
image: nginx:latest
hostname: artifacts
domainname: test777.com
volumes:
- '{SRC_DIR}/galaxy_ng/dev/test_artifacts:/usr/share/nginx/html'

pulp:
image: "localhost/oci_env/galaxy_ng:base"
# this is required in order to run podman inside the container
Expand Down
6 changes: 5 additions & 1 deletion profiles/base/run_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ cd /src/galaxy_ng/
# echo $MARKS


cat /proc/cpuinfo | grep processor
free -m


# TODO: fix marks
set -x

$VENVPATH/bin/pytest -v -r sx --color=yes -m "$HUB_TEST_MARKS" "$@" galaxy_ng/tests/integration
export PYTHONUNBUFFERED=1
$VENVPATH/bin/pytest -v -r sx --capture=no --color=yes -m "$HUB_TEST_MARKS" -k edit_logo "$@" galaxy_ng/tests/integration
RC=$?

exit $RC
Loading