From cc9fc915c24d9f5bc454f2ed3229cdacbd6a714c Mon Sep 17 00:00:00 2001 From: Stephen Gran Date: Fri, 1 Mar 2013 08:22:16 +0000 Subject: [PATCH] Add CRUD methods for tags to the EC2 API. This is an incomplete implementation of the EC2 tags API. In EC2, most resources are able to be tagged. See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html In openstack, the only currently 'taggable' resource is an instance, as it has an instance_metadata table associated. So far, only instance tagging has been implemented, but it is relatively simple to extend this to other resource types by creating the associated model and api calls. Additionally, in EC2 searches, shell-style globs are allowed, eg: fo* will match fo, foo, foobar fo? will match foo This has been left to do at a later date. DocImpact: Adds new API calls: CreateTags, DeleteTags, DescribeTags See: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateTags.html http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DeleteTags.html http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeTags.html Fixes: bug #1096821 Implements: blueprint ec2-tags-api Change-Id: Idf1108f6a3476cabdbdb32ff41c00aa4bc2d9ffe Signed-off-by: Stephen Gran --- nova/tests/test_db_api.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 19eb4d27..b5896399 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -97,6 +97,26 @@ class DbApiTestCase(DbTestCase): self.flags(osapi_compute_unique_server_name_scope=None) + def test_instance_metadata_get_all_query(self): + self.create_instances_with_args(metadata={'foo': 'bar'}) + self.create_instances_with_args(metadata={'baz': 'quux'}) + + result = db.instance_metadata_get_all(self.context, []) + self.assertEqual(2, len(result)) + + result = db.instance_metadata_get_all(self.context, + [{'key': 'foo'}]) + self.assertEqual(1, len(result)) + + result = db.instance_metadata_get_all(self.context, + [{'value': 'quux'}]) + self.assertEqual(1, len(result)) + + result = db.instance_metadata_get_all(self.context, + [{'value': 'quux'}, + {'key': 'foo'}]) + self.assertEqual(2, len(result)) + def test_ec2_ids_not_found_are_printable(self): def check_exc_format(method): try: