Skip to content

Commit

Permalink
XenAPI: Fix config section usage
Browse files Browse the repository at this point in the history
Change I2e9f720ddce284fc112d6a5651fd277e6e31a17a introduced xenserver
sections but a couple of CONF variables were not updated to use the
new sections.

Fixed the few remaining options and add unit tests to ensure they are
caught in future.

The unit tests highlighted that the functions behaved strangely in
the cases where the default was being provided - so updated to be
clear about getting the default.

Closes-bug: 1253064

Change-Id: Ic538069cd087aa3cdc0a1f7fdb94820d5d3b22b1
  • Loading branch information
Bob Ball committed Nov 22, 2013
1 parent 3e6f805 commit 32f1b41
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
17 changes: 13 additions & 4 deletions nova/tests/virt/xenapi/image/test_glance.py
Expand Up @@ -88,15 +88,16 @@ def test_download_image(self):

self.mox.VerifyAll()

def _get_upload_params(self, auto_disk_config=True):
def _get_upload_params(self, auto_disk_config=True,
expected_os_type='default'):
params = self._get_params()
params['vdi_uuids'] = ['fake_vdi_uuid']
params['properties'] = {'auto_disk_config': auto_disk_config,
'os_type': 'default'}
'os_type': expected_os_type}
return params

def _test_upload_image(self, auto_disk_config):
params = self._get_upload_params(auto_disk_config)
def _test_upload_image(self, auto_disk_config, expected_os_type='default'):
params = self._get_upload_params(auto_disk_config, expected_os_type)

self.mox.StubOutWithMock(self.session, 'call_plugin_serialized')
self.session.call_plugin_serialized('glance', 'upload_vhd', **params)
Expand All @@ -109,6 +110,14 @@ def _test_upload_image(self, auto_disk_config):
def test_upload_image(self):
self._test_upload_image(True)

def test_upload_image_None_os_type(self):
self.instance['os_type'] = None
self._test_upload_image(True, 'linux')

def test_upload_image_no_os_type(self):
del self.instance['os_type']
self._test_upload_image(True, 'linux')

def test_upload_image_auto_config_disk_disabled(self):
sys_meta = [{"key": "image_auto_disk_config", "value": "Disabled"}]
self.instance["system_metadata"] = sys_meta
Expand Down
23 changes: 23 additions & 0 deletions nova/tests/virt/xenapi/test_volume_utils.py
Expand Up @@ -33,3 +33,26 @@ def test_vbd_plug_check_synchronized(self, mock_synchronized):
session = mock.Mock()
volume_utils.vbd_plug(session, "vbd_ref", "vm_ref:123")
mock_synchronized.assert_called_once_with("xenapi-vbd-plug-vm_ref:123")


class ISCSIParametersTestCase(stubs.XenAPITestBaseNoDB):
def test_target_host(self):
self.assertEqual(volume_utils._get_target_host('host:port'),
'host')

self.assertEqual(volume_utils._get_target_host('host'),
'host')

# There is no default value
self.assertEqual(volume_utils._get_target_host(':port'),
None)

self.assertEqual(volume_utils._get_target_host(None),
None)

def test_target_port(self):
self.assertEqual(volume_utils._get_target_port('host:port'),
'port')

self.assertEqual(volume_utils._get_target_port('host'),
'3260')
3 changes: 2 additions & 1 deletion nova/virt/xenapi/image/glance.py
Expand Up @@ -59,7 +59,8 @@ def upload_image(self, context, session, instance, vdi_uuids, image_id):

props = params['properties'] = {}
props['auto_disk_config'] = instance['auto_disk_config']
props['os_type'] = instance['os_type'] or CONF.default_os_type
props['os_type'] = instance.get('os_type', None) or (
CONF.xenserver.default_os_type)

compression_level = vm_utils.get_compression_level()
if compression_level:
Expand Down
15 changes: 8 additions & 7 deletions nova/virt/xenapi/volume_utils.py
Expand Up @@ -300,17 +300,18 @@ def _get_volume_id(path_or_id):
def _get_target_host(iscsi_string):
"""Retrieve target host."""
if iscsi_string:
return iscsi_string[0:iscsi_string.find(':')]
elif iscsi_string is None or CONF.target_host:
return CONF.target_host
host = iscsi_string.split(':')[0]
if len(host) > 0:
return host
return CONF.xenserver.target_host


def _get_target_port(iscsi_string):
"""Retrieve target port."""
if iscsi_string:
return iscsi_string[iscsi_string.find(':') + 1:]
elif iscsi_string is None or CONF.target_port:
return CONF.target_port
if iscsi_string and ':' in iscsi_string:
return iscsi_string.split(':')[1]

return CONF.xenserver.target_port


def vbd_plug(session, vbd_ref, vm_ref):
Expand Down

0 comments on commit 32f1b41

Please sign in to comment.