From d31957737d7f1f2573a021090eaf5fbe10e9da4e Mon Sep 17 00:00:00 2001 From: Sugetha Kalyanaraman Date: Wed, 8 Nov 2023 10:22:43 -0800 Subject: [PATCH] Fix(cv_tag_v3): Long workspace name to avoid conflict (#679) * Fix(cv_tag_v3): Long workspace name to avoid conflict * pep8 fix * fix pylint error * FIX(cv_tag_v3): Format datetime with padding 0 --------- Co-authored-by: RYAN CHETCUTI --- .../cvp/molecule/cv_tag_v3/test_cv_tag_v3_device.yml | 1 - .../cvp/molecule/cv_tag_v3/test_cv_tag_v3_interface.yml | 1 - .../arista/cvp/plugins/module_utils/tag_tools.py | 9 +++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ansible_collections/arista/cvp/molecule/cv_tag_v3/test_cv_tag_v3_device.yml b/ansible_collections/arista/cvp/molecule/cv_tag_v3/test_cv_tag_v3_device.yml index 274f07fc6..e1a76b70e 100644 --- a/ansible_collections/arista/cvp/molecule/cv_tag_v3/test_cv_tag_v3_device.yml +++ b/ansible_collections/arista/cvp/molecule/cv_tag_v3/test_cv_tag_v3_device.yml @@ -5,7 +5,6 @@ gather_facts: no vars: DEVICE1: s1-leaf3 - DEVICE2: s1-leaf4 ASSIGN_DELETE_TAGS_AUTO_CREATE: diff --git a/ansible_collections/arista/cvp/molecule/cv_tag_v3/test_cv_tag_v3_interface.yml b/ansible_collections/arista/cvp/molecule/cv_tag_v3/test_cv_tag_v3_interface.yml index 1a861a480..ad1de20f6 100644 --- a/ansible_collections/arista/cvp/molecule/cv_tag_v3/test_cv_tag_v3_interface.yml +++ b/ansible_collections/arista/cvp/molecule/cv_tag_v3/test_cv_tag_v3_interface.yml @@ -5,7 +5,6 @@ gather_facts: no vars: DEVICE1: s1-leaf3 - DEVICE2: s1-leaf4 ASSIGN_DELETE_TAGS_AUTO_CREATE: diff --git a/ansible_collections/arista/cvp/plugins/module_utils/tag_tools.py b/ansible_collections/arista/cvp/plugins/module_utils/tag_tools.py index 8631bfd90..2a8cc9404 100644 --- a/ansible_collections/arista/cvp/plugins/module_utils/tag_tools.py +++ b/ansible_collections/arista/cvp/plugins/module_utils/tag_tools.py @@ -23,14 +23,13 @@ import logging import random import string +from datetime import datetime from ansible.module_utils.basic import AnsibleModule -import ansible_collections.arista.cvp.plugins.module_utils.logger # noqa # pylint: disable=unused-import from ansible_collections.arista.cvp.plugins.module_utils.response import CvApiResult, CvManagerResult, CvAnsibleResponse from ansible_collections.arista.cvp.plugins.module_utils.resources.schemas import v3 as schema from ansible_collections.arista.cvp.plugins.module_utils.tools_schema import validate_json_schema try: - from cvprac.cvp_client import CvpClient # noqa # pylint: disable=unused-import - from cvprac.cvp_client_errors import CvpApiError, CvpRequestError # noqa # pylint: disable=unused-import + from cvprac.cvp_client_errors import CvpRequestError HAS_CVPRAC = True except ImportError: HAS_CVPRAC = False @@ -110,7 +109,9 @@ def tasker(self, tags: list, mode: string, auto_create: bool = True): tag_manager = CvManagerResult(builder_name='tags_manager') # create workspace - workspace_name_id = "AnsibleWorkspace" + ''.join(random.choices(string.ascii_uppercase + string.digits, k=3)) + my_date = datetime.now() + datetime_string = my_date.strftime('%Y%m%d_%H%M%S') + workspace_name_id = "AW_" + ''.join(random.choices(string.ascii_uppercase + string.digits, k=6)) + datetime_string workspace_id = workspace_name_id workspace_name = workspace_name_id