Browse Source

Add failing test for #677

Mike Naberezny 9 years ago
parent
commit
19926c6404
1 changed files with 187 additions and 1 deletions
  1. 187 1
      supervisor/tests/test_options.py

+ 187 - 1
supervisor/tests/test_options.py

@@ -203,6 +203,42 @@ class ClientOptionsTests(unittest.TestCase):
         self.assertEqual(options.password, 'passwordhere')
         self.assertEqual(options.history_file, '/path/to/histdir/.supervisorctl.hist')
 
+    def test_options_supervisorctl_section_expands_here(self):
+        instance = self._makeOne()
+        text = lstrip('''
+        [supervisorctl]
+        history_file=%(here)s/sc_history
+        serverurl=unix://%(here)s/supervisord.sock
+        ''')
+        here = tempfile.mkdtemp()
+        supervisord_conf = os.path.join(here, 'supervisord.conf')
+        f = open(supervisord_conf, 'w')
+        f.write(text)
+        f.close()
+        try:
+            instance.configfile = supervisord_conf
+            instance.process_config(do_usage=False)
+            instance.realize(args=[])
+        finally:
+            try:
+                shutil.rmtree(here)
+            except OSError:
+                pass
+        options = instance.configroot.supervisorctl
+        self.assertEqual(options.history_file,
+           os.path.join(here, 'sc_history'))
+        self.assertEqual(options.serverurl,
+            os.path.join(here, 'serverurl'))
+
+    def test_read_config_not_found(self):
+        nonexistent = os.path.join(os.path.dirname(__file__), 'nonexistent')
+        instance = self._makeOne()
+        try:
+            instance.read_config(nonexistent)
+            self.fail("nothing raised")
+        except ValueError, exc:
+            self.assertTrue("could not find config file" in exc.args[0])
+
     def test_read_config_unreadable(self):
         instance = self._makeOne()
         def dummy_exists(fn):
@@ -581,7 +617,7 @@ class ServerOptionsTests(unittest.TestCase):
         programs = three
         """)
         instance.configfile = StringIO(text)
-        instance.process_config()
+        instance.process_config(do_usage=False)
 
         section = instance.configroot.supervisord
 
@@ -879,6 +915,35 @@ class ServerOptionsTests(unittest.TestCase):
                 "Must specify username if password is specified "
                 "in [unix_http_server]")
 
+    def test_options_afunix_file_expands_here(self):
+        instance = self._makeOne()
+        text = lstrip("""\
+        [supervisord]
+
+        [unix_http_server]
+        file=%(here)s/supervisord.sock
+        """)
+        here = tempfile.mkdtemp()
+        supervisord_conf = os.path.join(here, 'supervisord.conf')
+        f = open(supervisord_conf, 'w')
+        f.write(text)
+        f.close()
+        try:
+            instance.configfile = supervisord_conf
+            instance.process_config(do_usage=False)
+            instance.realize(args=[])
+            options = instance.configroot.supervisord
+            # unix_http_server
+            serverconf = options.server_configs[0]
+            self.assertEqual(serverconf['family'], socket.AF_UNIX)
+            self.assertEqual(serverconf['file'],
+                os.path.join(here, 'supervisord.sock'))
+        finally:
+            try:
+                shutil.rmtree(here)
+            except OSError:
+                pass
+
     def test_options_afinet_password_without_username(self):
         instance = self._makeOne()
         text = lstrip("""\
@@ -1336,6 +1401,127 @@ class ServerOptionsTests(unittest.TestCase):
         self.assertEqual(proc1.umask, 2)
         self.assertEqual(proc1.environment, dict(FAKE_ENV_VAR='/some/path'))
 
