mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-06 05:38:15 +02:00
clients/tests: merge branch 'th/test-client-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1591
This commit is contained in:
commit
17601acd3d
2 changed files with 8 additions and 10 deletions
|
|
@ -2146,8 +2146,11 @@ class TestNmCloudSetup(TestNmClient):
|
||||||
if pexpect is None:
|
if pexpect is None:
|
||||||
raise unittest.SkipTest("pexpect not available")
|
raise unittest.SkipTest("pexpect not available")
|
||||||
|
|
||||||
|
if tuple(sys.version_info[0:2]) < (3, 2):
|
||||||
|
# subprocess.Popen()'s "pass_fd" argument requires at least Python 3.2.
|
||||||
|
raise unittest.SkipTest("This test requires at least Python 3.2")
|
||||||
|
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
s.set_inheritable(True)
|
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||||
s.bind(("localhost", 0))
|
s.bind(("localhost", 0))
|
||||||
|
|
@ -2157,18 +2160,14 @@ class TestNmCloudSetup(TestNmClient):
|
||||||
# hallucinogenic substances.
|
# hallucinogenic substances.
|
||||||
s.listen(5)
|
s.listen(5)
|
||||||
|
|
||||||
def pass_socket():
|
|
||||||
os.dup2(s.fileno(), 3, inheritable=True)
|
|
||||||
|
|
||||||
service_path = PathConfiguration.test_cloud_meta_mock_path()
|
service_path = PathConfiguration.test_cloud_meta_mock_path()
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["LISTEN_FDS"] = "1"
|
env["LISTEN_FD"] = str(s.fileno())
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[sys.executable, service_path],
|
[sys.executable, service_path],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
env=env,
|
env=env,
|
||||||
pass_fds=(s.fileno(),),
|
pass_fds=(s.fileno(),),
|
||||||
preexec_fn=pass_socket,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.md_url = "http://%s:%d" % s.getsockname()
|
self.md_url = "http://%s:%d" % s.getsockname()
|
||||||
|
|
@ -2178,6 +2177,7 @@ class TestNmCloudSetup(TestNmClient):
|
||||||
func(self)
|
func(self)
|
||||||
self._nm_test_post()
|
self._nm_test_post()
|
||||||
|
|
||||||
|
p.stdin.close()
|
||||||
p.terminate()
|
p.terminate()
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,9 @@ class SocketHTTPServer(HTTPServer):
|
||||||
|
|
||||||
|
|
||||||
# See sd_listen_fds(3)
|
# See sd_listen_fds(3)
|
||||||
fileno = os.getenv("LISTEN_FDS")
|
fileno = os.getenv("LISTEN_FD")
|
||||||
if fileno is not None:
|
if fileno is not None:
|
||||||
if fileno != "1":
|
s = socket.socket(fileno=int(fileno))
|
||||||
raise Exception("Bad LISTEN_FDS")
|
|
||||||
s = socket.socket(fileno=3)
|
|
||||||
else:
|
else:
|
||||||
addr = ("localhost", 0)
|
addr = ("localhost", 0)
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue