From a5895b9d59212ab1a000b6e1d099cad4fe630c4d Mon Sep 17 00:00:00 2001
From: David-Sarah Hopwood <david-sarah@jacaranda.org>
Date: Sat, 29 Dec 2012 04:17:00 +0000
Subject: [PATCH] If a helper is not configured, make the banner on the welcome
 page say that, and have a white background. fixes #1735

Author: kick
Signed-off-by: David-Sarah Hopwood <davidsarah@jacaranda.org>
---
 src/allmydata/client.py            |  3 +++
 src/allmydata/test/test_client.py  | 18 +++++++++++++++
 src/allmydata/test/test_web.py     | 37 +++++++++++++++++++++++++++++-
 src/allmydata/web/root.py          |  8 +++++++
 src/allmydata/web/static/tahoe.css |  7 ++++--
 src/allmydata/web/welcome.xhtml    |  2 +-
 6 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/src/allmydata/client.py b/src/allmydata/client.py
index 1e4479bb..e1899971 100644
--- a/src/allmydata/client.py
+++ b/src/allmydata/client.py
@@ -306,6 +306,9 @@ class Client(node.Node, pollmixin.PollMixin):
 
     def init_client(self):
         helper_furl = self.get_config("client", "helper.furl", None)
+        if helper_furl in ("None", ""):
+            helper_furl = None
+
         DEP = self.DEFAULT_ENCODING_PARAMETERS
         DEP["k"] = int(self.get_config("client", "shares.needed", DEP["k"]))
         DEP["n"] = int(self.get_config("client", "shares.total", DEP["n"]))
diff --git a/src/allmydata/test/test_client.py b/src/allmydata/test/test_client.py
index 53734648..04458e68 100644
--- a/src/allmydata/test/test_client.py
+++ b/src/allmydata/test/test_client.py
@@ -172,6 +172,24 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
         self.failUnless("node.uptime" in stats)
         self.failUnless(isinstance(stats["node.uptime"], float))
 
+    def test_helper_furl(self):
+        basedir = "test_client.Basic.test_helper_furl"
+        os.mkdir(basedir)
+
+        def _check(config, expected_furl):
+            fileutil.write(os.path.join(basedir, "tahoe.cfg"),
+                           BASECONFIG + config)
+            c = client.Client(basedir)
+            uploader = c.getServiceNamed("uploader")
+            furl, connected = uploader.get_helper_info()
+            self.failUnlessEqual(furl, expected_furl)
+
+        _check("", None)
+        _check("helper.furl =\n", None)
+        _check("helper.furl = \n", None)
+        _check("helper.furl = None", None)
+        _check("helper.furl = pb://blah\n", "pb://blah")
+
     @mock.patch('allmydata.util.log.msg')
     @mock.patch('allmydata.frontends.drop_upload.DropUploader')
     def test_create_drop_uploader(self, mock_drop_uploader, mock_log_msg):
diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py
index 2c6c0ceb..576c3da3 100644
--- a/src/allmydata/test/test_web.py
+++ b/src/allmydata/test/test_web.py
@@ -80,6 +80,9 @@ class FakeNodeMaker(NodeMaker):
 
 class FakeUploader(service.Service):
     name = "uploader"
+    helper_furl = None
+    helper_connected = False
+
     def upload(self, uploadable):
         d = uploadable.get_size()
         d.addCallback(lambda size: uploadable.read(size))
@@ -100,8 +103,10 @@ class FakeUploader(service.Service):
             return ur
         d.addCallback(_got_data)
         return d
+
     def get_helper_info(self):
-        return (None, False)
+        return (self.helper_furl, self.helper_connected)
+
 
 def build_one_ds():
     ds = DownloadStatus("storage_index", 1234)
@@ -609,6 +614,36 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
         d.addCallback(_check)
         return d
 
