Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 1 | #!/usr/bin/python2 |
| 2 | |
| 3 | # |
| 4 | # Copyright 2018 the original author or authors. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | """ |
| 20 | vOLT-HA Automated Testing module |
| 21 | """ |
| 22 | import os |
| 23 | import time |
| 24 | import argparse |
| 25 | import volthaMngr |
Gilles Depatie | 84cb1e7 | 2018-10-26 12:41:33 -0400 | [diff] [blame] | 26 | import preprovisioning |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 27 | import discovery |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 28 | import authentication |
Gilles Depatie | 2e68369 | 2019-02-22 16:06:52 -0500 | [diff] [blame] | 29 | import dhcp |
Gilles Depatie | ed99efe | 2019-03-12 16:12:26 -0400 | [diff] [blame] | 30 | import unicast |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 31 | import logging |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 32 | |
| 33 | DEFAULT_LOG_DIR = '/tmp/voltha_test_results' |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 34 | DEFAULT_SIMTYPE = 'ponsim' |
Gilles Depatie | 1be639b | 2018-12-06 10:51:08 -0500 | [diff] [blame] | 35 | logging.basicConfig(level=logging.INFO) |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 36 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 37 | |
| 38 | def dir_init(log_dir=DEFAULT_LOG_DIR, voltha_dir=os.environ['VOLTHA_BASE']): |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 39 | """ |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 40 | |
| 41 | :param log_dir: default log dir |
| 42 | :param voltha_dir: voltha base dir |
| 43 | :return: root_dir, voltha_dir, log_dir |
| 44 | """ |
| 45 | logging.info(__file__) |
| 46 | |
| 47 | """ |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 48 | Init automated testing environment and return three directories: root dir, |
| 49 | voltha sources dir and log dir |
| 50 | """ |
| 51 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 52 | root_dir = os.path.abspath(os.path.dirname(__file__)) |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 53 | |
| 54 | currentTime = time.strftime("%Y-%m-%d-%H-%M-%S") |
| 55 | |
| 56 | # In future in order to keep the history of jobs, the run time should be |
| 57 | # added to the log directory name |
| 58 | # logDir += '_' + currentTime |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 59 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 60 | os.system('mkdir -p ' + log_dir + ' > /dev/null 2>&1') |
| 61 | os.system('rm -rf %s/*' % log_dir) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 62 | logging.info('Starting Voltha Test Case Suite at: %s\nRoot Directory: %s\n' |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 63 | 'VOLTHA Directory: %s\nLog Directory: %s' % |
| 64 | (currentTime, root_dir, voltha_dir, log_dir)) |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 65 | |
Gilles Depatie | 0bf3135 | 2019-02-04 13:48:41 -0500 | [diff] [blame] | 66 | return root_dir, voltha_dir, log_dir |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 67 | |
| 68 | |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 69 | def simtype_init(simtype=DEFAULT_SIMTYPE): |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 70 | """ |
| 71 | |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 72 | :param simtype: ponsim or bbsim |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 73 | :return: olt_type, onu_type, olt_host_ip, onu_count |
| 74 | """ |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 75 | if simtype == 'ponsim': |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 76 | olt_type = 'ponsim_olt' |
| 77 | onu_type = 'ponsim_onu' |
| 78 | olt_host_ip = 'olt.voltha.svc' |
| 79 | onu_count = 1 |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 80 | elif simtype == 'bbsim': |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 81 | olt_type = 'openolt' |
| 82 | onu_type = 'brcm_openomci_onu' |
| 83 | olt_host_ip = 'bbsim.voltha.svc' |
| 84 | onu_count = 16 |
| 85 | else: |
| 86 | olt_type = None |
| 87 | onu_type = None |
| 88 | olt_host_ip = None |
| 89 | onu_count = 0 |
| 90 | |
| 91 | return olt_type, onu_type, olt_host_ip, onu_count |
| 92 | |
| 93 | |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 94 | # |
| 95 | # MAIN |
| 96 | # |
| 97 | if __name__ == "__main__": |
| 98 | """ |
| 99 | Main entry point of the automated testing when executed directly |
| 100 | """ |
| 101 | |
| 102 | parser = argparse.ArgumentParser(description='VOLTHA Automated Testing') |
| 103 | parser.add_argument('-l', dest='logDir', default=DEFAULT_LOG_DIR, |
| 104 | help='log directory (default: %s).' % DEFAULT_LOG_DIR) |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 105 | parser.add_argument('-a', dest='simtype', choices=['ponsim', 'bbsim'], default=DEFAULT_SIMTYPE, |
| 106 | help='simtype (default: %s).' % DEFAULT_SIMTYPE) |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 107 | args = parser.parse_args() |
| 108 | |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 109 | ROOT_DIR, VOLTHA_DIR, LOG_DIR = dir_init(args.logDir) |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 110 | OLT_TYPE, ONU_TYPE, OLT_HOST_IP, ONU_COUNT = simtype_init(args.simtype) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 111 | |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 112 | volthaMngr.voltha_initialize(ROOT_DIR, VOLTHA_DIR, LOG_DIR, args.simtype) |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 113 | |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 114 | preprovisioning.run_test(OLT_HOST_IP, 50060, OLT_TYPE, ONU_TYPE, ONU_COUNT, LOG_DIR) |
Gilles Depatie | c9a26cf | 2019-05-10 15:43:12 -0400 | [diff] [blame] | 115 | |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 116 | discovery.run_test(OLT_HOST_IP, OLT_TYPE, ONU_TYPE, ONU_COUNT, LOG_DIR) |
Gilles Depatie | c68b3ad | 2018-08-21 16:29:03 -0400 | [diff] [blame] | 117 | |
Gilles Depatie | 493ea24 | 2019-05-21 14:38:08 -0400 | [diff] [blame] | 118 | authentication.run_test(ONU_COUNT, ROOT_DIR, VOLTHA_DIR, LOG_DIR, args.simtype) |
| 119 | |
| 120 | if args.simtype == 'ponsim': |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 121 | dhcp.run_test(ROOT_DIR, VOLTHA_DIR, LOG_DIR) |
Gilles Depatie | a85fe81 | 2019-01-23 15:55:53 -0500 | [diff] [blame] | 122 | |
Gilles Depatie | ea42371 | 2019-04-12 16:39:12 -0400 | [diff] [blame] | 123 | unicast.run_test(ONU_TYPE, ONU_COUNT, ROOT_DIR, VOLTHA_DIR, LOG_DIR) |