[Reproducible-commits] [reprotest] 03/04: Add domain and host variations

Ceridwen ceridwen-guest at moszumanska.debian.org
Wed Jul 27 22:24:01 UTC 2016


This is an automated email from the git hooks/post-receive script.

ceridwen-guest pushed a commit to branch variations
in repository reprotest.

commit c873ffbe9e9e53289869e611c31ea265d9a222b7
Author: Ceridwen <ceridwenv at gmail.com>
Date:   Wed Jul 27 18:21:05 2016 -0400

    Add domain and host variations
---
 reprotest/__init__.py | 36 ++++++++++++++++++++++++++++++++++++
 tests/mock_build.py   |  4 ++++
 2 files changed, 40 insertions(+)

diff --git a/reprotest/__init__.py b/reprotest/__init__.py
index 5b8894c..760663e 100644
--- a/reprotest/__init__.py
+++ b/reprotest/__init__.py
@@ -182,6 +182,34 @@ def build_path(script, env, build_path, testbed):
     yield script, env, new_build_path
 build_path.__doc__ += VARIATION_DOCSTRING
 
+def domain_host(what_to_change):
+    '''Creates a context manager that changes and reverts the domain or
+    host name.
+
+    Args:
+         what_to_change (str): host or domain.
+
+    '''
+    command = what_to_change + 'name'
+    new_name = 'i-capture-the-' + what_to_change
+    @_contextlib.contextmanager
+    def change_name(script, env, build_path, testbed):
+        '''Change and revert domain or host name before and after building,
+        respectively.'''
+        # Save the previous name in a local variable.
+        old_name = testbed.check_exec([command])
+        testbed.check_exec([command, new_name])
+        if old_name is not None:
+            revert = _shell_ast.SimpleCommand.make(command, old_name)
+            try:
+                yield script.append_cleanup(revert), env, build_path
+            finally:
+                testbed.check_exec(str(revert).split())
+        else:
+            yield script, env, build_path
+    change_name.__doc__ += VARIATION_DOCSTRING
+    return change_name
+
 def file_ordering(disorderfs_mount):
     '''Generate a context manager that mounts and unmounts disorderfs.
 
@@ -304,6 +332,10 @@ VARIATIONS = types.MappingProxyType(MultipleDispatch([
       environment_variable_variation(
           'CAPTURE_ENVIRONMENT', 'i_capture_the_environment'))),
     # TODO: this requires superuser privileges.
+    ('domain', (identity,
+    types.MappingProxyType(collections.OrderedDict(
+        [('user', identity),
+         ('root', domain_host('domain'))])))),
     ('file_ordering',
      (identity,
       types.MappingProxyType(collections.OrderedDict(
@@ -314,6 +346,10 @@ VARIATIONS = types.MappingProxyType(MultipleDispatch([
     ('home',
      (environment_variable_variation('HOME', '/nonexistent/first-build'),
       environment_variable_variation('HOME', '/nonexistent/second-build'))),
+    ('host', (identity,
+    types.MappingProxyType(collections.OrderedDict(
+        [('user', identity),
+         ('root', domain_host('host'))])))),
     ('kernel', (identity, kernel)),
     ('locales', (identity, locales)),
     ('path', (identity, path)),
diff --git a/tests/mock_build.py b/tests/mock_build.py
index 7469aa5..cf5e7f9 100755
--- a/tests/mock_build.py
+++ b/tests/mock_build.py
@@ -27,6 +27,8 @@ if __name__ == '__main__':
         output.append(os.getcwd().encode('ascii'))
     if 'captures_environment' in variations:
         output.append(str(os.environ).encode('ascii'))
+    if 'domain' in variations:
+        output.append(subprocess.check_output(['domainname']))
     # Like the above test, this test can theoretically fail by
     # producing the same file order, but this is unlikely, if not
     # as unlikely as in the above test.
@@ -40,6 +42,8 @@ if __name__ == '__main__':
             output.extend(p.name.encode('ascii') for p in test_file_order.iterdir())
     if 'home' in variations:
         output.append(os.path.expanduser('~').encode('ascii'))
+    if 'host' in variations:
+        output.append(subprocess.check_output(['hostname']))
     if 'kernel' in variations:
         output.append(subprocess.check_output(['uname', '-r']))
     if 'locales' in variations:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/reprotest.git



More information about the Reproducible-commits mailing list