api-ref: Improve os-instance_usage_audit_log samples
Improve api samples for os-instance_usage_audit_log and fix a parameter. Change-Id: I8436a6ab0610e41d8c6c95c55a263fdfbbf58476 Implements: blueprint api-ref-in-rst
This commit is contained in:
parent
cdfa50599c
commit
a7cbc90fb1
@ -68,7 +68,7 @@ Response
|
||||
|
||||
.. rest_parameters:: parameters.yaml
|
||||
|
||||
- instance_usage_audit_logs: instance_usage_audit_logs
|
||||
- instance_usage_audit_log: instance_usage_audit_logs
|
||||
- hosts_not_run: host_not_run
|
||||
- log: instance_usage_audit_log
|
||||
- errors: errors
|
||||
|
@ -1,17 +1,36 @@
|
||||
{
|
||||
"instance_usage_audit_logs": {
|
||||
"hosts_not_run": [
|
||||
"f4eb7cfd155f4574967f8b55a7faed75"
|
||||
"samplehost3"
|
||||
],
|
||||
"log": {},
|
||||
"num_hosts": 1,
|
||||
"num_hosts_done": 0,
|
||||
"log": {
|
||||
"samplehost0": {
|
||||
"errors": 1,
|
||||
"instances": 1,
|
||||
"message": "Instance usage audit ran for host samplehost0, 1 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
},
|
||||
"samplehost1": {
|
||||
"errors": 1,
|
||||
"instances": 2,
|
||||
"message": "Instance usage audit ran for host samplehost1, 2 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
},
|
||||
"samplehost2": {
|
||||
"errors": 1,
|
||||
"instances": 3,
|
||||
"message": "Instance usage audit ran for host samplehost2, 3 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
}
|
||||
},
|
||||
"num_hosts": 4,
|
||||
"num_hosts_done": 3,
|
||||
"num_hosts_not_run": 1,
|
||||
"num_hosts_running": 0,
|
||||
"overall_status": "0 of 1 hosts done. 0 errors.",
|
||||
"period_beginning": "2012-12-01 00:00:00",
|
||||
"period_ending": "2013-01-01 00:00:00",
|
||||
"total_errors": 0,
|
||||
"total_instances": 0
|
||||
"overall_status": "3 of 4 hosts done. 3 errors.",
|
||||
"period_beginning": "2012-06-01 00:00:00",
|
||||
"period_ending": "2012-07-01 00:00:00",
|
||||
"total_errors": 3,
|
||||
"total_instances": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,36 @@
|
||||
{
|
||||
"instance_usage_audit_log": {
|
||||
"hosts_not_run": [
|
||||
"8e33da2b48684ef3ab165444d6a7384c"
|
||||
"samplehost3"
|
||||
],
|
||||
"log": {},
|
||||
"num_hosts": 1,
|
||||
"num_hosts_done": 0,
|
||||
"log": {
|
||||
"samplehost0": {
|
||||
"errors": 1,
|
||||
"instances": 1,
|
||||
"message": "Instance usage audit ran for host samplehost0, 1 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
},
|
||||
"samplehost1": {
|
||||
"errors": 1,
|
||||
"instances": 2,
|
||||
"message": "Instance usage audit ran for host samplehost1, 2 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
},
|
||||
"samplehost2": {
|
||||
"errors": 1,
|
||||
"instances": 3,
|
||||
"message": "Instance usage audit ran for host samplehost2, 3 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
}
|
||||
},
|
||||
"num_hosts": 4,
|
||||
"num_hosts_done": 3,
|
||||
"num_hosts_not_run": 1,
|
||||
"num_hosts_running": 0,
|
||||
"overall_status": "0 of 1 hosts done. 0 errors.",
|
||||
"overall_status": "3 of 4 hosts done. 3 errors.",
|
||||
"period_beginning": "2012-06-01 00:00:00",
|
||||
"period_ending": "2012-07-01 00:00:00",
|
||||
"total_errors": 0,
|
||||
"total_instances": 0
|
||||
"total_errors": 3,
|
||||
"total_instances": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,36 @@
|
||||
{
|
||||
"instance_usage_audit_logs": {
|
||||
"hosts_not_run": [
|
||||
"%(host_name)s"
|
||||
"samplehost3"
|
||||
],
|
||||
"log": {},
|
||||
"num_hosts": 1,
|
||||
"num_hosts_done": 0,
|
||||
"log": {
|
||||
"samplehost0": {
|
||||
"errors": 1,
|
||||
"instances": 1,
|
||||
"message": "Instance usage audit ran for host samplehost0, 1 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
},
|
||||
"samplehost1": {
|
||||
"errors": 1,
|
||||
"instances": 2,
|
||||
"message": "Instance usage audit ran for host samplehost1, 2 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
},
|
||||
"samplehost2": {
|
||||
"errors": 1,
|
||||
"instances": 3,
|
||||
"message": "Instance usage audit ran for host samplehost2, 3 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
}
|
||||
},
|
||||
"num_hosts": 4,
|
||||
"num_hosts_done": 3,
|
||||
"num_hosts_not_run": 1,
|
||||
"num_hosts_running": 0,
|
||||
"overall_status": "0 of 1 hosts done. 0 errors.",
|
||||
"period_beginning": "%(xmltime)s",
|
||||
"period_ending": "%(xmltime)s",
|
||||
"total_errors": 0,
|
||||
"total_instances": 0
|
||||
"overall_status": "3 of 4 hosts done. 3 errors.",
|
||||
"period_beginning": "2012-06-01 00:00:00",
|
||||
"period_ending": "2012-07-01 00:00:00",
|
||||
"total_errors": 3,
|
||||
"total_instances": 6
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,36 @@
|
||||
{
|
||||
"instance_usage_audit_log": {
|
||||
"hosts_not_run": [
|
||||
"%(host_name)s"
|
||||
"samplehost3"
|
||||
],
|
||||
"log": {},
|
||||
"num_hosts": 1,
|
||||
"num_hosts_done": 0,
|
||||
"log": {
|
||||
"samplehost0": {
|
||||
"errors": 1,
|
||||
"instances": 1,
|
||||
"message": "Instance usage audit ran for host samplehost0, 1 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
},
|
||||
"samplehost1": {
|
||||
"errors": 1,
|
||||
"instances": 2,
|
||||
"message": "Instance usage audit ran for host samplehost1, 2 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
},
|
||||
"samplehost2": {
|
||||
"errors": 1,
|
||||
"instances": 3,
|
||||
"message": "Instance usage audit ran for host samplehost2, 3 instances in 0.01 seconds.",
|
||||
"state": "DONE"
|
||||
}
|
||||
},
|
||||
"num_hosts": 4,
|
||||
"num_hosts_done": 3,
|
||||
"num_hosts_not_run": 1,
|
||||
"num_hosts_running": 0,
|
||||
"overall_status": "0 of 1 hosts done. 0 errors.",
|
||||
"period_beginning": "%(xmltime)s",
|
||||
"period_ending": "%(xmltime)s",
|
||||
"total_errors": 0,
|
||||
"total_instances": 0
|
||||
"overall_status": "3 of 4 hosts done. 3 errors.",
|
||||
"period_beginning": "2012-06-01 00:00:00",
|
||||
"period_ending": "2012-07-01 00:00:00",
|
||||
"total_errors": 3,
|
||||
"total_instances": 6
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from datetime import datetime
|
||||
from six.moves import urllib
|
||||
|
||||
from nova import context
|
||||
from nova import objects
|
||||
from nova.tests.functional.api_sample_tests import api_sample_base
|
||||
|
||||
|
||||
@ -22,6 +25,44 @@ class InstanceUsageAuditLogJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
||||
ADMIN_API = True
|
||||
sample_dir = "os-instance-usage-audit-log"
|
||||
|
||||
def setUp(self):
|
||||
super(InstanceUsageAuditLogJsonTest, self).setUp()
|
||||
|
||||
def fake_service_get_all(self, context,
|
||||
filters=None, set_zones=False):
|
||||
services = [objects.Service(host='samplehost0'),
|
||||
objects.Service(host='samplehost1'),
|
||||
objects.Service(host='samplehost2'),
|
||||
objects.Service(host='samplehost3')]
|
||||
return services
|
||||
|
||||
def fake_utcnow(with_timezone=False):
|
||||
# It is not UTC time, but no effect for testing
|
||||
return datetime(2012, 7, 3, 19, 36, 5, 0)
|
||||
|
||||
self.stub_out('oslo_utils.timeutils.utcnow',
|
||||
fake_utcnow)
|
||||
self.stub_out('nova.compute.api.HostAPI.service_get_all',
|
||||
fake_service_get_all)
|
||||
|
||||
for i in range(0, 3):
|
||||
self._create_task_log('samplehost%d' % i, i + 1)
|
||||
|
||||
def _create_task_log(self, host, num_instances):
|
||||
task_log = objects.TaskLog(context.get_admin_context())
|
||||
task_log.task_name = 'instance_usage_audit'
|
||||
task_log.period_beginning = '2012-06-01 00:00:00'
|
||||
task_log.period_ending = '2012-07-01 00:00:00'
|
||||
task_log.host = host
|
||||
task_log.task_items = num_instances
|
||||
task_log.message = (
|
||||
'Instance usage audit ran for host %s, %s '
|
||||
'instances in 0.01 seconds.'
|
||||
% (host, num_instances))
|
||||
task_log.begin_task()
|
||||
task_log.errors = 1
|
||||
task_log.end_task()
|
||||
|
||||
def test_show_instance_usage_audit_log(self):
|
||||
response = self._do_get('os-instance_usage_audit_log/%s' %
|
||||
urllib.parse.quote('2012-07-05 10:00:00'))
|
||||
|
Loading…
Reference in New Issue
Block a user