From 6a333765e74388bffacbfe0b8c6d183941343795 Mon Sep 17 00:00:00 2001 From: Ina Panova Date: Mon, 1 Jun 2020 14:42:52 +0200 Subject: [PATCH] Auto create repos and distributions for the container push closes #6878 https://pulp.plan.io/issues/6878 --- CHANGES/6878.bugfix | 1 + pulp_container/app/viewsets.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 CHANGES/6878.bugfix diff --git a/CHANGES/6878.bugfix b/CHANGES/6878.bugfix new file mode 100644 index 000000000..0b9c36d55 --- /dev/null +++ b/CHANGES/6878.bugfix @@ -0,0 +1 @@ +Auto create repos and distributions for the container push. diff --git a/pulp_container/app/viewsets.py b/pulp_container/app/viewsets.py index e760a7429..a6db21804 100644 --- a/pulp_container/app/viewsets.py +++ b/pulp_container/app/viewsets.py @@ -594,11 +594,15 @@ def create(self, request, path): """ This methods handles the creation of an upload. """ - distribution = get_object_or_404(models.ContainerDistribution, base_path=path) - if distribution.repository: - repository = distribution.repository - else: - raise Http404("Repository {} does not exist.".format(path)) + # TODO add repo push type to distinguish from sync repo type + distribution, _ = models.ContainerDistribution.objects.get_or_create( + name=path, base_path=path) + repository = distribution.repository + if not repository: + repository, _ = models.ContainerRepository.objects.get_or_create(name=path) + distribution.repository = repository + distribution.save() + upload = models.Upload(repository=repository) upload.file.save(name='', content=ContentFile(''), save=False) upload.save()