+ # Common parameters
+ parent_parser = ArgumentParser(add_help=False)
+ parent_parser.add_argument('--failfast', help='Stop when a test fails rather than execute all tests',
+ dest='failfast', action="store_true", default=False)
+ parent_parser.add_argument('--failed', help='Set logs to show only failed tests. --debug disables this option',
+ dest='failed', action="store_true", default=False)
+ default_logger_file = os.path.dirname(__file__)+'/'+os.path.splitext(os.path.basename(__file__))[0]+'.log'
+ parent_parser.add_argument('--list-tests', help='List all available tests', dest='list_tests', action="store_true",
+ default=False)
+ parent_parser.add_argument('--logger_file', dest='logger_file', default=default_logger_file,
+ help='Set the logger file. By default '+default_logger_file)
+ parent_parser.add_argument("-t", '--tenant', dest='tenant_name', default="osm",
+ help="Set the openmano tenant to use for the test. By default 'osm'")
+ parent_parser.add_argument('--debug', help='Set logs to debug level', dest='debug', action="store_true")
+ parent_parser.add_argument('--timeout', help='Specify the instantiation timeout in seconds. By default 300',
+ dest='timeout', type=int, default=300)
+ parent_parser.add_argument('--test', '--tests', help='Specify the tests to run', dest='tests', action="append")
+
+ subparsers = parser.add_subparsers(help='test sets')
+
+ # Deployment test set
+ # -------------------
+ deploy_parser = subparsers.add_parser('deploy', parents=[parent_parser],
+ help="test deployment using descriptors at RO_test folder ")
+ deploy_parser.set_defaults(func=test_deploy)
+
+ # Mandatory arguments
+ mandatory_arguments = deploy_parser.add_argument_group('mandatory arguments')
+ mandatory_arguments.add_argument('-d', '--datacenter', required=True, help='Set the datacenter to test')
+ mandatory_arguments.add_argument("-i", '--image-name', required=True, dest="image_name",
+ help='Image name available at datacenter used for the tests')
+ mandatory_arguments.add_argument("-n", '--mgmt-net-name', required=True, dest='mgmt_net',
+ help='Set the vim management network to use for tests')
+
+ # Optional arguments
+ deploy_parser.add_argument('-m', '--manual-check', dest='manual', action="store_true", default=False,
+ help='Pause execution once deployed to allow manual checking of the '
+ 'deployed instance scenario')
+ deploy_parser.add_argument('-u', '--url', dest='endpoint_url', default='http://localhost:9090/openmano',
+ help="Set the openmano server url. By default 'http://localhost:9090/openmano'")
+
+ # Vimconn test set
+ # -------------------
+ vimconn_parser = subparsers.add_parser('vimconn', parents=[parent_parser], help="test vimconnector plugin")
+ vimconn_parser.set_defaults(func=test_vimconnector)
+ # Mandatory arguments
+ mandatory_arguments = vimconn_parser.add_argument_group('mandatory arguments')
+ mandatory_arguments.add_argument('--vimtype', choices=['vmware', 'aws', 'openstack', 'openvim'], required=True,
+ help='Set the vimconnector type to test')
+ # TODO add mandatory arguments for vimconn test
+ # mandatory_arguments.add_argument('-c', '--config', dest='config_param', required=True, help='<HELP>')
+
+ # Optional arguments
+ # TODO add optional arguments for vimconn tests
+ # vimconn_parser.add_argument("-i", '--image-name', dest='image_name', help='<HELP>'))
+
+ # Datacenter test set
+ # -------------------
+ vimconn_parser = subparsers.add_parser('vim', parents=[parent_parser], help="test vim")
+ vimconn_parser.set_defaults(func=test_vim)
+
+ # Mandatory arguments
+ mandatory_arguments = vimconn_parser.add_argument_group('mandatory arguments')
+ mandatory_arguments.add_argument('-d', '--datacenter', required=True, help='Set the datacenter to test')
+
+ # Optional arguments
+ vimconn_parser.add_argument('-u', '--url', dest='endpoint_url', default='http://localhost:9090/openmano',
+ help="Set the openmano server url. By default 'http://localhost:9090/openmano'")
+
+ argcomplete.autocomplete(parser)
+ args = parser.parse_args()
+ # print str(args)
+ test_config = {}
+
+ # default logger level is INFO. Options --debug and --failed override this, being --debug prioritary
+ logger_level = 'INFO'
+ if args.debug:
+ logger_level = 'DEBUG'
+ elif args.failed:
+ logger_level = 'WARNING'
+ logger_name = os.path.basename(__file__)
+ test_config["logger_name"] = logger_name
+ logger = logging.getLogger(logger_name)
+ logger.setLevel(logger_level)
+ failfast = args.failfast
+
+ # Configure a logging handler to store in a logging file
+ if args.logger_file:
+ fileHandler = logging.FileHandler(args.logger_file)
+ formatter_fileHandler = logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s')
+ fileHandler.setFormatter(formatter_fileHandler)
+ logger.addHandler(fileHandler)
+
+ # Configure a handler to print to stdout
+ consoleHandler = logging.StreamHandler(sys.stdout)
+ formatter_consoleHandler = logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s')
+ consoleHandler.setFormatter(formatter_consoleHandler)
+ logger.addHandler(consoleHandler)
+
+ logger.debug('Program started with the following arguments: ' + str(args))
+
+ # set test config parameters
+ test_config["timeout"] = args.timeout
+ test_config["test_number"] = 1
+
+ executed, failed = args.func(args)
+
+ # Log summary
+ logger.warning("Total number of tests: {}; Total number of failures/errors: {}".format(executed, failed))
+ sys.exit(1 if failed else 0)