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
diff --git a/database/schema/patch-2210-24-0.sql b/database/schema/patch-2210-24-0.sql
0deleted file mode 1006440deleted file mode 100644
index 2ba3f52..0000000
--- a/database/schema/patch-2210-24-0.sql
+++ /dev/null
@@ -1,11 +0,0 @@
1-- Copyright 2020 Canonical Ltd. This software is licensed under the
2-- GNU Affero General Public License version 3 (see the file LICENSE).
3
4SET client_min_messages=ERROR;
5
6ALTER TABLE OCIPushRule
7 ADD COLUMN tags text[];
8
9COMMENT ON COLUMN OCIPushRule.tags IS 'Tags to use on image upload.';
10
11INSERT INTO LaunchpadDatabaseRevision VALUES (2210, 24, 0);
diff --git a/lib/lp/oci/interfaces/ocipushrule.py b/lib/lp/oci/interfaces/ocipushrule.py
index 67db23e..f32927c 100644
--- a/lib/lp/oci/interfaces/ocipushrule.py
+++ b/lib/lp/oci/interfaces/ocipushrule.py
@@ -23,10 +23,12 @@ from lazr.restful.declarations import (
23 operation_parameters,23 operation_parameters,
24 )24 )
25from lazr.restful.fields import Reference25from lazr.restful.fields import Reference
26from lazr.restful.interface import copy_field
26from six.moves import http_client27from six.moves import http_client
27from zope.interface import Interface28from zope.interface import Interface
28from zope.schema import (29from zope.schema import (
29 Int,30 Int,
31 List,
30 TextLine,32 TextLine,
31 )33 )
3234
@@ -102,6 +104,13 @@ class IOCIPushRuleEditableAttributes(Interface):
102 def setNewImageName(image_name):104 def setNewImageName(image_name):
103 """Set the new image name, checking for uniqueness."""105 """Set the new image name, checking for uniqueness."""
104106
107 tags = exported(List(
108 value_type=TextLine(),
109 title=_("Tags"),
110 description=_("Tags to use on image upload."),
111 required=False,
112 readonly=False))
113
105114
106class IOCIPushRuleEdit(Interface):115class IOCIPushRuleEdit(Interface):
107 """`IOCIPushRule` methods that require launchpad.Edit116 """`IOCIPushRule` methods that require launchpad.Edit
diff --git a/lib/lp/oci/model/ocipushrule.py b/lib/lp/oci/model/ocipushrule.py
index 24d5e27..edea2a1 100644
--- a/lib/lp/oci/model/ocipushrule.py
+++ b/lib/lp/oci/model/ocipushrule.py
@@ -13,6 +13,7 @@ __all__ = [
1313
14from storm.locals import (14from storm.locals import (
15 Int,15 Int,
16 List,
16 Reference,17 Reference,
17 Storm,18 Storm,
18 Unicode,19 Unicode,
@@ -44,6 +45,8 @@ class OCIPushRule(Storm):
4445
45 image_name = Unicode(name="image_name", allow_none=False)46 image_name = Unicode(name="image_name", allow_none=False)
4647
48 _tags = List(name="tags", type=Unicode(), default_factory=list)
49
47 @property50 @property
48 def registry_url(self):51 def registry_url(self):
49 return self.registry_credentials.url52 return self.registry_credentials.url
@@ -71,6 +74,17 @@ class OCIPushRule(Storm):
71 """See `IOCIPushRule`."""74 """See `IOCIPushRule`."""
72 IStore(OCIPushRule).remove(self)75 IStore(OCIPushRule).remove(self)
7376
77 def _getTags(self):
78 return self._tags
79
80 def _setTags(self, tags):
81 # convert to a set to remove duplicates
82 set_tags = set(tags)
83 # XXX 2020-12-09 tag format validation lives here
84 self._tags = sorted(list(set_tags))
85
86 tags = property(_getTags, _setTags)
87
7488
75@implementer(IOCIPushRuleSet)89@implementer(IOCIPushRuleSet)
76class OCIPushRuleSet:90class OCIPushRuleSet:
diff --git a/lib/lp/oci/tests/test_ocipushrule.py b/lib/lp/oci/tests/test_ocipushrule.py
index 4c6db56..a87d869 100644
--- a/lib/lp/oci/tests/test_ocipushrule.py
+++ b/lib/lp/oci/tests/test_ocipushrule.py
@@ -4,9 +4,15 @@
4"""Tests for OCI registry push rules."""4"""Tests for OCI registry push rules."""
55
6from __future__ import absolute_import, print_function, unicode_literals6from __future__ import absolute_import, print_function, unicode_literals
7from lp.oci.model.ocipushrule import OCIPushRule
78
8from storm.store import Store9from storm.store import Store
9from testtools.matchers import MatchesStructure10from testtools.matchers import (
11 Equals,
12 MatchesListwise,
13 MatchesStructure,
14 )
15import transaction
10from zope.component import getUtility16from zope.component import getUtility
11from zope.schema import ValidationError17from zope.schema import ValidationError
1218
@@ -71,6 +77,25 @@ class TestOCIPushRule(OCIConfigHelperMixin, TestCaseWithFactory):
71 # Avoid trying to flush the incomplete object on cleanUp.77 # Avoid trying to flush the incomplete object on cleanUp.
72 Store.of(owner).rollback()78 Store.of(owner).rollback()
7379
80 def test_tags_set_tags(self):
81 tags = ['one', 'two', 'three']
82 push_rule = self.factory.makeOCIPushRule()
83 push_rule.tags = tags
84 transaction.commit()
85 final_push_rule = Store.of(push_rule).find(
86 OCIPushRule, OCIPushRule.id == push_rule.id).one()
87 for tag in tags:
88 self.assertIn(tag, final_push_rule.tags)
89
90 def test_tags_removes_duplicates(self):
91 tags = ['one', 'another', 'another', 'two']
92 push_rule = self.factory.makeOCIPushRule()
93 push_rule.tags = tags
94 self.assertThat(
95 push_rule.tags,
96 MatchesListwise(
97 [Equals('another'), Equals('one'), Equals('two')]))
98
7499
75class TestOCIPushRuleSet(OCIConfigHelperMixin, TestCaseWithFactory):100class TestOCIPushRuleSet(OCIConfigHelperMixin, TestCaseWithFactory):
76101

Subscribers

People subscribed via source and target branches

to status/vote changes: