mirror of
https://github.com/ceph/ceph
synced 2025-03-06 08:20:12 +00:00
cephadm: add tests
Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
1a54da0b01
commit
b4a77b7393
@ -2648,7 +2648,6 @@ def command_logs():
|
||||
|
||||
def list_networks():
|
||||
# type: () -> Dict[str,List[str]]
|
||||
r = {} # type: Dict[str,List[str]]
|
||||
|
||||
## sadly, 18.04's iproute2 4.15.0-2ubun doesn't support the -j flag,
|
||||
## so we'll need to use a regex to parse 'ip' command output.
|
||||
@ -2657,6 +2656,10 @@ def list_networks():
|
||||
#for x in j:
|
||||
|
||||
out, _, _ = call_throws([find_executable('ip'), 'route', 'ls'])
|
||||
return _parse_ip_route(out)
|
||||
|
||||
def _parse_ip_route(out):
|
||||
r = {} # type: Dict[str,List[str]]
|
||||
p = re.compile(r'^(\S+) (.*)scope link (.*)src (\S+)')
|
||||
for line in out.splitlines():
|
||||
m = p.findall(line)
|
||||
|
@ -43,3 +43,56 @@ class TestCephAdm(object):
|
||||
with pytest.raises(ValueError) as res:
|
||||
cd._parse_podman_version('podman version inval.id')
|
||||
assert 'inval' in str(res.value)
|
||||
|
||||
@pytest.mark.parametrize("test_input, expected", [
|
||||
(
|
||||
"""
|
||||
default via 192.168.178.1 dev enxd89ef3f34260 proto dhcp metric 100
|
||||
10.0.0.0/8 via 10.4.0.1 dev tun0 proto static metric 50
|
||||
10.3.0.0/21 via 10.4.0.1 dev tun0 proto static metric 50
|
||||
10.4.0.1 dev tun0 proto kernel scope link src 10.4.0.2 metric 50
|
||||
137.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50
|
||||
138.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50
|
||||
139.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50
|
||||
140.1.0.0/17 via 10.4.0.1 dev tun0 proto static metric 50
|
||||
141.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50
|
||||
169.254.0.0/16 dev docker0 scope link metric 1000
|
||||
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
|
||||
192.168.39.0/24 dev virbr1 proto kernel scope link src 192.168.39.1 linkdown
|
||||
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
|
||||
192.168.178.0/24 dev enxd89ef3f34260 proto kernel scope link src 192.168.178.28 metric 100
|
||||
192.168.178.1 dev enxd89ef3f34260 proto static scope link metric 100
|
||||
195.135.221.12 via 192.168.178.1 dev enxd89ef3f34260 proto static metric 100
|
||||
""",
|
||||
{
|
||||
'10.4.0.1': ['10.4.0.2'],
|
||||
'172.17.0.0/16': ['172.17.0.1'],
|
||||
'192.168.39.0/24': ['192.168.39.1'],
|
||||
'192.168.122.0/24': ['192.168.122.1'],
|
||||
'192.168.178.0/24': ['192.168.178.28']
|
||||
}
|
||||
), (
|
||||
"""
|
||||
default via 10.3.64.1 dev eno1 proto static metric 100
|
||||
10.3.64.0/24 dev eno1 proto kernel scope link src 10.3.64.23 metric 100
|
||||
10.3.64.0/24 dev eno1 proto kernel scope link src 10.3.64.27 metric 100
|
||||
10.88.0.0/16 dev cni-podman0 proto kernel scope link src 10.88.0.1 linkdown
|
||||
172.21.0.0/20 via 172.21.3.189 dev tun0
|
||||
172.21.1.0/20 via 172.21.3.189 dev tun0
|
||||
172.21.2.1 via 172.21.3.189 dev tun0
|
||||
172.21.3.1 dev tun0 proto kernel scope link src 172.21.3.2
|
||||
172.21.4.0/24 via 172.21.3.1 dev tun0
|
||||
172.21.5.0/24 via 172.21.3.1 dev tun0
|
||||
172.21.6.0/24 via 172.21.3.1 dev tun0
|
||||
172.21.7.0/24 via 172.21.3.1 dev tun0
|
||||
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
|
||||
""",
|
||||
{
|
||||
'10.3.64.0/24': ['10.3.64.23', '10.3.64.27'],
|
||||
'10.88.0.0/16': ['10.88.0.1'],
|
||||
'172.21.3.1': ['172.21.3.2'],
|
||||
'192.168.122.0/24': ['192.168.122.1']}
|
||||
),
|
||||
])
|
||||
def test_parse_ip_route(self, test_input, expected):
|
||||
assert cd._parse_ip_route(test_input) == expected
|
||||
|
Loading…
Reference in New Issue
Block a user