Merge "tests crud security report and task"
This commit is contained in:
commit
9d4acbad9e
|
@ -38,6 +38,50 @@ class ReportTestsV1(base.TestCase):
|
|||
self.security_client._version + '/security_reports')
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
def test_create_get_delete_report(self):
|
||||
|
||||
# Create a task to get security report from test_plugin
|
||||
plugin_id = None
|
||||
resp, body = self.security_client.get(
|
||||
self.security_client._version + '/plugins',
|
||||
)
|
||||
plugins = json.loads(body).get('plugins', None)
|
||||
if plugins is not None:
|
||||
for plugin in plugins:
|
||||
if (plugin.get('name', None) ==
|
||||
'cerberus.plugins.test_plugin.TestPlugin'):
|
||||
plugin_id = plugin.get('uuid', None)
|
||||
|
||||
self.assertIsNotNone(plugin_id,
|
||||
message='cerberus.plugins.test_plugin.TestPlugin '
|
||||
'must exist and have an id')
|
||||
task = {
|
||||
"name": "test_create_get_delete_report",
|
||||
"method": "get_security_reports",
|
||||
"plugin_id": plugin_id,
|
||||
"type": "unique"
|
||||
}
|
||||
headers = {'content-type': 'application/json'}
|
||||
resp, body = self.security_client.post(
|
||||
self.security_client._version + '/tasks', json.dumps(task),
|
||||
headers=headers)
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
# Check if security report has been stored in db and delete it
|
||||
report_id = 'test_plugin_report_id'
|
||||
resp, body = self.security_client.get(
|
||||
self.security_client._version + '/security_reports/' + report_id)
|
||||
report = json.loads(body)
|
||||
self.assertEqual('a1d869a1-6ab0-4f02-9e56-f83034bacfcb',
|
||||
report['component_id'])
|
||||
self.assertEqual(200, resp.status)
|
||||
|
||||
# Delete security report
|
||||
resp, body = self.security_client.delete(
|
||||
self.security_client._version + '/security_reports/' + report_id)
|
||||
|
||||
self.assertEqual(204, resp.status)
|
||||
|
||||
|
||||
class TaskTestsV1(base.TestCase):
|
||||
|
||||
|
@ -111,6 +155,74 @@ class TaskTestsV1(base.TestCase):
|
|||
)
|
||||
self.assertEqual(204, resp.status)
|
||||
|
||||
def test_create_get_stop_delete_recurrent_task_persistent(self):
|
||||
|
||||
# Get test_plugin
|
||||
plugin_id = None
|
||||
resp, body = self.security_client.get(
|
||||
self.security_client._version + '/plugins',
|
||||
)
|
||||
plugins = json.loads(body).get('plugins', None)
|
||||
if plugins is not None:
|
||||
for plugin in plugins:
|
||||
if (plugin.get('name', None) ==
|
||||
'cerberus.plugins.test_plugin.TestPlugin'):
|
||||
plugin_id = plugin.get('uuid', None)
|
||||
|
||||
self.assertIsNotNone(plugin_id,
|
||||
message='cerberus.plugins.test_plugin.TestPlugin '
|
||||
'must exist and have an id')
|
||||
|
||||
# create the task
|
||||
task = {
|
||||
'name': 'recurrent_persistent_task',
|
||||
'method': 'act_short',
|
||||
'plugin_id': plugin_id,
|
||||
'type': 'recurrent',
|
||||
'period': 3,
|
||||
'persistent': 'True'
|
||||
}
|
||||
headers = {'content-type': 'application/json'}
|
||||
resp, body = self.security_client.post(
|
||||
self.security_client._version + '/tasks', json.dumps(task),
|
||||
headers=headers)
|
||||
task_id = json.loads(body).get('id', None)
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertIsNotNone(task_id)
|
||||
|
||||
# Get the task through API
|
||||
resp, body = self.security_client.get(
|
||||
self.security_client._version + '/tasks/' + task_id,
|
||||
headers=headers)
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(task_id, json.loads(body)['id'])
|
||||
self.assertEqual('True', json.loads(body)['persistent'])
|
||||
self.assertEqual('recurrent', json.loads(body)['type'])
|
||||
self.assertEqual('running', json.loads(body)['state'])
|
||||
self.assertEqual(3, json.loads(body)['period'])
|
||||
|
||||
# Stop the task
|
||||
resp, body = self.security_client.post(
|
||||
self.security_client._version + '/tasks/' + task_id +
|
||||
'/action/stop', json.dumps({}), headers=headers)
|
||||
self.assertEqual(204, resp.status)
|
||||
|
||||
resp, body = self.security_client.get(
|
||||
self.security_client._version + '/tasks/' + task_id,
|
||||
headers=headers)
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual(task_id, json.loads(body)['id'])
|
||||
self.assertEqual('True', json.loads(body)['persistent'])
|
||||
self.assertEqual('recurrent', json.loads(body)['type'])
|
||||
self.assertEqual('stopped', json.loads(body)['state'])
|
||||
self.assertEqual(3, json.loads(body)['period'])
|
||||
|
||||
# Delete the task
|
||||
resp, body = self.security_client.delete(
|
||||
self.security_client._version + '/tasks/' + task_id,
|
||||
)
|
||||
self.assertEqual(204, resp.status)
|
||||
|
||||
|
||||
class PluginTestsV1(base.TestCase):
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class NotificationTests(base.TestCase):
|
|||
_service = 'security'
|
||||
|
||||
@test.attr(type='gate')
|
||||
@test.services("image")
|
||||
def test_notification_image(self):
|
||||
|
||||
# Create image
|
||||
|
@ -63,6 +64,7 @@ class NotificationTests(base.TestCase):
|
|||
self.assertEqual(len(task_list_1.get('tasks', 0)) - 1,
|
||||
len(task_list_2.get('tasks', 0)))
|
||||
|
||||
@test.services("telemetry")
|
||||
def test_notifier(self):
|
||||
|
||||
# Create a task to get security report from test_plugin
|
||||
|
@ -87,10 +89,8 @@ class NotificationTests(base.TestCase):
|
|||
'security.security_report.store')
|
||||
samples_number = len(resp)
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
task = {
|
||||
"name": "get_security_reports_test_plugin",
|
||||
"name": "test_notifier",
|
||||
"method": "get_security_reports",
|
||||
"plugin_id": plugin_id,
|
||||
"type": "unique"
|
||||
|
@ -117,6 +117,7 @@ class NotificationTests(base.TestCase):
|
|||
self.assertEqual(204, resp.status)
|
||||
|
||||
# Check if a sample has been created in Ceilometer
|
||||
time.sleep(5)
|
||||
resp = self.mgr.telemetry_client.list_samples(
|
||||
'security.security_report.store')
|
||||
self.assertEqual(samples_number + 1, len(resp))
|
||||
|
|
Loading…
Reference in New Issue