4685: run_test_server support for arv-git-httpd.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 6 Apr 2015 19:23:57 +0000 (15:23 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 6 Apr 2015 19:23:57 +0000 (15:23 -0400)
sdk/python/tests/run_test_server.py
services/api/config/application.default.yml
services/arv-git-httpd/main.go

index b9502f0f8e5bb5a6292da85bb69ef1f783163cab..99d66ca6c488f073f8fa69498564ca577c5c2ba2 100644 (file)
@@ -351,6 +351,26 @@ def run_keep_proxy():
 def stop_keep_proxy():
     kill_server_pid(os.path.join(TEST_TMPDIR, "keepproxy.pid"), 0)
 
+def run_arv_git():
+    stop_arv_git()
+
+    admin_token = auth_token('admin')
+    env = os.environ.copy()
+    env['ARVADOS_API_TOKEN'] = admin_token
+    shutil.rmtree(os.path.join(ARVADOS_DIR, "services/api/tmp/git"), ignore_errors=True)
+    os.mkdir(os.path.join(ARVADOS_DIR, "services/api/tmp/git"))
+    argh = subprocess.Popen(
+        ["arv-git-httpd",
+         "-address=:3005",
+         "-repo-root=%s" % os.path.join(ARVADOS_DIR, "services/api/tmp/git"),
+         "-pid={}/arv-git-httpd.pid".format(TEST_TMPDIR),
+         ],
+        env=env)
+
+def stop_arv_git():
+    kill_server_pid(os.path.join(TEST_TMPDIR, "arv-git-httpd.pid"), 0)
+
+
 def fixture(fix):
     '''load a fixture yaml file'''
     with open(os.path.join(SERVICES_SRC_DIR, 'api', "test", "fixtures",
@@ -391,6 +411,7 @@ class TestCaseWithServers(unittest.TestCase):
     MAIN_SERVER = None
     KEEP_SERVER = None
     KEEP_PROXY_SERVER = None
+    ARV_GIT_SERVER = None
 
     @staticmethod
     def _restore_dict(src, dest):
@@ -409,7 +430,8 @@ class TestCaseWithServers(unittest.TestCase):
         for server_kwargs, start_func, stop_func in (
                 (cls.MAIN_SERVER, run, reset),
                 (cls.KEEP_SERVER, run_keep, stop_keep),
-                (cls.KEEP_PROXY_SERVER, run_keep_proxy, stop_keep_proxy)):
+                (cls.KEEP_PROXY_SERVER, run_keep_proxy, stop_keep_proxy),
+                (cls.ARV_GIT_SERVER, run_arv_git, stop_arv_git)):
             if server_kwargs is not None:
                 start_func(**server_kwargs)
                 cls._cleanup_funcs.append(stop_func)
index 1696e2c56ebf9226126945c86b254144c7acd7fa..d6a58f9c087220125fa7ab2a2422ed06287c767c 100644 (file)
@@ -45,6 +45,8 @@ test:
   blob_signing_key: zfhgfenhffzltr9dixws36j1yhksjoll2grmku38mi7yxd66h5j4q9w4jzanezacp8s6q0ro3hxakfye02152hncy6zml2ed0uc
   user_profile_notification_address: arvados@example.com
   workbench_address: https://localhost:3001/
+  git_repositories_dir: <%= "#{Dir.pwd}/tmp/git" %>
+  git_host: http://localhost:3005
 
 common:
   # The prefix used for all database identifiers to identify the record as
index 0e92393e29ffc916e9a128f4cfe10aaa7930ef5e..2b585ffc930bb69730e678ebb2c98be4047e7af4 100644 (file)
@@ -2,6 +2,7 @@ package main
 
 import (
        "flag"
+       "fmt"
        "log"
        "os"
 )
@@ -10,6 +11,7 @@ type config struct {
        Addr       string
        GitCommand string
        Root       string
+       Pidfile    string
 }
 
 var theConfig *config
@@ -27,6 +29,12 @@ func init() {
        flag.StringVar(&theConfig.Root, "repo-root", cwd,
                "Path to git repositories.")
 
+       flag.StringVar(
+               &theConfig.Pidfile,
+               "pid",
+               "",
+               "Path to write pid file")
+
        // MakeArvadosClient returns an error if token is unset (even
        // though we don't need to do anything requiring
        // authentication yet). We can't do this in newArvadosClient()
@@ -42,7 +50,19 @@ func main() {
        if err := srv.Start(); err != nil {
                log.Fatal(err)
        }
+
+       if theConfig.Pidfile != "" {
+               f, err := os.Create(theConfig.Pidfile)
+               if err != nil {
+                       log.Fatalf("Error writing pid file (%s): %s", theConfig.Pidfile, err.Error())
+               }
+               fmt.Fprint(f, os.Getpid())
+               f.Close()
+               defer os.Remove(theConfig.Pidfile)
+       }
+
        log.Println("Listening at", srv.Addr)
+
        if err := srv.Wait(); err != nil {
                log.Fatal(err)
        }