From 6ac3d3626cdc1c8acef60e95bc12dd8729ac4fee Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Wed, 28 Aug 2013 11:28:48 +0800 Subject: [PATCH] Adds V3 API samples for migrations Partially implements blueprint v3-api-unittests DocImpact Change-Id: Ic1a1b96f00831b22c9499d3ac2953f3d08819905 --- .../os-migrations/migrations-get.json | 32 ++++++++ .../os-migrations/migrations-get.xml | 5 ++ .../os-migrations/migrations-get.json.tpl | 32 ++++++++ .../os-migrations/migrations-get.xml.tpl | 5 ++ nova/tests/integrated/v3/test_migrations.py | 73 +++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 doc/v3/api_samples/os-migrations/migrations-get.json create mode 100644 doc/v3/api_samples/os-migrations/migrations-get.xml create mode 100644 nova/tests/integrated/v3/api_samples/os-migrations/migrations-get.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/os-migrations/migrations-get.xml.tpl create mode 100644 nova/tests/integrated/v3/test_migrations.py diff --git a/doc/v3/api_samples/os-migrations/migrations-get.json b/doc/v3/api_samples/os-migrations/migrations-get.json new file mode 100644 index 000000000000..91775be77581 --- /dev/null +++ b/doc/v3/api_samples/os-migrations/migrations-get.json @@ -0,0 +1,32 @@ +{ + "migrations": [ + { + "created_at": "2012-10-29T13:42:02.000000", + "dest_compute": "compute2", + "dest_host": "1.2.3.4", + "dest_node": "node2", + "id": 1234, + "instance_uuid": "instance_id_123", + "new_instance_type_id": 2, + "old_instance_type_id": 1, + "source_compute": "compute1", + "source_node": "node1", + "status": "Done", + "updated_at": "2012-10-29T13:42:02.000000" + }, + { + "created_at": "2013-10-22T13:42:02.000000", + "dest_compute": "compute20", + "dest_host": "5.6.7.8", + "dest_node": "node20", + "id": 5678, + "instance_uuid": "instance_id_456", + "new_instance_type_id": 6, + "old_instance_type_id": 5, + "source_compute": "compute10", + "source_node": "node10", + "status": "Done", + "updated_at": "2013-10-22T13:42:02.000000" + } + ] +} \ No newline at end of file diff --git a/doc/v3/api_samples/os-migrations/migrations-get.xml b/doc/v3/api_samples/os-migrations/migrations-get.xml new file mode 100644 index 000000000000..f5c59c7f1b02 --- /dev/null +++ b/doc/v3/api_samples/os-migrations/migrations-get.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-migrations/migrations-get.json.tpl b/nova/tests/integrated/v3/api_samples/os-migrations/migrations-get.json.tpl new file mode 100644 index 000000000000..91775be77581 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-migrations/migrations-get.json.tpl @@ -0,0 +1,32 @@ +{ + "migrations": [ + { + "created_at": "2012-10-29T13:42:02.000000", + "dest_compute": "compute2", + "dest_host": "1.2.3.4", + "dest_node": "node2", + "id": 1234, + "instance_uuid": "instance_id_123", + "new_instance_type_id": 2, + "old_instance_type_id": 1, + "source_compute": "compute1", + "source_node": "node1", + "status": "Done", + "updated_at": "2012-10-29T13:42:02.000000" + }, + { + "created_at": "2013-10-22T13:42:02.000000", + "dest_compute": "compute20", + "dest_host": "5.6.7.8", + "dest_node": "node20", + "id": 5678, + "instance_uuid": "instance_id_456", + "new_instance_type_id": 6, + "old_instance_type_id": 5, + "source_compute": "compute10", + "source_node": "node10", + "status": "Done", + "updated_at": "2013-10-22T13:42:02.000000" + } + ] +} \ No newline at end of file diff --git a/nova/tests/integrated/v3/api_samples/os-migrations/migrations-get.xml.tpl b/nova/tests/integrated/v3/api_samples/os-migrations/migrations-get.xml.tpl new file mode 100644 index 000000000000..f5c59c7f1b02 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/os-migrations/migrations-get.xml.tpl @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/nova/tests/integrated/v3/test_migrations.py b/nova/tests/integrated/v3/test_migrations.py new file mode 100644 index 000000000000..5886f2275000 --- /dev/null +++ b/nova/tests/integrated/v3/test_migrations.py @@ -0,0 +1,73 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright 2012 Nebula, Inc. +# Copyright 2013 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import datetime + +from nova.compute import api as compute_api +from nova.tests.integrated.v3 import api_sample_base + + +class MigrationsSamplesJsonTest(api_sample_base.ApiSampleTestBaseV3): + extension_name = "os-migrations" + + def _stub_migrations(self, context, filters): + fake_migrations = [ + { + 'id': 1234, + 'source_node': 'node1', + 'dest_node': 'node2', + 'source_compute': 'compute1', + 'dest_compute': 'compute2', + 'dest_host': '1.2.3.4', + 'status': 'Done', + 'instance_uuid': 'instance_id_123', + 'old_instance_type_id': 1, + 'new_instance_type_id': 2, + 'created_at': datetime.datetime(2012, 10, 29, 13, 42, 2), + 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 2) + }, + { + 'id': 5678, + 'source_node': 'node10', + 'dest_node': 'node20', + 'source_compute': 'compute10', + 'dest_compute': 'compute20', + 'dest_host': '5.6.7.8', + 'status': 'Done', + 'instance_uuid': 'instance_id_456', + 'old_instance_type_id': 5, + 'new_instance_type_id': 6, + 'created_at': datetime.datetime(2013, 10, 22, 13, 42, 2), + 'updated_at': datetime.datetime(2013, 10, 22, 13, 42, 2) + } + ] + return fake_migrations + + def setUp(self): + super(MigrationsSamplesJsonTest, self).setUp() + self.stubs.Set(compute_api.API, 'get_migrations', + self._stub_migrations) + + def test_get_migrations(self): + response = self._do_get('os-migrations') + subs = self._get_regexes() + + self.assertEqual(response.status, 200) + self._verify_response('migrations-get', subs, response, 200) + + +class MigrationsSamplesXmlTest(MigrationsSamplesJsonTest): + ctype = 'xml'