blob: 6e21842fd447c9c21bf4e75a21d6cb9183270135 [file] [log] [blame]
Gilles Depatiec68b3ad2018-08-21 16:29:03 -04001#!/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"""
20vOLT-HA Automated Testing module
21"""
22import os
23import time
24import argparse
25import volthaMngr
Gilles Depatie84cb1e72018-10-26 12:41:33 -040026import preprovisioning
Gilles Depatie1be639b2018-12-06 10:51:08 -050027import discovery
Gilles Depatiea85fe812019-01-23 15:55:53 -050028import authentication
Gilles Depatie2e683692019-02-22 16:06:52 -050029import dhcp
Gilles Depatieed99efe2019-03-12 16:12:26 -040030import unicast
Gilles Depatie1be639b2018-12-06 10:51:08 -050031import logging
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040032
33DEFAULT_LOG_DIR = '/tmp/voltha_test_results'
Gilles Depatieea423712019-04-12 16:39:12 -040034DEFAULT_ADAPTER = 'ponsim'
Gilles Depatie1be639b2018-12-06 10:51:08 -050035logging.basicConfig(level=logging.INFO)
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040036
Gilles Depatie0bf31352019-02-04 13:48:41 -050037
38def dir_init(log_dir=DEFAULT_LOG_DIR, voltha_dir=os.environ['VOLTHA_BASE']):
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040039 """
Gilles Depatieea423712019-04-12 16:39:12 -040040
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 Depatiec68b3ad2018-08-21 16:29:03 -040048 Init automated testing environment and return three directories: root dir,
49 voltha sources dir and log dir
50 """
51
Gilles Depatie0bf31352019-02-04 13:48:41 -050052 root_dir = os.path.abspath(os.path.dirname(__file__))
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040053
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 Depatiea85fe812019-01-23 15:55:53 -050059
Gilles Depatie0bf31352019-02-04 13:48:41 -050060 os.system('mkdir -p ' + log_dir + ' > /dev/null 2>&1')
61 os.system('rm -rf %s/*' % log_dir)
Gilles Depatiea85fe812019-01-23 15:55:53 -050062 logging.info('Starting Voltha Test Case Suite at: %s\nRoot Directory: %s\n'
Gilles Depatie0bf31352019-02-04 13:48:41 -050063 'VOLTHA Directory: %s\nLog Directory: %s' %
64 (currentTime, root_dir, voltha_dir, log_dir))
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040065
Gilles Depatie0bf31352019-02-04 13:48:41 -050066 return root_dir, voltha_dir, log_dir
Gilles Depatiec68b3ad2018-08-21 16:29:03 -040067
68
Gilles Depatieea423712019-04-12 16:39:12 -040069def adapter_init(adapter=DEFAULT_ADAPTER):
70 """
71
72 :param adapter: ponsim or bbsim
73 :return: olt_type, onu_type, olt_host_ip, onu_count
74 """
75 if adapter == 'ponsim':
76 olt_type = 'ponsim_olt'
77 onu_type = 'ponsim_onu'
78 olt_host_ip = 'olt.voltha.svc'
79 onu_count = 1
80 elif adapter == 'bbsim':
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 Depatiec68b3ad2018-08-21 16:29:03 -040094#
95# MAIN
96#
97if __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 Depatieea423712019-04-12 16:39:12 -0400105 parser.add_argument('-a', dest='adapter', choices=['ponsim', 'bbsim'], default=DEFAULT_ADAPTER,
106 help='adapter (default: %s).' % DEFAULT_ADAPTER)
Gilles Depatiec68b3ad2018-08-21 16:29:03 -0400107 args = parser.parse_args()
108
Gilles Depatiea85fe812019-01-23 15:55:53 -0500109 ROOT_DIR, VOLTHA_DIR, LOG_DIR = dir_init(args.logDir)
Gilles Depatieea423712019-04-12 16:39:12 -0400110 OLT_TYPE, ONU_TYPE, OLT_HOST_IP, ONU_COUNT = adapter_init(args.adapter)
Gilles Depatiea85fe812019-01-23 15:55:53 -0500111
Gilles Depatieea423712019-04-12 16:39:12 -0400112 volthaMngr.voltha_initialize(ROOT_DIR, VOLTHA_DIR, LOG_DIR, args.adapter)
Gilles Depatiec68b3ad2018-08-21 16:29:03 -0400113
Gilles Depatieea423712019-04-12 16:39:12 -0400114 preprovisioning.run_test(OLT_HOST_IP, 50060, OLT_TYPE, ONU_TYPE, ONU_COUNT, LOG_DIR)
115 time.sleep(60)
116 discovery.run_test(OLT_HOST_IP, OLT_TYPE, ONU_TYPE, ONU_COUNT, LOG_DIR)
117 if args.adapter == 'ponsim':
118 authentication.run_test(ROOT_DIR, VOLTHA_DIR, LOG_DIR)
Gilles Depatiec68b3ad2018-08-21 16:29:03 -0400119
Gilles Depatieea423712019-04-12 16:39:12 -0400120 dhcp.run_test(ROOT_DIR, VOLTHA_DIR, LOG_DIR)
Gilles Depatiea85fe812019-01-23 15:55:53 -0500121
Gilles Depatieea423712019-04-12 16:39:12 -0400122 unicast.run_test(ONU_TYPE, ONU_COUNT, ROOT_DIR, VOLTHA_DIR, LOG_DIR)