diff options
author | Eli Halych <eli.halych@gmail.com> | 2020-12-03 09:56:50 +0000 |
---|---|---|
committer | Eli Halych <illia.halych@t-mobile.pl> | 2020-12-04 00:42:11 +0000 |
commit | a579a48948f0b61bb9d98e1591d1fe727a550dbb (patch) | |
tree | 7abd52518d5f5233a8e48440b7c6f952edbe7d72 /test/mocks/masspnfsim/MassPnfSim.py | |
parent | 59305b4e52464023a6350a1d69ced2eb23dee73e (diff) |
Add send requests to VES via HTTPS in Mass PNF Simulator
Details:
- Previously allowed only HTTP.
- HTTPS support added since VES accepts HTTPS and throws 400 Bad Request on HTTP.
- Added autogenerating Basic Authorization token based on user:password in Base64 to access real VES together with HTTPS.
- For this reason, simple HttpClient became part of RestTemplate that can ignore certificate checks for HTTPS when connecting to VES.
- Adjusted test cases.
Issue-ID: INT-1799
Signed-off-by: Eli Halych <illia.halych@t-mobile.pl>
Change-Id: I69eaeb4b10f903c3a3aa880dbb787034da4c30bb
Diffstat (limited to 'test/mocks/masspnfsim/MassPnfSim.py')
-rwxr-xr-x | test/mocks/masspnfsim/MassPnfSim.py | 23 |
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: |