]>
Commit | Line | Data |
---|---|---|
e306af50 | 1 | # type: ignore |
9f95a23c TL |
2 | import argparse |
3 | import mock | |
4 | import os | |
5 | import sys | |
6 | import unittest | |
7 | ||
8 | import pytest | |
9 | ||
10 | if sys.version_info >= (3, 3): | |
11 | from importlib.machinery import SourceFileLoader | |
12 | cd = SourceFileLoader('cephadm', 'cephadm').load_module() | |
13 | else: | |
14 | import imp | |
15 | cd = imp.load_source('cephadm', 'cephadm') | |
16 | ||
17 | class TestCephAdm(object): | |
18 | def test_is_fsid(self): | |
19 | assert not cd.is_fsid('no-uuid') | |
20 | ||
21 | def test__get_parser_image(self): | |
22 | args = cd._parse_args(['--image', 'foo', 'version']) | |
23 | assert args.image == 'foo' | |
24 | ||
25 | def test_CustomValidation(self): | |
26 | assert cd._parse_args(['deploy', '--name', 'mon.a', '--fsid', 'fsid']) | |
27 | ||
28 | with pytest.raises(SystemExit): | |
29 | cd._parse_args(['deploy', '--name', 'wrong', '--fsid', 'fsid']) | |
30 | ||
31 | @pytest.mark.parametrize("test_input, expected", [ | |
32 | ("podman version 1.6.2", (1,6,2)), | |
33 | ("podman version 1.6.2-stable2", (1,6,2)), | |
34 | ]) | |
35 | def test_parse_podman_version(self, test_input, expected): | |
36 | assert cd._parse_podman_version(test_input) == expected | |
37 | ||
38 | def test_parse_podman_version_invalid(self): | |
39 | with pytest.raises(ValueError) as res: | |
40 | cd._parse_podman_version('podman version inval.id') | |
41 | assert 'inval' in str(res.value) | |
42 | ||
43 | @pytest.mark.parametrize("test_input, expected", [ | |
44 | ( | |
45 | """ | |
46 | default via 192.168.178.1 dev enxd89ef3f34260 proto dhcp metric 100 | |
47 | 10.0.0.0/8 via 10.4.0.1 dev tun0 proto static metric 50 | |
48 | 10.3.0.0/21 via 10.4.0.1 dev tun0 proto static metric 50 | |
49 | 10.4.0.1 dev tun0 proto kernel scope link src 10.4.0.2 metric 50 | |
50 | 137.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50 | |
51 | 138.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50 | |
52 | 139.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50 | |
53 | 140.1.0.0/17 via 10.4.0.1 dev tun0 proto static metric 50 | |
54 | 141.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50 | |
55 | 169.254.0.0/16 dev docker0 scope link metric 1000 | |
56 | 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 | |
57 | 192.168.39.0/24 dev virbr1 proto kernel scope link src 192.168.39.1 linkdown | |
58 | 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown | |
59 | 192.168.178.0/24 dev enxd89ef3f34260 proto kernel scope link src 192.168.178.28 metric 100 | |
60 | 192.168.178.1 dev enxd89ef3f34260 proto static scope link metric 100 | |
61 | 195.135.221.12 via 192.168.178.1 dev enxd89ef3f34260 proto static metric 100 | |
62 | """, | |
63 | { | |
64 | '10.4.0.1': ['10.4.0.2'], | |
65 | '172.17.0.0/16': ['172.17.0.1'], | |
66 | '192.168.39.0/24': ['192.168.39.1'], | |
67 | '192.168.122.0/24': ['192.168.122.1'], | |
68 | '192.168.178.0/24': ['192.168.178.28'] | |
69 | } | |
70 | ), ( | |
71 | """ | |
72 | default via 10.3.64.1 dev eno1 proto static metric 100 | |
73 | 10.3.64.0/24 dev eno1 proto kernel scope link src 10.3.64.23 metric 100 | |
74 | 10.3.64.0/24 dev eno1 proto kernel scope link src 10.3.64.27 metric 100 | |
75 | 10.88.0.0/16 dev cni-podman0 proto kernel scope link src 10.88.0.1 linkdown | |
76 | 172.21.0.0/20 via 172.21.3.189 dev tun0 | |
77 | 172.21.1.0/20 via 172.21.3.189 dev tun0 | |
78 | 172.21.2.1 via 172.21.3.189 dev tun0 | |
79 | 172.21.3.1 dev tun0 proto kernel scope link src 172.21.3.2 | |
80 | 172.21.4.0/24 via 172.21.3.1 dev tun0 | |
81 | 172.21.5.0/24 via 172.21.3.1 dev tun0 | |
82 | 172.21.6.0/24 via 172.21.3.1 dev tun0 | |
83 | 172.21.7.0/24 via 172.21.3.1 dev tun0 | |
84 | 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown | |
85 | """, | |
86 | { | |
87 | '10.3.64.0/24': ['10.3.64.23', '10.3.64.27'], | |
88 | '10.88.0.0/16': ['10.88.0.1'], | |
89 | '172.21.3.1': ['172.21.3.2'], | |
90 | '192.168.122.0/24': ['192.168.122.1']} | |
91 | ), | |
92 | ]) | |
93 | def test_parse_ip_route(self, test_input, expected): | |
94 | assert cd._parse_ip_route(test_input) == expected |