From 128c75054bac5d31ba7a7ea0ebcb9a27aa12100d Mon Sep 17 00:00:00 2001 From: dineshbhor Date: Tue, 14 Mar 2017 17:53:46 +0530 Subject: [PATCH] Use HostAddressOpt for opts that accept IP and hostnames Some configuration options were accepting both IP addresses and hostnames. Since there was no specific OSLO opt type to support this, we were using 'StrOpt'. The support for 'HostAddressOpt' type was merged in Ocata and became available for use with oslo version 3.22. This patch changes the opt type of configuration options to use this more relevant opt type - HostAddressOpt. Co-Authored-By: John Garbutt Change-Id: I6116b4cc3deef4b9fad9383ea3e6a570a8becead --- nova/conf/remote_debug.py | 4 ++-- nova/conf/scheduler.py | 4 ++-- nova/conf/spice.py | 2 +- nova/conf/vmware.py | 4 ++-- nova/conf/vnc.py | 6 +++--- nova/conf/xenserver.py | 2 +- nova/tests/unit/test_service.py | 6 +++--- .../unit/virt/vmwareapi/test_configdrive.py | 2 +- .../unit/virt/vmwareapi/test_driver_api.py | 20 ++++++++++--------- .../unit/virt/vmwareapi/test_volumeops.py | 8 ++++---- 10 files changed, 30 insertions(+), 28 deletions(-) diff --git a/nova/conf/remote_debug.py b/nova/conf/remote_debug.py index f64b9450f0d6..7e464bcb4970 100644 --- a/nova/conf/remote_debug.py +++ b/nova/conf/remote_debug.py @@ -20,8 +20,8 @@ debugger_group = cfg.OptGroup('remote_debug', title='debugger options') CLI_OPTS = [ - cfg.StrOpt('host', - help=""" + cfg.HostAddressOpt('host', + help=""" Debug host (IP or name) to connect to. This command line parameter is used when you want to connect to a nova service via a debugger running on a different host. diff --git a/nova/conf/scheduler.py b/nova/conf/scheduler.py index 544883a46de3..99e36bea3788 100644 --- a/nova/conf/scheduler.py +++ b/nova/conf/scheduler.py @@ -586,8 +586,8 @@ Configuration options for enabling Trusted Platform Module. """) trusted_opts = [ - cfg.StrOpt("attestation_server", - help=""" + cfg.HostAddressOpt("attestation_server", + help=""" The host to use as the attestation server. Cloud computing pools can involve thousands of compute nodes located at diff --git a/nova/conf/spice.py b/nova/conf/spice.py index 9681a8d4be48..b640ae59a22c 100644 --- a/nova/conf/spice.py +++ b/nova/conf/spice.py @@ -31,7 +31,7 @@ Following requirements must be met in order to use SPICE: """) CLI_OPTS = [ - cfg.StrOpt('html5proxy_host', + cfg.HostAddressOpt('html5proxy_host', default='0.0.0.0', help=""" IP address or a hostname on which the ``nova-spicehtml5proxy`` service diff --git a/nova/conf/vmware.py b/nova/conf/vmware.py index 917039958509..6f2dff79a148 100644 --- a/nova/conf/vmware.py +++ b/nova/conf/vmware.py @@ -92,8 +92,8 @@ This option is ignored if serial_port_service_uri is not specified. ] vmwareapi_opts = [ - cfg.StrOpt('host_ip', - help=""" + cfg.HostAddressOpt('host_ip', + help=""" Hostname or IP address for connection to VMware vCenter host."""), cfg.PortOpt('host_port', default=443, diff --git a/nova/conf/vnc.py b/nova/conf/vnc.py index 844091f79d06..b503f6328e5c 100644 --- a/nova/conf/vnc.py +++ b/nova/conf/vnc.py @@ -54,7 +54,7 @@ Possible values: of supported keyboard layouts at ``/usr/share/qemu/keymaps``. """), - cfg.StrOpt( + cfg.HostAddressOpt( 'vncserver_listen', default='127.0.0.1', deprecated_group='DEFAULT', @@ -63,7 +63,7 @@ The IP address or hostname on which an instance should listen to for incoming VNC connection requests on this node. """), - cfg.StrOpt( + cfg.HostAddressOpt( 'vncserver_proxyclient_address', default='127.0.0.1', deprecated_group='DEFAULT', @@ -98,7 +98,7 @@ Related options: * novncproxy_port """), - cfg.StrOpt( + cfg.HostAddressOpt( 'xvpvncproxy_host', default='0.0.0.0', deprecated_group='DEFAULT', diff --git a/nova/conf/xenserver.py b/nova/conf/xenserver.py index 1cffeba72b4f..a6936a1c44d3 100644 --- a/nova/conf/xenserver.py +++ b/nova/conf/xenserver.py @@ -463,7 +463,7 @@ Related opitons: cfg.StrOpt('sr_base_path', default='/var/run/sr-mount', help='Base path to the storage repository on the XenServer host.'), - cfg.StrOpt('target_host', + cfg.HostAddressOpt('target_host', help=""" The iSCSI Target Host. diff --git a/nova/tests/unit/test_service.py b/nova/tests/unit/test_service.py index ee0ca2ba39e6..c6b36f34d0f5 100644 --- a/nova/tests/unit/test_service.py +++ b/nova/tests/unit/test_service.py @@ -33,9 +33,9 @@ from nova import test from nova.tests.unit import utils test_service_opts = [ - cfg.StrOpt("test_service_listen", - default='127.0.0.1', - help="Host to bind test service to"), + cfg.HostAddressOpt("test_service_listen", + default='127.0.0.1', + help="Host to bind test service to"), cfg.IntOpt("test_service_listen_port", default=0, help="Port number to bind test service to"), diff --git a/nova/tests/unit/virt/vmwareapi/test_configdrive.py b/nova/tests/unit/virt/vmwareapi/test_configdrive.py index 474c1513b895..b280c9c7e7c9 100644 --- a/nova/tests/unit/virt/vmwareapi/test_configdrive.py +++ b/nova/tests/unit/virt/vmwareapi/test_configdrive.py @@ -43,7 +43,7 @@ class ConfigDriveTestCase(test.NoDBTestCase): vm_util.vm_refs_cache_reset() self.context = context.RequestContext('fake', 'fake', is_admin=False) self.flags(cluster_name='test_cluster', - host_ip='test_url', + host_ip='testhostname', host_username='test_username', host_password='test_pass', use_linked_clone=False, group='vmware') diff --git a/nova/tests/unit/virt/vmwareapi/test_driver_api.py b/nova/tests/unit/virt/vmwareapi/test_driver_api.py index be81523fdcc1..e96648d1784a 100644 --- a/nova/tests/unit/virt/vmwareapi/test_driver_api.py +++ b/nova/tests/unit/virt/vmwareapi/test_driver_api.py @@ -67,6 +67,8 @@ from nova.virt.vmwareapi import volumeops CONF = nova.conf.CONF +HOST = 'testhostname' + DEFAULT_FLAVORS = [ {'memory_mb': 512, 'root_gb': 1, 'deleted_at': None, 'name': 'm1.tiny', 'deleted': 0, 'created_at': None, 'ephemeral_gb': 0, 'updated_at': None, @@ -201,7 +203,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): vm_util.vm_refs_cache_reset() self.context = context.RequestContext('fake', 'fake', is_admin=False) self.flags(cluster_name='test_cluster', - host_ip='test_url', + host_ip=HOST, host_username='test_username', host_password='test_pass', api_retry_count=1, @@ -215,7 +217,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): stubs.set_stubs(self) vmwareapi_fake.reset() nova.tests.unit.image.fake.stub_out_image_service(self) - service = self._create_service(host='test_url') + service = self._create_service(host=HOST) self.conn = driver.VMwareVCDriver(None, False) self.assertFalse(service.disabled) @@ -251,7 +253,7 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): self.assertFalse(self.conn.need_legacy_block_device_info) def test_get_host_ip_addr(self): - self.assertEqual('test_url', self.conn.get_host_ip_addr()) + self.assertEqual(HOST, self.conn.get_host_ip_addr()) def test_init_host_with_no_session(self): self.conn._session = mock.Mock() @@ -1700,9 +1702,9 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): connector_dict = self.conn.get_volume_connector(self.instance) fake_vm = self._get_vm_record() fake_vm_id = fake_vm.obj.value - self.assertEqual('test_url', connector_dict['ip']) + self.assertEqual(HOST, connector_dict['ip']) self.assertEqual('iscsi-name', connector_dict['initiator']) - self.assertEqual('test_url', connector_dict['host']) + self.assertEqual(HOST, connector_dict['host']) self.assertEqual(fake_vm_id, connector_dict['instance']) def _test_vmdk_connection_info(self, type): @@ -1891,8 +1893,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): def test_connection_info_get(self): self._create_vm() connector = self.conn.get_volume_connector(self.instance) - self.assertEqual('test_url', connector['ip']) - self.assertEqual('test_url', connector['host']) + self.assertEqual(HOST, connector['ip']) + self.assertEqual(HOST, connector['host']) self.assertEqual('iscsi-name', connector['initiator']) self.assertIn('instance', connector) @@ -1900,8 +1902,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): self._create_vm() self.conn.destroy(self.context, self.instance, self.network_info) connector = self.conn.get_volume_connector(self.instance) - self.assertEqual('test_url', connector['ip']) - self.assertEqual('test_url', connector['host']) + self.assertEqual(HOST, connector['ip']) + self.assertEqual(HOST, connector['host']) self.assertEqual('iscsi-name', connector['initiator']) self.assertNotIn('instance', connector) diff --git a/nova/tests/unit/virt/vmwareapi/test_volumeops.py b/nova/tests/unit/virt/vmwareapi/test_volumeops.py index c5776da972a7..2b36f72bd34a 100644 --- a/nova/tests/unit/virt/vmwareapi/test_volumeops.py +++ b/nova/tests/unit/virt/vmwareapi/test_volumeops.py @@ -661,8 +661,8 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase): vm_id = 'fake-vm' vm_ref = mock.MagicMock(value=vm_id) iqn = 'iscsi-name' - url = 'test_url' - self.flags(host_ip=url, group='vmware') + host_ip = 'testhostname' + self.flags(host_ip=host_ip, group='vmware') with test.nested( mock.patch.object(vm_util, 'get_vm_ref', return_value=vm_ref), @@ -675,7 +675,7 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase): self._instance) fake_iscsi_get_host_iqn.assert_called_once_with(self._instance) - self.assertEqual(url, connector['ip']) - self.assertEqual(url, connector['host']) + self.assertEqual(host_ip, connector['ip']) + self.assertEqual(host_ip, connector['host']) self.assertEqual(iqn, connector['initiator']) self.assertEqual(vm_id, connector['instance'])