review sims/tpce process management in 2.2.1 tests
[transportpce.git] / tests / transportpce_tests / 1.2.1 / test_utils.py
1 #!/usr/bin/env python
2 ##############################################################################
3 # Copyright (c) 2020 Orange, Inc. and others.  All rights reserved.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 import os
11 import subprocess
12
13 sims = {
14     'xpdra': {'port': '17830', 'configfile': 'oper-XPDRA.xml'},
15     'roadma': {'port': '17831', 'configfile': 'oper-ROADMA.xml'},
16     'roadmb': {'port': '17832', 'configfile': 'oper-ROADMB.xml'},
17     'roadmc': {'port': '17833', 'configfile': 'oper-ROADMC.xml'},
18     'xpdrc': {'port': '17834', 'configfile': 'oper-XPDRC.xml'},
19     'roadma-full': {'port': '17821', 'configfile': 'oper-ROADMA-full.xml'},
20     'roadmc-full': {'port': '17823', 'configfile': 'oper-ROADMC-full.xml'}
21 }
22
23 honeynode_executable = os.path.join(
24     os.path.dirname(os.path.realpath(__file__)),
25     "..", "..", "honeynode", "1.2.1", "honeynode-simulator", "honeycomb-tpce")
26 samples_directory = os.path.join(
27     os.path.dirname(os.path.realpath(__file__)),
28     "..", "..", "sample_configs", "openroadm", "1.2.1")
29
30
31 def start_sim(sim):
32     print("starting simulator for " + sim + "...")
33     if os.path.isfile(honeynode_executable):
34         with open(sim+'.log', 'w') as outfile:
35             return subprocess.Popen(
36                 [honeynode_executable, sims[sim]['port'], os.path.join(samples_directory, sims[sim]['configfile'])],
37                 stdout=outfile, stderr=outfile)
38
39
40 def start_tpce():
41     print("starting opendaylight...")
42     if "USE_LIGHTY" in os.environ and os.environ['USE_LIGHTY'] == 'True':
43         print("starting LIGHTY.IO TransportPCE build...")
44         executable = os.path.join(
45             os.path.dirname(os.path.realpath(__file__)),
46             "..", "..", "..", "lighty", "target", "tpce",
47             "clean-start-controller.sh")
48         with open('odl.log', 'w') as outfile:
49             return subprocess.Popen(
50                 ["sh", executable], stdout=outfile, stderr=outfile, stdin=None)
51     else:
52         print("starting KARAF TransportPCE build...")
53         executable = os.path.join(
54             os.path.dirname(os.path.realpath(__file__)),
55             "..", "..", "..", "karaf", "target", "assembly", "bin", "karaf")
56         with open('odl.log', 'w') as outfile:
57             return subprocess.Popen(
58                 ["sh", executable, "server"], stdout=outfile, stderr=outfile, stdin=None)