Created
January 27, 2014 20:25
-
-
Save tomprince/8656550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/hybridcluster/awesomeproxy/worker.py b/src/hybridcluster/awesomeproxy/worker.py | |
index 8741197..c6b55f5 100644 | |
--- a/src/hybridcluster/awesomeproxy/worker.py | |
+++ b/src/hybridcluster/awesomeproxy/worker.py | |
@@ -1671,9 +1671,10 @@ class Controller(hybridcluster.mixins.ReceiveCurrentMasters, pb.Root): | |
if isinstance(filesystem, basestring): | |
if site: | |
match = aliasMatch(self.websiteAliases, site) | |
- if match: | |
- return self._checkCurrentMastersJails( | |
+ result = self._checkCurrentMastersJails( | |
HybridUtils.site_dataset(match)) | |
+ if result: | |
+ return result | |
return (False, None) | |
diff --git a/src/hybridcluster/sitealias.py b/src/hybridcluster/sitealias.py | |
index 30e55b3..a7c5319 100644 | |
--- a/src/hybridcluster/sitealias.py | |
+++ b/src/hybridcluster/sitealias.py | |
@@ -26,7 +26,7 @@ def aliasMatch(websiteAliases, site): | |
@param site: A site name (C{bytes}) whose master site we wish to look up. | |
- @return: The name of the main site as C{bytes}, or C{None} if not found. | |
+ @return: The name of the main site as C{bytes}. | |
""" | |
# Split the site name on periods and do a dict lookup, replacing each | |
# component with a '*' one at a time, so that we match any wildcard | |
@@ -45,4 +45,4 @@ def aliasMatch(websiteAliases, site): | |
if attempt in websiteAliases: | |
return websiteAliases[attempt] | |
del components[0] | |
- return None | |
+ return site | |
diff --git a/src/hybridcluster/tests/test_sitealias.py b/src/hybridcluster/tests/test_sitealias.py | |
index b95069c..d7700d0 100644 | |
--- a/src/hybridcluster/tests/test_sitealias.py | |
+++ b/src/hybridcluster/tests/test_sitealias.py | |
@@ -13,10 +13,10 @@ class AliasMatchTests(SynchronousTestCase): | |
""" | |
def test_noMatch(self): | |
""" | |
- If no alias is found, C{None} is returned. | |
+ If no alias is found, the hostname is returned. | |
""" | |
aliases = {b"alias.com": b"real.com"} | |
- self.assertIs(aliasMatch(aliases, b"other.com"), None) | |
+ self.assertIs(aliasMatch(aliases, b"other.com"), b"other.com") | |
def test_match(self): | |
@@ -33,7 +33,7 @@ class AliasMatchTests(SynchronousTestCase): | |
A subdomain of an alias does not match if not explicitly included. | |
""" | |
aliases = {b"alias.com": b"real.com"} | |
- self.assertIs(aliasMatch(aliases, b"sub.alias.com"), None) | |
+ self.assertIs(aliasMatch(aliases, b"sub.alias.com"), b"sub.alias.com") | |
def test_wildcard(self): | |
diff --git a/src/hybridcluster/varnish.py b/src/hybridcluster/varnish.py | |
index 09ba3d2..1e8b6e7 100644 | |
--- a/src/hybridcluster/varnish.py | |
+++ b/src/hybridcluster/varnish.py | |
@@ -884,10 +884,7 @@ class FanoutResource(Resource): | |
# https://www.pivotaltracker.com/s/projects/787341/stories/61834490. | |
if host.startswith(b"www."): | |
host = host[4:] | |
- result = aliasMatch(self._juggler.websiteAliases, host) | |
- if result is None: | |
- return host | |
- return result | |
+ return aliasMatch(self._juggler.websiteAliases, host) | |
def render(self, request): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment