From 78594259e0a24fe6b9dd8b18ca31c57e7d83202a Mon Sep 17 00:00:00 2001 From: Quentin POLLET Date: Thu, 9 Apr 2020 22:45:02 +0200 Subject: [PATCH 1/4] GET DATA FOR TESTERS --- get_data_for_tests.py | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 get_data_for_tests.py diff --git a/get_data_for_tests.py b/get_data_for_tests.py new file mode 100644 index 00000000..d51fa0a3 --- /dev/null +++ b/get_data_for_tests.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +"""Get datas to test Synology DSM library.""" +from unittest import TestCase +from synology_dsm import SynologyDSM + +NB_SEPARATOR = 20 + + +################################# +# STEPS TO GET DATA FOR TESTERS # +################################# + +# Fill constants DO NOT COMMIT THEM ! +HOST = "host" +PORT = 443 +USERNAME = "user" +PASSWORD = "password" +HTTPS = True +VERSION = 6 + +# Launch the data getter like this : +# py.test get_data_for_tests.py + +# WARNING /!\ +# If you have `AssertionError: assert False` at `assert api.login()`, +# its because the NAS is unreachable/can't connect to account with cconstants you gave + +# It's gonna log data like : +# 1. Requested URL +# 2. Access token +# 3. Request response http code +# 4. Request response raw data (After "Succesfull returning data" log) + +# The raw data is needed data to Python tests +# Use SERIAL, SID, UNIQUE_KEY constants for required fields, see const_dsm_6.py as exemple +# You can push your const_dsm_[dsm_version].py file +# Commit message can be "Add DSM [dsm_version] test constants" + + +class TestSynologyDSM(TestCase): + """SynologyDSM test cases.""" + + def test_get_all(self): # pylint: disable=no-self-use + """Launch data getter.""" + print("-" * NB_SEPARATOR + " INIT " + "-" * NB_SEPARATOR) + api = SynologyDSM( + HOST, + PORT, + USERNAME, + PASSWORD, + use_https=HTTPS, + debugmode=True, + dsm_version=VERSION, + ) + + print("-" * NB_SEPARATOR + " LOGIN " + "-" * NB_SEPARATOR) + assert api.login() + print("-" * NB_SEPARATOR + " LOGIN_END " + "-" * NB_SEPARATOR) + + print("-" * NB_SEPARATOR + " INFORMATION " + "-" * NB_SEPARATOR) + assert api.information + print("-" * NB_SEPARATOR + " INFORMATION_END " + "-" * NB_SEPARATOR) + + print("-" * NB_SEPARATOR + " UTILIZATION " + "-" * NB_SEPARATOR) + assert api.utilisation + print("-" * NB_SEPARATOR + " UTILIZATION_END " + "-" * NB_SEPARATOR) + + print("-" * NB_SEPARATOR + " STORAGE " + "-" * NB_SEPARATOR) + assert api.storage + print("-" * NB_SEPARATOR + " STORAGE_END " + "-" * NB_SEPARATOR) + + print("-" * NB_SEPARATOR + " END " + "-" * NB_SEPARATOR) + assert False # Stop the test with error, so we see logs From 0a5b9df1d40169bd4472c7b73b2fcee79042e252 Mon Sep 17 00:00:00 2001 From: aaska Date: Sat, 11 Apr 2020 10:47:20 +0200 Subject: [PATCH 2/4] Update const_dsm_5.py Populated data from DSM 5.2-5967 Update 9 --- tests/const_dsm_5.py | 469 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 465 insertions(+), 4 deletions(-) diff --git a/tests/const_dsm_5.py b/tests/const_dsm_5.py index caf1d24f..6467d40a 100644 --- a/tests/const_dsm_5.py +++ b/tests/const_dsm_5.py @@ -3,10 +3,471 @@ from .const import SERIAL, SID, UNIQUE_KEY # pylint: disable=unused-import # DSM 5 RAW DATA -DSM_5_LOGIN = {} +DSM_5_LOGIN = { + {'data': {'sid': SID}, 'success': True} +} -DSM_5_INFORMATION = {} +DSM_5_INFORMATION = { + # Request failed +} -DSM_5_UTILIZATION = {} +DSM_5_UTILIZATION = { + { + "data": { + "cpu": { + "15min_load": 53, + "1min_load": 57, + "5min_load": 56, + "device": "System", + "other_load": 63, + "system_load": 10, + "user_load": 27 + }, + "disk": { + "disk": [ + { + "device": "sda", + "display_name": "Disk 1", + "read_access": 21, + "read_byte": 645529, + "type": "internal", + "utilization": 46, + "write_access": 4, + "write_byte": 86220 + }, + { + "device": "sdb", + "display_name": "Disk 2", + "read_access": 23, + "read_byte": 711338, + "type": "internal", + "utilization": 33, + "write_access": 4, + "write_byte": 95641 + }, + { + "device": "sdc", + "display_name": "Disk 3", + "read_access": 21, + "read_byte": 786841, + "type": "internal", + "utilization": 31, + "write_access": 5, + "write_byte": 99874 + }, + { + "device": "sdd", + "display_name": "Disk 4", + "read_access": 21, + "read_byte": 729907, + "type": "internal", + "utilization": 32, + "write_access": 4, + "write_byte": 76663 + }, + { + "device": "sdq", + "display_name": "USB Disk 1", + "read_access": 0, + "read_byte": 0, + "type": "usb", + "utilization": 0, + "write_access": 0, + "write_byte": 0 + } + ], + "total": { + "device": "total", + "read_access": 86, + "read_byte": 2873615, + "utilization": 28, + "write_access": 17, + "write_byte": 358398 + } + }, + "memory": { + "avail_real": 8188, + "avail_swap": 1933436, + "buffer": 3700, + "cached": 25636, + "device": "Memory", + "memory_size": 131072, + "real_usage": 68, + "si_disk": 5, + "so_disk": 3, + "swap_usage": 7, + "total_real": 118464, + "total_swap": 2097080 + }, + "network": [ + { + "device": "total", + "rx": 1680, + "tx": 553 + }, + { + "device": "eth0", + "rx": 1680, + "tx": 553 + } + ], + "space": { + "lun": [], + "total": { + "device": "total", + "read_access": 261, + "read_byte": 1069875, + "utilization": 100, + "write_access": 51, + "write_byte": 208896 + }, + "volume": [ + { + "device": "md2", + "display_name": "volume1", + "read_access": 261, + "read_byte": 1069875, + "utilization": 100, + "write_access": 51, + "write_byte": 208896 + } + ] + }, + "time": 1586592505 + }, + "success": True + } -DSM_5_STORAGE = {} +} + +DSM_5_STORAGE = { + { + "disks": [ + { + "container": { + "order": 0, + "str": "DS410j", + "supportPwrBtnDisable": False, + "type": "internal" + }, + "device": "/dev/sdd", + "disable_secera": False, + "diskType": "SATA", + "erase_time": 374, + "firm": "SC60", + "has_system": True, + "id": "sdd", + "is4Kn": False, + "isSsd": False, + "is_erasing": False, + "longName": "Disk 4", + "model": "ST3000VN007-2E4166 ", + "name": "Disk 4", + "num_id": 4, + "order": 4, + "portType": "normal", + "serial": "Z73095S2", + "size_total": "3000592982016", + "smart_status": "safe", + "status": "normal", + "support": False, + "temp": 42, + "used_by": "volume_1", + "vendor": "Seagate" + }, + { + "container": { + "order": 0, + "str": "DS410j", + "supportPwrBtnDisable": False, + "type": "internal" + }, + "device": "/dev/sdc", + "disable_secera": False, + "diskType": "SATA", + "erase_time": 410, + "firm": "80.00A80", + "has_system": True, + "id": "sdc", + "is4Kn": False, + "isSsd": False, + "is_erasing": False, + "longName": "Disk 3", + "model": "WD30EZRZ-00Z5HB0 ", + "name": "Disk 3", + "num_id": 3, + "order": 3, + "portType": "normal", + "serial": "WD-WCC4N0TEJ4F0", + "size_total": "3000592982016", + "smart_status": "safe", + "status": "normal", + "support": False, + "temp": 42, + "used_by": "volume_1", + "vendor": "WDC " + }, + { + "container": { + "order": 0, + "str": "DS410j", + "supportPwrBtnDisable": False, + "type": "internal" + }, + "device": "/dev/sdb", + "disable_secera": False, + "diskType": "SATA", + "erase_time": 408, + "firm": "82.00A82", + "has_system": True, + "id": "sdb", + "is4Kn": False, + "isSsd": False, + "is_erasing": False, + "longName": "Disk 2", + "model": "WD30EFRX-68EUZN0 ", + "name": "Disk 2", + "num_id": 2, + "order": 2, + "portType": "normal", + "serial": "WD-WCC4N6LSVCVX", + "size_total": "3000592982016", + "smart_status": "safe", + "status": "normal", + "support": False, + "temp": 43, + "used_by": "volume_1", + "vendor": "WDC " + }, + { + "container": { + "order": 0, + "str": "DS410j", + "supportPwrBtnDisable": False, + "type": "internal" + }, + "device": "/dev/sda", + "disable_secera": False, + "diskType": "SATA", + "erase_time": 0, + "firm": "82.00A82", + "has_system": True, + "id": "sda", + "is4Kn": False, + "isSsd": False, + "is_erasing": False, + "longName": "Disk 1", + "model": "WD30EFRX-68N32N0 ", + "name": "Disk 1", + "num_id": 1, + "order": 1, + "portType": "normal", + "serial": "WD-WCC7K5YA5H40", + "size_total": "3000592982016", + "smart_status": "90%", + "status": "normal", + "support": False, + "temp": 44, + "used_by": "volume_1", + "vendor": "WDC " + } + ], + "env": { + "batchtask": { + "max_task": 64, + "remain_task": 64 + }, + "bay_number": "4", + "ebox": [], + "fs_acting": False, + "is_space_actioning": False, + "isns": { + "address": "", + "enabled": False + }, + "isns_server": "", + "max_fs_bytes": "17592181850112", + "max_fs_bytes_high_end": "219902325555200", + "model_name": "DS410j", + "ram_enough_for_fs_high_end": False, + "ram_size": 0, + "ram_size_required": 32, + "settingSwap": False, + "showpooltab": False, + "status": { + "system_crashed": False, + "system_need_repair": False + }, + "support": { + "ebox": False, + "raid_cross": False, + "sysdef": True + }, + "unique_key": UNIQUE_KEY + }, + "hotSpares": [], + "iscsiLuns": [ + { + "can_do": { + "data_scrubbing": True, + "delete": True, + "expand_by_disk": 1, + "migrate": { + "to_raid5+spare": "1-1", + "to_raid6": 1 + } + }, + "id": "iscsilun_LUN-1", + "is_actioning": False, + "iscsi_lun": { + "blkNum": "19614744", + "device_type": "file", + "lid": 1, + "location": "volume_1", + "mapped_targets": [ + 1 + ], + "name": "LUN-1", + "restored_time": "0", + "rootpath": "/volume1", + "size": "10737418240", + "thin_provision": False, + "uuid": "fcf3a450-681c-06cb-fbb9-0400bdbe0780", + "vaai_extent_size": "0", + "vaai_support": False + }, + "num_id": 1, + "progress": { + "percent": "-1", + "step": "none" + }, + "status": "normal" + } + ], + "iscsiTargets": [ + { + "auth": { + "mutual_username": "", + "type": "none", + "username": "" + }, + "data_chksum": 0, + "enabled": True, + "hdr_chksum": 0, + "iqn": "iqn.2000-01.com.synology:DiskStation.name", + "mapped_logical_unit_number": [ + 0 + ], + "mapped_luns": [ + 1 + ], + "masking": [ + { + "iqn": "iqn.2000-01.com.synology:default.acl", + "permission": "rw" + } + ], + "multi_sessions": False, + "name": "Target-1", + "num_id": 1, + "recv_seg_bytes": 262144, + "remote": [], + "send_seg_bytes": 4096, + "status": "online", + "tid": 1 + } + ], + "ports": [], + "storagePools": [], + "success": True, + "volumes": [ + { + "can_do": { + "data_scrubbing": True, + "delete": True, + "expand_by_disk": 1, + "migrate": { + "to_raid5+spare": "1-1", + "to_raid6": 1 + } + }, + "container": "internal", + "device_type": "raid_5", + "disk_failure_number": 0, + "disks": [ + "sda", + "sdb", + "sdc", + "sdd" + ], + "eppool_used": "10042748928", + "fs_type": "ext3", + "id": "volume_1", + "is_acting": False, + "is_actioning": False, + "is_inode_full": False, + "is_writable": True, + "max_fs_size": "17592181850112", + "maximal_disk_size": "0", + "minimal_disk_size": "2995767869440", + "num_id": 1, + "pool_path": "", + "progress": { + "percent": "-1", + "step": "none" + }, + "size": { + "free_inode": "547237217", + "total": "8846249701376", + "total_device": "8987275100160", + "total_inode": "548544512", + "used": "5719795761152" + }, + "space_path": "/dev/md2", + "spares": [], + "ssd_trim": { + "support": "not support" + }, + "status": "normal", + "suggestions": [], + "timebackup": True, + "used_by_gluster": False, + "vol_path": "/volume1", + "vspace_can_do": { + "drbd": { + "resize": { + "can_do": False, + "errCode": 53504, + "stopService": False + } + }, + "flashcache": { + "apply": { + "can_do": False, + "errCode": 53504, + "stopService": False + }, + "remove": { + "can_do": False, + "errCode": 53504, + "stopService": False + }, + "resize": { + "can_do": False, + "errCode": 53504, + "stopService": False + } + }, + "snapshot": { + "resize": { + "can_do": True, + "errCode": 0, + "stopService": False + } + } + } + } + ] + } + +} From c462bf23f90d669e685c490f7d625c9ac0bcc3aa Mon Sep 17 00:00:00 2001 From: aaska Date: Wed, 15 Apr 2020 12:34:24 +0200 Subject: [PATCH 3/4] Update tests/const_dsm_5.py Co-Authored-By: Quentame --- tests/const_dsm_5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/const_dsm_5.py b/tests/const_dsm_5.py index 6467d40a..6fea5a34 100644 --- a/tests/const_dsm_5.py +++ b/tests/const_dsm_5.py @@ -5,7 +5,7 @@ # DSM 5 RAW DATA DSM_5_LOGIN = { {'data': {'sid': SID}, 'success': True} -} +DSM_5_LOGIN = {'data': {'sid': SID}, 'success': True} DSM_5_INFORMATION = { # Request failed From 9750d7f463bfca1963fbd24d964c2b4cf7da62e3 Mon Sep 17 00:00:00 2001 From: Quentame Date: Wed, 15 Apr 2020 13:51:20 +0200 Subject: [PATCH 4/4] Update tests/const_dsm_5.py --- tests/const_dsm_5.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/const_dsm_5.py b/tests/const_dsm_5.py index 6fea5a34..b4368a4d 100644 --- a/tests/const_dsm_5.py +++ b/tests/const_dsm_5.py @@ -3,8 +3,6 @@ from .const import SERIAL, SID, UNIQUE_KEY # pylint: disable=unused-import # DSM 5 RAW DATA -DSM_5_LOGIN = { - {'data': {'sid': SID}, 'success': True} DSM_5_LOGIN = {'data': {'sid': SID}, 'success': True} DSM_5_INFORMATION = {