summaryrefslogtreecommitdiff
path: root/nova/tests/unit/compute/test_instance_list.py
diff options
context:
space:
mode:
authorSurya Seetharaman <suryaseetharaman.9@gmail.com>2018-08-16 15:51:35 +0200
committerSurya Seetharaman <suryaseetharaman.9@gmail.com>2018-09-20 22:02:26 +0200
commit21c5f3e2e5eee162e9781f733f2eac7ebd94655f (patch)
tree67a35ff074d7015a41537e415a1f33c1e7ee52b4 /nova/tests/unit/compute/test_instance_list.py
parentc5788293aaa3b9617ee2efac48c969c49a5016e3 (diff)
downloadnova-21c5f3e2e5eee162e9781f733f2eac7ebd94655f.tar.gz
Making instance/migration listing skipping down cells configurable
Presently if a cell is down, the instances in that cell are skipped from results. Sometimes this may not be desirable for operators as it may confuse the users who saw more instances in their previous listing than now. This patch adds a new api config option called list_records_by_skipping_down_cells which can be set to False (True by default) if the operator desires to just return an API error altogether if the user has any instance in the down cell instead of skipping. This is essentially a configurable revert of change I308b494ab07f6936bef94f4c9da45e9473e3534d for bug 1726301 so that operators can opt into the 500 response behaviour during listing. Change-Id: Id749761c58d4e1bc001b745d49b6ff0f3732e133 Related-Bug: #1726301
Diffstat (limited to 'nova/tests/unit/compute/test_instance_list.py')
-rw-r--r--nova/tests/unit/compute/test_instance_list.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/nova/tests/unit/compute/test_instance_list.py b/nova/tests/unit/compute/test_instance_list.py
index c3be17dbb4..644d1e00bd 100644
--- a/nova/tests/unit/compute/test_instance_list.py
+++ b/nova/tests/unit/compute/test_instance_list.py
@@ -12,10 +12,12 @@
import mock
from oslo_utils.fixture import uuidsentinel as uuids
+import six
from nova.compute import instance_list
from nova.compute import multi_cell_list
from nova import context as nova_context
+from nova import exception
from nova import objects
from nova import test
from nova.tests import fixtures
@@ -185,6 +187,32 @@ class TestInstanceList(test.NoDBTestCase):
# return the results from the up cell, ignoring the down cell.
self.assertEqual(uuid_initial, uuid_final)
+ @mock.patch('nova.context.scatter_gather_cells')
+ def test_get_instances_by_not_skipping_down_cells(self, mock_sg):
+ self.flags(list_records_by_skipping_down_cells=False, group='api')
+ inst_cell0 = self.insts[uuids.cell0]
+
+ def wrap(thing):
+ return multi_cell_list.RecordWrapper(ctx, self.context, thing)
+
+ ctx = nova_context.RequestContext()
+ instances = [wrap(inst) for inst in inst_cell0]
+
+ # creating one up cell and two down cells
+ ret_val = {}
+ ret_val[uuids.cell0] = instances
+ ret_val[uuids.cell1] = [wrap(nova_context.raised_exception_sentinel)]
+ ret_val[uuids.cell2] = [wrap(nova_context.did_not_respond_sentinel)]
+ mock_sg.return_value = ret_val
+
+ # Raises exception if a cell is down without skipping them
+ # as CONF.api.list_records_by_skipping_down_cells is set to False.
+ # This would in turn result in an API 500 internal error.
+ exp = self.assertRaises(exception.NovaException,
+ instance_list.get_instance_objects_sorted, self.context, {}, None,
+ None, [], None, None)
+ self.assertIn('configuration indicates', six.text_type(exp))
+
def test_batch_size_fixed(self):
fixed_size = 200
self.flags(instance_list_cells_batch_strategy='fixed', group='api')