launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #14041
[Merge] lp:~gz/maas/1.2_backport_manual_tags into lp:maas/1.2
Martin Packman has proposed merging lp:~gz/maas/1.2_backport_manual_tags into lp:maas/1.2.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~gz/maas/1.2_backport_manual_tags/+merge/133123
Bring 'manual' tag support back to the quantal release of MaaS. This is a trivial change to allow some admin flexibility, not a major feature.
For the original merge proposal, see:
<https://code.launchpad.net/~gz/maas/manual_tags/+merge/131232>
--
https://code.launchpad.net/~gz/maas/1.2_backport_manual_tags/+merge/133123
Your team MAAS Maintainers is requested to review the proposed merge of lp:~gz/maas/1.2_backport_manual_tags into lp:maas/1.2.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py 2012-10-30 15:15:30 +0000
+++ src/maasserver/forms.py 2012-11-06 18:25:27 +0000
@@ -859,6 +859,8 @@
def clean_definition(self):
definition = self.cleaned_data['definition']
+ if not definition:
+ return ""
try:
etree.XPath(definition)
except etree.XPathSyntaxError as e:
=== modified file 'src/maasserver/models/tag.py'
--- src/maasserver/models/tag.py 2012-10-10 10:25:28 +0000
+++ src/maasserver/models/tag.py 2012-11-06 18:25:27 +0000
@@ -99,7 +99,7 @@
name = CharField(max_length=256, unique=True, editable=True,
validators=[RegexValidator(_tag_name_regex)])
- definition = TextField()
+ definition = TextField(blank=True)
comment = TextField(blank=True)
objects = TagManager()
@@ -121,6 +121,8 @@
def populate_nodes(self):
"""Find all nodes that match this tag, and update them."""
from maasserver.populate_tags import populate_tags
+ if not self.definition:
+ return
# before we pass off any work, ensure the definition is valid XPATH
try:
etree.XPath(self.definition)
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-11-02 09:48:02 +0000
+++ src/maasserver/tests/test_api.py 2012-11-06 18:25:27 +0000
@@ -2896,6 +2896,18 @@
self.assertEqual({'rebuilding': tag.name}, parsed_result)
self.assertItemsEqual([node_matching], tag.node_set.all())
+ def test_POST_rebuild_leaves_manual_tags(self):
+ tag = factory.make_tag(definition='')
+ node = factory.make_node()
+ node.tags.add(tag)
+ self.assertItemsEqual([node], tag.node_set.all())
+ self.become_admin()
+ response = self.client.post(self.get_tag_uri(tag), {'op': 'rebuild'})
+ self.assertEqual(httplib.OK, response.status_code)
+ parsed_result = json.loads(response.content)
+ self.assertEqual({'rebuilding': tag.name}, parsed_result)
+ self.assertItemsEqual([node], tag.node_set.all())
+
def test_POST_rebuild_unknown_404(self):
self.become_admin()
response = self.client.post(
@@ -2948,6 +2960,24 @@
self.assertEqual(definition, parsed_result['definition'])
self.assertTrue(Tag.objects.filter(name=name).exists())
+ def test_POST_new_without_definition_creates_tag(self):
+ self.become_admin()
+ name = factory.getRandomString()
+ comment = factory.getRandomString()
+ response = self.client.post(
+ self.get_uri('tags/'),
+ {
+ 'op': 'new',
+ 'name': name,
+ 'comment': comment,
+ })
+ self.assertEqual(httplib.OK, response.status_code)
+ parsed_result = json.loads(response.content)
+ self.assertEqual(name, parsed_result['name'])
+ self.assertEqual(comment, parsed_result['comment'])
+ self.assertEqual("", parsed_result['definition'])
+ self.assertTrue(Tag.objects.filter(name=name).exists())
+
def test_POST_new_invalid_tag_name(self):
self.become_admin()
# We do not check the full possible set of invalid names here, a more