Stop handling cells v1 in '/os-hypervisors' API
Part of blueprint remove-cells-v1 Change-Id: I5d2ff94bc7c2f0b282e3abf1b50d96aeed9c8407 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
fb14f24cc3
commit
27e88f6a66
|
@ -27,7 +27,6 @@ from nova.api.openstack.compute.schemas import hypervisors as hyper_schema
|
||||||
from nova.api.openstack.compute.views import hypervisors as hyper_view
|
from nova.api.openstack.compute.views import hypervisors as hyper_view
|
||||||
from nova.api.openstack import wsgi
|
from nova.api.openstack import wsgi
|
||||||
from nova.api import validation
|
from nova.api import validation
|
||||||
from nova.cells import utils as cells_utils
|
|
||||||
from nova import compute
|
from nova import compute
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
|
@ -267,11 +266,6 @@ class HypervisorsController(wsgi.Controller):
|
||||||
msg = _('Invalid uuid %s') % hypervisor_id
|
msg = _('Invalid uuid %s') % hypervisor_id
|
||||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||||
else:
|
else:
|
||||||
# This API is supported for cells v1 and as such the id can be
|
|
||||||
# a cell v1 delimited string, so we have to parse it first.
|
|
||||||
if cells_utils.CELL_ITEM_SEP in str(hypervisor_id):
|
|
||||||
hypervisor_id = cells_utils.split_cell_and_item(
|
|
||||||
hypervisor_id)[1]
|
|
||||||
try:
|
try:
|
||||||
utils.validate_integer(hypervisor_id, 'id')
|
utils.validate_integer(hypervisor_id, 'id')
|
||||||
except exception.InvalidInput:
|
except exception.InvalidInput:
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from nova.cells import utils as cells_utils
|
|
||||||
from nova import objects
|
|
||||||
from nova.tests.functional.api_sample_tests import api_sample_base
|
from nova.tests.functional.api_sample_tests import api_sample_base
|
||||||
from nova.virt import fake
|
from nova.virt import fake
|
||||||
|
|
||||||
|
@ -94,48 +92,6 @@ class HypervisorsSampleJsonTests(api_sample_base.ApiSampleTestBaseV21):
|
||||||
self._verify_response('hypervisors-uptime-resp', subs, response, 200)
|
self._verify_response('hypervisors-uptime-resp', subs, response, 200)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("nova.servicegroup.API.service_is_up", return_value=True)
|
|
||||||
class HypervisorsCellsSampleJsonTests(api_sample_base.ApiSampleTestBaseV21):
|
|
||||||
ADMIN_API = True
|
|
||||||
sample_dir = "os-hypervisors"
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.flags(enable=True, cell_type='api', group='cells')
|
|
||||||
super(HypervisorsCellsSampleJsonTests, self).setUp()
|
|
||||||
|
|
||||||
def test_hypervisor_uptime(self, mocks):
|
|
||||||
fake_hypervisor = objects.ComputeNode(id=1, host='fake-mini',
|
|
||||||
hypervisor_hostname='fake-mini')
|
|
||||||
|
|
||||||
def fake_get_host_uptime(self, context, hyp):
|
|
||||||
return (" 08:32:11 up 93 days, 18:25, 12 users, load average:"
|
|
||||||
" 0.20, 0.12, 0.14")
|
|
||||||
|
|
||||||
def fake_compute_node_get(self, context, hyp):
|
|
||||||
return fake_hypervisor
|
|
||||||
|
|
||||||
def fake_service_get_by_compute_host(self, context, host):
|
|
||||||
return cells_utils.ServiceProxy(
|
|
||||||
objects.Service(id=1, host='fake-mini', disabled=False,
|
|
||||||
disabled_reason=None),
|
|
||||||
'cell1')
|
|
||||||
|
|
||||||
self.stub_out(
|
|
||||||
'nova.compute.cells_api.HostAPI.compute_node_get',
|
|
||||||
fake_compute_node_get)
|
|
||||||
self.stub_out(
|
|
||||||
'nova.compute.cells_api.HostAPI.service_get_by_compute_host',
|
|
||||||
fake_service_get_by_compute_host)
|
|
||||||
self.stub_out(
|
|
||||||
'nova.compute.cells_api.HostAPI.get_host_uptime',
|
|
||||||
fake_get_host_uptime)
|
|
||||||
|
|
||||||
hypervisor_id = fake_hypervisor.id
|
|
||||||
response = self._do_get('os-hypervisors/%s/uptime' % hypervisor_id)
|
|
||||||
subs = {'hypervisor_id': str(hypervisor_id)}
|
|
||||||
self._verify_response('hypervisors-uptime-resp', subs, response, 200)
|
|
||||||
|
|
||||||
|
|
||||||
class HypervisorsSampleJson228Tests(HypervisorsSampleJsonTests):
|
class HypervisorsSampleJson228Tests(HypervisorsSampleJsonTests):
|
||||||
microversion = '2.28'
|
microversion = '2.28'
|
||||||
scenarios = [('v2_28', {'api_major_version': 'v2.1'})]
|
scenarios = [('v2_28', {'api_major_version': 'v2.1'})]
|
||||||
|
|
|
@ -24,7 +24,6 @@ from webob import exc
|
||||||
|
|
||||||
from nova.api.openstack.compute import hypervisors \
|
from nova.api.openstack.compute import hypervisors \
|
||||||
as hypervisors_v21
|
as hypervisors_v21
|
||||||
from nova.cells import utils as cells_utils
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova import test
|
from nova import test
|
||||||
|
@ -188,7 +187,7 @@ class HypervisorsTestV21(test.NoDBTestCase):
|
||||||
# compute node primary key integer id or the uuid.
|
# compute node primary key integer id or the uuid.
|
||||||
expect_uuid_for_id = False
|
expect_uuid_for_id = False
|
||||||
|
|
||||||
# copying the objects locally so the cells testcases can provide their own
|
# TODO(stephenfin): These should just be defined here
|
||||||
TEST_HYPERS_OBJ = copy.deepcopy(TEST_HYPERS_OBJ)
|
TEST_HYPERS_OBJ = copy.deepcopy(TEST_HYPERS_OBJ)
|
||||||
TEST_SERVICES = copy.deepcopy(TEST_SERVICES)
|
TEST_SERVICES = copy.deepcopy(TEST_SERVICES)
|
||||||
TEST_SERVERS = copy.deepcopy(TEST_SERVERS)
|
TEST_SERVERS = copy.deepcopy(TEST_SERVERS)
|
||||||
|
@ -723,93 +722,6 @@ class HypervisorsTestV21(test.NoDBTestCase):
|
||||||
self.controller.statistics, req)
|
self.controller.statistics, req)
|
||||||
|
|
||||||
|
|
||||||
_CELL_PATH = 'cell1'
|
|
||||||
|
|
||||||
|
|
||||||
class CellHypervisorsTestV21(HypervisorsTestV21):
|
|
||||||
TEST_HYPERS_OBJ = [cells_utils.ComputeNodeProxy(obj, _CELL_PATH)
|
|
||||||
for obj in TEST_HYPERS_OBJ]
|
|
||||||
TEST_SERVICES = [cells_utils.ServiceProxy(obj, _CELL_PATH)
|
|
||||||
for obj in TEST_SERVICES]
|
|
||||||
|
|
||||||
TEST_SERVERS = [dict(server,
|
|
||||||
host=cells_utils.cell_with_item(_CELL_PATH,
|
|
||||||
server['host']))
|
|
||||||
for server in TEST_SERVERS]
|
|
||||||
|
|
||||||
DETAIL_HYPERS_DICTS = copy.deepcopy(HypervisorsTestV21.DETAIL_HYPERS_DICTS)
|
|
||||||
DETAIL_HYPERS_DICTS = [dict(hyp, id=cells_utils.cell_with_item(_CELL_PATH,
|
|
||||||
hyp['id']),
|
|
||||||
service=dict(hyp['service'],
|
|
||||||
id=cells_utils.cell_with_item(
|
|
||||||
_CELL_PATH,
|
|
||||||
hyp['service']['id']),
|
|
||||||
host=cells_utils.cell_with_item(
|
|
||||||
_CELL_PATH,
|
|
||||||
hyp['service']['host'])))
|
|
||||||
for hyp in DETAIL_HYPERS_DICTS]
|
|
||||||
|
|
||||||
INDEX_HYPER_DICTS = copy.deepcopy(HypervisorsTestV21.INDEX_HYPER_DICTS)
|
|
||||||
INDEX_HYPER_DICTS = [dict(hyp, id=cells_utils.cell_with_item(_CELL_PATH,
|
|
||||||
hyp['id']))
|
|
||||||
for hyp in INDEX_HYPER_DICTS]
|
|
||||||
|
|
||||||
# __deepcopy__ is added for copying an object locally in
|
|
||||||
# _test_view_hypervisor_detail_cpuinfo_null
|
|
||||||
cells_utils.ComputeNodeProxy.__deepcopy__ = (lambda self, memo:
|
|
||||||
cells_utils.ComputeNodeProxy(copy.deepcopy(self._obj, memo),
|
|
||||||
self._cell_path))
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def fake_compute_node_get_all(cls, context, limit=None, marker=None):
|
|
||||||
return cls.TEST_HYPERS_OBJ
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def fake_compute_node_search_by_hypervisor(cls, context, hypervisor_re):
|
|
||||||
return cls.TEST_HYPERS_OBJ
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def fake_compute_node_get(cls, context, compute_id):
|
|
||||||
for hyper in cls.TEST_HYPERS_OBJ:
|
|
||||||
if hyper.id == compute_id:
|
|
||||||
return hyper
|
|
||||||
raise exception.ComputeHostNotFound(host=compute_id)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def fake_service_get_by_compute_host(cls, context, host):
|
|
||||||
for service in cls.TEST_SERVICES:
|
|
||||||
if service.host == host:
|
|
||||||
return service
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def fake_instance_get_all_by_host(cls, context, host):
|
|
||||||
results = []
|
|
||||||
for inst in cls.TEST_SERVERS:
|
|
||||||
if inst['host'] == host:
|
|
||||||
results.append(inst)
|
|
||||||
return results
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
|
|
||||||
self.flags(enable=True, cell_type='api', group='cells')
|
|
||||||
|
|
||||||
super(CellHypervisorsTestV21, self).setUp()
|
|
||||||
|
|
||||||
host_api = self.controller.host_api
|
|
||||||
host_api.compute_node_get_all = mock.MagicMock(
|
|
||||||
side_effect=self.fake_compute_node_get_all)
|
|
||||||
host_api.service_get_by_compute_host = mock.MagicMock(
|
|
||||||
side_effect=self.fake_service_get_by_compute_host)
|
|
||||||
host_api.compute_node_search_by_hypervisor = mock.MagicMock(
|
|
||||||
side_effect=self.fake_compute_node_search_by_hypervisor)
|
|
||||||
host_api.compute_node_get = mock.MagicMock(
|
|
||||||
side_effect=self.fake_compute_node_get)
|
|
||||||
host_api.compute_node_statistics = mock.MagicMock(
|
|
||||||
side_effect=fake_compute_node_statistics)
|
|
||||||
host_api.instance_get_all_by_host = mock.MagicMock(
|
|
||||||
side_effect=self.fake_instance_get_all_by_host)
|
|
||||||
|
|
||||||
|
|
||||||
class HypervisorsTestV228(HypervisorsTestV21):
|
class HypervisorsTestV228(HypervisorsTestV21):
|
||||||
api_version = '2.28'
|
api_version = '2.28'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue