From 6a16798b59209cc6e7839a9feaaa9804bdcef6eb Mon Sep 17 00:00:00 2001 From: ghanshyam Date: Tue, 24 Mar 2015 16:18:24 +0900 Subject: [PATCH] Merge cell functional tests for V2 and V2.1 Currently v2 and v2.1 have separate functional tests and their corresponding sample files. As v2 and v2.1 are supposed to be identical, there is overhead to maintain two set of functional tests and sample files. We can have one set of tests which can run for both v2 and v2.1. This commit merges cell functional tests. In V2 cell has following extensions - os-cells - os-cell-capacities In V2.1 above extensions have been merged together in os-cell plugins Change-Id: I42adfa5de21e3af03761fc12d04498de5112f385 --- .../cells-capacities-resp.json | 18 ---- doc/api_samples/os-cells/cells-get-resp.json | 9 -- .../os-cells/cells-list-empty-resp.json | 3 - doc/api_samples/os-cells/cells-list-resp.json | 39 -------- .../cells-capacities-resp.json.tpl | 18 ---- .../os-cells/cells-get-resp.json.tpl | 9 -- .../os-cells/cells-list-empty-resp.json.tpl | 4 - .../os-cells/cells-list-resp.json.tpl | 39 -------- nova/tests/functional/test_api_samples.py | 99 ------------------- nova/tests/functional/v3/test_cells.py | 19 ++++ 10 files changed, 19 insertions(+), 238 deletions(-) delete mode 100644 doc/api_samples/os-cell-capacities/cells-capacities-resp.json delete mode 100644 doc/api_samples/os-cells/cells-get-resp.json delete mode 100644 doc/api_samples/os-cells/cells-list-empty-resp.json delete mode 100644 doc/api_samples/os-cells/cells-list-resp.json delete mode 100644 nova/tests/functional/api_samples/os-cell-capacities/cells-capacities-resp.json.tpl delete mode 100644 nova/tests/functional/api_samples/os-cells/cells-get-resp.json.tpl delete mode 100644 nova/tests/functional/api_samples/os-cells/cells-list-empty-resp.json.tpl delete mode 100644 nova/tests/functional/api_samples/os-cells/cells-list-resp.json.tpl diff --git a/doc/api_samples/os-cell-capacities/cells-capacities-resp.json b/doc/api_samples/os-cell-capacities/cells-capacities-resp.json deleted file mode 100644 index b926f8d1df27..000000000000 --- a/doc/api_samples/os-cell-capacities/cells-capacities-resp.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "cell": { - "capacities": { - "ram_free": { - "units_by_mb": { - "8192": 0, "512": 13, "4096": 1, "2048": 3, "16384": 0 - }, - "total_mb": 7680 - }, - "disk_free": { - "units_by_mb": { - "81920": 11, "20480": 46, "40960": 23, "163840": 5, "0": 0 - }, - "total_mb": 1052672 - } - } - } -} diff --git a/doc/api_samples/os-cells/cells-get-resp.json b/doc/api_samples/os-cells/cells-get-resp.json deleted file mode 100644 index 62eb8ec31d20..000000000000 --- a/doc/api_samples/os-cells/cells-get-resp.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "cell": { - "name": "cell3", - "rpc_host": null, - "rpc_port": null, - "type": "child", - "username": "username3" - } -} \ No newline at end of file diff --git a/doc/api_samples/os-cells/cells-list-empty-resp.json b/doc/api_samples/os-cells/cells-list-empty-resp.json deleted file mode 100644 index 5325a4e855e2..000000000000 --- a/doc/api_samples/os-cells/cells-list-empty-resp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "cells": [] -} \ No newline at end of file diff --git a/doc/api_samples/os-cells/cells-list-resp.json b/doc/api_samples/os-cells/cells-list-resp.json deleted file mode 100644 index 97ea4c6dd32d..000000000000 --- a/doc/api_samples/os-cells/cells-list-resp.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "name": "cell1", - "rpc_host": null, - "rpc_port": null, - "type": "child", - "username": "username1" - }, - { - "name": "cell3", - "rpc_host": null, - "rpc_port": null, - "type": "child", - "username": "username3" - }, - { - "name": "cell5", - "rpc_host": null, - "rpc_port": null, - "type": "child", - "username": "username5" - }, - { - "name": "cell2", - "rpc_host": null, - "rpc_port": null, - "type": "parent", - "username": "username2" - }, - { - "name": "cell4", - "rpc_host": null, - "rpc_port": null, - "type": "parent", - "username": "username4" - } - ] -} \ No newline at end of file diff --git a/nova/tests/functional/api_samples/os-cell-capacities/cells-capacities-resp.json.tpl b/nova/tests/functional/api_samples/os-cell-capacities/cells-capacities-resp.json.tpl deleted file mode 100644 index b926f8d1df27..000000000000 --- a/nova/tests/functional/api_samples/os-cell-capacities/cells-capacities-resp.json.tpl +++ /dev/null @@ -1,18 +0,0 @@ -{ - "cell": { - "capacities": { - "ram_free": { - "units_by_mb": { - "8192": 0, "512": 13, "4096": 1, "2048": 3, "16384": 0 - }, - "total_mb": 7680 - }, - "disk_free": { - "units_by_mb": { - "81920": 11, "20480": 46, "40960": 23, "163840": 5, "0": 0 - }, - "total_mb": 1052672 - } - } - } -} diff --git a/nova/tests/functional/api_samples/os-cells/cells-get-resp.json.tpl b/nova/tests/functional/api_samples/os-cells/cells-get-resp.json.tpl deleted file mode 100644 index 2993b1df881f..000000000000 --- a/nova/tests/functional/api_samples/os-cells/cells-get-resp.json.tpl +++ /dev/null @@ -1,9 +0,0 @@ -{ - "cell": { - "name": "cell3", - "username": "username3", - "rpc_host": null, - "rpc_port": null, - "type": "child" - } -} diff --git a/nova/tests/functional/api_samples/os-cells/cells-list-empty-resp.json.tpl b/nova/tests/functional/api_samples/os-cells/cells-list-empty-resp.json.tpl deleted file mode 100644 index b16e12cd6940..000000000000 --- a/nova/tests/functional/api_samples/os-cells/cells-list-empty-resp.json.tpl +++ /dev/null @@ -1,4 +0,0 @@ -{ - "cells": [] -} - diff --git a/nova/tests/functional/api_samples/os-cells/cells-list-resp.json.tpl b/nova/tests/functional/api_samples/os-cells/cells-list-resp.json.tpl deleted file mode 100644 index 3d7a6c207c33..000000000000 --- a/nova/tests/functional/api_samples/os-cells/cells-list-resp.json.tpl +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "name": "cell1", - "username": "username1", - "rpc_host": null, - "rpc_port": null, - "type": "child" - }, - { - "name": "cell2", - "username": "username2", - "rpc_host": null, - "rpc_port": null, - "type": "parent" - }, - { - "name": "cell3", - "username": "username3", - "rpc_host": null, - "rpc_port": null, - "type": "child" - }, - { - "name": "cell4", - "username": "username4", - "rpc_host": null, - "rpc_port": null, - "type": "parent" - }, - { - "name": "cell5", - "username": "username5", - "rpc_host": null, - "rpc_port": null, - "type": "child" - } - ] -} diff --git a/nova/tests/functional/test_api_samples.py b/nova/tests/functional/test_api_samples.py index 25092988f945..bee93861b77e 100644 --- a/nova/tests/functional/test_api_samples.py +++ b/nova/tests/functional/test_api_samples.py @@ -34,8 +34,6 @@ from nova.api.metadata import password from nova.api.openstack.compute.contrib import fping from nova.api.openstack.compute import extensions # Import extensions to pull in osapi_compute_extension CONF option used below. -from nova.cells import rpcapi as cells_rpcapi -from nova.cells import state from nova.cloudpipe import pipelib from nova.compute import api as compute_api from nova.compute import cells_api as cells_api @@ -2560,103 +2558,6 @@ class BaremetalNodesJsonTest(ApiSampleTestBaseV2): self._verify_response('baremetal-node-get-resp', subs, response, 200) -class CellsSampleJsonTest(ApiSampleTestBaseV2): - extension_name = "nova.api.openstack.compute.contrib.cells.Cells" - - def setUp(self): - # db_check_interval < 0 makes cells manager always hit the DB - self.flags(enable=True, db_check_interval=-1, group='cells') - super(CellsSampleJsonTest, self).setUp() - self._stub_cells() - - def _stub_cells(self, num_cells=5): - self.cells = [] - self.cells_next_id = 1 - - def _fake_cell_get_all(context): - return self.cells - - def _fake_cell_get(inst, context, cell_name): - for cell in self.cells: - if cell['name'] == cell_name: - return cell - raise exception.CellNotFound(cell_name=cell_name) - - for x in xrange(num_cells): - cell = models.Cell() - our_id = self.cells_next_id - self.cells_next_id += 1 - cell.update({'id': our_id, - 'name': 'cell%s' % our_id, - 'transport_url': 'rabbit://username%s@/' % our_id, - 'is_parent': our_id % 2 == 0}) - self.cells.append(cell) - - self.stubs.Set(db, 'cell_get_all', _fake_cell_get_all) - self.stubs.Set(cells_rpcapi.CellsAPI, 'cell_get', _fake_cell_get) - - def test_cells_empty_list(self): - # Override this - self._stub_cells(num_cells=0) - response = self._do_get('os-cells') - subs = self._get_regexes() - self._verify_response('cells-list-empty-resp', subs, response, 200) - - def test_cells_list(self): - response = self._do_get('os-cells') - subs = self._get_regexes() - self._verify_response('cells-list-resp', subs, response, 200) - - def test_cells_get(self): - response = self._do_get('os-cells/cell3') - subs = self._get_regexes() - self._verify_response('cells-get-resp', subs, response, 200) - - -class CellsCapacitySampleJsonTest(ApiSampleTestBaseV2): - extends_name = ("nova.api.openstack.compute.contrib.cells.Cells") - extension_name = ("nova.api.openstack.compute.contrib." - "cell_capacities.Cell_capacities") - - def setUp(self): - self.flags(enable=True, db_check_interval=-1, group='cells') - super(CellsCapacitySampleJsonTest, self).setUp() - # (navneetk/kaushikc) : Mock cell capacity to avoid the capacity - # being calculated from the compute nodes in the environment - self._mock_cell_capacity() - - def test_get_cell_capacity(self): - state_manager = state.CellStateManager() - my_state = state_manager.get_my_state() - response = self._do_get('os-cells/%s/capacities' % - my_state.name) - subs = self._get_regexes() - return self._verify_response('cells-capacities-resp', - subs, response, 200) - - def test_get_all_cells_capacity(self): - response = self._do_get('os-cells/capacities') - subs = self._get_regexes() - return self._verify_response('cells-capacities-resp', - subs, response, 200) - - def _mock_cell_capacity(self): - self.mox.StubOutWithMock(self.cells.manager.state_manager, - 'get_our_capacities') - response = {"ram_free": - {"units_by_mb": {"8192": 0, "512": 13, - "4096": 1, "2048": 3, "16384": 0}, - "total_mb": 7680}, - "disk_free": - {"units_by_mb": {"81920": 11, "20480": 46, - "40960": 23, "163840": 5, "0": 0}, - "total_mb": 1052672} - } - self.cells.manager.state_manager.get_our_capacities(). \ - AndReturn(response) - self.mox.ReplayAll() - - class BlockDeviceMappingV2BootJsonTest(ServersSampleBase): extension_name = ('nova.api.openstack.compute.contrib.' 'block_device_mapping_v2_boot.' diff --git a/nova/tests/functional/v3/test_cells.py b/nova/tests/functional/v3/test_cells.py index 993c365222d3..57f577001782 100644 --- a/nova/tests/functional/v3/test_cells.py +++ b/nova/tests/functional/v3/test_cells.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg + from nova.cells import rpcapi as cells_rpcapi from nova.cells import state from nova import db @@ -20,9 +22,26 @@ from nova.db.sqlalchemy import models from nova import exception from nova.tests.functional.v3 import api_sample_base +CONF = cfg.CONF +CONF.import_opt('osapi_compute_extension', + 'nova.api.openstack.compute.extensions') + class CellsSampleJsonTest(api_sample_base.ApiSampleTestBaseV3): extension_name = "os-cells" + # TODO(gmann): Overriding '_api_version' till all functional tests + # are merged between v2 and v2.1. After that base class variable + # itself can be changed to 'v2' + _api_version = 'v2' + + def _get_flags(self): + f = super(CellsSampleJsonTest, self)._get_flags() + f['osapi_compute_extension'] = CONF.osapi_compute_extension[:] + f['osapi_compute_extension'].append( + 'nova.api.openstack.compute.contrib.cells.Cells') + f['osapi_compute_extension'].append('nova.api.openstack.compute.' + 'contrib.cell_capacities.Cell_capacities') + return f def setUp(self): # db_check_interval < 0 makes cells manager always hit the DB