launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #05829
url weirdness in tests??
Hi
I will attempt to describe a behaviour with respect to the configured
root url that I saw when writing some tests. There's 2 different
versions of the url you can get (with and without the 8085 port) and I'd
like to understand why. I also highlight a couple of test cases that
would fail were they to be reworked using the new api introduced with
the branch to removed hard coded urls from tests.
I first noticed the issue when the test below failed:
root = getUtility(ILaunchpadRoot)
browser = self.getViewBrowser(
root, "+daily-builds", rootsite='code')
root_url = BaseLayer.appserver_root_url(facet='code')
self.assertEqual(
browser.url, "%s/+daily-builds" % root_url)
In the above code snippet,
browser.url =
http://code.launchpad.dev/+daily-builds
"%s/+daily-builds" % root_url =
http://code.launchpad.dev:8085/+daily-builds
Other aspects of getViewBrowser() work fine. eg browser.contents has the
correct data etc
Digging a bit deeper, BaseLayer.appserver_root_url() calls through to a
method on CanonicalConfig, which in turn calls:
root_url = str(getattr(self.vhost, facet).rooturl)
^^^ the above results in http://code.launchpad.dev:8085
The data comes from a file:
configs/testrunner-appserver/launchpad-lazr.conf
which has stuff like:
[vhost.code]
rooturl: http://code.launchpad.dev:8085/
The url property on the browser object returned from getViewBrowser
comes from calling canonical_url() on the root object. This internally
calls:
root_url = allvhosts.configs[rootsite].rooturl
^^^ the above results in http://code.launchpad.dev
The root_url value comes from the constructor of VirtualHostConfig:
(/canonical/launchpad/webapp/vhosts.py)
rooturl = '%s://%s/' % (protocol, hostname)
The above ignores the port of 8085 defined elsewhere. Indeed, the config
file schema-lazr.conf says:
# Explicit root URL for this virtual host.
# If this is not provided, the root URL is calculated
# based on the host name.
# Example: https://launchpad.net/
# datatype: string
rooturl: none
So in essence we have CanonicalConfig() which provides one value for
root_url containing a port, and AllVirtualHostsConfiguration() which
uses VirtualHostConfig() to provide root urls without the port.
Just for kicks, I hard coded in the port number in the VirtualHostConfig
constructor:
rooturl = '%s://%s:8085/' % (protocol, hostname)
I ran a bunch of tests, including the one at the top of this email. I
ran various doc tests, unit tests, windmill tests etc. They all passed
except for a new TestBranchMergeQueue test case which still uses hard
coded urls rather than the new BaseLayer.appserver_root_url() method.
The failing code was:
browser = self.getUserBrowser(canonical_url(branch), user=rockstar)
self.assertEqual(
'http://code.launchpad.dev/~rockstar/+merge-queues/libbob-queue',
browser.url)
The above test is exactly the same type as my one in the top of this
email. If I were to covert it to the new paradigm:
browser = self.getUserBrowser(canonical_url(branch), user=rockstar)
root_url = BaseLayer.appserver_root_url(facet='code')
self.assertEqual(
'%s/~rockstar/+merge-queues/libbob-queue' % root_url,
browser.url)
The above code is "correct", but would fail without my 8085 port hard
wiring hack mentioned just before, since root_url above would have 8085
and browser.url wouldn't.
So, what to do? It seems to me that there is a legitimate issue in that
key runtime classes - CanonicalConfig and AllVirtualHostsConfiguration -
provide different information from different config files and which
version of root_url you get depends on who you ask. browser.url (via
canonical_url()) gets its value by asking AllVirtualHostsConfiguration
and BaseLayer.appserver_root_url() gets its value by asking
CanonicalConfig. I think we need one true answer for root url etc
provided by one class? So CanonicalConfig should delegate to
AllVirtualHostsConfiguration or I think preferably visa versa. This
would mean that the root urls from the testrunner-appserver config files
would be used for tests, and presumably the correct values from
elsewhere for running Launchpad?
Am I way off base here? Any clarification much appreciated. I need to
get this sorted out so that I can complete the work to remove hard coded
urls from all tests.
Follow ups