← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ilasc/turnip:set-repack-stats-on-job-complete into turnip:master

 

Ioana Lasc has proposed merging ~ilasc/turnip:set-repack-stats-on-job-complete into turnip:master.

Commit message:
LP gets repack stats on job completion

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ilasc/turnip/+git/turnip/+merge/402391

When the repack succeeded send confirmation to LP.
LP will then call synchronously the new GET call that we add on the RepackAPI.

Diagram details: https://chat.canonical.com/canonical/pl/3h7smw6rxingm8ytgifhmind7r
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/turnip:set-repack-stats-on-job-complete into turnip:master.
diff --git a/turnip/api/store.py b/turnip/api/store.py
index f1e4664..a2b869d 100644
--- a/turnip/api/store.py
+++ b/turnip/api/store.py
@@ -32,8 +32,9 @@ import six
 
 from turnip.config import config
 from turnip.helpers import TimeoutServerProxy
-from turnip.pack.helpers import ensure_config
+from turnip.pack.helpers import ensure_config, get_repack_data
 from turnip.tasks import app, logger as tasks_logger
+from twisted.web import xmlrpc
 
 logger = logging.getLogger(__name__)
 
@@ -491,6 +492,16 @@ def repack(repo_path):
         logger.info(
             "Repack completed for repository: "
             "%s", repo_path)
+        try:
+            xmlrpc_endpoint = config.get("virtinfo_endpoint")
+            xmlrpc_timeout = float(config.get("virtinfo_timeout"))
+            xmlrpc_auth_params = {"user": "+launchpad-services"}
+            xmlrpc_proxy = TimeoutServerProxy(
+                xmlrpc_endpoint, timeout=xmlrpc_timeout, allow_none=True)        
+            xmlrpc_proxy.updateRepackStats(repo_path, xmlrpc_auth_params)
+        except xmlrpc.Fault as e:
+            logger.info("Failed to signal LP to update its repack stats for "
+            "this repository %s after repack completed.", repo_path)
     except subprocess.CalledProcessError:
         logger.info(
             "Repack failed for repository: "
diff --git a/turnip/api/views.py b/turnip/api/views.py
index 5bb8d8f..b94f36f 100644
--- a/turnip/api/views.py
+++ b/turnip/api/views.py
@@ -12,6 +12,7 @@ from pyramid.response import Response
 
 from turnip.config import config
 from turnip.api import store
+from turnip.pack.helpers import get_repack_data
 
 
 def is_valid_path(repo_store, repo_path):
@@ -151,6 +152,16 @@ class RepackAPI(BaseAPI):
         store.repack.apply_async(kwargs=kwargs)
         return Response(status=200)
 
+    @validate_path
+    def get(self, repo_store, repo_name):
+        repo_path = os.path.join(repo_store, repo_name)
+        if not os.path.exists(repo_path):
+            self.request.errors.add(
+                'body', 'name', 'repository does not exist')
+            raise exc.HTTPNotFound()
+        kwargs = dict(repo_path=repo_path)
+        return get_repack_data(repo_path)
+
 
 @resource(path='/repo/{name}/gc')
 class GarbageCollectAPI(BaseAPI):