You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ja...@apache.org on 2015/07/08 04:19:43 UTC

[1/3] trafficserver git commit: Add tests for reloading the hosts file

Repository: trafficserver
Updated Branches:
  refs/heads/master 078a9a8c0 -> f98ad39f5


Add tests for reloading the hosts file


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/f98ad39f
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/f98ad39f
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/f98ad39f

Branch: refs/heads/master
Commit: f98ad39f52826f825905266e784ac88e7252f26a
Parents: c857fe7
Author: Thomas Jackson <ja...@apache.org>
Authored: Tue Jul 7 18:59:38 2015 -0700
Committer: Thomas Jackson <ja...@apache.org>
Committed: Tue Jul 7 19:19:31 2015 -0700

----------------------------------------------------------------------
 ci/tsqa/tests/test_hostdb.py | 92 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 82 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f98ad39f/ci/tsqa/tests/test_hostdb.py
----------------------------------------------------------------------
diff --git a/ci/tsqa/tests/test_hostdb.py b/ci/tsqa/tests/test_hostdb.py
index e17d79a..25ac640 100644
--- a/ci/tsqa/tests/test_hostdb.py
+++ b/ci/tsqa/tests/test_hostdb.py
@@ -21,10 +21,41 @@ Test hostdb
 import os
 import requests
 import time
-import tsqa.test_cases
+import logging
+import SocketServer
 
+import tsqa.test_cases
 import helpers
 
+log = logging.getLogger(__name__)
+
+
+class EchoServerIpHandler(SocketServer.BaseRequestHandler):
+    """
+    A subclass of RequestHandler which will return a connection uuid
+    """
+
+    def handle(self):
+        # Receive the data in small chunks and retransmit it
+        while True:
+            data = self.request.recv(4096).strip()
+            if data:
+                log.debug('Sending data back to the client')
+            else:
+                log.debug('Client disconnected')
+                break
+            resp = ('HTTP/1.1 200 OK\r\n'
+                    'Content-Length: 0\r\n'
+                    'Content-Type: text/html; charset=UTF-8\r\n'
+                    'Connection: keep-alive\r\n'
+                    'X-Server-Ip: {server_ip}\r\n'
+                    'X-Server-Port: {server_port}\r\n'
+                    '\r\n'.format(
+                        server_ip=self.request.getsockname()[0],
+                        server_port=self.request.getsockname()[0],
+                    ))
+            self.request.sendall(resp)
+
 
 class TestHostDBPartiallyFailedDNS(helpers.EnvironmentCase):
     '''
@@ -95,30 +126,71 @@ class TestHostDBHostsFile(helpers.EnvironmentCase, tsqa.test_cases.HTTPBinCase):
     '''
     @classmethod
     def setUpEnv(cls, env):
-        hosts_file_path = os.path.join(env.layout.prefix, 'hosts')
-        with open(hosts_file_path, 'w') as fh:
-            fh.write('127.0.0.1 local')
+        cls.hosts_file_path = os.path.join(env.layout.prefix, 'hosts')
+        with open(cls.hosts_file_path, 'w') as fh:
+            fh.write('127.0.0.1 local\n')
+            fh.write('127.0.0.2 local2\n')
 
         cls.configs['records.config']['CONFIG'].update({
             'proxy.config.http.response_server_enabled': 2,  # only add server headers when there weren't any
             'proxy.config.hostdb.lookup_timeout': 2,
             'proxy.config.url_remap.remap_required': 1,
             'proxy.config.http.connect_attempts_max_retries': 1,
-            'proxy.config.hostdb.host_file.interval': 30,
-            'proxy.config.hostdb.host_file.path': hosts_file_path,
+            'proxy.config.hostdb.host_file.interval': 1,
+            'proxy.config.hostdb.host_file.path': cls.hosts_file_path,
             'proxy.config.diags.debug.enabled': 1,
             'proxy.config.diags.debug.tags': 'hostdb',
         })
-
-        cls.configs['remap.config'].add_line('map http://local/ http://local:{0}/'.format(cls.http_endpoint.address[1]))
+        # create a socket server
+        cls.socket_server = tsqa.endpoint.SocketServerDaemon(EchoServerIpHandler)
+        cls.socket_server.start()
+        cls.socket_server.ready.wait()
+        cls.configs['remap.config'].add_line('map http://local/ http://local:{0}/'.format(cls.socket_server.port))
+        cls.configs['remap.config'].add_line('map http://local2/ http://local2:{0}/'.format(cls.socket_server.port))
+        cls.configs['remap.config'].add_line('map http://local3/ http://local3:{0}/'.format(cls.socket_server.port))
 
 
     def test_basic(self):
+        '''
+        Test basic fnctionality of hosts files
+        '''
         # TODO add stat, then wait for the stat to increment
-        time.sleep(5)  # wait for the continuation to load the hosts file
+        time.sleep(2)  # wait for the continuation to load the hosts file
         ret = requests.get(
             'http://local/get',
             proxies=self.proxies,
         )
         self.assertEqual(ret.status_code, 200)
