Change in vdsm[master]: vdscli: 'port' argument must be an int
fromani at redhat.com
fromani at redhat.com
Tue Nov 18 10:32:28 UTC 2014
Francesco Romani has uploaded a new change for review.
Change subject: vdscli: 'port' argument must be an int
......................................................................
vdscli: 'port' argument must be an int
The 'port' parameter of the cannonizeHostPort
function should be an int, not a string, and
should be treated as such.
This patch fixes the code to so, removing
TODOs along the way.
Change-Id: Ic2af987cc0a381e10d898888562865f877a24686
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M lib/vdsm/vdscli.py
M tests/vdsClientTests.py
M vdsm/clientIF.py
M vdsm/virt/migration.py
4 files changed, 12 insertions(+), 13 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/73/35273/1
diff --git a/lib/vdsm/vdscli.py b/lib/vdsm/vdscli.py
index d4bd39a..2908775 100644
--- a/lib/vdsm/vdscli.py
+++ b/lib/vdsm/vdscli.py
@@ -30,7 +30,7 @@
_USE_SSL = False
_TRUSTED_STORE_PATH = '/etc/pki/vdsm'
_ADDRESS = '0'
-_PORT = '54321'
+_PORT = 54321
def wrap_transport(transport):
@@ -67,7 +67,7 @@
config.read(VDSM_CONF)
_USE_SSL = config.getboolean('vars', 'ssl')
_TRUSTED_STORE_PATH = config.get('vars', 'trust_store_path')
- _PORT = config.get('addresses', 'management_port')
+ _PORT = config.getint('addresses', 'management_port')
_ADDRESS = config.get('addresses', 'management_ip')
except:
pass
@@ -86,9 +86,10 @@
# hostPort is in rfc3986 'host [ ":" port ]' format
hostPort = re.match(r'(?P<Host>.+?)(:(?P<Port>\d+))?$', hostPort)
addr = hostPort.group('Host')
- port = hostPort.group('Port') or port
+ if hostPort.group('Port'):
+ port = int(hostPort.group('Port'))
- return addr + ':' + port
+ return '%s:%i' % (addr, port)
def connect(hostPort=None, useSSL=None, tsPath=None,
diff --git a/tests/vdsClientTests.py b/tests/vdsClientTests.py
index aee4fa7..071da94 100644
--- a/tests/vdsClientTests.py
+++ b/tests/vdsClientTests.py
@@ -546,11 +546,11 @@
self.assertIsIpAddressWithPort(vdscli.cannonizeHostPort(None))
def testNoneArgumentAndPort(self):
- port = '65432'
+ port = 65432
res = vdscli.cannonizeHostPort(None, port)
self.assertIsIpAddressWithPort(res)
# address must include the given port
- self.assertTrue(res.endswith(port))
+ self.assertTrue(res.endswith(str(port)))
def testEmptyAddress(self):
# FIXME: fix cannonizeHostPort to handle this error or to
@@ -571,18 +571,16 @@
self.assertTrue(res.endswith(str(port)))
def testAddressWithPortParameter(self):
- # TODO: fix cannonizeHostPort to require port as int
addr = '127.0.0.1'
- port = '65432'
+ port = 65432
res = vdscli.cannonizeHostPort(addr, port)
self.assertIsIpAddressWithPort(res)
# address must include the given port
- self.assertTrue(res.endswith(port))
+ self.assertTrue(res.endswith(str(port)))
def testAddressWithBadPortParameter(self):
- # TODO: fix cannonizeHostPort to require port as int
addr = '127.0.0.1'
- port = 65432
+ port = '65432'
self.assertRaises(TypeError,
vdscli.cannonizeHostPort,
addr, port)
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index a17fd20..f16a096 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -104,7 +104,7 @@
self.threadLocal.client = ''
host = config.get('addresses', 'management_ip')
- port = config.get('addresses', 'management_port')
+ port = config.getint('addresses', 'management_port')
self._createAcceptor(host, port)
self._prepareXMLRPCBinding()
self._prepareJSONRPCBinding()
diff --git a/vdsm/virt/migration.py b/vdsm/virt/migration.py
index 2d890c0..7015c16 100644
--- a/vdsm/virt/migration.py
+++ b/vdsm/virt/migration.py
@@ -107,7 +107,7 @@
# This assumes xmlrpc
hostPort = vdscli.cannonizeHostPort(
self._dst,
- config.get('addresses', 'management_port'))
+ config.getint('addresses', 'management_port'))
self.remoteHost, _ = hostPort.rsplit(':', 1)
if config.getboolean('vars', 'ssl'):
--
To view, visit http://gerrit.ovirt.org/35273
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic2af987cc0a381e10d898888562865f877a24686
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
More information about the vdsm-patches
mailing list