You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by br...@apache.org on 2015/07/23 06:01:53 UTC
[2/5] trafficserver git commit: TS-3780: Logs_xml: add logging field
for incoming (interface) ip. TESTS
TS-3780: Logs_xml: add logging field for incoming (interface) ip. TESTS
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/e3997919
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/e3997919
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/e3997919
Branch: refs/heads/master
Commit: e39979197066c4e32cfee8dd6ca9301d4fbc02b3
Parents: 063cb57
Author: Zizhong Zhang <zi...@linkedin.com>
Authored: Mon Jul 20 22:45:16 2015 -0700
Committer: Zizhong Zhang <zi...@linkedin.com>
Committed: Mon Jul 20 22:45:16 2015 -0700
----------------------------------------------------------------------
ci/tsqa/tests/test_custom_log.py | 71 +++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e3997919/ci/tsqa/tests/test_custom_log.py
----------------------------------------------------------------------
diff --git a/ci/tsqa/tests/test_custom_log.py b/ci/tsqa/tests/test_custom_log.py
new file mode 100644
index 0000000..37573b7
--- /dev/null
+++ b/ci/tsqa/tests/test_custom_log.py
@@ -0,0 +1,71 @@
+'''
+Test custom log field
+'''
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import requests
+import time
+import logging
+import SocketServer
+import random
+import tsqa.test_cases
+import helpers
+import json
+
+log = logging.getLogger(__name__)
+
+class TestCustomLogField(helpers.EnvironmentCase):
+ '''
+ Tests for a customed log field called hii
+ '''
+ @classmethod
+ def setUpEnv(cls, env):
+
+ cls.configs['remap.config'].add_line(
+ 'map / http://www.linkedin.com/ @action=deny'
+ )
+ cls.log_file_name = 'test_log_field'
+ cls.configs['records.config']['CONFIG'].update({
+ 'proxy.config.log.custom_logs_enabled': 1,
+ })
+
+ cls.log_file_path = os.path.join(cls.environment.layout.prefix, 'var/log/test_log_field.log')
+ cls.log_etc_file = os.path.join(cls.environment.layout.prefix, 'etc/trafficserver/logs_xml.config')
+ cls.configs['logs_xml.config'].add_line('<LogFormat><Name = "testlogfield"/><Format = "%<hii> %<hiih>"/></LogFormat>')
+ cls.configs['logs_xml.config'].add_line('<LogObject><Format = "testlogfield"/><Filename = "test_log_field"/><Mode = "ascii"/></LogObject>')
+
+ def ip_to_hex(self, ipstr):
+ num_list = ipstr.split('.')
+ int_value = (int(num_list[0]) << 24) + (int(num_list[1]) << 16) + (int(num_list[2]) << 8) + (int(num_list[3]))
+ return hex(int_value).upper()[2:]
+
+ def test_log_field(self):
+ random.seed()
+ times = 10
+ for i in xrange(times):
+ request_ip = "127.%d.%d.%d" % (random.randint(1, 255), random.randint(1, 255), random.randint(1, 255))
+ url = 'http://%s:%s' % (request_ip, self.configs['records.config']['CONFIG']['proxy.config.http.server_ports'])
+ r = requests.get(url)
+ #get the last line of the log file
+ time.sleep(10)
+ with open(self.log_file_path) as f:
+ for line in f:
+ pass
+ expected_line = "%s %s\n" % (request_ip, self.ip_to_hex(request_ip))
+ self.assertEqual(line, expected_line)