From 0b2125e64c628c90633b08dbe4033bcbb5fafe92 Mon Sep 17 00:00:00 2001 From: Matt Rabe Date: Tue, 31 May 2016 23:14:41 +0200 Subject: [PATCH] Raise an exception if no active VIOSes in build_tx_feed_task get_active_vioses returns an empty list if there aren't any active VIOSes. If an empty list is used as the feed to a FeedTask then we get a generic error explaining that the FeedTask can't have an empty feed. This change attempts to make the error more clear in the event there aren't any active VIOSes when build_tx_feed_task is called by raising an exception explaining that there aren't any active VIOSes. Change-Id: I3d67c653131952bfc13bbbda2e67486c0291c4cc Closes-Bug: #1581652 --- nova_powervm/tests/virt/powervm/test_vios.py | 16 ++++++++++++++++ nova_powervm/virt/powervm/exception.py | 4 ++++ nova_powervm/virt/powervm/vios.py | 8 ++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/nova_powervm/tests/virt/powervm/test_vios.py b/nova_powervm/tests/virt/powervm/test_vios.py index d0b21bec..e507af40 100644 --- a/nova_powervm/tests/virt/powervm/test_vios.py +++ b/nova_powervm/tests/virt/powervm/test_vios.py @@ -103,6 +103,22 @@ class TestVios(test.TestCase): result = set(vios.get_physical_wwpns(self.adpt, 'fake_uuid')) self.assertSetEqual(expected, result) + @mock.patch('nova_powervm.virt.powervm.vios.get_active_vioses') + @mock.patch('pypowervm.utils.transaction.FeedTask') + def test_build_tx_feed_task(self, mock_feed_task, mock_get_active_vioses): + mock_get_active_vioses.return_value = ['vios1', 'vios2'] + mock_feed_task.return_value = 'mock_feed' + self.assertEqual('mock_feed', + vios.build_tx_feed_task(mock.MagicMock(), + mock.MagicMock())) + + @mock.patch('nova_powervm.virt.powervm.vios.get_active_vioses') + def test_build_tx_feed_task_w_empty_feed(self, mock_get_active_vioses): + mock_get_active_vioses.return_value = [] + self.assertRaises( + nova_pvm_exc.NoActiveViosForFeedTask, vios.build_tx_feed_task, + mock.MagicMock(), mock.MagicMock()) + @mock.patch('retrying.retry') @mock.patch('nova_powervm.virt.powervm.vios.get_active_vioses') @mock.patch('nova_powervm.virt.powervm.vios.get_inactive_running_vioses') diff --git a/nova_powervm/virt/powervm/exception.py b/nova_powervm/virt/powervm/exception.py index 362778da..b4109864 100644 --- a/nova_powervm/virt/powervm/exception.py +++ b/nova_powervm/virt/powervm/exception.py @@ -125,6 +125,10 @@ class ViosNotAvailable(nex.NovaException): "I/O Servers and then restart the Nova Compute Agent.") +class NoActiveViosForFeedTask(nex.NovaException): + msg_fmt = _("There are no active Virtual I/O Servers available.") + + class InvalidRebuild(nex.NovaException): msg_fmt = _("Unable to rebuild virtual machine on new host. Error is " "%(error)s") diff --git a/nova_powervm/virt/powervm/vios.py b/nova_powervm/virt/powervm/vios.py index bd9d9a08..5884b77e 100644 --- a/nova_powervm/virt/powervm/vios.py +++ b/nova_powervm/virt/powervm/vios.py @@ -127,8 +127,12 @@ def build_tx_feed_task(adapter, host_uuid, name='vio_feed_mgr', in defaults to all storage options (as this is most common case for using a transaction manager). """ - return pvm_tx.FeedTask(name, - get_active_vioses(adapter, host_uuid, xag=xag)) + + active_vio_feed = get_active_vioses(adapter, xag=xag) + if not active_vio_feed: + raise nova_pvm_exc.NoActiveViosForFeedTask() + + return pvm_tx.FeedTask(name, active_vio_feed) def validate_vios_ready(adapter, host_uuid):