Merge ~twom/launchpad:oci-policy-push-tags-to-the-limit into launchpad:master

Proposed by Tom Wardill
Status: Superseded
Proposed branch: ~twom/launchpad:oci-policy-push-tags-to-the-limit
Merge into: launchpad:master
Prerequisite: ~twom/launchpad:db-oci-policy-push-tags-to-the-limit
Diff against target: 133 lines (+49/-12)
4 files modified
dev/null (+0/-11)
lib/lp/oci/interfaces/ocipushrule.py (+9/-0)
lib/lp/oci/model/ocipushrule.py (+14/-0)
lib/lp/oci/tests/test_ocipushrule.py (+26/-1)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+394959@code.launchpad.net

This proposal has been superseded by a proposal from 2020-12-09.

Commit message

Add tag support to OCIPushRule

Description of the change

Use the text[] column for tags to add tag support to OCIPushRule.
No validation on the tags other than uniqueness, and the tags aren't currently used on push. This is just model and interface support.

Can't land until after https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/394958

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM. Added just a couple of minor possible improvements.

review: Approve
Revision history for this message
Tom Wardill (twom) :
3e012bd... by Tom Wardill

Use text[] column instead of class

Unmerged commits

3e012bd... by Tom Wardill

Use text[] column instead of class

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/database/schema/patch-2210-24-0.sql b/database/schema/patch-2210-24-0.sql
2deleted file mode 100644
3index 2ba3f52..0000000
4--- a/database/schema/patch-2210-24-0.sql
5+++ /dev/null
6@@ -1,11 +0,0 @@
7--- Copyright 2020 Canonical Ltd. This software is licensed under the
8--- GNU Affero General Public License version 3 (see the file LICENSE).
9-
10-SET client_min_messages=ERROR;
11-
12-ALTER TABLE OCIPushRule
13- ADD COLUMN tags text[];
14-
15-COMMENT ON COLUMN OCIPushRule.tags IS 'Tags to use on image upload.';
16-
17-INSERT INTO LaunchpadDatabaseRevision VALUES (2210, 24, 0);
18diff --git a/lib/lp/oci/interfaces/ocipushrule.py b/lib/lp/oci/interfaces/ocipushrule.py
19index 67db23e..f32927c 100644
20--- a/lib/lp/oci/interfaces/ocipushrule.py
21+++ b/lib/lp/oci/interfaces/ocipushrule.py
22@@ -23,10 +23,12 @@ from lazr.restful.declarations import (
23 operation_parameters,
24 )
25 from lazr.restful.fields import Reference
26+from lazr.restful.interface import copy_field
27 from six.moves import http_client
28 from zope.interface import Interface
29 from zope.schema import (
30 Int,
31+ List,
32 TextLine,
33 )
34
35@@ -102,6 +104,13 @@ class IOCIPushRuleEditableAttributes(Interface):
36 def setNewImageName(image_name):
37 """Set the new image name, checking for uniqueness."""
38
39+ tags = exported(List(
40+ value_type=TextLine(),
41+ title=_("Tags"),
42+ description=_("Tags to use on image upload."),
43+ required=False,
44+ readonly=False))
45+
46
47 class IOCIPushRuleEdit(Interface):
48 """`IOCIPushRule` methods that require launchpad.Edit
49diff --git a/lib/lp/oci/model/ocipushrule.py b/lib/lp/oci/model/ocipushrule.py
50index 24d5e27..edea2a1 100644
51--- a/lib/lp/oci/model/ocipushrule.py
52+++ b/lib/lp/oci/model/ocipushrule.py
53@@ -13,6 +13,7 @@ __all__ = [
54
55 from storm.locals import (
56 Int,
57+ List,
58 Reference,
59 Storm,
60 Unicode,
61@@ -44,6 +45,8 @@ class OCIPushRule(Storm):
62
63 image_name = Unicode(name="image_name", allow_none=False)
64
65+ _tags = List(name="tags", type=Unicode(), default_factory=list)
66+
67 @property
68 def registry_url(self):
69 return self.registry_credentials.url
70@@ -71,6 +74,17 @@ class OCIPushRule(Storm):
71 """See `IOCIPushRule`."""
72 IStore(OCIPushRule).remove(self)
73
74+ def _getTags(self):
75+ return self._tags
76+
77+ def _setTags(self, tags):
78+ # convert to a set to remove duplicates
79+ set_tags = set(tags)
80+ # XXX 2020-12-09 tag format validation lives here
81+ self._tags = sorted(list(set_tags))
82+
83+ tags = property(_getTags, _setTags)
84+
85
86 @implementer(IOCIPushRuleSet)
87 class OCIPushRuleSet:
88diff --git a/lib/lp/oci/tests/test_ocipushrule.py b/lib/lp/oci/tests/test_ocipushrule.py
89index 4c6db56..a87d869 100644
90--- a/lib/lp/oci/tests/test_ocipushrule.py
91+++ b/lib/lp/oci/tests/test_ocipushrule.py
92@@ -4,9 +4,15 @@
93 """Tests for OCI registry push rules."""
94
95 from __future__ import absolute_import, print_function, unicode_literals
96+from lp.oci.model.ocipushrule import OCIPushRule
97
98 from storm.store import Store
99-from testtools.matchers import MatchesStructure
100+from testtools.matchers import (
101+ Equals,
102+ MatchesListwise,
103+ MatchesStructure,
104+ )
105+import transaction
106 from zope.component import getUtility
107 from zope.schema import ValidationError
108
109@@ -71,6 +77,25 @@ class TestOCIPushRule(OCIConfigHelperMixin, TestCaseWithFactory):
110 # Avoid trying to flush the incomplete object on cleanUp.
111 Store.of(owner).rollback()
112
113+ def test_tags_set_tags(self):
114+ tags = ['one', 'two', 'three']
115+ push_rule = self.factory.makeOCIPushRule()
116+ push_rule.tags = tags
117+ transaction.commit()
118+ final_push_rule = Store.of(push_rule).find(
119+ OCIPushRule, OCIPushRule.id == push_rule.id).one()
120+ for tag in tags:
121+ self.assertIn(tag, final_push_rule.tags)
122+
123+ def test_tags_removes_duplicates(self):
124+ tags = ['one', 'another', 'another', 'two']
125+ push_rule = self.factory.makeOCIPushRule()
126+ push_rule.tags = tags
127+ self.assertThat(
128+ push_rule.tags,
129+ MatchesListwise(
130+ [Equals('another'), Equals('one'), Equals('two')]))
131+
132
133 class TestOCIPushRuleSet(OCIConfigHelperMixin, TestCaseWithFactory):
134

Subscribers

People subscribed via source and target branches

to status/vote changes: