Skip to content

Commit

Permalink
frontend, backend: implement chroot deletion in Pulp
Browse files Browse the repository at this point in the history
Fix #3306
  • Loading branch information
FrostyX committed Jun 24, 2024
1 parent b655d6e commit b810e0f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
19 changes: 9 additions & 10 deletions backend/copr_backend/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from copr_common.worker_manager import WorkerManager

from copr_backend.worker_manager import BackendQueueTask
from copr_backend.storage import storage_for_job
from copr_backend.storage import storage_for_job, storage_for_enum

from .sign import create_user_keys, CoprKeygenRequestError
from .exceptions import CreateRepoError, CoprSignError, FrontendClientException
Expand Down Expand Up @@ -387,17 +387,16 @@ def run(self):
self.log.info("Action delete project chroot.")

ext_data = json.loads(self.data["data"])
ownername = ext_data["ownername"]
projectname = ext_data["projectname"]
chrootname = ext_data["chrootname"]
storage = storage_for_enum(ext_data["storage"], self.opts, self.log)

chroot_path = os.path.join(self.destdir, ownername, projectname, chrootname)
self.log.info("Going to delete: %s", chroot_path)
# Fake a Job interface
job = Munch()
job.project_owner = ext_data["ownername"]
job.project_name = ext_data["projectname"]
job.chroot = ext_data["chrootname"]
job.uses_devel_repo = False

if not os.path.isdir(chroot_path):
self.log.error("Directory %s not found", chroot_path)
return BackendResultEnum("success")
shutil.rmtree(chroot_path)
storage.delete_repository(job)
return BackendResultEnum("success")


Expand Down
16 changes: 16 additions & 0 deletions backend/copr_backend/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,19 @@ def upload_artifact(self, path):
url = self.url("api/v3/artifacts/")
data = {"file": fp}
return requests.post(url, files=data, **self.request_params)

def delete_repository(self, repository):
"""
Delete an RPM repository
https://pulpproject.org/pulp_rpm/restapi/#tag/Repositories:-Rpm/operation/repositories_rpm_rpm_delete
"""
url = self.config["base_url"] + repository
return requests.delete(url, **self.request_params)

def delete_distribution(self, distribution):
"""
Delete an RPM distribution
https://pulpproject.org/pulp_rpm/restapi/#tag/Distributions:-Rpm/operation/distributions_rpm_rpm_delete
"""
url = self.config["base_url"] + distribution
return requests.delete(url, **self.request_params)
26 changes: 26 additions & 0 deletions backend/copr_backend/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import shutil
from copr_common.enums import StorageEnum
from copr_backend.helpers import call_copr_repo
from copr_backend.pulp import PulpClient
Expand Down Expand Up @@ -50,6 +51,12 @@ def publish_repository(self, job):
"""
raise NotImplementedError

def delete_repository(self, job):
"""
Delete a repository and all of its builds
"""
raise NotImplementedError


class BackendStorage(Storage):
"""
Expand Down Expand Up @@ -91,6 +98,19 @@ def publish_repository(self, job):
logger=self.log,
appstream=appstream)

def delete_repository(self, job):
ownername = job.project_owner
projectname = job.project_name
chrootname = job.chroot
chroot_path = os.path.join(
self.opts.destdir, ownername, projectname, chrootname)

self.log.info("Going to delete: %s", chroot_path)
if not os.path.isdir(chroot_path):
self.log.error("Directory %s not found", chroot_path)
return
shutil.rmtree(chroot_path)


class PulpStorage(Storage):
"""
Expand Down Expand Up @@ -178,6 +198,12 @@ def publish_repository(self, job):
return False
return True

def delete_repository(self, job):
repository = self._get_repository(job)
distribution = self._get_distribution(job)
self.client.delete_repository(repository)
self.client.delete_distribution(distribution)

def _repository_name(self, job):
return "/".join([
job.project_owner,
Expand Down
1 change: 1 addition & 0 deletions frontend/coprs_frontend/coprs/logic/actions_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def send_delete_chroot(cls, copr_chroot):
"ownername": copr_chroot.copr.owner_name,
"projectname": copr_chroot.copr.name,
"chrootname": copr_chroot.name,
"storage": copr_chroot.copr.storage,
}

action = models.Action(
Expand Down

0 comments on commit b810e0f

Please sign in to comment.