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 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}" } } } diff --git a/requirements.txt b/requirements.txt index 5f65994..a21f7e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -pyOpenSSL>=19.1.0, <20 -requests>=2.25.0 , <3 +pyOpenSSL>=21.0.0, <22 +requests>=2.26.0 , <3 requests-mock pytest flake8 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", 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