]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fake-imds: apply "ruff format" and "ruff check --fix"
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 17 May 2026 17:48:35 +0000 (02:48 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 17 May 2026 17:48:35 +0000 (02:48 +0900)
test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/fake-imds.py

index e0a28ca766baac24f98c260f3d13214ef89a2e96..4eb3c95836acaf1678093fb1f3164ab164a1b929 100755 (executable)
@@ -1,15 +1,17 @@
 #!/usr/bin/python3
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
-import os, socket
+import os
+import socket
 from http.server import BaseHTTPRequestHandler, HTTPServer
 
+
 def sd_notify(state: str) -> bool:
-    notify_socket = os.environ.get("NOTIFY_SOCKET")
+    notify_socket = os.environ.get('NOTIFY_SOCKET')
     if not notify_socket:
         return False
-    if notify_socket.startswith("@"):
-        notify_socket = "\0" + notify_socket[1:]
+    if notify_socket.startswith('@'):
+        notify_socket = '\0' + notify_socket[1:]
     try:
         with socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) as sock:
             sock.sendto(state.encode(), notify_socket)
@@ -18,34 +20,36 @@ def sd_notify(state: str) -> bool:
 
     return True
 
+
 class Handler(BaseHTTPRequestHandler):
     def do_GET(self):
-        if self.path == "/userdata":
-            body = b"{\"systemd.credentials\":[{\"name\":\"acredtest\",\"text\":\"avalue\"}]}"
+        if self.path == '/userdata':
+            body = b'{"systemd.credentials":[{"name":"acredtest","text":"avalue"}]}'
             self.send_response(200)
-            self.send_header("Content-Type", "text/plain")
-            self.send_header("Content-Length", len(body))
+            self.send_header('Content-Type', 'text/plain')
+            self.send_header('Content-Length', len(body))
             self.end_headers()
             self.wfile.write(body)
-        elif self.path == "/hostname":
-            body = b"piff"
+        elif self.path == '/hostname':
+            body = b'piff'
             self.send_response(200)
-            self.send_header("Content-Type", "text/plain")
-            self.send_header("Content-Length", len(body))
+            self.send_header('Content-Type', 'text/plain')
+            self.send_header('Content-Length', len(body))
             self.end_headers()
             self.wfile.write(body)
         else:
             self.send_error(404)
 
     def log_message(self, fmt, *args):
-        print(f"{self.address_string()} - {fmt % args}")
+        print(f'{self.address_string()} - {fmt % args}')
+
 
-PORT=8088
+PORT = 8088
 
-server = HTTPServer(("", PORT), Handler)
-print(f"Serving on http://localhost:{PORT}/")
+server = HTTPServer(('', PORT), Handler)
+print(f'Serving on http://localhost:{PORT}/')
 try:
-    sd_notify("READY=1")
+    sd_notify('READY=1')
     server.serve_forever()
 except KeyboardInterrupt:
-    print("\nStopped.")
+    print('\nStopped.')