Skip to content

Commit

Permalink
Update unit tests rockstor#2508
Browse files Browse the repository at this point in the history
  • Loading branch information
FroggyFlox committed Mar 3, 2023
1 parent cffa735 commit b274990
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 15 deletions.
14 changes: 14 additions & 0 deletions src/rockstor/storageadmin/fixtures/test_config_backup.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
"role": null
}
},
{
"model": "storageadmin.pool",
"pk": 4,
"fields": {
"name": "rock-pool2",
"uuid": "3176aa98-a939-4f7b-aa6c-70c18570fc8e",
"size": 5242880,
"raid": "single",
"toc": "2023-03-03T21:21:14.952Z",
"compression": "no",
"mnt_options": "",
"role": null
}
},
{
"model": "storageadmin.share",
"pk": 3,
Expand Down
94 changes: 79 additions & 15 deletions src/rockstor/storageadmin/tests/test_config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
"""
Fixture creation instructions:
System needs 1 non system pool 'rock-pool', at any raid level.
System needs 2 non system pools:
- 'rock-pool', at any raid level.
- 'rock-pool2', at any raid level.
- Create 1 share named 'test_share01'
- Create 1 share named 'test_share02'
export DJANGO_SETTINGS_MODULE="settings"
poetry run django-admin dumpdata storageadmin.pool storageadmin.share \
--natural-foreign --indent 4 > \
src/rockstor/storageadmin/fixtures/test_config_backup.json
Expand Down Expand Up @@ -1192,6 +1195,42 @@ class ConfigBackupTests(APITestMixin):
"model": "smart_manager.taskdefinition",
"pk": 3,
},
{
"model": "smart_manager.taskdefinition",
"pk": 4,
"fields": {
"name": "rockpool_scrub",
"task_type": "scrub",
"json_meta": '{"pool_name": "rock-pool", "pool": "2"}',
"enabled": False,
"crontab": "42 3 * * 5",
"crontabwindow": "*-*-*-*-*-*",
},
},
{
"model": "smart_manager.taskdefinition",
"pk": 5,
"fields": {
"name": "boguspool_scrub",
"task_type": "scrub",
"json_meta": '{"pool_name": "bogus-pool", "pool": "99"}',
"enabled": False,
"crontab": "42 3 * * 5",
"crontabwindow": "*-*-*-*-*-*",
},
},
{
"model": "smart_manager.taskdefinition",
"pk": 6,
"fields": {
"name": "rockpool2_scrub",
"task_type": "scrub",
"json_meta": '{"pool_name": "rock-pool2", "pool": "3"}',
"enabled": False,
"crontab": "42 3 * * 5",
"crontabwindow": "*-*-*-*-*-*",
},
},
]

@classmethod
Expand Down Expand Up @@ -1865,7 +1904,6 @@ def test_validate_taskdef_meta(self):
"max_count": "4",
}
]

out = [
{
"writable": True,
Expand All @@ -1876,6 +1914,14 @@ def test_validate_taskdef_meta(self):
}
]

task_type.append("scrub")
taskdef_meta.append({"pool_name": "rock-pool", "pool": "2"})
out.append({"pool_name": "rock-pool", "pool": "2"})

task_type.append("scrub")
taskdef_meta.append({"pool_name": "rock-pool2", "pool": "3"})
out.append({"pool_name": "rock-pool2", "pool": "4"})

for t, m, o in zip(task_type, taskdef_meta, out):
ret = validate_taskdef_meta(self.sa_ml, m, t)
self.assertEqual(
Expand All @@ -1893,20 +1939,38 @@ def test_validate_task_definitions(self):
- invalid metadata: wrong share ID in backup file (snap_daily_ts02 in sm_ml)
- invalid metadata: share does not exist on target system (snap_daily_ts04 in sm_ml)
"""
out = [{
"task_type": "snapshot",
"name": "snap_daily_ts01",
"crontabwindow": "*-*-*-*-*-*",
"enabled": False,
"crontab": "42 3 * * *",
"meta": {
"writable": True,
"visible": True,
"prefix": "snap_daily_ts01",
"share": "3",
"max_count": "4",
out = [
{
"task_type": "snapshot",
"name": "snap_daily_ts01",
"crontabwindow": "*-*-*-*-*-*",
"enabled": False,
"crontab": "42 3 * * *",
"meta": {
"writable": True,
"visible": True,
"prefix": "snap_daily_ts01",
"share": "3",
"max_count": "4",
},
},
{
"task_type": "scrub",
"name": "rockpool_scrub",
"crontabwindow": "*-*-*-*-*-*",
"enabled": False,
"crontab": "42 3 * * 5",
"meta": {"pool_name": "rock-pool", "pool": "2"},
},
{
"task_type": "scrub",
"name": "rockpool2_scrub",
"crontabwindow": "*-*-*-*-*-*",
"enabled": False,
"crontab": "42 3 * * 5",
"meta": {"pool_name": "rock-pool2", "pool": "4"},
},
}]
]
ret = validate_task_definitions(self.sm_ml, self.sa_ml)
self.assertEqual(
ret,
Expand Down

0 comments on commit b274990

Please sign in to comment.