1''' 2''' 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, software 14# distributed under the License is distributed on an "AS IS" BASIS, 15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16# See the License for the specific language governing permissions and 17# limitations under the License. 18 19import os 20 21Test.Summary = ''' 22Test custom log file format 23''' 24 25# this test depends on Linux specific behavior regarding loopback addresses 26Test.SkipUnless( 27 Condition.IsPlatform("linux") 28) 29 30# Define default ATS 31ts = Test.MakeATSProcess("ts") 32 33# setup some config file for this server 34ts.Disk.remap_config.AddLine( 35 'map / http://www.linkedin.com/ @action=deny' 36) 37 38ts.Disk.logging_yaml.AddLines( 39 ''' 40logging: 41 formats: 42 - name: custom 43 format: "%<hii> %<hiih>" 44 logs: 45 - filename: test_log_field 46 format: custom 47'''.split("\n") 48) 49 50# ######################################################################### 51# at the end of the different test run a custom log file should exist 52# Because of this we expect the testruns to pass the real test is if the 53# customlog file exists and passes the format check 54Test.Disk.File(os.path.join(ts.Variables.LOGDIR, 'test_log_field.log'), 55 exists=True, content='gold/custom.gold') 56 57# first test is a miss for default 58tr = Test.AddTestRun() 59tr.Processes.Default.Command = 'curl "http://127.0.0.1:{0}" --verbose'.format( 60 ts.Variables.port) 61tr.Processes.Default.ReturnCode = 0 62tr.Processes.Default.StartBefore(Test.Processes.ts) 63 64tr = Test.AddTestRun() 65tr.Processes.Default.Command = 'curl "http://127.1.1.1:{0}" --verbose'.format( 66 ts.Variables.port) 67tr.Processes.Default.ReturnCode = 0 68 69tr = Test.AddTestRun() 70tr.Processes.Default.Command = 'curl "http://127.2.2.2:{0}" --verbose'.format( 71 ts.Variables.port) 72tr.Processes.Default.ReturnCode = 0 73 74tr = Test.AddTestRun() 75tr.Processes.Default.Command = 'curl "http://127.3.3.3:{0}" --verbose'.format( 76 ts.Variables.port) 77tr.Processes.Default.ReturnCode = 0 78 79tr = Test.AddTestRun() 80tr.Processes.Default.Command = 'curl "http://127.3.0.1:{0}" --verbose'.format( 81 ts.Variables.port) 82tr.Processes.Default.ReturnCode = 0 83 84tr = Test.AddTestRun() 85tr.Processes.Default.Command = 'curl "http://127.43.2.1:{0}" --verbose'.format( 86 ts.Variables.port) 87tr.Processes.Default.ReturnCode = 0 88 89tr = Test.AddTestRun() 90tr.Processes.Default.Command = 'curl "http://127.213.213.132:{0}" --verbose'.format( 91 ts.Variables.port) 92tr.Processes.Default.ReturnCode = 0 93 94tr = Test.AddTestRun() 95tr.Processes.Default.Command = 'curl "http://127.123.32.243:{0}" --verbose'.format( 96 ts.Variables.port) 97tr.Processes.Default.ReturnCode = 0 98 99# Wait for log file to appear, then wait one extra second to make sure TS is done writing it. 100test_run = Test.AddTestRun() 101test_run.Processes.Default.Command = ( 102 os.path.join(Test.Variables.AtsTestToolsDir, 'condwait') + ' 60 1 -f ' + 103 os.path.join(ts.Variables.LOGDIR, 'test_log_field.log') 104) 105test_run.Processes.Default.ReturnCode = 0 106