|
| 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 | + |
| 19 | +Test.Summary = ''' |
| 20 | +Test next hop selection using strategies.yaml with consistent hashing. |
| 21 | +''' |
| 22 | + |
| 23 | +dns = Test.MakeDNServer("dns") |
| 24 | + |
| 25 | +# Define and populate next hop MicroServer instances. |
| 26 | +# |
| 27 | +num_nh = 8 |
| 28 | +server_nh = [] |
| 29 | +response_header = { |
| 30 | + "headers": |
| 31 | + "HTTP/1.1 200 OK\r\n" |
| 32 | + "Connection: close\r\n" |
| 33 | + "Cache-control: max-age=85000\r\n" |
| 34 | + "\r\n", |
| 35 | + "timestamp": "1469733493.993", |
| 36 | + "body": "xxx\n" |
| 37 | +} |
| 38 | +for i in range(num_nh): |
| 39 | + server = Test.MakeOriginServer(f"server{i}") |
| 40 | + for j in range(32): |
| 41 | + request_header = { |
| 42 | + "headers": |
| 43 | + f"GET /obj{j} HTTP/1.1\r\n" |
| 44 | + "Host: does.not.matter\r\n" # But cannot be omitted. |
| 45 | + "\r\n", |
| 46 | + "timestamp": "1469733493.993", |
| 47 | + "body": "" |
| 48 | + } |
| 49 | + server.addResponse("sessionlog.json", request_header, response_header) |
| 50 | + server_nh.append(server) |
| 51 | + |
| 52 | +#ts = Test.MakeATSProcess("ts", command="traffic_server 2> trace.log", block_for_debug=True) |
| 53 | +ts = Test.MakeATSProcess("ts", command="traffic_server 2> trace.log") |
| 54 | + |
| 55 | +ts.Disk.records_config.update({ |
| 56 | + 'proxy.config.diags.debug.enabled': 1, |
| 57 | + 'proxy.config.diags.debug.tags': 'http|dns|parent|next_hop|host_statuses|hostdb', |
| 58 | + 'proxy.config.dns.nameservers': f"127.0.0.1:{dns.Variables.Port}", # Only nameservers if resolv_conf NULL. |
| 59 | + 'proxy.config.dns.resolv_conf': "NULL", # This defaults to /etc/resvolv.conf (OS namesevers) if not NULL. |
| 60 | + 'proxy.config.http.cache.http': 0, |
| 61 | + 'proxy.config.http.uncacheable_requests_bypass_parent': 0, |
| 62 | + 'proxy.config.http.no_dns_just_forward_to_parent': 1, |
| 63 | + 'proxy.config.http.parent_proxy.mark_down_hostdb': 0, |
| 64 | + 'proxy.config.http.parent_proxy.self_detect': 0, |
| 65 | +}) |
| 66 | + |
| 67 | +ts.Disk.File(ts.Variables.CONFIGDIR + "/strategies.yaml", id="strategies", typename="ats:config") |
| 68 | +s = ts.Disk.strategies |
| 69 | +s.AddLine("groups:") |
| 70 | +s.AddLine(" - &g1") |
| 71 | +for i in range(num_nh): |
| 72 | + dns.addRecords(records={f"next_hop{i}": ["127.0.0.1"]}) |
| 73 | + s.AddLine(f" - host: next_hop{i}") |
| 74 | + s.AddLine(f" protocol:") |
| 75 | + s.AddLine(f" - scheme: http") |
| 76 | + s.AddLine(f" port: {server_nh[i].Variables.Port}") |
| 77 | + #s.AddLine(f" health_check_url: http://next_hop{i}:{server_nh[i].Variables.Port}") |
| 78 | + s.AddLine(f" weight: 1.0") |
| 79 | +s.AddLine("") |
| 80 | +s.AddLine("strategies:") |
| 81 | +s.AddLine(" - strategy: the-strategy") |
| 82 | +s.AddLine(" policy: consistent_hash") |
| 83 | +s.AddLine(" hash_key: path") |
| 84 | +s.AddLine(" go_direct: false") |
| 85 | +s.AddLine(" parent_is_proxy: true") |
| 86 | +s.AddLine(" ignore_self_detect: true") |
| 87 | +s.AddLine(" groups:") |
| 88 | +s.AddLine(" - *g1") |
| 89 | +s.AddLine(" scheme: http") |
| 90 | +#s.AddLine(" fallover:") |
| 91 | +#s.AddLine(" max_simple_retries: 2") |
| 92 | +#s.AddLine(" ring_mode: exhaust_ring") |
| 93 | +#s.AddLine(" response_codes:") |
| 94 | +#s.AddLine(" - 404") |
| 95 | +#s.AddLine(" health_check:") |
| 96 | +#s.AddLine(" - passive") |
| 97 | + |
| 98 | +ts.Disk.remap_config.AddLine( |
| 99 | + "map http://dummy.com http://not_used @strategy=the-strategy" |
| 100 | +) |
| 101 | + |
| 102 | +tr = Test.AddTestRun() |
| 103 | +tr.Processes.Default.StartBefore(dns) |
| 104 | +for i in range(num_nh): |
| 105 | + tr.Processes.Default.StartBefore(server_nh[i]) |
| 106 | +tr.Processes.Default.StartBefore(Test.Processes.ts) |
| 107 | +tr.Processes.Default.Command = 'echo start TS, DNS server and next hop HTTP servers' |
| 108 | +tr.Processes.Default.ReturnCode = 0 |
| 109 | + |
| 110 | +for i in range(32): |
| 111 | + tr = Test.AddTestRun() |
| 112 | + tr.Processes.Default.Command = ( |
| 113 | + f'curl --verbose --proxy 127.0.0.1:{ts.Variables.port} http://dummy.com/obj{i}' |
| 114 | + ) |
| 115 | + tr.Processes.Default.ReturnCode = 0 |
| 116 | + |
| 117 | +tr = Test.AddTestRun() |
| 118 | +tr.Processes.Default.Command = ( |
| 119 | + "grep -F PARENT_SPECIFIED trace.log | sed 's/^.*result->result://' | sed 's/[.].*$$//'" |
| 120 | +) |
| 121 | +tr.Processes.Default.Streams.stdout = "trace.gold" |
| 122 | +tr.Processes.Default.ReturnCode = 0 |
0 commit comments