Repository: buildbot/buildbot

Issue:
improve documentation for LibVirtSlave
This ticket is a migrated Trac ticket [3062](http://trac.buildbot.net/ticket/3062)

People contributed to the original ticket: @sa2ajj
Ticket created on: `Nov 24 2014`
Ticket last modified on: `Nov 24 2014`

---

Per discussion on [[IRC|http://irclogs.jackgrigg.com/irc.freenode.net/buildbot/2014-11-24#i_3505372]], there are ways to run build slaves on a remote machine and there are cases when they can only be run on the machine where master resides.


---

_Comment from_: @sa2ajj
_Date_: `Nov 24 2014`

Might be useful for the update: http://libvirt.org/remote.html




Discussion:

Resolving patch:
diff --git a/master/buildbot/db/connector.py b/master/buildbot/db/connector.py
--- a/master/buildbot/db/connector.py
+++ b/master/buildbot/db/connector.py
@@ -16,6 +16,7 @@
 import textwrap
 
 from buildbot import config
+from buildbot import util
 from buildbot.db import builders
 from buildbot.db import buildrequests
 from buildbot.db import builds
@@ -99,7 +100,8 @@ def __init__(self, master, basedir):
     def setup(self, check_version=True, verbose=True):
         db_url = self.configured_url = self.master.config.db['db_url']
 
-        log.msg("Setting up database with URL %r" % (db_url,))
+        log.msg("Setting up database with URL %r"
+                % util.stripUrlPassword(db_url))
 
         # set up the engine and pool
         self._engine = enginestrategy.create_engine(db_url,
diff --git a/master/buildbot/util/__init__.py b/master/buildbot/util/__init__.py
--- a/master/buildbot/util/__init__.py
+++ b/master/buildbot/util/__init__.py
@@ -22,6 +22,7 @@
 import string
 import time
 import types
+import urlparse
 
 from twisted.python import reflect
 
@@ -267,6 +268,15 @@ def check_functional_environment(config):
         ]))
 
 
+_netloc_url_re = re.compile(r':[^@]*@')
+
+
+def stripUrlPassword(url):
+    parts = list(urlparse.urlsplit(url))
+    parts[1] = _netloc_url_re.sub(':xxxx@', parts[1])
+    return urlparse.urlunsplit(parts)
+
+
 __all__ = [
     'naturalSort', 'now', 'formatInterval', 'ComparableMixin', 'json',
     'safeTranslate', 'none_or_str',


Test patch:
diff --git a/master/buildbot/test/unit/test_util.py b/master/buildbot/test/unit/test_util.py
--- a/master/buildbot/test/unit/test_util.py
+++ b/master/buildbot/test/unit/test_util.py
@@ -287,3 +287,27 @@ def err():
         config = mock.Mock()
         util.check_functional_environment(config)
         config.error.assert_called_with(mock.ANY)
+
+
+class StripUrlPassword(unittest.TestCase):
+
+    def test_simple_url(self):
+        self.assertEqual(util.stripUrlPassword('http://foo.com/bar'),
+                         'http://foo.com/bar')
+
+    def test_username(self):
+        self.assertEqual(util.stripUrlPassword('http://d@foo.com/bar'),
+                         'http://d@foo.com/bar')
+
+    def test_username_with_at(self):
+        self.assertEqual(util.stripUrlPassword('http://d@bb.net@foo.com/bar'),
+                         'http://d@bb.net@foo.com/bar')
+
+    def test_username_pass(self):
+        self.assertEqual(util.stripUrlPassword('http://d:secret@foo.com/bar'),
+                         'http://d:xxxx@foo.com/bar')
+
+    def test_username_pass_with_at(self):
+        self.assertEqual(
+            util.stripUrlPassword('http://d@bb.net:scrt@foo.com/bar'),
+            'http://d@bb.net:xxxx@foo.com/bar')