Merge ~fnordahl/ubuntu/+source/python-os-vif:bug/1892132-ussuri into ~ubuntu-openstack-dev/ubuntu/+source/python-os-vif:stable/ussuri
- Git
- lp:~fnordahl/ubuntu/+source/python-os-vif
- bug/1892132-ussuri
- Merge into stable/ussuri
Proposed by
Frode Nordahl
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 0119aebdc0949b9f3a74f78f1c275d1f51ee59c7 | ||||
Proposed branch: | ~fnordahl/ubuntu/+source/python-os-vif:bug/1892132-ussuri | ||||
Merge into: | ~ubuntu-openstack-dev/ubuntu/+source/python-os-vif:stable/ussuri | ||||
Diff against target: |
696 lines (+670/-0) 4 files modified
debian/changelog (+9/-0) debian/patches/Fix-os-vif-fails-to-get-the-correct-UpLink-Representor.patch (+168/-0) debian/patches/Refactor-code-of-linux_net-to-more-cleaner-and-increase-performace.patch (+491/-0) debian/patches/series (+2/-0) |
||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Corey Bryant | Pending | ||
Chris MacNaughton | Pending | ||
Ubuntu OpenStack uploaders | Pending | ||
Review via email: mp+405805@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/debian/changelog b/debian/changelog | |||
2 | index e2673a2..b62c1c2 100644 | |||
3 | --- a/debian/changelog | |||
4 | +++ b/debian/changelog | |||
5 | @@ -1,3 +1,12 @@ | |||
6 | 1 | python-os-vif (2.0.0-0ubuntu1.2) UNRELEASED; urgency=medium | ||
7 | 2 | |||
8 | 3 | * Add support for switchdev NICs that link representor ports to parent PCI | ||
9 | 4 | device. (LP: #1892132) | ||
10 | 5 | - d/p/Refactor-code-of-linux_net-to-more-cleaner-and-increase-performace.patch | ||
11 | 6 | - d/p/Fix-os-vif-fails-to-get-the-correct-UpLink-Representor.patch | ||
12 | 7 | |||
13 | 8 | -- Frode Nordahl <frode.nordahl@canonical.com> Fri, 16 Jul 2021 09:43:06 +0000 | ||
14 | 9 | |||
15 | 1 | python-os-vif (2.0.0-0ubuntu1.1) UNRELEASED; urgency=medium | 10 | python-os-vif (2.0.0-0ubuntu1.1) UNRELEASED; urgency=medium |
16 | 2 | 11 | ||
17 | 3 | [ Corey Bryant ] | 12 | [ Corey Bryant ] |
18 | diff --git a/debian/patches/Fix-os-vif-fails-to-get-the-correct-UpLink-Representor.patch b/debian/patches/Fix-os-vif-fails-to-get-the-correct-UpLink-Representor.patch | |||
19 | 4 | new file mode 100644 | 13 | new file mode 100644 |
20 | index 0000000..bb82b13 | |||
21 | --- /dev/null | |||
22 | +++ b/debian/patches/Fix-os-vif-fails-to-get-the-correct-UpLink-Representor.patch | |||
23 | @@ -0,0 +1,168 @@ | |||
24 | 1 | From ssh://review.opendev.org:29418/openstack/os-vif | ||
25 | 2 | * branch refs/changes/67/765967/5 -> FETCH_HEAD | ||
26 | 3 | From 1226d46cc8bde9531821c68465a05292528142f0 Mon Sep 17 00:00:00 2001 | ||
27 | 4 | From: Mamduh Alassi <mamduhala@mellanox.com> | ||
28 | 5 | Date: Wed, 12 Aug 2020 16:24:47 +0300 | ||
29 | 6 | Subject: [PATCH] Fix - os-vif fails to get the correct UpLink Representor | ||
30 | 7 | |||
31 | 8 | Till kernel 5.7 PF and VF representors are exposed as virtual device. | ||
32 | 9 | They are not linked to its parent PCI device like how uplink | ||
33 | 10 | representor is linked. | ||
34 | 11 | |||
35 | 12 | Starting from kernel 5.8 due to new change [1] the PF and VF representors are | ||
36 | 13 | linked to their parent PCI device, and so "get_ifname_by_pci_address" fails | ||
37 | 14 | to get the correct UpLink Representor. | ||
38 | 15 | |||
39 | 16 | This patch modifys the behviour of "get_ifname_by_pci_address" to | ||
40 | 17 | check the physical port name of the netdev in | ||
41 | 18 | vf_pci_addr_path/physfn/net to match the formart for the uplink "p\d+". | ||
42 | 19 | |||
43 | 20 | [1] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=123f0f53dd64b67e34142485fe866a8a581f12f1 | ||
44 | 21 | |||
45 | 22 | Closes-Bug: #1892132 | ||
46 | 23 | Change-Id: I49f6ae3f0e6bfbf555c8284bfd70371ce90da0c7 | ||
47 | 24 | (cherry picked from commit a28aafa796378b8a36ccb51d2c0010a44f622d14) | ||
48 | 25 | --- | ||
49 | 26 | .../notes/bug-1892132-812e6d5ce0588ebb.yaml | 10 +++++ | ||
50 | 27 | vif_plug_ovs/linux_net.py | 28 +++++++++--- | ||
51 | 28 | vif_plug_ovs/tests/unit/test_linux_net.py | 44 +++++++++++++++++-- | ||
52 | 29 | 3 files changed, 74 insertions(+), 8 deletions(-) | ||
53 | 30 | create mode 100644 releasenotes/notes/bug-1892132-812e6d5ce0588ebb.yaml | ||
54 | 31 | |||
55 | 32 | diff --git a/releasenotes/notes/bug-1892132-812e6d5ce0588ebb.yaml b/releasenotes/notes/bug-1892132-812e6d5ce0588ebb.yaml | ||
56 | 33 | new file mode 100644 | ||
57 | 34 | index 0000000..f7604dd | ||
58 | 35 | --- /dev/null | ||
59 | 36 | +++ b/releasenotes/notes/bug-1892132-812e6d5ce0588ebb.yaml | ||
60 | 37 | @@ -0,0 +1,10 @@ | ||
61 | 38 | +--- | ||
62 | 39 | +fixes: | ||
63 | 40 | + - | | ||
64 | 41 | + Linux kernel 5.8 changed the sysfs interface that is used to | ||
65 | 42 | + discover the interfaces used for OVS offloads for certain NIC | ||
66 | 43 | + models. This results in network plugging failure, as described | ||
67 | 44 | + in `bug #1892132`_. This release fixes the plugging issue by | ||
68 | 45 | + properly handling the new sysfs structure. | ||
69 | 46 | + | ||
70 | 47 | + .. _bug #1892132: https://bugs.launchpad.net/os-vif/+bug/1892132 | ||
71 | 48 | diff --git a/vif_plug_ovs/linux_net.py b/vif_plug_ovs/linux_net.py | ||
72 | 49 | index 3e77585..f7b120c 100644 | ||
73 | 50 | --- a/vif_plug_ovs/linux_net.py | ||
74 | 51 | +++ b/vif_plug_ovs/linux_net.py | ||
75 | 52 | @@ -45,6 +45,8 @@ VF_RE = re.compile(r"vf(\d+)", re.IGNORECASE) | ||
76 | 53 | PF_RE = re.compile(r"pf(\d+)", re.IGNORECASE) | ||
77 | 54 | # bus_info (bdf) contains <bus>:<dev>.<func> | ||
78 | 55 | PF_FUNC_RE = re.compile(r"\.(\d+)", 0) | ||
79 | 56 | +# phys_port_name contains p## | ||
80 | 57 | +UPLINK_PORT_RE = re.compile(r"p(\d+)", re.IGNORECASE) | ||
81 | 58 | |||
82 | 59 | _SRIOV_TOTALVFS = "sriov_totalvfs" | ||
83 | 60 | NIC_NAME_LEN = 14 | ||
84 | 61 | @@ -327,12 +329,28 @@ def get_ifname_by_pci_address(pci_addr, pf_interface=False, switchdev=False): | ||
85 | 62 | itself based on the argument of pf_interface. | ||
86 | 63 | """ | ||
87 | 64 | dev_path = _get_sysfs_netdev_path(pci_addr, pf_interface) | ||
88 | 65 | - # make the if statement later more readable | ||
89 | 66 | - ignore_switchdev = not switchdev | ||
90 | 67 | try: | ||
91 | 68 | - for netdev in os.listdir(dev_path): | ||
92 | 69 | - if ignore_switchdev or _is_switchdev(netdev): | ||
93 | 70 | - return netdev | ||
94 | 71 | + devices = os.listdir(dev_path) | ||
95 | 72 | + | ||
96 | 73 | + # Return the first netdev in case of switchdev=False | ||
97 | 74 | + if not switchdev: | ||
98 | 75 | + return devices[0] | ||
99 | 76 | + elif pf_interface: | ||
100 | 77 | + fallback_netdev = None | ||
101 | 78 | + for netdev in devices: | ||
102 | 79 | + # Return the uplink representor in case of switchdev=True | ||
103 | 80 | + if _is_switchdev(netdev): | ||
104 | 81 | + fallback_netdev = netdev if fallback_netdev is None \ | ||
105 | 82 | + else fallback_netdev | ||
106 | 83 | + phys_port_name = _get_phys_port_name(netdev) | ||
107 | 84 | + if phys_port_name is not None and \ | ||
108 | 85 | + UPLINK_PORT_RE.search(phys_port_name): | ||
109 | 86 | + return netdev | ||
110 | 87 | + | ||
111 | 88 | + # Fallback to first switchdev netdev in case of switchdev=True | ||
112 | 89 | + if fallback_netdev is not None: | ||
113 | 90 | + return fallback_netdev | ||
114 | 91 | + | ||
115 | 92 | except Exception: | ||
116 | 93 | raise exception.PciDeviceNotFoundById(id=pci_addr) | ||
117 | 94 | raise exception.PciDeviceNotFoundById(id=pci_addr) | ||
118 | 95 | diff --git a/vif_plug_ovs/tests/unit/test_linux_net.py b/vif_plug_ovs/tests/unit/test_linux_net.py | ||
119 | 96 | index a5404ea..e19ce94 100644 | ||
120 | 97 | --- a/vif_plug_ovs/tests/unit/test_linux_net.py | ||
121 | 98 | +++ b/vif_plug_ovs/tests/unit/test_linux_net.py | ||
122 | 99 | @@ -260,26 +260,64 @@ class LinuxNetTest(testtools.TestCase): | ||
123 | 100 | |||
124 | 101 | @mock.patch.object(os, 'listdir') | ||
125 | 102 | @mock.patch.object(linux_net, '_get_phys_switch_id') | ||
126 | 103 | + @mock.patch.object(linux_net, "_get_phys_port_name") | ||
127 | 104 | def test_physical_function_interface_name( | ||
128 | 105 | - self, mock__get_phys_switch_id, mock_listdir): | ||
129 | 106 | + self, mock__get_phys_port_name, mock__get_phys_switch_id, | ||
130 | 107 | + mock_listdir): | ||
131 | 108 | mock_listdir.return_value = ['foo', 'bar'] | ||
132 | 109 | mock__get_phys_switch_id.side_effect = ( | ||
133 | 110 | ['', 'valid_switch']) | ||
134 | 111 | + mock__get_phys_port_name.side_effect = (["p1"]) | ||
135 | 112 | ifname = linux_net.get_ifname_by_pci_address( | ||
136 | 113 | '0000:00:00.1', pf_interface=True, switchdev=False) | ||
137 | 114 | self.assertEqual(ifname, 'foo') | ||
138 | 115 | |||
139 | 116 | @mock.patch.object(os, 'listdir') | ||
140 | 117 | - @mock.patch.object(linux_net, '_get_phys_switch_id') | ||
141 | 118 | + @mock.patch.object(linux_net, "_get_phys_switch_id") | ||
142 | 119 | + @mock.patch.object(linux_net, "_get_phys_port_name") | ||
143 | 120 | def test_physical_function_interface_name_with_switchdev( | ||
144 | 121 | - self, mock__get_phys_switch_id, mock_listdir): | ||
145 | 122 | + self, mock__get_phys_port_name, mock__get_phys_switch_id, | ||
146 | 123 | + mock_listdir): | ||
147 | 124 | mock_listdir.return_value = ['foo', 'bar'] | ||
148 | 125 | mock__get_phys_switch_id.side_effect = ( | ||
149 | 126 | ['', 'valid_switch']) | ||
150 | 127 | + mock__get_phys_port_name.side_effect = (["p1s0"]) | ||
151 | 128 | ifname = linux_net.get_ifname_by_pci_address( | ||
152 | 129 | '0000:00:00.1', pf_interface=True, switchdev=True) | ||
153 | 130 | self.assertEqual(ifname, 'bar') | ||
154 | 131 | |||
155 | 132 | + @mock.patch.object(os, 'listdir') | ||
156 | 133 | + @mock.patch.object(linux_net, "_get_phys_switch_id") | ||
157 | 134 | + @mock.patch.object(linux_net, "_get_phys_port_name") | ||
158 | 135 | + def test_physical_function_interface_name_with_representors( | ||
159 | 136 | + self, mock__get_phys_port_name, mock__get_phys_switch_id, | ||
160 | 137 | + mock_listdir): | ||
161 | 138 | + # Get the PF that matches the phys_port_name regex | ||
162 | 139 | + mock_listdir.return_value = ['enp2s0f0_0', 'enp2s0f0_1', 'enp2s0f0'] | ||
163 | 140 | + mock__get_phys_switch_id.side_effect = ( | ||
164 | 141 | + ['valid_switch', 'valid_switch', 'valid_switch']) | ||
165 | 142 | + mock__get_phys_port_name.side_effect = (["pf0vf0", "pf0vf1", "p0"]) | ||
166 | 143 | + ifname = linux_net.get_ifname_by_pci_address( | ||
167 | 144 | + '0000:00:00.1', pf_interface=True, switchdev=True) | ||
168 | 145 | + self.assertEqual(ifname, 'enp2s0f0') | ||
169 | 146 | + | ||
170 | 147 | + @mock.patch.object(os, 'listdir') | ||
171 | 148 | + @mock.patch.object(linux_net, "_get_phys_switch_id") | ||
172 | 149 | + @mock.patch.object(linux_net, "_get_phys_port_name") | ||
173 | 150 | + def test_physical_function_interface_name_with_fallback_To_first_netdev( | ||
174 | 151 | + self, mock__get_phys_port_name, mock__get_phys_switch_id, | ||
175 | 152 | + mock_listdir): | ||
176 | 153 | + # Try with switchdev mode to get PF but fail because there is no match | ||
177 | 154 | + # for the phys_port_name then fallback to first interface found | ||
178 | 155 | + mock_listdir.return_value = ['enp2s0f0_0', 'enp2s0f0_1', 'enp2s0f0'] | ||
179 | 156 | + mock__get_phys_switch_id.side_effect = (['valid_switch', | ||
180 | 157 | + 'valid_switch', | ||
181 | 158 | + 'valid_switch']) | ||
182 | 159 | + mock__get_phys_port_name.side_effect = (["pf0vf0", "pf0vf1", "pf0vf2"]) | ||
183 | 160 | + ifname = linux_net.get_ifname_by_pci_address( | ||
184 | 161 | + '0000:00:00.1', pf_interface=True, switchdev=True) | ||
185 | 162 | + self.assertEqual(ifname, 'enp2s0f0_0') | ||
186 | 163 | + | ||
187 | 164 | @mock.patch.object(os, 'listdir') | ||
188 | 165 | def test_get_ifname_by_pci_address_exception(self, mock_listdir): | ||
189 | 166 | mock_listdir.side_effect = OSError('No such file or directory') | ||
190 | 167 | -- | ||
191 | 168 | 2.31.1 | ||
192 | diff --git a/debian/patches/Refactor-code-of-linux_net-to-more-cleaner-and-increase-performace.patch b/debian/patches/Refactor-code-of-linux_net-to-more-cleaner-and-increase-performace.patch | |||
193 | 0 | new file mode 100644 | 169 | new file mode 100644 |
194 | index 0000000..e895a24 | |||
195 | --- /dev/null | |||
196 | +++ b/debian/patches/Refactor-code-of-linux_net-to-more-cleaner-and-increase-performace.patch | |||
197 | @@ -0,0 +1,491 @@ | |||
198 | 1 | From ssh://review.opendev.org:29418/openstack/os-vif | ||
199 | 2 | * branch refs/changes/19/765419/6 -> FETCH_HEAD | ||
200 | 3 | From 3e1d898b752c327165aeca1fec0919d858a87ec4 Mon Sep 17 00:00:00 2001 | ||
201 | 4 | From: Mamduh <mamduhala@nvidia.com> | ||
202 | 5 | Date: Tue, 18 Aug 2020 12:40:10 +0300 | ||
203 | 6 | Subject: [PATCH] Refactor code of linux_net to more cleaner and increase | ||
204 | 7 | performace | ||
205 | 8 | |||
206 | 9 | The patch adds new functions '_get_phys_port_name' for reading physical | ||
207 | 10 | port name of the SR-IOV port and '_get_phys_switch_id' for reading | ||
208 | 11 | physical port switch ID of the SR-IOV port, in addition to refactoring | ||
209 | 12 | 'get_representor_port' to use the new functions and decrease calls for | ||
210 | 13 | "_get_pf_func" and netdevs associated with the PF will now be processed | ||
211 | 14 | in the loop, however it will not be matching 'phys_port_name' which | ||
212 | 15 | ensures the correct behaviour. | ||
213 | 16 | |||
214 | 17 | In addition to updating the unit test for linux_net and remove not | ||
215 | 18 | needed mocks | ||
216 | 19 | |||
217 | 20 | Conflicts: | ||
218 | 21 | vif_plug_ovs/linux_net.py | ||
219 | 22 | vif_plug_ovs/tests/unit/test_linux_net.py | ||
220 | 23 | |||
221 | 24 | Related-Bug: #1892132 | ||
222 | 25 | Change-Id: I3fdbea4f48cb79ebfd03a4da21e2232ccafb7a76 | ||
223 | 26 | (cherry picked from commit 167bb030f1143f37ce189673d831bd572f64d4ad) | ||
224 | 27 | --- | ||
225 | 28 | vif_plug_ovs/linux_net.py | 77 ++++--- | ||
226 | 29 | vif_plug_ovs/tests/unit/test_linux_net.py | 250 ++++++++-------------- | ||
227 | 30 | 2 files changed, 139 insertions(+), 188 deletions(-) | ||
228 | 31 | |||
229 | 32 | diff --git a/vif_plug_ovs/linux_net.py b/vif_plug_ovs/linux_net.py | ||
230 | 33 | index 20baab3..3e77585 100644 | ||
231 | 34 | --- a/vif_plug_ovs/linux_net.py | ||
232 | 35 | +++ b/vif_plug_ovs/linux_net.py | ||
233 | 36 | @@ -239,46 +239,35 @@ def get_representor_port(pf_ifname, vf_num): | ||
234 | 37 | VF number in the phys_port_name. That interface is the representor for | ||
235 | 38 | the requested VF. | ||
236 | 39 | """ | ||
237 | 40 | - pf_path = "/sys/class/net/%s" % pf_ifname | ||
238 | 41 | - pf_sw_id_file = os.path.join(pf_path, "phys_switch_id") | ||
239 | 42 | |||
240 | 43 | pf_sw_id = None | ||
241 | 44 | try: | ||
242 | 45 | - with open(pf_sw_id_file, 'r') as fd: | ||
243 | 46 | - pf_sw_id = fd.readline().rstrip() | ||
244 | 47 | + pf_sw_id = _get_phys_switch_id(pf_ifname) | ||
245 | 48 | except (OSError, IOError): | ||
246 | 49 | raise exception.RepresentorNotFound(ifname=pf_ifname, vf_num=vf_num) | ||
247 | 50 | |||
248 | 51 | - pf_subsystem_file = os.path.join(pf_path, "subsystem") | ||
249 | 52 | + pf_subsystem_file = "/sys/class/net/%s/subsystem" % pf_ifname | ||
250 | 53 | try: | ||
251 | 54 | devices = os.listdir(pf_subsystem_file) | ||
252 | 55 | except (OSError, IOError): | ||
253 | 56 | raise exception.RepresentorNotFound(ifname=pf_ifname, vf_num=vf_num) | ||
254 | 57 | |||
255 | 58 | - for device in devices: | ||
256 | 59 | - address_str, pf = get_function_by_ifname(device) | ||
257 | 60 | - if pf: | ||
258 | 61 | - continue | ||
259 | 62 | + ifname_pf_func = _get_pf_func(pf_ifname) | ||
260 | 63 | + if ifname_pf_func is None: | ||
261 | 64 | + raise exception.RepresentorNotFound(ifname=pf_ifname, vf_num=vf_num) | ||
262 | 65 | |||
263 | 66 | - device_path = "/sys/class/net/%s" % device | ||
264 | 67 | - device_sw_id_file = os.path.join(device_path, "phys_switch_id") | ||
265 | 68 | + for device in devices: | ||
266 | 69 | try: | ||
267 | 70 | - with open(device_sw_id_file, 'r') as fd: | ||
268 | 71 | - device_sw_id = fd.readline().rstrip() | ||
269 | 72 | + device_sw_id = _get_phys_switch_id(device) | ||
270 | 73 | + if not device_sw_id or device_sw_id != pf_sw_id: | ||
271 | 74 | + continue | ||
272 | 75 | except (OSError, IOError): | ||
273 | 76 | continue | ||
274 | 77 | |||
275 | 78 | - if device_sw_id != pf_sw_id: | ||
276 | 79 | - continue | ||
277 | 80 | - device_port_name_file = ( | ||
278 | 81 | - os.path.join(device_path, 'phys_port_name')) | ||
279 | 82 | - | ||
280 | 83 | - if not os.path.isfile(device_port_name_file): | ||
281 | 84 | - continue | ||
282 | 85 | - | ||
283 | 86 | try: | ||
284 | 87 | - with open(device_port_name_file, 'r') as fd: | ||
285 | 88 | - phys_port_name = fd.readline().rstrip() | ||
286 | 89 | + phys_port_name = _get_phys_port_name(device) | ||
287 | 90 | + if phys_port_name is None: | ||
288 | 91 | + continue | ||
289 | 92 | except (OSError, IOError): | ||
290 | 93 | continue | ||
291 | 94 | |||
292 | 95 | @@ -287,12 +276,8 @@ def get_representor_port(pf_ifname, vf_num): | ||
293 | 96 | # the PCI func number of pf_ifname. | ||
294 | 97 | rep_parent_pf_func = _parse_pf_number(phys_port_name) | ||
295 | 98 | if rep_parent_pf_func is not None: | ||
296 | 99 | - ifname_pf_func = _get_pf_func(pf_ifname) | ||
297 | 100 | - if ifname_pf_func is None: | ||
298 | 101 | - continue | ||
299 | 102 | - if int(rep_parent_pf_func) != int(ifname_pf_func): | ||
300 | 103 | - continue | ||
301 | 104 | - | ||
302 | 105 | + if int(rep_parent_pf_func) != int(ifname_pf_func): | ||
303 | 106 | + continue | ||
304 | 107 | representor_num = _parse_vf_number(phys_port_name) | ||
305 | 108 | # Note: representor_num can be 0, referring to VF0 | ||
306 | 109 | if representor_num is None: | ||
307 | 110 | @@ -321,9 +306,7 @@ def _get_sysfs_netdev_path(pci_addr, pf_interface): | ||
308 | 111 | def _is_switchdev(netdev): | ||
309 | 112 | """Returns True if a netdev has a readable phys_switch_id""" | ||
310 | 113 | try: | ||
311 | 114 | - sw_id_file = "/sys/class/net/%s/phys_switch_id" % netdev | ||
312 | 115 | - with open(sw_id_file, 'r') as fd: | ||
313 | 116 | - phys_switch_id = fd.readline().rstrip() | ||
314 | 117 | + phys_switch_id = _get_phys_switch_id(netdev) | ||
315 | 118 | if phys_switch_id != "" and phys_switch_id is not None: | ||
316 | 119 | return True | ||
317 | 120 | except (OSError, IOError): | ||
318 | 121 | @@ -389,3 +372,33 @@ def get_pf_pci_from_vf(vf_pci): | ||
319 | 122 | """ | ||
320 | 123 | physfn_path = os.readlink("/sys/bus/pci/devices/%s/physfn" % vf_pci) | ||
321 | 124 | return os.path.basename(physfn_path) | ||
322 | 125 | + | ||
323 | 126 | + | ||
324 | 127 | +def _get_phys_port_name(ifname): | ||
325 | 128 | + """Get the interface name and return its phys_port_name | ||
326 | 129 | + | ||
327 | 130 | + :param ifname: The interface name | ||
328 | 131 | + :return: The phys_port_name of the given ifname | ||
329 | 132 | + """ | ||
330 | 133 | + phys_port_name_path = "/sys/class/net/%s/phys_port_name" % ifname | ||
331 | 134 | + | ||
332 | 135 | + if not os.path.isfile(phys_port_name_path): | ||
333 | 136 | + return None | ||
334 | 137 | + | ||
335 | 138 | + with open(phys_port_name_path, 'r') as fd: | ||
336 | 139 | + return fd.readline().strip() | ||
337 | 140 | + | ||
338 | 141 | + | ||
339 | 142 | +def _get_phys_switch_id(ifname): | ||
340 | 143 | + """Get the interface name and return its phys_switch_id | ||
341 | 144 | + | ||
342 | 145 | + :param ifname: The interface name | ||
343 | 146 | + :return: The phys_switch_id of the given ifname | ||
344 | 147 | + """ | ||
345 | 148 | + phys_port_name_path = "/sys/class/net/%s/phys_switch_id" % ifname | ||
346 | 149 | + | ||
347 | 150 | + if not os.path.isfile(phys_port_name_path): | ||
348 | 151 | + return None | ||
349 | 152 | + | ||
350 | 153 | + with open(phys_port_name_path, 'r') as fd: | ||
351 | 154 | + return fd.readline().strip() | ||
352 | 155 | diff --git a/vif_plug_ovs/tests/unit/test_linux_net.py b/vif_plug_ovs/tests/unit/test_linux_net.py | ||
353 | 156 | index 4eaa1f7..a5404ea 100644 | ||
354 | 157 | --- a/vif_plug_ovs/tests/unit/test_linux_net.py | ||
355 | 158 | +++ b/vif_plug_ovs/tests/unit/test_linux_net.py | ||
356 | 159 | @@ -132,47 +132,22 @@ class LinuxNetTest(testtools.TestCase): | ||
357 | 160 | linux_net.add_bridge_port("br0", "vnet1") | ||
358 | 161 | mock_set.assert_called_once_with("vnet1", master="br0") | ||
359 | 162 | |||
360 | 163 | - @mock.patch('six.moves.builtins.open') | ||
361 | 164 | - @mock.patch.object(os.path, 'isfile') | ||
362 | 165 | - def test_is_switchdev_ioerror(self, mock_isfile, mock_open): | ||
363 | 166 | - mock_isfile.side_effect = [True] | ||
364 | 167 | - mock_open.return_value.__enter__ = lambda s: s | ||
365 | 168 | - readline_mock = mock_open.return_value.readline | ||
366 | 169 | - readline_mock.side_effect = ( | ||
367 | 170 | - [IOError()]) | ||
368 | 171 | + @mock.patch.object(linux_net, '_get_phys_switch_id') | ||
369 | 172 | + def test_is_switchdev_ioerror(self, mock__get_phys_switch_id): | ||
370 | 173 | + mock__get_phys_switch_id.side_effect = ([IOError()]) | ||
371 | 174 | test_switchdev = linux_net._is_switchdev('pf_ifname') | ||
372 | 175 | self.assertEqual(test_switchdev, False) | ||
373 | 176 | |||
374 | 177 | - @mock.patch('six.moves.builtins.open') | ||
375 | 178 | - @mock.patch.object(os.path, 'isfile') | ||
376 | 179 | - def test_is_switchdev_empty(self, mock_isfile, mock_open): | ||
377 | 180 | - mock_isfile.side_effect = [True] | ||
378 | 181 | - mock_open.return_value.__enter__ = lambda s: s | ||
379 | 182 | - readline_mock = mock_open.return_value.readline | ||
380 | 183 | - readline_mock.side_effect = ( | ||
381 | 184 | - ['']) | ||
382 | 185 | - open_calls = ( | ||
383 | 186 | - [mock.call('/sys/class/net/pf_ifname/phys_switch_id', 'r'), | ||
384 | 187 | - mock.call().readline(), | ||
385 | 188 | - mock.call().__exit__(None, None, None)]) | ||
386 | 189 | + @mock.patch.object(linux_net, '_get_phys_switch_id') | ||
387 | 190 | + def test_is_switchdev_empty(self, mock__get_phys_switch_id): | ||
388 | 191 | + mock__get_phys_switch_id.return_value = '' | ||
389 | 192 | test_switchdev = linux_net._is_switchdev('pf_ifname') | ||
390 | 193 | - mock_open.assert_has_calls(open_calls) | ||
391 | 194 | self.assertEqual(test_switchdev, False) | ||
392 | 195 | |||
393 | 196 | - @mock.patch('six.moves.builtins.open') | ||
394 | 197 | - @mock.patch.object(os.path, 'isfile') | ||
395 | 198 | - def test_is_switchdev_positive(self, mock_isfile, mock_open): | ||
396 | 199 | - mock_isfile.side_effect = [True] | ||
397 | 200 | - mock_open.return_value.__enter__ = lambda s: s | ||
398 | 201 | - readline_mock = mock_open.return_value.readline | ||
399 | 202 | - readline_mock.side_effect = ( | ||
400 | 203 | - ['pf_sw_id']) | ||
401 | 204 | - open_calls = ( | ||
402 | 205 | - [mock.call('/sys/class/net/pf_ifname/phys_switch_id', 'r'), | ||
403 | 206 | - mock.call().readline(), | ||
404 | 207 | - mock.call().__exit__(None, None, None)]) | ||
405 | 208 | + @mock.patch.object(linux_net, '_get_phys_switch_id') | ||
406 | 209 | + def test_is_switchdev_positive(self, mock__get_phys_switch_id): | ||
407 | 210 | + mock__get_phys_switch_id.return_value = 'pf_sw_id' | ||
408 | 211 | test_switchdev = linux_net._is_switchdev('pf_ifname') | ||
409 | 212 | - mock_open.assert_has_calls(open_calls) | ||
410 | 213 | self.assertEqual(test_switchdev, True) | ||
411 | 214 | |||
412 | 215 | def test_parse_vf_number(self): | ||
413 | 216 | @@ -191,184 +166,115 @@ class LinuxNetTest(testtools.TestCase): | ||
414 | 217 | self.assertEqual(linux_net._parse_pf_number("pf31"), "31") | ||
415 | 218 | self.assertIsNone(linux_net._parse_pf_number("g4rbl3d")) | ||
416 | 219 | |||
417 | 220 | - @mock.patch('six.moves.builtins.open') | ||
418 | 221 | - @mock.patch.object(os.path, 'isfile') | ||
419 | 222 | @mock.patch.object(os, 'listdir') | ||
420 | 223 | - @mock.patch.object(linux_net, "get_function_by_ifname") | ||
421 | 224 | - def test_get_representor_port(self, mock_get_function_by_ifname, | ||
422 | 225 | - mock_listdir, mock_isfile, mock_open): | ||
423 | 226 | + @mock.patch.object(linux_net, "_get_pf_func") | ||
424 | 227 | + @mock.patch.object(linux_net, "_get_phys_port_name") | ||
425 | 228 | + @mock.patch.object(linux_net, '_get_phys_switch_id') | ||
426 | 229 | + def test_get_representor_port(self, mock__get_phys_switch_id, | ||
427 | 230 | + mock__get_phys_port_name, | ||
428 | 231 | + mock__get_pf_func, | ||
429 | 232 | + mock_listdir): | ||
430 | 233 | mock_listdir.return_value = [ | ||
431 | 234 | 'pf_ifname', 'rep_vf_1', 'rep_vf_2' | ||
432 | 235 | ] | ||
433 | 236 | - mock_isfile.side_effect = [True, True] | ||
434 | 237 | - mock_open.return_value.__enter__ = lambda s: s | ||
435 | 238 | - readline_mock = mock_open.return_value.readline | ||
436 | 239 | - readline_mock.side_effect = ( | ||
437 | 240 | - ['pf_sw_id', 'pf_sw_id', '1', 'pf_sw_id', 'pf0vf2']) | ||
438 | 241 | - # PCI IDs mocked: | ||
439 | 242 | - # PF0: 0000:0a:00.0 | ||
440 | 243 | - # PF0VF1: 0000:0a:02.1 PF0VF2: 0000:0a:02.2 | ||
441 | 244 | - mock_get_function_by_ifname.side_effect = ( | ||
442 | 245 | - [("0000:0a:00.0", True), | ||
443 | 246 | - ("0000:0a:02.1", False), | ||
444 | 247 | - ("0000:0a:02.2", False), ("0000:0a:00.0", True)]) | ||
445 | 248 | - open_calls = ( | ||
446 | 249 | - [mock.call('/sys/class/net/pf_ifname/phys_switch_id', 'r'), | ||
447 | 250 | - mock.call().readline(), | ||
448 | 251 | - mock.call().__exit__(None, None, None), | ||
449 | 252 | - mock.call('/sys/class/net/rep_vf_1/phys_switch_id', 'r'), | ||
450 | 253 | - mock.call().readline(), | ||
451 | 254 | - mock.call().__exit__(None, None, None), | ||
452 | 255 | - mock.call('/sys/class/net/rep_vf_1/phys_port_name', 'r'), | ||
453 | 256 | - mock.call().readline(), | ||
454 | 257 | - mock.call().__exit__(None, None, None), | ||
455 | 258 | - mock.call('/sys/class/net/rep_vf_2/phys_switch_id', 'r'), | ||
456 | 259 | - mock.call().readline(), | ||
457 | 260 | - mock.call().__exit__(None, None, None), | ||
458 | 261 | - mock.call('/sys/class/net/rep_vf_2/phys_port_name', 'r'), | ||
459 | 262 | - mock.call().readline(), | ||
460 | 263 | - mock.call().__exit__(None, None, None)]) | ||
461 | 264 | + mock__get_phys_switch_id.return_value = 'pf_sw_id' | ||
462 | 265 | + mock__get_pf_func.return_value = "0" | ||
463 | 266 | + mock__get_phys_port_name.side_effect = (['1', "pf0vf1", "pf0vf2"]) | ||
464 | 267 | ifname = linux_net.get_representor_port('pf_ifname', '2') | ||
465 | 268 | - mock_open.assert_has_calls(open_calls) | ||
466 | 269 | self.assertEqual('rep_vf_2', ifname) | ||
467 | 270 | |||
468 | 271 | - @mock.patch('six.moves.builtins.open') | ||
469 | 272 | - @mock.patch.object(os.path, 'isfile') | ||
470 | 273 | @mock.patch.object(os, 'listdir') | ||
471 | 274 | - @mock.patch.object(linux_net, "get_function_by_ifname") | ||
472 | 275 | + @mock.patch.object(linux_net, "_get_pf_func") | ||
473 | 276 | + @mock.patch.object(linux_net, "_get_phys_port_name") | ||
474 | 277 | + @mock.patch.object(linux_net, "_get_phys_switch_id") | ||
475 | 278 | def test_get_representor_port_2_pfs( | ||
476 | 279 | - self, mock_get_function_by_ifname, mock_listdir, mock_isfile, | ||
477 | 280 | - mock_open): | ||
478 | 281 | + self, mock__get_phys_switch_id, mock__get_phys_port_name, | ||
479 | 282 | + mock__get_pf_func, mock_listdir): | ||
480 | 283 | mock_listdir.return_value = [ | ||
481 | 284 | 'pf_ifname1', 'pf_ifname2', 'rep_pf1_vf_1', 'rep_pf1_vf_2', | ||
482 | 285 | 'rep_pf2_vf_1', 'rep_pf2_vf_2', | ||
483 | 286 | ] | ||
484 | 287 | - mock_isfile.side_effect = [True, True, True, True] | ||
485 | 288 | - mock_open.return_value.__enter__ = lambda s: s | ||
486 | 289 | - readline_mock = mock_open.return_value.readline | ||
487 | 290 | - readline_mock.side_effect = ( | ||
488 | 291 | - ['pf_sw_id', | ||
489 | 292 | - 'pf_sw_id', 'VF1@PF1', 'pf_sw_id', 'vf2@pf1', | ||
490 | 293 | - 'pf_sw_id', 'pf2vf1', 'pf_sw_id', 'pf2vf2']) | ||
491 | 294 | - # PCI IDs mocked: | ||
492 | 295 | - # PF1: 0000:0a:00.1 PF2: 0000:0a:00.2 | ||
493 | 296 | - # PF1VF1: 0000:0a:02.1 PF1VF2: 0000:0a:02.2 | ||
494 | 297 | - # PF2VF1: 0000:0a:04.1 PF2VF2: 0000:0a:04.2 | ||
495 | 298 | - mock_get_function_by_ifname.side_effect = ( | ||
496 | 299 | - [("0000:0a:00.1", True), ("0000:0a:00.2", True), | ||
497 | 300 | - ("0000:0a:02.1", False), ("0000:0a:00.2", True), | ||
498 | 301 | - ("0000:0a:02.2", False), ("0000:0a:00.2", True), | ||
499 | 302 | - ("0000:0a:04.1", False), ("0000:0a:00.2", True), | ||
500 | 303 | - ("0000:0a:04.2", False), ("0000:0a:00.2", True)]) | ||
501 | 304 | + mock__get_phys_switch_id.return_value = 'pf_sw_id' | ||
502 | 305 | + mock__get_pf_func.return_value = "2" | ||
503 | 306 | + mock__get_phys_port_name.side_effect = ( | ||
504 | 307 | + ["p1", "p2", "VF1@PF1", "pf2vf1", "vf2@pf1", "pf2vf2"]) | ||
505 | 308 | ifname = linux_net.get_representor_port('pf_ifname2', '2') | ||
506 | 309 | self.assertEqual('rep_pf2_vf_2', ifname) | ||
507 | 310 | |||
508 | 311 | - @mock.patch('six.moves.builtins.open') | ||
509 | 312 | - @mock.patch.object(os.path, 'isfile') | ||
510 | 313 | @mock.patch.object(os, 'listdir') | ||
511 | 314 | - @mock.patch.object(linux_net, "get_function_by_ifname") | ||
512 | 315 | + @mock.patch.object(linux_net, "_get_pf_func") | ||
513 | 316 | + @mock.patch.object(linux_net, "_get_phys_switch_id") | ||
514 | 317 | + @mock.patch.object(linux_net, "_get_phys_port_name") | ||
515 | 318 | def test_get_representor_port_not_found( | ||
516 | 319 | - self, mock_get_function_by_ifname, mock_listdir, mock_isfile, | ||
517 | 320 | - mock_open): | ||
518 | 321 | + self, mock__get_phys_port_name, mock__get_phys_switch_id, | ||
519 | 322 | + mock__get_pf_func, mock_listdir): | ||
520 | 323 | mock_listdir.return_value = [ | ||
521 | 324 | 'pf_ifname', 'rep_vf_1', 'rep_vf_2' | ||
522 | 325 | ] | ||
523 | 326 | - mock_isfile.side_effect = [True, True] | ||
524 | 327 | - mock_open.return_value.__enter__ = lambda s: s | ||
525 | 328 | - readline_mock = mock_open.return_value.readline | ||
526 | 329 | - readline_mock.side_effect = ( | ||
527 | 330 | - ['pf_sw_id', 'pf_sw_id', '1', 'pf_sw_id', '2']) | ||
528 | 331 | - # PCI IDs mocked: | ||
529 | 332 | - # PF0: 0000:0a:00.0 | ||
530 | 333 | - # PF0VF1: 0000:0a:02.1 PF0VF2: 0000:0a:02.2 | ||
531 | 334 | - mock_get_function_by_ifname.side_effect = ( | ||
532 | 335 | - [("0000:0a:00.0", True), | ||
533 | 336 | - ("0000:0a:02.1", False), | ||
534 | 337 | - ("0000:0a:02.2", False)]) | ||
535 | 338 | + mock__get_phys_switch_id.return_value = 'pf_sw_id' | ||
536 | 339 | + mock__get_pf_func.return_value = "0" | ||
537 | 340 | + mock__get_phys_port_name.side_effect = ( | ||
538 | 341 | + ["p0", "1", "2"]) | ||
539 | 342 | self.assertRaises( | ||
540 | 343 | exception.RepresentorNotFound, | ||
541 | 344 | linux_net.get_representor_port, | ||
542 | 345 | 'pf_ifname', '3'), | ||
543 | 346 | |||
544 | 347 | - @mock.patch('six.moves.builtins.open') | ||
545 | 348 | - @mock.patch.object(os.path, 'isfile') | ||
546 | 349 | @mock.patch.object(os, 'listdir') | ||
547 | 350 | - @mock.patch.object(linux_net, "get_function_by_ifname") | ||
548 | 351 | + @mock.patch.object(linux_net, "_get_pf_func") | ||
549 | 352 | + @mock.patch.object(linux_net, "_get_phys_port_name") | ||
550 | 353 | + @mock.patch.object(linux_net, "_get_phys_switch_id") | ||
551 | 354 | def test_get_representor_port_exception_io_error( | ||
552 | 355 | - self, mock_get_function_by_ifname, mock_listdir, mock_isfile, | ||
553 | 356 | - mock_open): | ||
554 | 357 | + self, mock__get_phys_switch_id, mock__get_phys_port_name, | ||
555 | 358 | + mock__get_pf_func, mock_listdir): | ||
556 | 359 | mock_listdir.return_value = [ | ||
557 | 360 | 'pf_ifname', 'rep_vf_1', 'rep_vf_2' | ||
558 | 361 | ] | ||
559 | 362 | - mock_isfile.side_effect = [True, True] | ||
560 | 363 | - mock_open.return_value.__enter__ = lambda s: s | ||
561 | 364 | - readline_mock = mock_open.return_value.readline | ||
562 | 365 | - readline_mock.side_effect = ( | ||
563 | 366 | + mock__get_phys_switch_id.side_effect = ( | ||
564 | 367 | ['pf_sw_id', 'pf_sw_id', IOError(), 'pf_sw_id', '2']) | ||
565 | 368 | - # PCI IDs mocked: | ||
566 | 369 | - # PF0: 0000:0a:00.0 | ||
567 | 370 | - # PF0VF1: 0000:0a:02.1 PF0VF2: 0000:0a:02.2 | ||
568 | 371 | - mock_get_function_by_ifname.side_effect = ( | ||
569 | 372 | - [("0000:0a:00.0", True), | ||
570 | 373 | - ("0000:0a:02.1", False), | ||
571 | 374 | - ("0000:0a:02.2", False), ("0000:0a:00.0", True)]) | ||
572 | 375 | + mock__get_pf_func.return_value = "0" | ||
573 | 376 | + mock__get_phys_port_name.side_effect = ( | ||
574 | 377 | + ["p0", "pf0vf0", "pf0vf1"]) | ||
575 | 378 | self.assertRaises( | ||
576 | 379 | exception.RepresentorNotFound, | ||
577 | 380 | linux_net.get_representor_port, | ||
578 | 381 | 'pf_ifname', '3') | ||
579 | 382 | |||
580 | 383 | - @mock.patch('six.moves.builtins.open') | ||
581 | 384 | - @mock.patch.object(os.path, 'isfile') | ||
582 | 385 | @mock.patch.object(os, 'listdir') | ||
583 | 386 | - @mock.patch.object(linux_net, "get_function_by_ifname") | ||
584 | 387 | + @mock.patch.object(linux_net, "_get_pf_func") | ||
585 | 388 | + @mock.patch.object(linux_net, "_get_phys_port_name") | ||
586 | 389 | + @mock.patch.object(linux_net, "_get_phys_switch_id") | ||
587 | 390 | def test_get_representor_port_exception_value_error( | ||
588 | 391 | - self, mock_get_function_by_ifname, mock_listdir, mock_isfile, | ||
589 | 392 | - mock_open): | ||
590 | 393 | + self, mock__get_phys_switch_id, mock__get_phys_port_name, | ||
591 | 394 | + mock__get_pf_func, mock_listdir): | ||
592 | 395 | mock_listdir.return_value = [ | ||
593 | 396 | 'pf_ifname', 'rep_vf_1', 'rep_vf_2' | ||
594 | 397 | ] | ||
595 | 398 | - mock_isfile.side_effect = [True, True] | ||
596 | 399 | - mock_open.return_value.__enter__ = lambda s: s | ||
597 | 400 | - readline_mock = mock_open.return_value.readline | ||
598 | 401 | - readline_mock.side_effect = ( | ||
599 | 402 | - ['pf_sw_id', 'pf_sw_id', '1', 'pf_sw_id', 'a']) | ||
600 | 403 | - # PCI IDs mocked: | ||
601 | 404 | - # PF0: 0000:0a:00.0 | ||
602 | 405 | - # PF0VF1: 0000:0a:02.1 PF0VF2: 0000:0a:02.2 | ||
603 | 406 | - mock_get_function_by_ifname.side_effect = ( | ||
604 | 407 | - [("0000:0a:00.0", True), | ||
605 | 408 | - ("0000:0a:02.1", False), | ||
606 | 409 | - ("0000:0a:02.2", False)]) | ||
607 | 410 | + mock__get_phys_switch_id.return_value = 'pf_sw_id' | ||
608 | 411 | + mock__get_phys_port_name.side_effect = (['p0', '1', 'a']) | ||
609 | 412 | + mock__get_pf_func.return_value = "0" | ||
610 | 413 | self.assertRaises( | ||
611 | 414 | exception.RepresentorNotFound, | ||
612 | 415 | linux_net.get_representor_port, | ||
613 | 416 | 'pf_ifname', '3') | ||
614 | 417 | |||
615 | 418 | - @mock.patch('six.moves.builtins.open') | ||
616 | 419 | - @mock.patch.object(os.path, 'isfile') | ||
617 | 420 | @mock.patch.object(os, 'listdir') | ||
618 | 421 | - def test_physical_function_inferface_name( | ||
619 | 422 | - self, mock_listdir, mock_isfile, mock_open): | ||
620 | 423 | + @mock.patch.object(linux_net, '_get_phys_switch_id') | ||
621 | 424 | + def test_physical_function_interface_name( | ||
622 | 425 | + self, mock__get_phys_switch_id, mock_listdir): | ||
623 | 426 | mock_listdir.return_value = ['foo', 'bar'] | ||
624 | 427 | - mock_isfile.side_effect = [True, True] | ||
625 | 428 | - mock_open.return_value.__enter__ = lambda s: s | ||
626 | 429 | - readline_mock = mock_open.return_value.readline | ||
627 | 430 | - readline_mock.side_effect = ( | ||
628 | 431 | + mock__get_phys_switch_id.side_effect = ( | ||
629 | 432 | ['', 'valid_switch']) | ||
630 | 433 | ifname = linux_net.get_ifname_by_pci_address( | ||
631 | 434 | '0000:00:00.1', pf_interface=True, switchdev=False) | ||
632 | 435 | self.assertEqual(ifname, 'foo') | ||
633 | 436 | |||
634 | 437 | - @mock.patch('six.moves.builtins.open') | ||
635 | 438 | - @mock.patch.object(os.path, 'isfile') | ||
636 | 439 | @mock.patch.object(os, 'listdir') | ||
637 | 440 | - def test_physical_function_inferface_name_with_switchdev( | ||
638 | 441 | - self, mock_listdir, mock_isfile, mock_open): | ||
639 | 442 | + @mock.patch.object(linux_net, '_get_phys_switch_id') | ||
640 | 443 | + def test_physical_function_interface_name_with_switchdev( | ||
641 | 444 | + self, mock__get_phys_switch_id, mock_listdir): | ||
642 | 445 | mock_listdir.return_value = ['foo', 'bar'] | ||
643 | 446 | - mock_isfile.side_effect = [True, True] | ||
644 | 447 | - mock_open.return_value.__enter__ = lambda s: s | ||
645 | 448 | - readline_mock = mock_open.return_value.readline | ||
646 | 449 | - readline_mock.side_effect = ( | ||
647 | 450 | + mock__get_phys_switch_id.side_effect = ( | ||
648 | 451 | ['', 'valid_switch']) | ||
649 | 452 | ifname = linux_net.get_ifname_by_pci_address( | ||
650 | 453 | '0000:00:00.1', pf_interface=True, switchdev=True) | ||
651 | 454 | @@ -419,3 +325,35 @@ class LinuxNetTest(testtools.TestCase): | ||
652 | 455 | linux_net.get_vf_num_by_pci_address, | ||
653 | 456 | '0000:00:00.1' | ||
654 | 457 | ) | ||
655 | 458 | + | ||
656 | 459 | + @mock.patch('builtins.open') | ||
657 | 460 | + @mock.patch.object(os.path, 'isfile') | ||
658 | 461 | + def test__get_phys_port_name(self, mock_isfile, mock_open): | ||
659 | 462 | + mock_open.return_value.__enter__ = lambda s: s | ||
660 | 463 | + readline_mock = mock_open.return_value.readline | ||
661 | 464 | + readline_mock.return_value = 'pf0vf0' | ||
662 | 465 | + mock_isfile.return_value = True | ||
663 | 466 | + phys_port_name = linux_net._get_phys_port_name("vf_ifname") | ||
664 | 467 | + self.assertEqual(phys_port_name, 'pf0vf0') | ||
665 | 468 | + | ||
666 | 469 | + @mock.patch.object(os.path, 'isfile') | ||
667 | 470 | + def test__get_phys_port_name_not_found(self, mock_isfile): | ||
668 | 471 | + mock_isfile.return_value = False | ||
669 | 472 | + phys_port_name = linux_net._get_phys_port_name("vf_ifname") | ||
670 | 473 | + self.assertIsNone(phys_port_name) | ||
671 | 474 | + | ||
672 | 475 | + @mock.patch('builtins.open') | ||
673 | 476 | + @mock.patch.object(os.path, 'isfile') | ||
674 | 477 | + def test__get_phys_switch_id(self, mock_isfile, mock_open): | ||
675 | 478 | + mock_open.return_value.__enter__ = lambda s: s | ||
676 | 479 | + readline_mock = mock_open.return_value.readline | ||
677 | 480 | + readline_mock.return_value = '66e40000039b0398' | ||
678 | 481 | + mock_isfile.return_value = True | ||
679 | 482 | + phys_port_name = linux_net._get_phys_switch_id("ifname") | ||
680 | 483 | + self.assertEqual(phys_port_name, '66e40000039b0398') | ||
681 | 484 | + | ||
682 | 485 | + @mock.patch.object(os.path, 'isfile') | ||
683 | 486 | + def test__get_phys_switch_id_not_found(self, mock_isfile): | ||
684 | 487 | + mock_isfile.return_value = False | ||
685 | 488 | + phys_port_name = linux_net._get_phys_switch_id("ifname") | ||
686 | 489 | + self.assertIsNone(phys_port_name) | ||
687 | 490 | -- | ||
688 | 491 | 2.31.1 | ||
689 | diff --git a/debian/patches/series b/debian/patches/series | |||
690 | 0 | new file mode 100644 | 492 | new file mode 100644 |
691 | index 0000000..2467eb6 | |||
692 | --- /dev/null | |||
693 | +++ b/debian/patches/series | |||
694 | @@ -0,0 +1,2 @@ | |||
695 | 1 | Refactor-code-of-linux_net-to-more-cleaner-and-increase-performace.patch | ||
696 | 2 | Fix-os-vif-fails-to-get-the-correct-UpLink-Representor.patch |