[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Support additional test torrc options



commit 394852cf08e7eb65904918591b503696bcac86de
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri Jun 7 15:42:47 2019 -0700

    Support additional test torrc options
    
    Teor would like to run stem's integ tests against a Chutnet network...
    
      https://trac.torproject.org/projects/tor/ticket/30702
    
    Highly unusual use case, but making it possible. Stem now accepts a
    STEM_TEST_CONFIG environment variable that overwrites any internal
    testing configuration values (see test/settings.cfg), along with
    a 'integ.extra_torrc' option.
    
    So to use this...
    
    1. Write a file that overwrites our integ.extra_torrc
       configuration. Available macros include...
    
       [DATA_DIR]
       [OR_PORT]
       [SOCKS_PORT]
    
    2. Set STEM_TEST_CONFIG to the path of that file.
    
    3. Run our integ tests, and check the beginning of the output where it says
       'writing torrc' to confirm that the torrc looks as you expect.
    
    For example...
    
      % cat /home/atagar/Desktop/stem/my_test_config
      integ.extra_torrc
      |Nickname Demo[OR_PORT]
      |FetchUselessDescriptors 1
    
      % export STEM_TEST_CONFIG=/home/atagar/Desktop/stem/my_test_config
    
      % ./run_tests.py --integ
      ...
    
      Setting up a test instance...
        making test directory (/home/atagar/Desktop/stem/test/data)... done
        configuring logger (/home/atagar/Desktop/stem/test/data/log)... done
        writing torrc (/home/atagar/Desktop/stem/test/data/torrc)... done
          # Configuration for stem's integration tests
    
          DataDirectory /home/atagar/Desktop/stem/test/data
          SocksPort 1112
          ORPort 1113
          ExitRelay 0
          PublishServerDescriptor 0
          AssumeReachable 1
          DownloadExtraInfo 1
          Log notice stdout
          Log debug file /home/atagar/Desktop/stem/test/data/tor_log
    
          # Torrc options for the RUN_OPEN target
    
          ControlPort 1111
    
          # Torrc options from /home/atagar/Desktop/stem/my_test_config
    
          Nickname Demo1113
          FetchUselessDescriptors 1
---
 run_tests.py      |  3 +++
 test/runner.py    | 36 ++++++++++++++++++------------------
 test/settings.cfg | 25 +++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index ef31a05e..77db73b5 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -187,6 +187,9 @@ def main():
   test_config = stem.util.conf.get_config('test')
   test_config.load(os.path.join(test.STEM_BASE, 'test', 'settings.cfg'))
 
+  if 'STEM_TEST_CONFIG' in os.environ:
+    test_config.load(os.environ['STEM_TEST_CONFIG'])
+
   try:
     args = test.arguments.parse(sys.argv[1:])
     test.task.TOR_VERSION.args = (args.tor_path,)
diff --git a/test/runner.py b/test/runner.py
index b7da06a4..c343ed57 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -52,6 +52,8 @@ import test
 from test.output import println, STATUS, ERROR, SUBSTATUS, NO_NL
 
 CONFIG = stem.util.conf.config_dict('test', {
+  'integ.torrc': '',
+  'integ.extra_torrc': '',
   'integ.test_directory': './test/data',
   'integ.log': './test/data/log',
   'target.torrc': {},
@@ -60,18 +62,6 @@ CONFIG = stem.util.conf.config_dict('test', {
 SOCKS_PORT = 1112
 ORPORT = 1113
 
-BASE_TORRC = """# configuration for stem integration tests
-DataDirectory %%s
-SocksPort %i
-ORPort %i
-ExitRelay 0
-PublishServerDescriptor 0
-AssumeReachable 1
-DownloadExtraInfo 1
-Log notice stdout
-Log debug file %%s/tor_log
-""" % (SOCKS_PORT, ORPORT)
-
 # singleton Runner instance
 INTEG_RUNNER = None
 
@@ -221,22 +211,32 @@ class Runner(object):
         data_dir_path = './%s' % os.path.basename(self._test_dir)
 
       config_csv = CONFIG['target.torrc'].get(config_target)
-      extra_torrc_opts = []
+      target_torrc_opts = []
 
       if config_csv:
         for opt in config_csv.split(','):
           opt = opt.strip()
 
           if opt in Torrc.keys():
-            extra_torrc_opts.append(Torrc[opt])
+            target_torrc_opts.append(Torrc[opt])
           else:
             raise ValueError("'%s' isn't a test.runner.Torrc enumeration" % opt)
 
-      self._custom_opts = extra_torrc_opts
-      self._torrc_contents = BASE_TORRC % (data_dir_path, data_dir_path)
+      self._custom_opts = target_torrc_opts
+
+      self._torrc_contents = CONFIG['integ.torrc']
+
+      if target_torrc_opts:
+        self._torrc_contents += '\n\n# Torrc options for the %s target\n\n' % config_target
+        self._torrc_contents += '\n'.join(target_torrc_opts)
+
+      if CONFIG['integ.extra_torrc']:
+        self._torrc_contents += '\n\n# Torrc options from %s\n\n' % os.environ['STEM_TEST_CONFIG']
+        self._torrc_contents += CONFIG['integ.extra_torrc']
 
-      if extra_torrc_opts:
-        self._torrc_contents += '\n'.join(extra_torrc_opts) + '\n'
+      self._torrc_contents = self._torrc_contents.replace('[DATA_DIR]', data_dir_path)
+      self._torrc_contents = self._torrc_contents.replace('[SOCKS_PORT]', str(SOCKS_PORT))
+      self._torrc_contents = self._torrc_contents.replace('[OR_PORT]', str(ORPORT))
 
       try:
         self._tor_cwd = os.getcwd()
diff --git a/test/settings.cfg b/test/settings.cfg
index 5b4feb60..6a2f5914 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -19,6 +19,31 @@ integ.test_directory ./test/data
 exclude_paths .*/stem/test/data/.*
 integ.log ./test/data/log
 
+integ.torrc
+|# Configuration for stem's integration tests
+|
+|DataDirectory [DATA_DIR]
+|SocksPort [SOCKS_PORT]
+|ORPort [OR_PORT]
+|ExitRelay 0
+|PublishServerDescriptor 0
+|AssumeReachable 1
+|DownloadExtraInfo 1
+|Log notice stdout
+|Log debug file [DATA_DIR]/tor_log
+
+# To append additional torrc options you can overwrite the following. For
+# example...
+#
+#   % cat /home/atagar/Desktop/stem/my_test_config 
+#   integ.extra_torrc
+#   |Nickname StemTestDemo
+#   |FetchUselessDescriptors 1
+#
+#   % export STEM_TEST_CONFIG=/home/atagar/Desktop/stem
+
+integ.extra_torrc
+
 # The following are less testing framework attributes that aren't as commonly
 # reconfigured.
 #

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits