aboutsummaryrefslogtreecommitdiffstats
path: root/test/vcpe
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2019-12-16 13:43:43 +0100
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-01-10 08:42:03 +0000
commit22e206080ef3c4503175948fdbeb1cd3cc8e240e (patch)
treeed3bd31939247966d8b46537f70d5c54aea21789 /test/vcpe
parent9afc5c707646215d2b541bafbd89c5d96fbc5f6e (diff)
Use argparse library to parse command line options
Change-Id: I75028c59109a9db902f7869ab1b987cc0c02e321 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com> Issue-ID: INT-1399
Diffstat (limited to 'test/vcpe')
-rwxr-xr-xtest/vcpe/vcpe.py83
1 files changed, 56 insertions, 27 deletions
diff --git a/test/vcpe/vcpe.py b/test/vcpe/vcpe.py
index c58b60adb..89e2a97c2 100755
--- a/test/vcpe/vcpe.py
+++ b/test/vcpe/vcpe.py
@@ -14,6 +14,8 @@ import csar_parser
import config_sdnc_so
import json
import urllib3
+import argparse
+from collections import OrderedDict
# disable InsecureRequestWarning warning in requests < 2.16.0
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
@@ -257,40 +259,67 @@ def test():
print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04')))
-if __name__ == '__main__':
- print('----------------------------------------------------------------------------------------------------')
- print(' vcpe.py: Brief info about this program')
-# print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)')
- print(' vcpe.py init: Add customer service data to SDNC and SO DBs.')
- print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
- print(' vcpe.py brg: Deploy brg only (for testing after infra succeeds).')
- print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs')
- print(' vcpe.py loop: Test closed loop control (packet loss set to 22)')
- print(' vcpe.py noloss: Set vGMUX packet loss to 0')
- print('----------------------------------------------------------------------------------------------------')
+def get_arg_parser(modes):
+ """
+ Parse cmd line options and return ArgumentParser object
+ :param modes: map of supported script modes
+ :return: ArgumentParser object
+ """
+ # Build usage synopsis string
+ usage = "\n"*2
+ for k,v in modes.items():
+ usage += 'vcpe.py {0:12} {1}\n'.format(k + ':',v)
- if len(sys.argv) != 2:
- sys.exit()
+ parser = argparse.ArgumentParser(usage=usage, formatter_class=
+ argparse.ArgumentDefaultsHelpFormatter)
+ parser.add_argument('mode',metavar='MODE',
+ help='Script mode: {0}'.format('|'.join(modes.keys())),
+ choices=modes.keys())
- if sys.argv[1] == 'sdc':
- print('Under development')
- elif sys.argv[1] == 'init':
- init()
- init_so_sdnc()
- elif sys.argv[1] == 'infra':
+ return parser
+
+if __name__ == '__main__':
+ # Supported modes matrix
+ # OrderedDict object has to be used to preserve desired modes
+ # order in synopsis text
+ modes = OrderedDict()
+# modes["sdc"] = "Onboard VNFs, design and distribute vCPE services (under development)"
+ modes["init"] = "Add customer service data to SDNC and SO DBs"
+ modes["infra"] = "Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG"
+ modes["brg"] = "Deploy brg only (for testing after infra succeeds)"
+ modes["customer"] = "Deploy customer service, including vGW and VxLANs"
+ modes["loop"] = "Test closed loop control (packet loss set to 22)"
+ modes["noloss"] = "Set vGMUX packet loss to 0"
+ modes["test"] = ""
+ modes["sniro"] = "Config SNIRO homing emulator"
+
+ parser = get_arg_parser(modes)
+
+ try:
+ assert len(sys.argv) != 1
+ except AssertionError:
+ # No cmd line opts given, print help
+ parser.print_help()
+ sys.exit(1)
+ else:
+ args = parser.parse_args()
+
+ if args.mode == 'init':
+ init()
+ init_so_sdnc()
+ elif args.mode == 'infra':
#if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
- deploy_infra()
- elif sys.argv[1] == 'customer':
+ deploy_infra()
+ elif args.mode == 'customer':
if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
deploy_custom_service()
- elif sys.argv[1] == 'loop':
+ elif args.mode == 'loop':
closed_loop(22)
- elif sys.argv[1] == 'noloss':
+ elif args.mode == 'noloss':
closed_loop(0)
- elif sys.argv[1] == 'brg':
+ elif args.mode == 'brg':
deploy_brg_only()
- elif sys.argv[1] == 'sniro':
+ elif args.mode == 'sniro':
tmp_sniro()
- elif sys.argv[1] == 'test':
+ elif args.mode == 'test':
test()
-