Martin Packman has proposed merging lp:~gz/maas/populate_tags into lp:maas with
lp:~gz/maas/populate_mem_and_cpu as a prerequisite.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~gz/maas/populate_tags/+merge/125722
When hardware_details is updated, fill in any matching tags and remove any that
no longer match. Again, this means bypassing django, but all the messiness is
contained in one function at least. There a few tidy ups to do still, but this
should get us rolling with the basics needed from constraints.
Resumbit to include prereq branch.
--
https://code.launchpad.net/~gz/maas/populate_tags/+merge/125722
Your team MAAS Maintainers is requested to review the proposed merge of
lp:~gz/maas/populate_tags into lp:maas.
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py 2012-09-21 14:14:40 +0000
+++ src/maasserver/models/node.py 2012-09-21 14:14:40 +0000
@@ -347,8 +347,17 @@
cpu_count, memory = cursor.fetchone()
node.cpu_count = cpu_count or 0
node.memory = memory or 0
+ for tag in Tag.objects.all():
+ cursor.execute(
+ "SELECT xpath_exists(%s, hardware_details)"
+ " FROM maasserver_node WHERE id = %s",
+ [tag.definition, node.id])
+ has_tag, = cursor.fetchone()
+ if has_tag:
+ node.tags.add(tag)
+ else:
+ node.tags.remove(tag)
node.save()
- # TODO: update node-tag links
class Node(CleanSave, TimestampedModel):
=== modified file 'src/metadataserver/tests/test_api.py'
--- src/metadataserver/tests/test_api.py 2012-09-21 14:14:40 +0000
+++ src/metadataserver/tests/test_api.py 2012-09-21 14:14:40 +0000
@@ -528,6 +528,30 @@
node = reload_object(node)
self.assertEqual(4, node.memory)
+ def test_signal_lshw_tags_match(self):
+ tag1 = factory.make_tag(factory.getRandomString(10), "/node")
+ tag2 = factory.make_tag(factory.getRandomString(10), "//node")
+ node = factory.make_node(status=NODE_STATUS.COMMISSIONING)
+ client = self.make_node_client(node=node)
+ xmlbytes = '<node/>'.encode("utf-8")
+ response = self.call_signal(client, files={'01-lshw.out': xmlbytes})
+ self.assertEqual(httplib.OK, response.status_code)
+ node = reload_object(node)
+ self.assertEqual([tag1, tag2], list(node.tags.all()))
+
+ def test_signal_lshw_tags_no_match(self):
+ tag1 = factory.make_tag(factory.getRandomString(10), "/missing")
+ tag2 = factory.make_tag(factory.getRandomString(10), "/nothing")
+ node = factory.make_node(status=NODE_STATUS.COMMISSIONING)
+ node.tags = [tag2]
+ node.save()
+ client = self.make_node_client(node=node)
+ xmlbytes = '<node/>'.encode("utf-8")
+ response = self.call_signal(client, files={'01-lshw.out': xmlbytes})
+ self.assertEqual(httplib.OK, response.status_code)
+ node = reload_object(node)
+ self.assertEqual([], list(node.tags.all()))
+
def test_api_retrieves_node_metadata_by_mac(self):
mac = factory.make_mac_address()
url = reverse(
_______________________________________________
Mailing list: https://launchpad.net/~launchpad-reviewers
Post to : [email protected]
Unsubscribe : https://launchpad.net/~launchpad-reviewers
More help : https://help.launchpad.net/ListHelp