Skip to content

Commit

Permalink
Backport #1069 (#1084)
Browse files Browse the repository at this point in the history
* Backport ed72e26 (#993)

* Refactoring + speeding up tests (#1002)

* Replace pulp.pulp_installer with pulp.squeezer to speed upload test

ansible-lint takes too much time on pulp.pulp_installer,
using pulp.squeezer to get a faster test

* Refactor functional tests

No-Issue

(cherry picked from commit 24f28be)

* Allow functional test configuration of URL and PASSWORD (#1026)

Issue: AAH-1015
(cherry picked from commit ab38653)

* Test Container Repository Tags endpoint (#1032)

* Add functional test for Container Repository Tags endpoint
Issue: AAH-906

(cherry picked from commit ada466b)

* Enable azure test at nightly latest workflow (#1005)

* Enable azure test at nightly latest workflow

No-Issue

(cherry picked from commit 7c6643e)

* Add functional tests for manifest lists (#1047)

* Add functional tests for AAH-964

Issue: AAH-964

* add cleanups

(cherry picked from commit 2a492fb)

* Backport e74ea6b (#1069)

* Move container test to api dir (#1035)

No-Issue

(cherry picked from commit 3bc4d42)

Co-authored-by: Fabricio Aguiar <[email protected]>
Co-authored-by: Bruno Rocha <[email protected]>
Co-authored-by: Brian McLaughlin <[email protected]>
  • Loading branch information
4 people authored Dec 15, 2021
1 parent b7b830d commit a0d7008
Show file tree
Hide file tree
Showing 32 changed files with 601 additions and 424 deletions.
1 change: 1 addition & 0 deletions .github/workflows/nightly_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
matrix:
env:
- TEST: pulp
- TEST: azure
- TEST: s3

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ VARSYAML
fi

cat >> vars/main.yaml << VARSYAML
pulp_settings: {"allowed_export_paths": "/tmp", "allowed_import_paths": "/tmp", "rh_entitlement_required": "insights"}
pulp_settings: {"allowed_export_paths": "/tmp", "allowed_import_paths": "/tmp", "galaxy_api_default_distribution_base_path": "published", "galaxy_enable_api_access_log": true, "galaxy_require_content_approval": false, "rh_entitlement_required": "insights"}
pulp_scheme: https
pulp_container_tag: https
Expand Down
1 change: 1 addition & 0 deletions CHANGES/1015.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make functional test URL and PASSWORD customizable
1 change: 1 addition & 0 deletions functest_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
git+https://github.com/pulp/pulp-smash.git#egg=pulp-smash
pulp-container>=2.8.0,<2.9.0
pytest
orionutils
9 changes: 9 additions & 0 deletions galaxy_ng/app/access_control/access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class CollectionAccessPolicy(UnauthenticatedCollectionAccessMixin, AccessPolicyB
NAME = 'CollectionViewSet'

def can_update_collection(self, request, view, permission):
if getattr(self, "swagger_fake_view", False):
# If OpenAPI schema is requested, don't check for update permissions
return False
collection = view.get_object()
namespace = models.Namespace.objects.get(name=collection.namespace)
return request.user.has_perm('galaxy.upload_to_namespace', namespace)
Expand All @@ -96,10 +99,16 @@ class UserAccessPolicy(AccessPolicyBase):
NAME = 'UserViewSet'

def user_is_superuser(self, request, view, action):
if getattr(self, "swagger_fake_view", False):
# If OpenAPI schema is requested, don't check for superuser
return False
user = view.get_object()
return user.is_superuser

def is_current_user(self, request, view, action):
if getattr(self, "swagger_fake_view", False):
# If OpenAPI schema is requested, don't check for current user
return False
return request.user == view.get_object()


Expand Down
73 changes: 0 additions & 73 deletions galaxy_ng/app/api/pagination.py

This file was deleted.

7 changes: 7 additions & 0 deletions galaxy_ng/app/api/ui/serializers/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
AnsibleDistribution,
CollectionVersion,
)
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
import semantic_version

Expand Down Expand Up @@ -57,6 +58,7 @@ class CollectionMetadataSerializer(Serializer):
license = serializers.ListField(serializers.CharField())
tags = serializers.SerializerMethodField()

@extend_schema_field(serializers.ListField)
def get_tags(self, collection_version):
# TODO(awcrosby): remove when galaxy_pulp no longer used in _ui
if isinstance(collection_version, dict):
Expand All @@ -78,6 +80,7 @@ class CollectionVersionBaseSerializer(Serializer):
class CollectionVersionSerializer(CollectionVersionBaseSerializer):
repository_list = serializers.SerializerMethodField()

@extend_schema_field(serializers.ListField)
def get_repository_list(self, collection_version):
"""Repository list where content is in the latest RepositoryVersion."""

Expand Down Expand Up @@ -114,6 +117,7 @@ class _CollectionSerializer(Serializer):
download_count = serializers.IntegerField(default=0)
latest_version = serializers.SerializerMethodField()

@extend_schema_field(NamespaceSummarySerializer)
def get_namespace(self, obj):
namespace = Namespace.objects.get(name=obj.namespace)
return NamespaceSummarySerializer(namespace).data
Expand All @@ -122,6 +126,7 @@ def get_namespace(self, obj):
class CollectionListSerializer(_CollectionSerializer):
deprecated = serializers.BooleanField()

@extend_schema_field(CollectionVersionBaseSerializer)
def get_latest_version(self, obj):
return CollectionVersionBaseSerializer(obj).data

Expand All @@ -131,9 +136,11 @@ class CollectionDetailSerializer(_CollectionSerializer):

# TODO: rename field to "version_details" since with
# "version" query param this won't always be the latest version
@extend_schema_field(CollectionVersionDetailSerializer)
def get_latest_version(self, obj):
return CollectionVersionDetailSerializer(obj).data

@extend_schema_field(CollectionVersionSummarySerializer(many=True))
def get_all_versions(self, obj):
path = self.context['request'].parser_context['kwargs']['path']
distro = AnsibleDistribution.objects.get(base_path=path)
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/app/api/ui/serializers/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meta:
'content_count'
)

def get_content_count(self, repo):
def get_content_count(self, repo) -> int:
return repo.latest_version().content.count()


Expand Down
18 changes: 16 additions & 2 deletions galaxy_ng/app/api/ui/serializers/execution_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from django.core import exceptions
from django.db import transaction
from django.utils.translation import gettext_lazy as _
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema_field

from guardian.shortcuts import get_users_with_perms

Expand Down Expand Up @@ -34,6 +36,7 @@ class Meta:
"my_permissions",
)

@extend_schema_field(serializers.ListField)
def get_owners(self, namespace):
return get_users_with_perms(namespace, with_group_users=False).values_list(
"username", flat=True
Expand Down Expand Up @@ -80,18 +83,22 @@ class Meta:

fields = read_only_fields

def get_namespace(self, distro):
def get_namespace(self, distro) -> str:
return distro.namespace.name

@extend_schema_field(OpenApiTypes.UUID)
def get_id(self, distro):
return distro.pk

@extend_schema_field(OpenApiTypes.DATETIME)
def get_created(self, distro):
return distro.repository.pulp_created

@extend_schema_field(OpenApiTypes.DATETIME)
def get_updated(self, distro):
return distro.repository.pulp_last_updated

@extend_schema_field(OpenApiTypes.OBJECT)
def get_pulp(self, distro):
repo = distro.repository
remote = None
Expand Down Expand Up @@ -158,6 +165,7 @@ class Meta:
"image_manifests"
)

@extend_schema_field(OpenApiTypes.OBJECT)
def get_layers(self, obj):
layers = []
# use the prefetched blob_list and artifact_list instead of obj.blobs and
Expand All @@ -170,11 +178,13 @@ def get_layers(self, obj):
)
return layers

@extend_schema_field(OpenApiTypes.OBJECT)
def get_config_blob(self, obj):
if not obj.config_blob:
return {}
return {"digest": obj.config_blob.digest, "media_type": obj.config_blob.media_type}

@extend_schema_field(serializers.ListField)
def get_tags(self, obj):
tags = []
# tagget_manifests returns all tags on the manifest, not just the ones
Expand Down Expand Up @@ -211,6 +221,7 @@ class Meta:


class ContainerManifestDetailSerializer(ContainerManifestSerializer):
@extend_schema_field(OpenApiTypes.OBJECT)
def get_config_blob(self, obj):
with obj.config_blob._artifacts.first().file.open() as f:
config_json = json.load(f)
Expand All @@ -230,9 +241,11 @@ class Meta:
model = core_models.RepositoryVersion
fields = ("pulp_id", "added", "removed", "pulp_created", "number")

@extend_schema_field(serializers.ListField(child=serializers.JSONField()))
def get_added(self, obj):
return [self._content_info(content.content) for content in obj.added_memberships.all()]

@extend_schema_field(serializers.ListField(child=serializers.JSONField()))
def get_removed(self, obj):
return [self._content_info(content.content) for content in obj.removed_memberships.all()]

Expand Down Expand Up @@ -309,10 +322,11 @@ class Meta:
'client_key': {'write_only': True},
}

@extend_schema_field(serializers.ListField)
def get_write_only_fields(self, obj):
return utils.get_write_only_fields(self, obj)

def get_is_indexable(self, obj):
def get_is_indexable(self, obj) -> bool:
if obj.get_registry_backend():
return True
return False
Expand Down
3 changes: 3 additions & 0 deletions galaxy_ng/app/api/ui/serializers/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.conf import settings
from django.contrib.auth import password_validation
from django.utils.translation import gettext_lazy as _
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema_field

from rest_framework import serializers
from rest_framework.exceptions import ValidationError
Expand Down Expand Up @@ -143,6 +145,7 @@ class Meta(UserSerializer.Meta):
**UserSerializer.Meta.extra_kwargs
)

@extend_schema_field(OpenApiTypes.OBJECT)
def get_model_permissions(self, obj):

permissions = {
Expand Down
6 changes: 6 additions & 0 deletions galaxy_ng/app/api/ui/views/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _
from drf_spectacular.utils import extend_schema

from pulp_container.app import models as pulp_models
from pulpcore.plugin.viewsets import (
OperationPostponedResponse,
)
from pulpcore.plugin.serializers import AsyncOperationResponseSerializer
from pulpcore.plugin.tasking import dispatch

from galaxy_ng.app.api import base as api_base
Expand Down Expand Up @@ -58,6 +60,10 @@ class ContainerSyncRegistryView(api_base.APIView):
permission_classes = [access_policy.ContainerRegistryRemoteAccessPolicy]
action = 'sync'

@extend_schema(
description="Trigger an asynchronous sync task",
responses={202: AsyncOperationResponseSerializer},
)
def post(self, request: Request, *args, **kwargs) -> Response:
registry = get_object_or_404(models.ContainerRegistryRemote, pk=kwargs['pk'])

Expand Down
6 changes: 6 additions & 0 deletions galaxy_ng/app/api/ui/viewsets/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class CollectionViewSet(

def get_queryset(self):
"""Returns a CollectionVersions queryset for specified distribution."""
if getattr(self, "swagger_fake_view", False):
# OpenAPI spec generation
return CollectionVersion.objects.none()
path = self.kwargs.get('path')
if path is None:
raise Http404(_("Distribution base path is required"))
Expand Down Expand Up @@ -91,6 +94,9 @@ def get_queryset(self):
def get_object(self):
"""Return CollectionVersion object, latest or via query param 'version'."""
version = self.request.query_params.get('version', None)
if getattr(self, "swagger_fake_view", False):
# OpenAPI spec generation
return CollectionVersion.objects.none()

if not version:
queryset = self.get_queryset()
Expand Down
12 changes: 12 additions & 0 deletions galaxy_ng/app/api/ui/viewsets/execution_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class ContainerContentBaseViewset(api_base.ModelViewSet):
permission_classes = [access_policy.ContainerRepositoryAccessPolicy]

def get_distro(self):
if getattr(self, "swagger_fake_view", False):
# OpenAPI will generate a fake view with this attribute set
return models.ContainerDistribution.objects.none()
return get_object_or_404(
models.ContainerDistribution, base_path=self.kwargs["base_path"])

Expand All @@ -177,6 +180,9 @@ class ContainerTagViewset(ContainerContentBaseViewset):
filterset_class = TagFilter

def get_queryset(self):
if getattr(self, "swagger_fake_view", False):
# OpenAPI will generate a fake view with this attribute set
return container_models.Tag.objects.none()
repo = self.get_distro().repository
repo_version = repo.latest_version()
return repo_version.get_content(container_models.Tag.objects)
Expand All @@ -193,6 +199,9 @@ def get_serializer_class(self):
return serializers.ContainerManifestSerializer

def get_queryset(self):
if getattr(self, "swagger_fake_view", False):
# OpenAPI will generate a fake view with this attribute set
return container_models.Manifest.objects.none()
repo = self.get_distro().repository
repo_version = repo.latest_version()
repo_content = repo_version.content.all()
Expand Down Expand Up @@ -297,6 +306,9 @@ class ContainerRepositoryHistoryViewSet(ContainerContentBaseViewset):
filterset_class = HistoryFilter

def get_queryset(self):
if getattr(self, "swagger_fake_view", False):
# OpenAPI will generate a fake view with this attribute set
return core_models.RepositoryVersion.objects.none()
repo = self.get_distro().repository

allowed_content_types = ['container.manifest', 'container.tag']
Expand Down
Loading

0 comments on commit a0d7008

Please sign in to comment.