From 9af4c1f24101f4c77454017629b496df379f1299 Mon Sep 17 00:00:00 2001 From: Drew Thorstensen Date: Tue, 19 Apr 2016 13:46:17 -0400 Subject: [PATCH] Allow multiple session connection attempts We have seen scenarios where users have rebooted their systems and the ceilometer-powervm process has started before the backing PowerVM REST server. This generally indicates a packaging issue (where the ceilometer-powervm package should depend on the others). However, there is the ability in the PowerVM Session to make multiple attempts. This change set takes advantage of the multiple attempts provided by the pypowervm session. That means that if the REST server is booting, the ceilometer-powervm will wait up to 10 minutes for the REST server to finish starting. The REST server should start much faster than that, and this is just an upper limit timeout. Change-Id: If9569eccbdb9107e5892f03a91a035e1d5943e5e Closes-Bug: 1570404 --- .../compute/virt/powervm/inspector.py | 8 +++-- .../compute/virt/powervm/test_inspector.py | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ceilometer_powervm/compute/virt/powervm/inspector.py b/ceilometer_powervm/compute/virt/powervm/inspector.py index 2d4d02c..d384c3c 100644 --- a/ceilometer_powervm/compute/virt/powervm/inspector.py +++ b/ceilometer_powervm/compute/virt/powervm/inspector.py @@ -43,10 +43,12 @@ class PowerVMInspector(virt_inspector.Inspector): def __init__(self): super(PowerVMInspector, self).__init__() - # Build the adapter to the PowerVM API. + # Build the adapter. May need to attempt the connection multiple times + # in case the REST server is starting. + session = pvm_adpt.Session(conn_tries=300) self.adpt = pvm_adpt.Adapter( - pvm_adpt.Session(), helpers=[log_hlp.log_helper, - vio_hlp.vios_busy_retry_helper]) + session, helpers=[log_hlp.log_helper, + vio_hlp.vios_busy_retry_helper]) # Get the host system UUID host_uuid = self._get_host_uuid(self.adpt) diff --git a/ceilometer_powervm/tests/compute/virt/powervm/test_inspector.py b/ceilometer_powervm/tests/compute/virt/powervm/test_inspector.py index ab185a7..e15a797 100644 --- a/ceilometer_powervm/tests/compute/virt/powervm/test_inspector.py +++ b/ceilometer_powervm/tests/compute/virt/powervm/test_inspector.py @@ -19,12 +19,45 @@ import mock from ceilometer.compute.virt import inspector as virt_inspector from oslotest import base +from pypowervm.helpers import log_helper as log_hlp +from pypowervm.helpers import vios_busy as vio_hlp from pypowervm.tests import test_fixtures as api_fx from ceilometer_powervm.compute.virt.powervm import inspector as p_inspect from ceilometer_powervm.tests.compute.virt.powervm import pvm_fixtures +class TestPowerVMInspectorInit(base.BaseTestCase): + """Tests the initialization of the VM Inspector.""" + + @mock.patch('pypowervm.tasks.monitor.util.LparMetricCache') + @mock.patch('pypowervm.tasks.monitor.util.ensure_ltm_monitors') + @mock.patch('ceilometer_powervm.compute.virt.powervm.inspector.' + 'PowerVMInspector._get_host_uuid') + @mock.patch('pypowervm.adapter.Adapter') + @mock.patch('pypowervm.adapter.Session') + def test_init(self, mock_session, mock_adapter, mock_get_host_uuid, + mock_ensure_ltm, mock_cache): + # Mock up data + mock_get_host_uuid.return_value = 'host_uuid' + + # Invoke + inspector = p_inspect.PowerVMInspector() + + # Validate + mock_session.assert_called_once_with(conn_tries=300) + mock_adapter.assert_called_once_with( + mock_session.return_value, + helpers=[log_hlp.log_helper, vio_hlp.vios_busy_retry_helper]) + + mock_get_host_uuid.assert_called_once_with(mock_adapter.return_value) + mock_ensure_ltm.assert_called_once_with(mock_adapter.return_value, + 'host_uuid') + mock_cache.assert_called_once_with(mock_adapter.return_value, + 'host_uuid') + self.assertEqual(mock_cache.return_value, inspector.vm_metrics) + + class TestPowerVMInspector(base.BaseTestCase): def setUp(self):