aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xtest/mocks/mass-pnf-sim/mass-pnf-sim.py21
-rw-r--r--test/mocks/mass-pnf-sim/requirements.txt1
2 files changed, 22 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')
diff --git a/test/mocks/mass-pnf-sim/requirements.txt b/test/mocks/mass-pnf-sim/requirements.txt
index 442e1c37b..7e9b64bd9 100644
--- a/test/mocks/mass-pnf-sim/requirements.txt
+++ b/test/mocks/mass-pnf-sim/requirements.txt
@@ -1,2 +1,3 @@
argparse
ipaddress
+requests