Fix a bug that caused exception on XenServer 7.1 with Cummulative Update (#52303)
- xenserver module_util: fixed a bug in gather_vm_params function where an exception was generated if XenServer product_version_text_short parameter contained non numeric characters, e.g. "7.1 CU1" on XenServer version 7.1 with Cummulative Update 1. Code was changed to use product_version parameter instead which is all numeric. - xenserver module_util: get_xenserver_version function is changed to return a list of integers for major, minor and update version instead of list of strings. - xenserver module_util: unit tests are updated according to changes. - xenserver module_util: removed unused imports.
This commit is contained in:
parent
409345ee97
commit
922af44d7d
3 changed files with 13 additions and 9 deletions
|
@ -17,9 +17,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.urls import fetch_url
|
|
||||||
from ansible.module_utils.six import integer_types, iteritems, string_types
|
|
||||||
from ansible.module_utils.basic import env_fallback
|
from ansible.module_utils.basic import env_fallback
|
||||||
from ansible.module_utils.ansible_release import __version__ as ANSIBLE_VERSION
|
from ansible.module_utils.ansible_release import __version__ as ANSIBLE_VERSION
|
||||||
|
|
||||||
|
@ -408,7 +405,7 @@ def gather_vm_params(module, vm_ref):
|
||||||
# Detect customization agent.
|
# Detect customization agent.
|
||||||
xenserver_version = get_xenserver_version(module)
|
xenserver_version = get_xenserver_version(module)
|
||||||
|
|
||||||
if (int(xenserver_version[0]) >= 7 and int(xenserver_version[1]) >= 0 and vm_params.get('guest_metrics') and
|
if (xenserver_version[0] >= 7 and xenserver_version[1] >= 0 and vm_params.get('guest_metrics') and
|
||||||
"feature-static-ip-setting" in vm_params['guest_metrics']['other']):
|
"feature-static-ip-setting" in vm_params['guest_metrics']['other']):
|
||||||
vm_params['customization_agent'] = "native"
|
vm_params['customization_agent'] = "native"
|
||||||
else:
|
else:
|
||||||
|
@ -756,12 +753,19 @@ def get_xenserver_version(module):
|
||||||
module: Reference to Ansible module object.
|
module: Reference to Ansible module object.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: Element [0] is major version. Element [1] i minor version.
|
list: Element [0] is major version. Element [1] is minor version.
|
||||||
|
Element [2] is update number.
|
||||||
"""
|
"""
|
||||||
xapi_session = XAPI.connect(module)
|
xapi_session = XAPI.connect(module)
|
||||||
|
|
||||||
host_ref = xapi_session.xenapi.session.get_this_host(xapi_session._session)
|
host_ref = xapi_session.xenapi.session.get_this_host(xapi_session._session)
|
||||||
return xapi_session.xenapi.host.get_software_version(host_ref)['product_version_text_short'].split('.')
|
|
||||||
|
try:
|
||||||
|
xenserver_version = [int(version_number) for version_number in xapi_session.xenapi.host.get_software_version(host_ref)['product_version'].split('.')]
|
||||||
|
except ValueError:
|
||||||
|
xenserver_version = [0, 0, 0]
|
||||||
|
|
||||||
|
return xenserver_version
|
||||||
|
|
||||||
|
|
||||||
class XAPI(object):
|
class XAPI(object):
|
||||||
|
|
|
@ -68,7 +68,7 @@ def test_gather_vm_params_and_facts(mocker, fake_ansible_module, XenAPI, xenserv
|
||||||
|
|
||||||
mocked_xenapi.configure_mock(**mocked_returns)
|
mocked_xenapi.configure_mock(**mocked_returns)
|
||||||
|
|
||||||
mocker.patch('ansible.module_utils.xenserver.get_xenserver_version', return_value=['7', '2'])
|
mocker.patch('ansible.module_utils.xenserver.get_xenserver_version', return_value=[7, 2, 0])
|
||||||
|
|
||||||
vm_ref = list(fixture_data_from_file[params_file]['VM'].keys())[0]
|
vm_ref = list(fixture_data_from_file[params_file]['VM'].keys())[0]
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ def test_xenserverobject(mocker, fake_ansible_module, XenAPI, xenserver):
|
||||||
"pool.get_all.return_value": [fake_xenapi_ref('pool')],
|
"pool.get_all.return_value": [fake_xenapi_ref('pool')],
|
||||||
"pool.get_default_SR.return_value": fake_xenapi_ref('SR'),
|
"pool.get_default_SR.return_value": fake_xenapi_ref('SR'),
|
||||||
"session.get_this_host.return_value": fake_xenapi_ref('host'),
|
"session.get_this_host.return_value": fake_xenapi_ref('host'),
|
||||||
"host.get_software_version.return_value": {"product_version_text_short": "7.2"},
|
"host.get_software_version.return_value": {"product_version": "7.2.0"},
|
||||||
}
|
}
|
||||||
|
|
||||||
mocked_xenapi.configure_mock(**mocked_returns)
|
mocked_xenapi.configure_mock(**mocked_returns)
|
||||||
|
@ -47,4 +47,4 @@ def test_xenserverobject(mocker, fake_ansible_module, XenAPI, xenserver):
|
||||||
xso = xenserver.XenServerObject(fake_ansible_module)
|
xso = xenserver.XenServerObject(fake_ansible_module)
|
||||||
|
|
||||||
assert xso.pool_ref == fake_xenapi_ref('pool')
|
assert xso.pool_ref == fake_xenapi_ref('pool')
|
||||||
assert xso.xenserver_version == ['7', '2']
|
assert xso.xenserver_version == [7, 2, 0]
|
||||||
|
|
Loading…
Reference in a new issue