Change in vdsm[master]: network: add hosttail_join to address.py

ishaby at redhat.com ishaby at redhat.com
Wed Mar 30 12:10:07 UTC 2016


Idan Shaby has uploaded a new change for review.

Change subject: network: add hosttail_join to address.py
......................................................................

network: add hosttail_join to address.py

Change-Id: Ic0b778445117090072d64c89ccfd94aaf3c12fa3
Related-To: https://bugzilla.redhat.com/1305529
Signed-off-by: Idan Shaby <ishaby at redhat.com>
---
M lib/vdsm/common/network/address.py
M tests/common/network_test.py
2 files changed, 31 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/73/55473/1

diff --git a/lib/vdsm/common/network/address.py b/lib/vdsm/common/network/address.py
index a45941f..1cb703a 100644
--- a/lib/vdsm/common/network/address.py
+++ b/lib/vdsm/common/network/address.py
@@ -44,6 +44,20 @@
     return host, tail
 
 
+def hosttail_join(host, tail):
+    """
+    Given a host and a tail, this method returns:
+    - "[host]:tail" if the host contains at least one colon,
+                    for example when the host is an IPv6 address.
+    - "host:tail"   otherwise
+
+    The tail part may be a port or a path (for mount points).
+    """
+    if ":" in host:
+        host = "[" + host + "]"
+    return host + ":" + tail
+
+
 def _is_ipv6_addr_soft_check(addr):
     return addr.startswith('[')
 
diff --git a/tests/common/network_test.py b/tests/common/network_test.py
index 62cc531..7bcbbdf 100644
--- a/tests/common/network_test.py
+++ b/tests/common/network_test.py
@@ -18,11 +18,12 @@
 #
 from __future__ import absolute_import
 
-from testlib import VdsmTestCase
+from testlib import VdsmTestCase, expandPermutations, permutations
 
 from vdsm.common.network import address as ipaddress
 
 
+ at expandPermutations
 class TestIpAddressHostTail(VdsmTestCase):
 
     def test_hosttail_ipv4(self):
@@ -66,3 +67,18 @@
     def test_hosttail_ipv6_no_brackets_returns_garbage(self):
         self.assertNotEqual(('2001::1', '4321'),
                             ipaddress.hosttail_split('2001::1:4321'))
+
+    @permutations([
+        # (host, tail, expected_return_value)
+        ("server", "/", "server:/"),
+        ("server", "/path", "server:/path"),
+        ("ser:ver", "/path", "[ser:ver]:/path"),
+        ("12.34.56.78", "/path", "12.34.56.78:/path"),
+        ("2001:db8::60fe:5bf:febc:912", "/path",
+         "[2001:db8::60fe:5bf:febc:912]:/path"),
+        ("[2001:db8::60fe:5bf:febc:912]", "/path",
+         "[[2001:db8::60fe:5bf:febc:912]]:/path"),
+    ])
+    def test_hosttail_join(self, host, tail, expected_return_value):
+        self.assertEquals(expected_return_value,
+                          ipaddress.hosttail_join(host, tail))


-- 
To view, visit https://gerrit.ovirt.org/55473
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0b778445117090072d64c89ccfd94aaf3c12fa3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Idan Shaby <ishaby at redhat.com>


More information about the vdsm-patches mailing list