aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/masspnfsim/MassPnfSim.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/mocks/masspnfsim/MassPnfSim.py')
-rwxr-xr-xtest/mocks/masspnfsim/MassPnfSim.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/test/mocks/masspnfsim/MassPnfSim.py b/test/mocks/masspnfsim/MassPnfSim.py
index 01b2489c1..c9c84e8c9 100755
--- a/test/mocks/masspnfsim/MassPnfSim.py
+++ b/test/mocks/masspnfsim/MassPnfSim.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import logging
+import base64
from subprocess import run, CalledProcessError
import argparse
import ipaddress
@@ -35,6 +36,14 @@ def validate_ip(ip):
else:
return ip_valid
+def get_auth_token_base64(plain):
+ '''Converts user:password to Base64.'''
+ basic_auth_plain = plain
+ basic_auth_bytes = basic_auth_plain.encode('ascii')
+ basic_auth_base64_bytes = base64.b64encode(basic_auth_bytes)
+ basic_auth_base64 = basic_auth_base64_bytes.decode('ascii')
+ return basic_auth_base64
+
def get_parser():
'''Process input arguments'''
@@ -62,6 +71,8 @@ def get_parser():
# Trigger command parser
parser_trigger = subparsers.add_parser('trigger', help='Trigger one single VES event from each simulator')
parser_trigger.add_argument('--count', help='Instance count to trigger', type=int, metavar='INT', default=0)
+ parser_trigger.add_argument('--user', help='VES auth username', type=str, metavar='USERNAME')
+ parser_trigger.add_argument('--password', help='VES auth password', type=str, metavar='PASSWORD')
# Stop-simulator command parser
parser_stopsimulator = subparsers.add_parser('stop_simulator', help='Stop sending PNF registration messages')
parser_stopsimulator.add_argument('--count', help='Instance count to stop', type=int, metavar='INT', default=0)
@@ -71,6 +82,8 @@ def get_parser():
metavar='INT', required=True)
parser_triggerstart.add_argument('--triggerend', help='Last simulator id to trigger', type=int,
metavar='INT', required=True)
+ parser_triggerstart.add_argument('--user', help='VES auth username', type=str, metavar='USERNAME')
+ parser_triggerstart.add_argument('--password', help='VES auth password', type=str, metavar='PASSWORD')
# Status command parser
parser_status = subparsers.add_parser('status', help='Status')
parser_status.add_argument('--count', help='Instance count to show status for', type=int, metavar='INT', default=0)
@@ -137,7 +150,7 @@ class MassPnfSim:
self.logger = logging.getLogger(__name__)
self.logger.setLevel(self.log_lvl)
self.sim_dirname_pattern = "pnf-sim-lw-"
- self.mvn_build_cmd = 'mvn clean package docker:build -Dcheckstyle.skip'
+ self.mvn_build_cmd = 'mvn clean package docker:build -Dcheckstyle.skip '
self.docker_compose_status_cmd = 'docker-compose ps'
def _run_cmd(self, cmd, dir_context='.'):
@@ -418,11 +431,17 @@ class MassPnfSim:
sim_ip = self._get_sim_instance_data(i)
self.logger.info(f'Triggering {self.sim_dirname_pattern}{i} instance:')
self.logger.info(f' PNF-Sim IP: {sim_ip}')
+ # create a Basic auth token
+ plaintext_auth = f"{args.user}:{args.password}"
+ basic_auth_base64 = get_auth_token_base64(plaintext_auth)
+ basic_auth_token = f"Basic {basic_auth_base64}"
+ self.logger.info((basic_auth_base64))
# setup req headers
req_headers = {
"Content-Type": "application/json",
"X-ONAP-RequestID": "123",
- "X-InvocationID": "456"
+ "X-InvocationID": "456",
+ "Authorization": basic_auth_token
}
self.logger.debug(f' Request headers: {req_headers}')
try: