From d2a69b6edf69769dca5b3b360b3193a6a7637efe Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 11:01:40 +0100 Subject: [PATCH 1/8] Update requirements.txt Updated requests requirement and removed pyOpenSSL since it is no longer th recommended secure option for Requests --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5f65994..54acab1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ -pyOpenSSL>=19.1.0, <20 -requests>=2.25.0 , <3 +requests>=2.26.0 , <3 requests-mock pytest flake8 From d9ac237f6c6f4fe4193c8f1670aadcb069fc4311 Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 11:33:55 +0100 Subject: [PATCH 2/8] Update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 54acab1..cbe5a91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +pyOpenSSL>=21.1.0, <22 requests>=2.26.0 , <3 requests-mock pytest From b5079f19cca59b35bb281359b12afb8194e7dc47 Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 11:46:33 +0100 Subject: [PATCH 3/8] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cbe5a91..3a38c28 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pyOpenSSL>=21.1.0, <22 +pyOpenSSL>=21.1.0 requests>=2.26.0 , <3 requests-mock pytest From 50937fe86549e2966a0f8c9643b44f98b05ddd0a Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 11:47:30 +0100 Subject: [PATCH 4/8] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3a38c28..a21f7e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pyOpenSSL>=21.1.0 +pyOpenSSL>=21.0.0, <22 requests>=2.26.0 , <3 requests-mock pytest From 330bde966dd538fe0f9e05da501fc9dfbdf866d3 Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 17:03:48 +0100 Subject: [PATCH 5/8] Add option for targetDN in snapshot --- aciClient/aci.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aciClient/aci.py b/aciClient/aci.py index 48c9f06..135b8df 100644 --- a/aciClient/aci.py +++ b/aciClient/aci.py @@ -223,7 +223,7 @@ def deleteMo(self, dn) -> int: # ============================================================================== # snapshot # ============================================================================== - def snapshot(self, description="snapshot") -> bool: + def snapshot(self, description="snapshot", target_dn="") -> bool: self.__logger.debug(f'snapshot called {description}') json_payload = [ @@ -239,7 +239,7 @@ def snapshot(self, description="snapshot") -> bool: "name": "aciclient", "nameAlias": "", "snapshot": "yes", - "targetDn": "" + "targetDn": f"{target_dn}" } } } From 03284eed4ea0635dce48c0296f9cf2a83a26a7b5 Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 17:15:37 +0100 Subject: [PATCH 6/8] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 914d536..b5bf26f 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,10 @@ try: aciclient.logout() except Exception as e: logger.exception("Stack Trace") - ``` -For automatic authentication token refresh you can set refresh to True + +For automatic authentication token refresh you can set variable ```refresh``` to True + ```python aciclient = aciClient.ACI(apic_hostname, apic_username, apic_password, refresh=True) ``` @@ -96,8 +97,9 @@ aciclient.deleteMo('uni/tn-XYZ') ``` ### create snapshot +You can specify a tenant in variable ```target_dn``` or not provide any to do a fabric-wide snapshot. ```python -aci.snapshot('test') +aci.snapshot(description='test', target_dn='/uni/tn-test') ``` ## Testing From 1a0dcc13a79246bb75eafa740435425216c52cb3 Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 17:20:14 +0100 Subject: [PATCH 7/8] Added snapshot per tenant test --- test/test_aci.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test_aci.py b/test/test_aci.py index 80160e1..c1ae15e 100644 --- a/test/test_aci.py +++ b/test/test_aci.py @@ -255,3 +255,28 @@ def test_snapshot_nok(requests_mock): aci.login() resp = aci.snapshot(description='unit_test') assert not resp + +def test_snapshot_tenant_ok(requests_mock): + requests_mock.post(f'https://{__BASE_URL}/api/mo.json', json={"totalCount": "0", "imdata": []}) + requests_mock.post(f'https://{__BASE_URL}/api/aaaLogin.json', json={'imdata': [ + {'aaaLogin': {'attributes': {'token': 'tokenxyz'}}} + ]}) + + aci = ACI(apicIp=__BASE_URL, apicUser='admin', apicPasword='unkown') + aci.login() + resp = aci.snapshot(description='unit_test', target_dn='/uni/tn-test') + assert resp + + +def test_snapshot_tenant_nok(requests_mock): + requests_mock.post(f'https://{__BASE_URL}/api/mo.json', + json={"totalCount": "0", "imdata": [{"error": {"attributes": {"text": "Error UnitTest"}}}]}, + status_code=400) + requests_mock.post(f'https://{__BASE_URL}/api/aaaLogin.json', json={'imdata': [ + {'aaaLogin': {'attributes': {'token': 'tokenxyz'}}} + ]}) + + aci = ACI(apicIp=__BASE_URL, apicUser='admin', apicPasword='unkown') + aci.login() + resp = aci.snapshot(description='unit_test', target_dn='/uni/tn-test') + assert not resp From 9bc472dfcff7ed95bbfed0b5d965dd451e4b0a9c Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 17:20:53 +0100 Subject: [PATCH 8/8] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 62f801c..a6402fd 100644 --- a/setup.py +++ b/setup.py @@ -7,14 +7,14 @@ long_description = f.read() setup(name='aciClient', - version='1.3', + version='1.4', description='aci communication helper class', url='http://www.netcloud.ch', author='mze', author_email='nc_dev@netcloud.ch', license='MIT', packages=['aciClient'], - install_requires=['requests>=2.25.0 , <3', 'pyOpenSSL>=19.1.0, <20'], + install_requires=['requests>=2.26.0 , <3', 'pyOpenSSL>=21.0.0, <22'], long_description=long_description, long_description_content_type='text/markdown', python_requires=">=3.6",