Skip to content

Commit

Permalink
(t) Refresh/remove all test fixtures and update tests accordingly roc…
Browse files Browse the repository at this point in the history
…kstor#2384

As a result of major Django changes enacted in 'Update Django within current Python 2
constrains rockstor#2254' rockstor#2365, and following on from the fixture re-enablement spin-off of
the former: '(t) Test fixtures non functional rockstor#2382' rockstor#2383 we have a test wide
requirement to update or remove our now mostly outdated and newly re-enabled fixtures.

Our prior work-around for the previously dysfunctional fixtures was extensive in-test
db object mocking. This has become unworkable and incompatible with our newer Django.

## Includes
- remove now outdated trailing '/' in task post calls rockstor#2384
Thanks to FroggyFlox for pointers: in GitHub issue rockstor#2370 we recently
removed the trailing slash for post calls on tasks. Adjust task unit
tests accordingly.
- minor existing fixture update to be compatible with newer auth arrangement via
independent fixture.
- del redundant/legacy fixture/inheritance - multiple tests.
- Addition on now independent test_api.json auth feature.
- Black formatting.
- del redundant/legacy fixture/inheritance - test_pool_balance.
- Remove redundant fixtures and their references.
- Addition on now independent test_api.json auth feature.
- Add test run command.
- Addition instructions on fixture content and creation.
- Removing numerous now incompatible db object mocking as we now have working fixtures.
- Improve test_api.py re setUpClass/tearDownClass supers rockstor#2382
Thanks to FroggyFlox on Github for follow-up work in this area.
- Restore previously remarked out, existing snapshot delete test.
- move smart run_test mock down to system - test_disk_smart.py.
Thanks to FroggyFlox on GitHub. Our initial mock was failing, covered up by as yet
only local testing. Moving the mock to the source of its definition resolves a failed
mock.
- Reviving a number of previously unworkable tests.
- Improving test group names for clarity.
- Test re-ordering for clarity.
- Breaking out more tests into their own sets rather than repeat for all raid levels.
- Improved/simplified mocking.
- add todo, debug logging, and comments to pool.py concerning issue rockstor#2384
- Simplify mocking of pool_usage in line with recent tested code
changes.
  • Loading branch information
phillxnet committed Jun 29, 2022
1 parent e0b03a6 commit 976871e
Show file tree
Hide file tree
Showing 42 changed files with 3,575 additions and 56,347 deletions.
51 changes: 0 additions & 51 deletions src/rockstor/smart_manager/fixtures/scheduled_tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,6 @@
"model": "auth.user",
"pk": 1
},
{
"fields": {
"pqgroup_rusage": 16,
"group": "root",
"name": "home",
"perms": "755",
"pqgroup": "2015/1",
"eusage": 16,
"uuid": null,
"pqgroup_eusage": 16,
"compression_algo": null,
"owner": "root",
"replica": false,
"qgroup": "0/257",
"toc": "2019-07-30T17:27:39.474Z",
"subvol_name": "home",
"rusage": 16,
"pool": 1,
"size": 7035904
},
"model": "storageadmin.share",
"pk": 1
},
{
"fields": {
"pqgroup_rusage": 16,
Expand All @@ -63,34 +40,6 @@
"model": "storageadmin.share",
"pk": 4
},
{
"fields": {
"raid": "single",
"compression": "no",
"uuid": "cc05c31d-6a89-47cd-bbba-c8f4419d9a9b",
"name": "rockstor_rockstor",
"mnt_options": null,
"role": "root",
"toc": "2019-07-30T17:27:39.257Z",
"size": 7035904
},
"model": "storageadmin.pool",
"pk": 1
},
{
"fields": {
"raid": "single",
"compression": "no",
"uuid": "56395eae-ab39-4649-85d4-072847eb56a2",
"name": "main_pool",
"mnt_options": null,
"role": null,
"toc": "2019-07-30T17:27:39.276Z",
"size": 5242880
},
"model": "storageadmin.pool",
"pk": 2
},
{
"fields": {
"raid": "single",
Expand Down
31 changes: 0 additions & 31 deletions src/rockstor/smart_manager/fixtures/services.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,36 +124,5 @@
"display_name": "NUT-UPS",
"name": "nut"
}
},
{
"pk": 1,
"model": "auth.user",
"fields": {
"username": "admin",
"first_name": "",
"last_name": "",
"is_active": true,
"is_superuser": false,
"is_staff": false,
"last_login": "2014-11-05T14:19:15.421Z",
"groups": [],
"user_permissions": [],
"password": "pbkdf2_sha256$12000$bIlTp3bZu4if$HhIMeQVPN/0NJz0NtrVj7ib8h+xHZkUT/md5DaPlq6A=",
"email": "",
"date_joined": "2014-11-05T14:19:13.535Z"
}
},
{
"pk": 1,
"model": "oauth2_provider.application",
"fields": {
"redirect_uris": "",
"name": "cliapp",
"client_type": "confidential",
"user": 1,
"client_id": "y5s_6Ge1yP.xUacU_U9_;t.bdAosyX43a2Of.kdH",
"client_secret": "wIsVYk0=14O?JylV.Y7p2lcOnIeWmC_lZEuKy@[email protected]=ttbOzG-e;U:qlkpx-:Vr3-l-Gh1ab2nkukMRkst01EsvBL-5Ld_jw6I-K",
"authorization_grant_type": "client-credentials"
}
}
]
149 changes: 87 additions & 62 deletions src/rockstor/smart_manager/tests/test_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@