+    def test_options_supervisord_section_expands_here(self):
+        instance = self._makeOne()
+        text = lstrip('''\
+        [supervisord]
+        childlogdir=%(here)s
+        directory=%(here)s
+        logfile=%(here)s/supervisord.log
+        pidfile=%(here)s/supervisord.pid
+        ''')
+        here = tempfile.mkdtemp()
+        supervisord_conf = os.path.join(here, 'supervisord.conf')
+        f = open(supervisord_conf, 'w')
+        f.write(text)
+        f.close()
+        try:
+            instance.configfile = supervisord_conf
+            instance.process_config(do_usage=False)
+            instance.realize(args=[])
+        finally:
+            try:
+                shutil.rmtree(here)
+            except OSError:
+                pass
+        self.assertEqual(instance.childlogdir,
+            os.path.join(here))
+        self.assertEqual(instance.directory,
+            os.path.join(here))
+        self.assertEqual(instance.logfile,
+            os.path.join(here, 'supervisord.log'))
+        self.assertEqual(instance.pidfile,
+            os.path.join(here, 'supervisord.pid'))
+
+    def test_options_program_section_expands_here(self):
+        instance = self._makeOne()
+        text = lstrip('''
+        [supervisord]
+
+        [program:cat]
+        command=%(here)s/bin/cat
+        directory=%(here)s/thedirectory
+        environment=FOO=%(here)s/foo
+        serverurl=unix://%(here)s/supervisord.sock
+        stdout_logfile=%(here)s/stdout.log
+        stderr_logfile=%(here)s/stderr.log
+        ''')
+        here = tempfile.mkdtemp()
+        supervisord_conf = os.path.join(here, 'supervisord.conf')
+        f = open(supervisord_conf, 'w')
+        f.write(text)
+        f.close()
+        try:
+            instance.configfile = supervisord_conf
+            instance.process_config(do_usage=False)
+            instance.realize(args=[])
+        finally:
+            try:
+                shutil.rmtree(here)
+            except OSError:
+                pass
+        options = instance.configroot.supervisord
+        group = options.process_group_configs[0]
+        self.assertEqual(group.name, 'cat')
+        proc = group.process_configs[0]
+        self.assertEqual(proc.directory,
+            os.path.join(here, 'thedirectory'))
+        self.assertEqual(proc.command,
+            os.path.join(here, 'bin/cat'))
+        self.assertEqual(proc.environment,
+            {'FOO': os.path.join(here, 'foo')})
+        self.assertEqual(proc.serverurl,
+            'unix://' + os.path.join(here, 'supervisord.sock'))
+        self.assertEqual(proc.stdout_logfile,
+            os.path.join(here, 'stdout.log'))
+        self.assertEqual(proc.stderr_logfile,
+            os.path.join(here, 'stderr.log'))
+
+    def test_options_eventlistener_section_expands_here(self):
+        instance = self._makeOne()
+        text = lstrip('''
+        [supervisord]
+
+        [eventlistener:memmon]
+        events=TICK_60
+        command=%(here)s/bin/memmon
+        directory=%(here)s/thedirectory
+        environment=FOO=%(here)s/foo
+        serverurl=unix://%(here)s/supervisord.sock
+        stdout_logfile=%(here)s/stdout.log
+        stderr_logfile=%(here)s/stderr.log
+        ''')
+        here = tempfile.mkdtemp()
+        supervisord_conf = os.path.join(here, 'supervisord.conf')
+        f = open(supervisord_conf, 'w')
+        f.write(text)
+        f.close()
+        try:
+            instance.configfile = supervisord_conf
+            instance.process_config(do_usage=False)
+            instance.realize(args=[])
+        finally:
+            try:
+                shutil.rmtree(here)
+            except OSError:
+                pass
+        options = instance.configroot.supervisord
+        group = options.process_group_configs[0]
+        self.assertEqual(group.name, 'memmon')
+        proc = group.process_configs[0]
+        self.assertEqual(proc.directory,
+            os.path.join(here, 'thedirectory'))
+        self.assertEqual(proc.command,
+            os.path.join(here, 'bin/memmon'))
+        self.assertEqual(proc.environment,
+            {'FOO': os.path.join(here, 'foo')})
+        self.assertEqual(proc.serverurl,
+            'unix://' + os.path.join(here, 'supervisord.sock'))
+        self.assertEqual(proc.stdout_logfile,
+            os.path.join(here, 'stdout.log'))
+        self.assertEqual(proc.stderr_logfile,
+            os.path.join(here, 'stderr.log'))
+
     def test_processes_from_section_bad_program_name_spaces(self):
         instance = self._makeOne()
         text = lstrip("""\