From ff1b77f71a72d6f812f8ebe0d6f72b0d3259c894 Mon Sep 17 00:00:00 2001 From: Juergen Leopold Date: Tue, 18 Apr 2017 10:04:53 +0000 Subject: [PATCH] Handles exception in init_host() if CPC is not found This code writes an error log in the nova log if the CPC is not found in the init_host() method of the DPMDriver. This will help to debug problems. The error message contains information about the HMC host, HMC userid and CPC UUID that were used. Closes-Bug: #1659037 Change-Id: I4606cefc9943c0a1a3a0db0c496dcce5c468407f Signed-off-by: Juergen Leopold --- nova_dpm/tests/unit/virt/dpm/test_driver.py | 5 +++++ nova_dpm/virt/dpm/driver.py | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/nova_dpm/tests/unit/virt/dpm/test_driver.py b/nova_dpm/tests/unit/virt/dpm/test_driver.py index 03a601f..4696fcc 100644 --- a/nova_dpm/tests/unit/virt/dpm/test_driver.py +++ b/nova_dpm/tests/unit/virt/dpm/test_driver.py @@ -80,6 +80,11 @@ class DPMdriverInitHostTestCase(TestCase): self.flags(group="dpm", max_memory=512) self.dpmdriver.init_host(None) + def test_cpc_not_exists(self): + self.flags(group="dpm", cpc_object_id="abc") + self.assertRaises(SystemExit, + self.dpmdriver.init_host, None) + def test_get_available_resource(self): host_properties = self.dpmdriver.get_available_resource(None) self.assertEqual('cpc_1', host_properties['cpc_name']) diff --git a/nova_dpm/virt/dpm/driver.py b/nova_dpm/virt/dpm/driver.py index 2ef8774..847046f 100644 --- a/nova_dpm/virt/dpm/driver.py +++ b/nova_dpm/virt/dpm/driver.py @@ -33,6 +33,9 @@ from nova_dpm.virt.dpm import utils from nova_dpm.virt.dpm import vm from oslo_log import log as logging from oslo_utils import importutils +import sys +import zhmcclient + LOG = logging.getLogger(__name__) CONF = nova_dpm.conf.CONF @@ -71,9 +74,15 @@ class DPMDriver(driver.ComputeDriver): def init_host(self, host): """Driver initialization of the hypervisor node""" LOG.debug("init_host") - - self._cpc = self._client.cpcs.find(**{ - "object-id": CONF.dpm.cpc_object_id}) + try: + self._cpc = self._client.cpcs.find(**{ + "object-id": CONF.dpm.cpc_object_id}) + except zhmcclient.NotFound: + LOG.error("Matching hypervisor %s not found for object-id %s " + "and username %s on HMC %s", + CONF.host, CONF.dpm.cpc_object_id, + CONF.dpm.hmc_username, CONF.dpm.hmc) + sys.exit(1) LOG.debug("Matching hypervisor found %s for object-id %s and CPC %s", CONF.host, CONF.dpm.cpc_object_id, self._cpc.properties['name'])