Merge "Add tempest tests for os-aggregate update"
diff --git a/tempest/api/compute/admin/test_aggregates.py b/tempest/api/compute/admin/test_aggregates.py
index 40b005d..14ab236 100644
--- a/tempest/api/compute/admin/test_aggregates.py
+++ b/tempest/api/compute/admin/test_aggregates.py
@@ -97,6 +97,38 @@
         self.assertEqual(aggregate['availability_zone'],
                          body['availability_zone'])
 
+    @attr(type='gate')
+    def test_aggregate_create_update_with_az(self):
+        # Update an aggregate and ensure properties are updated correctly
+        self.useFixture(fixtures.LockFixture('availability_zone'))
+        aggregate_name = rand_name(self.aggregate_name_prefix)
+        az_name = rand_name(self.az_name_prefix)
+        resp, aggregate = self.client.create_aggregate(aggregate_name, az_name)
+        self.addCleanup(self.client.delete_aggregate, aggregate['id'])
+
+        self.assertEqual(200, resp.status)
+        self.assertEqual(aggregate_name, aggregate['name'])
+        self.assertEqual(az_name, aggregate['availability_zone'])
+        self.assertIsNotNone(aggregate['id'])
+
+        aggregate_id = aggregate['id']
+        new_aggregate_name = aggregate_name + '_new'
+        new_az_name = az_name + '_new'
+
+        resp, resp_aggregate = self.client.update_aggregate(aggregate_id,
+                                                            new_aggregate_name,
+                                                            new_az_name)
+        self.assertEqual(200, resp.status)
+        self.assertEqual(new_aggregate_name, resp_aggregate['name'])
+        self.assertEqual(new_az_name, resp_aggregate['availability_zone'])
+
+        resp, aggregates = self.client.list_aggregates()
+        self.assertEqual(200, resp.status)
+        self.assertIn((aggregate_id, new_aggregate_name, new_az_name),
+                      map(lambda x:
+                         (x['id'], x['name'], x['availability_zone']),
+                          aggregates))
+
     @attr(type=['negative', 'gate'])
     def test_aggregate_create_as_user(self):
         # Regular user is not allowed to create an aggregate.
diff --git a/tempest/services/compute/json/aggregates_client.py b/tempest/services/compute/json/aggregates_client.py
index 7ae1eee..75ce9ff 100644
--- a/tempest/services/compute/json/aggregates_client.py
+++ b/tempest/services/compute/json/aggregates_client.py
@@ -52,6 +52,19 @@
         body = json.loads(body)
         return resp, body['aggregate']
 
+    def update_aggregate(self, aggregate_id, name, availability_zone=None):
+        """Update a aggregate."""
+        put_body = {
+            'name': name,
+            'availability_zone': availability_zone
+        }
+        put_body = json.dumps({'aggregate': put_body})
+        resp, body = self.put('os-aggregates/%s' % str(aggregate_id),
+                              put_body, self.headers)
+
+        body = json.loads(body)
+        return resp, body['aggregate']
+
     def delete_aggregate(self, aggregate_id):
         """Deletes the given aggregate."""
         return self.delete("os-aggregates/%s" % str(aggregate_id))
diff --git a/tempest/services/compute/xml/aggregates_client.py b/tempest/services/compute/xml/aggregates_client.py
index 0ef8e22..8ef0af6 100644
--- a/tempest/services/compute/xml/aggregates_client.py
+++ b/tempest/services/compute/xml/aggregates_client.py
@@ -72,6 +72,17 @@
         aggregate = self._format_aggregate(etree.fromstring(body))
         return resp, aggregate
 
+    def update_aggregate(self, aggregate_id, name, availability_zone=None):
+        """Update a aggregate."""
+        put_body = Element("aggregate",
+                           name=name,
+                           availability_zone=availability_zone)
+        resp, body = self.put('os-aggregates/%s' % str(aggregate_id),
+                              str(Document(put_body)),
+                              self.headers)
+        aggregate = self._format_aggregate(etree.fromstring(body))
+        return resp, aggregate
+
     def delete_aggregate(self, aggregate_id):
         """Deletes the given aggregate."""
         return self.delete("os-aggregates/%s" % str(aggregate_id),