def normalize_path(path): """ Normalizes any path using fileUtils.normpath. The input's form can be: 1. Remote path - "server:port:/path", where: - The "port:" part is not mandatory. - The "server" part can be a dns name, an ipv4 address or an ipv6 address using quoted form. - If the input doesn't contain a colon, a HosttailError will be raised. Since this format is ambiguous, we treat an input that looks like a port as a port, and otherwise as a path without a leading slash. 2. Local path - "/path/to/device" 3. Other, where we just call os.path.normpath. """ if path.startswith("/") or ":" not in path: return normpath(path) host, tail = address.hosttail_split(path) if ":" in tail: port, path = tail.split(':', 1) if is_port(port): tail = port + ":" + normpath(path) else: tail = normpath(tail) else: tail = normpath(tail) return address.hosttail_join(host, tail)
def normalize_path(path): """ Normalizes a path using normpath. This method expects an input of one of the forms: 1. "server:port:/path", where: - The "port:" part is not mandatory. - The "server" part can be a dns name, an ipv4 address or an ipv6 address using quoted form. - If the input doesn't contain a colon, a HosttailError will be raised. Since this format is ambiguous, we treat an input that looks like a port as a port, and otherwise as a path without a leading slash. 2. "/path/to/device" """ if path.startswith("/"): return normpath(path) host, tail = address.hosttail_split(path) if ":" in tail: port, path = tail.split(':', 1) if is_port(port): tail = port + ":" + normpath(path) else: tail = normpath(tail) else: tail = normpath(tail) return address.hosttail_join(host, tail)
def discoverydb_discover(discoveryType, iface, portal): rc, out, err = _runCmd(["-m", "discoverydb", "-t", discoveryType, "-I", iface, "-p", portal, "--discover"]) if rc == 0: res = [] for line in out: rest, iqn = line.split() rest, tpgt = rest.split(",") ip, port = hosttail_split(rest) res.append((ip, int(port), int(tpgt), iqn)) return res if not iface_exists(iface): raise IscsiInterfaceDoesNotExistError(iface) if rc == ISCSI_ERR_LOGIN_AUTH_FAILED: raise IscsiAuthenticationError(rc, out, err) raise IscsiDiscoverdbError(rc, out, err)
def discoverydb_discover(discoveryType, iface, portal): rc, out, err = _runCmd([ "-m", "discoverydb", "-t", discoveryType, "-I", iface, "-p", portal, "--discover" ]) if rc == 0: res = [] for line in out: rest, iqn = line.split() rest, tpgt = rest.split(",") ip, port = hosttail_split(rest) res.append((ip, int(port), int(tpgt), iqn)) return res if not iface_exists(iface): raise IscsiInterfaceDoesNotExistError(iface) if rc == ISCSI_ERR_LOGIN_AUTH_FAILED: raise IscsiAuthenticationError(rc, out, err) raise IscsiDiscoverdbError(rc, out, err)
def discoverydb_discover(discoveryType, iface, portal): try: out = run_cmd([ "-m", "discoverydb", "-t", discoveryType, "-I", iface, "-p", portal, "--discover" ]) except cmdutils.Error as e: if not iface_exists(iface): raise IscsiInterfaceDoesNotExistError(iface) if e.rc == ISCSI_ERR_LOGIN_AUTH_FAILED: raise IscsiAuthenticationError(e.rc, e.out, e.err) raise IscsiDiscoverdbError(e.rc, e.out, e.err) res = [] for line in out.splitlines(): rest, iqn = line.split() rest, tpgt = rest.split(",") ip, port = hosttail_split(rest) res.append((ip, int(port), int(tpgt), iqn)) return res
def test_hosttail_ipv6_no_brackets_returns_garbage(self): self.assertNotEqual(('2001::1', '4321'), ipaddress.hosttail_split('2001::1:4321'))
def test_hosttail_only_port(self): with self.assertRaises(ipaddress.HosttailError): ipaddress.hosttail_split(':123')
def test_hosttail_only_host(self): with self.assertRaises(ipaddress.HosttailError): ipaddress.hosttail_split('hostname:')
def test_hosttail_no_colon(self): with self.assertRaises(ipaddress.HosttailError): ipaddress.hosttail_split('bad hostname')
def test_hosttail_ipv6_with_colon_in_path(self): self.assertEqual(('2001::1', '/a:b:c/path'), ipaddress.hosttail_split('[2001::1]:/a:b:c/path'))
def test_hosttail_hostpath_with_colon_in_path(self): self.assertEqual(('FQDN.host', '/path/a:b:c'), ipaddress.hosttail_split( 'FQDN.host:/path/a:b:c'))
def test_hosttail_hostpath(self): self.assertEqual(('FQDN.host', '/ovirt/rules/the/world'), ipaddress.hosttail_split( 'FQDN.host:/ovirt/rules/the/world'))
def test_hosttail_namedhost(self): self.assertEqual(('TestHost', '4321'), ipaddress.hosttail_split('TestHost:4321'))
def test_hosttail_ipv6(self): self.assertEqual(('2001::1', '4321'), ipaddress.hosttail_split('[2001::1]:4321'))
def test_hosttail_ipv4(self): self.assertEqual(('1.2.3.4', '4321'), ipaddress.hosttail_split('1.2.3.4:4321'))