~ursinha/ubuntu-ci-services-itself/private-only-is-env-variable

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
PPA Assigner
============

*Purpose:*

* Workaround LP limitations:

 * we need 2 empty PPAs for each ticket (the isolated one for the ticket’s feature and one for the merge to trunk attempt for the feature)
 * since LP cannot fully remove a PPA (it will be in the database forever), we’ll manage a pool of PPAs that can be reused and will be cleaned when a ticket is closed.


Design
------

The Launchpad API provides the ability to list all the PPAs owned by a user.
We can create a user that owns the "ppa pool". We can start with an initial
group of PPAs and them grow that if needed.

The service itself will be a django + REST. It will have a simple data model::

 class PPA(models.Model):
     name = models.CharField(max_length=4096)

     state = models.CharField(choice=['reserved', 'dirty', 'cleaning', 'free'])
     ticket_id = models.PositiveIntegerField()


REST APIs
---------

list
~~~~
List all PPAs and their locked status. Just a standard REST get call::

  curl --dump-header - http://localhost:8000/api/v1/ppa/

populate
~~~~~~~~
Find all PPAs owned by the Launchpad user and ensure they are defined
in the model. The following naming pattern will be used::

  # pattern
  ci_pool-XXX

  # so the first two PPAs
  ci_pool-001
  ci_pool-002


The REST call will be a PATCH request with::

  {"populate": true}

get_ppa
~~~~~~~
Find an unlocked ppa, lock it, and return it.

Curl Usage for Getting a ppa::

  curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"ticket_id": 3}' http://localhost:8000/api/v1/ppa/


If no free PPAs exist an HttpNotFound error will be returned with a message
explaining there are no free PPAs.


release_ppa
~~~~~~~~~~~
Takes the ppa returned from the get_ppa call and releases it::

 curl --dump-header - -H "Content-Type: application/json" -X PATCH --data '{"state": "dirty"}' http://localhost:8000/api/v1/ppa/<X>/

We'll then have a daemon running that polls for "dirty" PPAs. It will ask
launchpad to clean each PPA using LP's "requestDeletion" API. At this point
the PPA will move to the "cleaning" state. The daemon will also periodically
poll LP to check the "date_removed" attribute of each item in the publication
history. Once they are all non-null, it will transition that PPA into the
"clean" state so that its available to the pool again.