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 for using of runroot from traffic_layout.
23'''
24Test.ContinueOnFail = True
25Test.SkipUnless(Test.Variables.BINDIR.startswith(Test.Variables.PREFIX),
26                "need to guarantee bin path starts with prefix for runroot")
27
28# create two runroot for testing
29path = os.path.join(Test.RunDirectory, "runroot")
30tr = Test.AddTestRun()
31tr.Processes.Default.Command = "$ATS_BIN/traffic_layout init --path " + path
32f = tr.Disk.File(os.path.join(path, "runroot.yaml"))
33f.Exists = True
34
35path2 = os.path.join(Test.RunDirectory, "runroot2")
36tr = Test.AddTestRun()
37tr.Processes.Default.Command = "$ATS_BIN/traffic_layout init --path " + path2
38f = tr.Disk.File(os.path.join(path2, "runroot.yaml"))
39f.Exists = True
40
41# 1. --run-root use path cmd
42tr = Test.AddTestRun("use runroot via commandline")
43tr.Processes.Default.Command = "$ATS_BIN/traffic_layout info --run-root=" + path
44tr.Processes.Default.ReturnCode = 0
45tr.Processes.Default.Streams.All = Testers.ContainsExpression("PREFIX: " + path, "commandline runroot path")
46
47# 2. use cwd as runroot
48tr = Test.AddTestRun("use runroot via cwd")
49tr.Processes.Default.Command = "cd " + path + ";" + "$ATS_BIN/traffic_layout info"
50tr.Processes.Default.ReturnCode = 0
51tr.Processes.Default.Streams.All = Testers.ContainsExpression("PREFIX: " + path, "cwd runroot path")
52
53# 4. use path directly bin
54bin_path = Test.Variables.BINDIR[Test.Variables.BINDIR.find(Test.Variables.PREFIX) + len(Test.Variables.PREFIX) + 1:]
55tr = Test.AddTestRun("use runroot via bin executable")
56tr.Processes.Default.Command = os.path.join(path, os.path.join(bin_path, "traffic_layout") + " info")
57tr.Processes.Default.ReturnCode = 0
58tr.Processes.Default.Streams.All = Testers.ContainsExpression("PREFIX: " + path, "bin path")
59
60# 3. TS_RUNROOT ENV variable
61tr = Test.AddTestRun("use runroot via TS_RUNROOT")
62tr.Processes.Default.Env["TS_RUNROOT"] = path2
63tr.Processes.Default.Command = "$ATS_BIN/traffic_layout info"
64tr.Processes.Default.ReturnCode = 0
65tr.Processes.Default.Streams.All = Testers.ContainsExpression("PREFIX: " + path2, "$TS_RUNROOT Env path")
66