From c00de2e48231d4e0b69c368c713c735816f32a6c Mon Sep 17 00:00:00 2001 From: Joao Victor Portal Date: Tue, 29 Mar 2022 12:26:41 -0300 Subject: [PATCH] Add tenant parameter in API request methods This parameter was not added before because it was not needed in NFV code, but it will be used in Horizon and Distcloud code. The test plan is the same of the already merged change https://review.opendev.org/c/starlingx/nfv/+/833910. Test Plan: PASS: Successfully deploy a Distributed Cloud (1 subcloud) using an image with this commit present and verify in the contents of "/var/log/nfv-vim-api.log" that the NFV VIM API server started successfully in the central cloud and in the subcloud. PASS: In the deployed subcloud, execute command "sw-manager patch-strategy show" and check that the command was successful. PASS: In the deployed subcloud, execute each of the following commands and check that the log of the received requests are present in "/var/log/nfv-vim-api.log" with the fields "user", "tenant" and "domain" correctly filled: sw-manager patch-strategy apply sw-manager patch-strategy abort sw-manager patch-strategy create sw-manager patch-strategy delete PASS: In the deployed central cloud, create and execute a patch-strategy using dcmanager CLI to verify the compatibility with the changes. PASS: In the deployed central cloud, create and execute a patch-strategy using Horizon interface to verify the compatibility with the changes. PASS: Successfully build package "nfv" as Debian package. Story: 2009824 Task: 44878 Signed-off-by: Joao Victor Portal Change-Id: I2774b36081de77f358a9713d0f3cf5992525ee91 --- .../nfv_client/openstack/sw_update.py | 29 ++++++++++++------- .../nfv_client/sw_update/_sw_update.py | 13 ++++++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/nfv/nfv-client/nfv_client/openstack/sw_update.py b/nfv/nfv-client/nfv_client/openstack/sw_update.py index 65a132a0..83f23e85 100755 --- a/nfv/nfv-client/nfv_client/openstack/sw_update.py +++ b/nfv/nfv-client/nfv_client/openstack/sw_update.py @@ -180,7 +180,7 @@ def _get_strategy_object_from_response(response): def get_strategies(token_id, url, strategy_name, username=None, - user_domain_name=None): + user_domain_name=None, tenant=None): """ Software Update - Get Strategies """ @@ -189,7 +189,8 @@ def get_strategies(token_id, url, strategy_name, username=None, api_cmd_headers = dict() if username: api_cmd_headers['X-User'] = username - api_cmd_headers['X-Tenant'] = username + if tenant: + api_cmd_headers['X-Tenant'] = tenant if user_domain_name: api_cmd_headers['X-User-Domain-Name'] = user_domain_name api_cmd_headers['X-Auth-Token'] = token_id @@ -202,7 +203,7 @@ def get_strategies(token_id, url, strategy_name, username=None, def get_strategy(token_id, url, strategy_name, strategy_uuid, username=None, - user_domain_name=None): + user_domain_name=None, tenant=None): """ Software Update - Get Strategy """ @@ -212,7 +213,8 @@ def get_strategy(token_id, url, strategy_name, strategy_uuid, username=None, api_cmd_headers = dict() if username: api_cmd_headers['X-User'] = username - api_cmd_headers['X-Tenant'] = username + if tenant: + api_cmd_headers['X-Tenant'] = tenant if user_domain_name: api_cmd_headers['X-User-Domain-Name'] = user_domain_name api_cmd_headers['X-Auth-Token'] = token_id @@ -236,6 +238,7 @@ def create_strategy(token_id, alarm_restrictions, username=None, user_domain_name=None, + tenant=None, **kwargs): """ Software Update - Create Strategy @@ -246,7 +249,8 @@ def create_strategy(token_id, api_cmd_headers['Content-Type'] = "application/json" if username: api_cmd_headers['X-User'] = username - api_cmd_headers['X-Tenant'] = username + if tenant: + api_cmd_headers['X-Tenant'] = tenant if user_domain_name: api_cmd_headers['X-User-Domain-Name'] = user_domain_name api_cmd_headers['X-Auth-Token'] = token_id @@ -297,7 +301,7 @@ def create_strategy(token_id, def delete_strategy(token_id, url, strategy_name, force=False, - username=None, user_domain_name=None): + username=None, user_domain_name=None, tenant=None): """ Software Update - Delete Strategy """ @@ -307,7 +311,8 @@ def delete_strategy(token_id, url, strategy_name, force=False, api_cmd_headers['Content-Type'] = "application/json" if username: api_cmd_headers['X-User'] = username - api_cmd_headers['X-Tenant'] = username + if tenant: + api_cmd_headers['X-Tenant'] = tenant if user_domain_name: api_cmd_headers['X-User-Domain-Name'] = user_domain_name api_cmd_headers['X-Auth-Token'] = token_id @@ -327,7 +332,7 @@ def delete_strategy(token_id, url, strategy_name, force=False, def apply_strategy(token_id, url, strategy_name, stage_id=None, - username=None, user_domain_name=None): + username=None, user_domain_name=None, tenant=None): """ Software Update - Apply Strategy """ @@ -337,7 +342,8 @@ def apply_strategy(token_id, url, strategy_name, stage_id=None, api_cmd_headers['Content-Type'] = "application/json" if username: api_cmd_headers['X-User'] = username - api_cmd_headers['X-Tenant'] = username + if tenant: + api_cmd_headers['X-Tenant'] = tenant if user_domain_name: api_cmd_headers['X-User-Domain-Name'] = user_domain_name api_cmd_headers['X-Auth-Token'] = token_id @@ -358,7 +364,7 @@ def apply_strategy(token_id, url, strategy_name, stage_id=None, def abort_strategy(token_id, url, strategy_name, stage_id, username=None, - user_domain_name=None): + user_domain_name=None, tenant=None): """ Software Update - Abort Strategy """ @@ -368,7 +374,8 @@ def abort_strategy(token_id, url, strategy_name, stage_id, username=None, api_cmd_headers['Content-Type'] = "application/json" if username: api_cmd_headers['X-User'] = username - api_cmd_headers['X-Tenant'] = username + if tenant: + api_cmd_headers['X-Tenant'] = tenant if user_domain_name: api_cmd_headers['X-User-Domain-Name'] = user_domain_name api_cmd_headers['X-Auth-Token'] = token_id diff --git a/nfv/nfv-client/nfv_client/sw_update/_sw_update.py b/nfv/nfv-client/nfv_client/sw_update/_sw_update.py index 418c79ca..a2be6051 100755 --- a/nfv/nfv-client/nfv_client/sw_update/_sw_update.py +++ b/nfv/nfv-client/nfv_client/sw_update/_sw_update.py @@ -211,6 +211,7 @@ def create_strategy(os_auth_uri, os_project_name, os_project_domain_name, default_instance_action, alarm_restrictions, os_username, os_user_domain_name, + os_username, **kwargs) if not strategy: raise Exception("Strategy creation failed") @@ -235,7 +236,8 @@ def delete_strategy(os_auth_uri, os_project_name, os_project_domain_name, success = sw_update.delete_strategy(token.get_id(), url, strategy_name, force, - os_username, os_user_domain_name) + os_username, os_user_domain_name, + os_username) if success: print("Strategy deleted") return @@ -260,7 +262,8 @@ def apply_strategy(os_auth_uri, os_project_name, os_project_domain_name, strategy = sw_update.apply_strategy(token.get_id(), url, strategy_name, stage_id, - os_username, os_user_domain_name) + os_username, os_user_domain_name, + os_username) if not strategy: if stage_id is None: raise Exception("Strategy apply failed") @@ -287,7 +290,8 @@ def abort_strategy(os_auth_uri, os_project_name, os_project_domain_name, strategy = sw_update.abort_strategy(token.get_id(), url, strategy_name, stage_id, - os_username, os_user_domain_name) + os_username, os_user_domain_name, + os_username) if not strategy: if stage_id is None: raise Exception("Strategy abort failed") @@ -313,7 +317,8 @@ def show_strategy(os_auth_uri, os_project_name, os_project_domain_name, raise ValueError("NFV-VIM URL is invalid") strategy = sw_update.get_strategies(token.get_id(), url, strategy_name, - os_username, os_user_domain_name) + os_username, os_user_domain_name, + os_username) if not strategy: print("No strategy available") return