aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/mass-pnf-sim/mass-pnf-sim.py
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-05-05 03:50:38 -0700
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-05-05 03:50:38 -0700
commit8200d2a58fcfcd2c4d1e445cfe61ebfdd183fd2c (patch)
tree69b51b1c786270f22751e406e51d0a120e862cf2 /test/mocks/mass-pnf-sim/mass-pnf-sim.py
parentc29b94608c9f172f801a1dc1e6ef221d5bd61819 (diff)
Add helper functions for input options validation
Change-Id: I0c8cd452fbf740f3b1c7988bf7aa7341a747c75e Issue-ID: INT-1577 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/mocks/mass-pnf-sim/mass-pnf-sim.py')
-rwxr-xr-xtest/mocks/mass-pnf-sim/mass-pnf-sim.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/mocks/mass-pnf-sim/mass-pnf-sim.py b/test/mocks/mass-pnf-sim/mass-pnf-sim.py
index c331d24bb..c70c351ae 100755
--- a/test/mocks/mass-pnf-sim/mass-pnf-sim.py
+++ b/test/mocks/mass-pnf-sim/mass-pnf-sim.py
@@ -4,6 +4,27 @@ import sys
import subprocess
import ipaddress
import time
+from requests import get
+from requests.exceptions import MissingSchema, InvalidSchema, InvalidURL, ConnectionError, ConnectTimeout
+
+def validate_url(url):
+ '''Helper function to perform --urlves input param validation'''
+ try:
+ get(url, timeout=0.001)
+ except (MissingSchema, InvalidSchema, InvalidURL):
+ raise argparse.ArgumentTypeError(f'{url} is not a valid URL')
+ except (ConnectionError, ConnectTimeout):
+ pass
+ return url
+
+def validate_ip(ip):
+ '''Helper function to validate input param is a vaild IP address'''
+ try:
+ ip_valid = ipaddress.ip_address(ip)
+ except ValueError:
+ raise argparse.ArgumentTypeError(f'{ip} is not a valid IP address')
+ else:
+ return ip_valid
parser = argparse.ArgumentParser()
parser.add_argument('--bootstrap', help='Bootstrap the system')