-        self.assertEqual('127.0.0.1', ret.json()['origin'])
+        self.assertEqual('127.0.0.1', ret.headers['X-Server-Ip'])
+
+        ret = requests.get(
+            'http://local2/get',
+            proxies=self.proxies,
+        )
+        self.assertEqual(ret.status_code, 200)
+        self.assertEqual('127.0.0.2', ret.headers['X-Server-Ip'])
+
+    def test_reload(self):
+        '''
+        Test that changes to hosts file get loaded within host_file.interval
+        '''
+        # TODO add stat, then wait for the stat to increment
+        time.sleep(2)  # wait for the continuation to load the hosts file
+        ret = requests.get(
+            'http://local3/get',
+            proxies=self.proxies,
+        )
+        self.assertEqual(ret.status_code, 502)
+
+        with open(self.hosts_file_path, 'a') as fh:
+            fh.write('127.0.0.3 local3\n')
+
+        # TODO add stat, then wait for the stat to increment, with a timeout
+        time.sleep(2)
+
+        ret = requests.get(
+            'http://local3/get',
+            proxies=self.proxies,
+        )
+        self.assertEqual(ret.status_code, 200)
+        self.assertEqual('127.0.0.3', ret.headers['X-Server-Ip'])


[2/3] trafficserver git commit: Add basic tests for the Hosts file implementation in ATS

Posted by ja...@apache.org.
Add basic tests for the Hosts file implementation in ATS


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/c857fe71
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/c857fe71
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/c857fe71

Branch: refs/heads/master
Commit: c857fe719276e3ee9e186e062cba66a7eb35a376
Parents: 0c030e2
Author: Thomas Jackson <ja...@apache.org>
Authored: Mon Jul 6 19:50:23 2015 -0700
Committer: Thomas Jackson <ja...@apache.org>
Committed: Tue Jul 7 19:19:31 2015 -0700

----------------------------------------------------------------------
 ci/tsqa/tests/test_hostdb.py | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c857fe71/ci/tsqa/tests/test_hostdb.py
----------------------------------------------------------------------
diff --git a/ci/tsqa/tests/test_hostdb.py b/ci/tsqa/tests/test_hostdb.py
index bd5c307..e17d79a 100644
--- a/ci/tsqa/tests/test_hostdb.py
+++ b/ci/tsqa/tests/test_hostdb.py
@@ -21,6 +21,7 @@ Test hostdb
 import os
 import requests
 import time
+import tsqa.test_cases
 
 import helpers
 
@@ -86,3 +87,38 @@ class TestHostDBFailedDNS(helpers.EnvironmentCase):
         self.assertGreater(time.time() - start, self.configs['records.config']['CONFIG']['proxy.config.hostdb.lookup_timeout'])
         self.assertEqual(ret.status_code, 502)
         self.assertIn('ATS', ret.headers['server'])
+
+
+class TestHostDBHostsFile(helpers.EnvironmentCase, tsqa.test_cases.HTTPBinCase):
+    '''
+    Tests for hostdb's host-file implementation
+    '''
+    @classmethod
+    def setUpEnv(cls, env):
+        hosts_file_path = os.path.join(env.layout.prefix, 'hosts')
+        with open(hosts_file_path, 'w') as fh:
+            fh.write('127.0.0.1 local')
+
+        cls.configs['records.config']['CONFIG'].update({
+            'proxy.config.http.response_server_enabled': 2,  # only add server headers when there weren't any
+            'proxy.config.hostdb.lookup_timeout': 2,
+            'proxy.config.url_remap.remap_required': 1,
+            'proxy.config.http.connect_attempts_max_retries': 1,
+            'proxy.config.hostdb.host_file.interval': 30,
+            'proxy.config.hostdb.host_file.path': hosts_file_path,
+            'proxy.config.diags.debug.enabled': 1,
+            'proxy.config.diags.debug.tags': 'hostdb',
+        })
+
+        cls.configs['remap.config'].add_line('map http://local/ http://local:{0}/'.format(cls.http_endpoint.address[1]))
+
+
+    def test_basic(self):
+        # TODO add stat, then wait for the stat to increment
+        time.sleep(5)  # wait for the continuation to load the hosts file
+        ret = requests.get(
+            'http://local/get',
+            proxies=self.proxies,
+        )
+        self.assertEqual(ret.status_code, 200)
+        self.assertEqual('127.0.0.1', ret.json()['origin'])


[3/3] trafficserver git commit: Allow for loopback addresses in a hosts file

Posted by ja...@apache.org.
Allow for loopback addresses in a hosts file


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/0c030e25
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/0c030e25
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/0c030e25

Branch: refs/heads/master
Commit: 0c030e25290dc10a8193b4e605ce884caed97ae6
Parents: 078a9a8
Author: Thomas Jackson <ja...@apache.org>
Authored: Mon Jul 6 19:21:53 2015 -0700
Committer: Thomas Jackson <ja...@apache.org>
Committed: Tue Jul 7 19:19:31 2015 -0700

----------------------------------------------------------------------
 iocore/hostdb/HostDB.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0c030e25/iocore/hostdb/HostDB.cc
----------------------------------------------------------------------
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index 72d86f5..cd029db 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -2615,7 +2615,7 @@ ParseHostLine(char *l)
   // Elements should be the address then a list of host names.
   // Don't use RecHttpLoadIp because the address *must* be literal.
   IpAddr ip;
-  if (n_elts > 1 && 0 == ip.load(elts[0]) && !ip.isLoopback()) {
+  if (n_elts > 1 && 0 == ip.load(elts[0])) {
     for (int i = 1; i < n_elts; ++i) {
       ts::ConstBuffer name(elts[i], strlen(elts[i]));
       // If we don't have an entry already (host files only support single IPs for a given name)