+    def test_helper_status(self):
+        d = defer.succeed(None)
+
+        # set helper furl to None
+        def _set_helper_not_configured2(ign):
+            self.s.uploader.helper_furl = None
+            return self.GET("/")
+        d.addCallback(_set_helper_not_configured2)
+        d.addCallback(lambda res:
+                      self.failUnlessIn('Connected to helper?: <span>not configured</span>', res))
+
+        # enable helper, not connected
+        def _set_helper_not_connected(ign):
+            self.s.uploader.helper_furl = "pb://someHelper"
+            self.s.uploader.helper_connected = False
+            return self.GET("/")
+        d.addCallback(_set_helper_not_connected)
+        d.addCallback(lambda res:
+                      self.failUnlessIn('Connected to helper?: <span>no</span>', res))
+
+        # enable helper, connected
+        def _set_helper_connected(ign):
+            self.s.uploader.helper_furl = "pb://someHelper"
+            self.s.uploader.helper_connected = True
+            return self.GET("/")
+        d.addCallback(_set_helper_connected)
+        d.addCallback(lambda res:
+                      self.failUnlessIn('Connected to helper?: <span>yes</span>', res))
+        return d
+
     def test_storage(self):
         d = self.GET("/storage")
         def _check(res):
diff --git a/src/allmydata/web/root.py b/src/allmydata/web/root.py
index 2cd315d9..6f467cc8 100644
--- a/src/allmydata/web/root.py
+++ b/src/allmydata/web/root.py
@@ -200,6 +200,7 @@ class Root(rend.Page):
 
     def data_introducer_furl(self, ctx, data):
         return self.client.introducer_furl
+
     def data_connected_to_introducer(self, ctx, data):
         if self.client.connected_to_introducer():
             return "yes"
@@ -212,12 +213,19 @@ class Root(rend.Page):
             return None
         furl, connected = uploader.get_helper_info()
         return furl
+
+    def data_connected_to_helper_description(self, ctx, data):
+        return self.data_connected_to_helper(ctx, data).replace('-', ' ')
+
     def data_connected_to_helper(self, ctx, data):
         try:
             uploader = self.client.getServiceNamed("uploader")
         except KeyError:
             return "no" # we don't even have an Uploader
         furl, connected = uploader.get_helper_info()
+
+        if furl is None:
+            return "not-configured"
         if connected:
             return "yes"
         return "no"
diff --git a/src/allmydata/web/static/tahoe.css b/src/allmydata/web/static/tahoe.css
index 297bbe44..4a94d49c 100644
--- a/src/allmydata/web/static/tahoe.css
+++ b/src/allmydata/web/static/tahoe.css
@@ -6,7 +6,7 @@ pre.overflow {
                padding: .25em;
                overflow: auto;
                }
-               
+
 /* ----------------------------------------------------------------------- */
 
 /* colors borrowed from the Allmydata logo */
@@ -34,7 +34,6 @@ th {
 
 .table-headings-top th {
     text-align: center;
-    
 }
 .table-headings-left th {
     text-align: right;
@@ -52,6 +51,10 @@ legend {
   border: 1px solid #F00;
   background-color: #FBB;
 }
+.connected-not-configured {
+  border: 1px solid #AAA;
+  background-color: #FFF;
+}
 
 .encoded, .nodeid {
   font-family: monospace;
diff --git a/src/allmydata/web/welcome.xhtml b/src/allmydata/web/welcome.xhtml
index b493ee79..f88c02ca 100644
--- a/src/allmydata/web/welcome.xhtml
+++ b/src/allmydata/web/welcome.xhtml
@@ -47,7 +47,7 @@
   <div>
     <n:attr name="class">connected-<n:invisible n:render="string" n:data="connected_to_helper" /></n:attr>
     <div>Helper: <span n:render="string" n:data="helper_furl" /></div>
-    <div>Connected to helper?: <span n:render="string" n:data="connected_to_helper" /></div>
+    <div>Connected to helper?: <span n:render="string" n:data="connected_to_helper_description" /></div>
   </div>
 
   <p>Connected to <span n:render="string" n:data="connected_storage_servers" />
-- 
2.45.2