class SNMPTests(APITestCase):
multi_db = True
fixtures = ['services.json']
BASE_URL = '/api/sm/services/snmpd'
# TODO Requires command to reproduce minimal fixture:
# "services.json" fixture requires only the smart_manager.service model.
fixtures = ["test_api.json", "services.json"]
BASE_URL = "/api/sm/services/snmpd"

def session_login(self):
self.client.login(username='admin', password='admin')
self.client.login(username="admin", password="admin")

def test_snmp_0(self):
"""
Expand All @@ -39,105 +41,128 @@ def test_snmp_0_1(self):
"""
config happy path
"""
config = {'syslocation': 'Rockstor Labs',
'syscontact': '[email protected]',
'rocommunity': 'public',
'aux': (), }
data = {'config': config, }
config = {
"syslocation": "Rockstor Labs",
"syscontact": "[email protected]",
"rocommunity": "public",
"aux": (),
}
data = {"config": config}
self.session_login()
response = self.client.post('%s/config' % self.BASE_URL, data=data)
self.assertEqual(response.status_code, status.HTTP_200_OK,
msg=response.content)
response = self.client.post("%s/config" % self.BASE_URL, data=data)
self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.content)

def test_snmp_1(self):
"""
config without input
"""
self.session_login()
response = self.client.post('%s/config' % self.BASE_URL)
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content)
response = self.client.post("%s/config" % self.BASE_URL)
self.assertEqual(
response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content,
)

def test_snmp_2(self):
"""
config without syslocation
"""
config = {'syscontact': '[email protected]',
'rocommunity': 'public',
'aux': (), }
data = {'config': config, }
config = {
"syscontact": "[email protected]",
"rocommunity": "public",
"aux": (),
}
data = {"config": config}
self.session_login()
response = self.client.post('%s/config' % self.BASE_URL, data=data)
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content)
response = self.client.post("%s/config" % self.BASE_URL, data=data)
self.assertEqual(
response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content,
)

def test_snmp_3(self):
"""
config without syscontact
"""
config = {'syslocation': 'Rockstor Labs',
'rocommunity': 'public',
'aux': (), }
config = {"syslocation": "Rockstor Labs", "rocommunity": "public", "aux": ()}
self.session_login()
response = self.client.post('%s/config' % self.BASE_URL,
data={'config': config, })
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content)
response = self.client.post(
"%s/config" % self.BASE_URL, data={"config": config}
)
self.assertEqual(
response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content,
)

def test_snmp_4(self):
"""
config without rocommunity
"""
config = {'syslocation': 'Rockstor Labs',
'syscontact': '[email protected]',
'aux': (), }
config = {
"syslocation": "Rockstor Labs",
"syscontact": "[email protected]",
"aux": (),
}
self.session_login()
response = self.client.post('%s/config' % self.BASE_URL,
data={'config': config, })
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content)
response = self.client.post(
"%s/config" % self.BASE_URL, data={"config": config}
)
self.assertEqual(
response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content,
)

def test_snmp_5(self):
"""
config without aux
"""
config = {'syslocation': 'Rockstor Labs',
'syscontact': '[email protected]',
'rocommunity': 'public', }
config = {
"syslocation": "Rockstor Labs",
"syscontact": "[email protected]",
"rocommunity": "public",
}
self.session_login()
response = self.client.post('%s/config' % self.BASE_URL,
data={'config': config, })
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content)
response = self.client.post(
"%s/config" % self.BASE_URL, data={"config": config}
)
self.assertEqual(
response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content,
)

def test_snmp_6(self):
"""
config with wrong aux type
"""
config = {'syslocation': 'Rockstor Labs',
'syscontact': '[email protected]',
'rocommunity': 'public',
'aux': 'foo', }
config = {
"syslocation": "Rockstor Labs",
"syscontact": "[email protected]",
"rocommunity": "public",
"aux": "foo",
}
self.session_login()
response = self.client.post('%s/config' % self.BASE_URL,
data={'config': config, })
self.assertEqual(response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content)
response = self.client.post(
"%s/config" % self.BASE_URL, data={"config": config}
)
self.assertEqual(
response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
msg=response.content,
)

def test_snmp_7(self):
"""
start/stop tests
"""
self.session_login()
response = self.client.post('%s/start' % self.BASE_URL)
self.assertEqual(response.status_code, status.HTTP_200_OK,
msg=response.content)
response2 = self.client.post('%s/stop' % self.BASE_URL)
self.assertEqual(response2.status_code, status.HTTP_200_OK,
msg=response.content)
response = self.client.post("%s/start" % self.BASE_URL)
self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.content)
response2 = self.client.post("%s/stop" % self.BASE_URL)
self.assertEqual(
response2.status_code, status.HTTP_200_OK, msg=response.content
)
23 changes: 20 additions & 3 deletions src/rockstor/smart_manager/tests/test_task_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@


class TaskSchedulerTests(APITestCase):
# Fixture needs to contain
# auth.user matching our session_login() credentials
# storageadmin.pool containing a pool for a scrub task to be defined against.
# storageadmin.share containing a share to accommodate a snapshot task against.
# smart_manager.taskdefinition containing:
# - scrub task (against the fixture defined pool)
# - snapshot task (against the fixture defined share id (on the fixture pool))
# - reboot task
# - shutdown task
# - suspend task
#
# TODO Untested fixture creation command.
# bin/django dumpdata auth.user storageadmin.pool storageadmin.share
# smart_manager.taskdefinition --natural-foreign --indent 4 >
# src/rockstor/storageadmin/fixtures/test_pool_scrub_balance_minimal.json
#
# ./bin/test -v 2 -p test_task_scheduler.py
multi_db = True
fixtures = ["scheduled_tasks.json"]
BASE_URL = "/api/sm/tasks"
Expand Down Expand Up @@ -96,7 +113,7 @@ def test_post_valid(self):
]
self.session_login()
for data in datalist:
response = self.client.post("{}/".format(self.BASE_URL), data=data)
response = self.client.post("{}".format(self.BASE_URL), data=data)
self.assertEqual(
response.status_code, status.HTTP_200_OK, msg=response.content
)
Expand All @@ -116,7 +133,7 @@ def test_post_name_exists(self):
}

self.session_login()
response = self.client.post("{}/".format(self.BASE_URL), data=data)
response = self.client.post("{}".format(self.BASE_URL), data=data)
self.assertEqual(
response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
Expand All @@ -138,7 +155,7 @@ def test_post_invalid_type(self):
}

self.session_login()
response = self.client.post("{}/".format(self.BASE_URL), data=data)
response = self.client.post("{}".format(self.BASE_URL), data=data)
self.assertEqual(
response.status_code,
status.HTTP_500_INTERNAL_SERVER_ERROR,
Expand Down
Loading

0 comments on commit 976871e

Please sign in to comment.