|
1 | 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | | -import os |
4 | 3 | import pytest |
5 | | -import subprocess |
6 | 4 |
|
7 | 5 | from processes import ManagedProcess |
8 | 6 | from providers import Provider, S2N |
@@ -122,45 +120,3 @@ def _fn( |
122 | 120 | p.kill() |
123 | 121 | else: |
124 | 122 | p.join() |
125 | | - |
126 | | - |
127 | | -def _swap_mtu(device, new_mtu): |
128 | | - """ |
129 | | - Swap the device's current MTU for the requested MTU. |
130 | | - Return the original MTU so it can be reset later. |
131 | | - """ |
132 | | - cmd = ["ip", "link", "show", device] |
133 | | - p = subprocess.Popen( |
134 | | - cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE |
135 | | - ) |
136 | | - mtu = 65536 |
137 | | - for line in p.stdout.readlines(): |
138 | | - s = line.decode("utf-8") |
139 | | - pieces = s.split(" ") |
140 | | - if len(pieces) >= 4 and pieces[3] == "mtu": |
141 | | - mtu = int(pieces[4]) |
142 | | - |
143 | | - p.wait() |
144 | | - |
145 | | - subprocess.call(["ip", "link", "set", device, "mtu", str(new_mtu)]) |
146 | | - |
147 | | - return int(mtu) |
148 | | - |
149 | | - |
150 | | -@pytest.fixture(scope="module") |
151 | | -def custom_mtu(): |
152 | | - """ |
153 | | - This fixture will swap the loopback's MTU from the default |
154 | | - to 1500, which is more reasonable for a network device. |
155 | | - Using a fixture allows us to reset the MTU even if the test |
156 | | - fails. |
157 | | -
|
158 | | - These values are all hardcoded because they are only used |
159 | | - from a single test. This simplifies the use of the fixture. |
160 | | - """ |
161 | | - if os.geteuid() != 0: |
162 | | - pytest.skip("Test needs root privileges to modify lo MTU") |
163 | | - |
164 | | - original_mtu = _swap_mtu("lo", 1500) |
165 | | - yield |
166 | | - _swap_mtu("lo", original_mtu) |
0 commit comments