From ff17c6fd898403da58c30672fe0276be75f410e3 Mon Sep 17 00:00:00 2001 From: Mate Lakat Date: Tue, 14 Aug 2012 14:50:50 +0100 Subject: XCP-XAPI version fix Fixes bug 1033933. On an Kronos installation (Ubuntu + XCP-XAPI), the reported software_version dictionary did not contain both product_version and product_brand. This caused a KeyError. With this fix, the session's product_version and product_brand will default to None in such cases. The resize operation's name in these cases will default to VDI.resize. Change-Id: Ic0db4128a7b27c08c24461562423bcecd1373e58 --- nova/tests/test_xenapi.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 5ab059d07..7dab9bbc1 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -2534,3 +2534,66 @@ class XenAPIInjectMetadataTestCase(stubs.XenAPITestBase): 'vm-data/user-metadata/c': '3', }, }) + + +class VMOpsTestCase(test.TestCase): + def _get_mock_session(self, product_brand, product_version): + class Mock(object): + pass + + mock_session = Mock() + mock_session.product_brand = product_brand + mock_session.product_version = product_version + + return mock_session + + def test_check_resize_func_name_defaults_to_VDI_resize(self): + session = self._get_mock_session(None, None) + ops = vmops.VMOps(session) + + self.assertEquals( + 'VDI.resize', + ops.check_resize_func_name()) + + +class XenAPISessionTestCase(test.TestCase): + def _get_mock_xapisession(self, software_version): + class XcpXapiSession(xenapi_conn.XenAPISession): + def __init__(_ignore): + "Skip the superclass's dirty init" + + def _get_software_version(_ignore): + return software_version + + return XcpXapiSession() + + def test_get_product_version_product_brand_does_not_fail(self): + session = self._get_mock_xapisession({ + 'build_number': '0', + 'date': '2012-08-03', + 'hostname': 'komainu', + 'linux': '3.2.0-27-generic', + 'network_backend': 'bridge', + 'platform_name': 'XCP_Kronos', + 'platform_version': '1.6.0', + 'xapi': '1.3', + 'xen': '4.1.2', + 'xencenter_max': '1.10', + 'xencenter_min': '1.10' + }) + + self.assertEquals( + (None, None), + session._get_product_version_and_brand() + ) + + def test_get_product_version_product_brand_xs_6(self): + session = self._get_mock_xapisession({ + 'product_brand': 'XenServer', + 'product_version': '6.0.50' + }) + + self.assertEquals( + ((6, 0, 50), 'XenServer'), + session._get_product_version_and_brand() + ) -- cgit