From 24f26b26d0ee56f0d61ce083ad88c02bfa5f72d2 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 18 Feb 2021 10:21:31 +0200 Subject: feat: handle Unix domain sockets --- subplot/summain.py | 21 +++++++++++++++++++++ subplot/summain.yaml | 6 ++++++ summain.md | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/subplot/summain.py b/subplot/summain.py index 4efc8c4..e137ade 100644 --- a/subplot/summain.py +++ b/subplot/summain.py @@ -1,5 +1,7 @@ +import difflib import logging import os +import socket def install_summain(ctx): @@ -21,6 +23,15 @@ def create_symlink(ctx, linkname=None, target=None): os.symlink(target, linkname) +def create_socket(ctx, filename=None): + fd = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + fd.bind(filename) + + +def set_mode(ctx, filename=None, mode=None): + os.chmod(filename, int(mode, 8)) + + def set_atime(ctx, filename=None, timestamp=None): st = os.lstat(filename) os.utime(filename, (int(timestamp), int(st.st_mtime)), follow_symlinks=False) @@ -38,7 +49,17 @@ def output_matches_file(ctx, filename=None): actual = runcmd_get_stdout(ctx) expected = get_file(filename).decode("UTF-8") + diff = "".join( + line.rstrip("\n") + "\n" + for line in difflib.unified_diff( + expected.splitlines(), + actual.splitlines(), + fromfile="expected", + tofile="actual", + ) + ) logging.debug("output_matches:") logging.debug(f" actual:\n{actual}") logging.debug(f" expect:\n{expected}") + logging.debug(f" diff:\n{diff}") assert_eq(actual, expected) diff --git a/subplot/summain.yaml b/subplot/summain.yaml index 2fd12a5..8df3642 100644 --- a/subplot/summain.yaml +++ b/subplot/summain.yaml @@ -4,9 +4,15 @@ - given: directory {dirname} function: create_directory +- given: socket {filename} + function: create_socket + - given: file {filename} function: create_file +- given: file {filename} has mode {mode} + function: set_mode + - given: symlink {linkname} pointing at {target} function: create_symlink diff --git a/summain.md b/summain.md index db22d04..1631622 100644 --- a/summain.md +++ b/summain.md @@ -202,3 +202,38 @@ functions: - subplot/summain.py - subplot/runcmd.py ... + +## Unix domain socket + +~~~scenario +given an installed summain +given socket aaa +and file aaa has mode 0700 +and mtime for aaa is 44 +when I run summain aaa +then output matches file socket.yaml +~~~ + +```{#socket.yaml .file .numberLines} +--- +path: aaa +mode: srwx------ +mtime: 44 +mtime_nsec: 0 +nlink: 1 +size: 0 +sha256: ~ +target: ~ +``` + +--- +title: "Summain—deterministic file manifests" +author: Lars Wirzenius +template: python +bindings: + - subplot/summain.yaml + - subplot/runcmd.yaml +functions: + - subplot/summain.py + - subplot/runcmd.py +... -- cgit v1.2.1