Merge "port Instance_usage_audit_log API into v3 part2"

This commit is contained in:
Jenkins 2013-07-08 21:09:07 +00:00 committed by Gerrit Code Review
commit e39e0c9299
5 changed files with 26 additions and 20 deletions

View File

@ -87,6 +87,7 @@
"compute_extension:instance_actions": "", "compute_extension:instance_actions": "",
"compute_extension:instance_actions:events": "rule:admin_api", "compute_extension:instance_actions:events": "rule:admin_api",
"compute_extension:instance_usage_audit_log": "rule:admin_api", "compute_extension:instance_usage_audit_log": "rule:admin_api",
"compute_extension:v3:os-instance-usage-audit-log": "rule:admin_api",
"compute_extension:v3:ips:discoverable": "", "compute_extension:v3:ips:discoverable": "",
"compute_extension:keypairs": "", "compute_extension:keypairs": "",
"compute_extension:v3:os-keypairs:discoverable": "", "compute_extension:v3:os-keypairs:discoverable": "",

View File

@ -28,9 +28,9 @@ from nova import utils
CONF = cfg.CONF CONF = cfg.CONF
CONF.import_opt('compute_topic', 'nova.compute.rpcapi') CONF.import_opt('compute_topic', 'nova.compute.rpcapi')
ALIAS = "os-instance-usage-audit-log"
authorize = extensions.extension_authorizer('compute', authorize = extensions.extension_authorizer('compute',
'instance_usage_audit_log') 'v3:' + ALIAS)
class InstanceUsageAuditLogController(object): class InstanceUsageAuditLogController(object):
@ -41,7 +41,7 @@ class InstanceUsageAuditLogController(object):
context = req.environ['nova.context'] context = req.environ['nova.context']
authorize(context) authorize(context)
task_log = self._get_audit_task_logs(context) task_log = self._get_audit_task_logs(context)
return {'instance_usage_audit_logs': task_log} return {'instance_usage_audit_log': task_log}
def show(self, req, id): def show(self, req, id):
context = req.environ['nova.context'] context = req.environ['nova.context']
@ -124,14 +124,19 @@ class InstanceUsageAuditLogController(object):
log=log) log=log)
class Instance_usage_audit_log(extensions.ExtensionDescriptor): class InstanceUsageAuditLog(extensions.V3APIExtensionBase):
"""Admin-only Task Log Monitoring.""" """Admin-only Task Log Monitoring."""
name = "OSInstanceUsageAuditLog" name = "InstanceUsageAuditLog"
alias = "os-instance_usage_audit_log" alias = ALIAS
namespace = "http://docs.openstack.org/ext/services/api/v1.1" namespace = "http://docs.openstack.org/ext/services/api/v3"
updated = "2012-07-06T01:00:00+00:00" version = 1
def get_resources(self): def get_resources(self):
ext = extensions.ResourceExtension('os-instance_usage_audit_log', ext = extensions.ResourceExtension(ALIAS,
InstanceUsageAuditLogController()) InstanceUsageAuditLogController())
return [ext] return [ext]
def get_controller_extensions(self):
"""It's an abstract function V3APIExtensionBase and the extension
will not be loaded without it."""
return []

View File

@ -15,7 +15,8 @@
import datetime import datetime
from nova.api.openstack.compute.contrib import instance_usage_audit_log as ial from nova.api.openstack.compute.plugins.v3 import \
instance_usage_audit_log as ial
from nova import context from nova import context
from nova import db from nova import db
from nova.openstack.common import timeutils from nova.openstack.common import timeutils
@ -118,7 +119,7 @@ class InstanceUsageAuditLogTest(test.TestCase):
return TEST_COMPUTE_SERVICES return TEST_COMPUTE_SERVICES
self.stubs.Set(utils, 'last_completed_audit_period', self.stubs.Set(utils, 'last_completed_audit_period',
fake_last_completed_audit_period) fake_last_completed_audit_period)
self.stubs.Set(db, 'service_get_all', self.stubs.Set(db, 'service_get_all',
fake_service_get_all) fake_service_get_all)
self.stubs.Set(db, 'task_log_get_all', self.stubs.Set(db, 'task_log_get_all',
@ -129,10 +130,10 @@ class InstanceUsageAuditLogTest(test.TestCase):
timeutils.clear_time_override() timeutils.clear_time_override()
def test_index(self): def test_index(self):
req = fakes.HTTPRequest.blank('/v2/fake/os-instance_usage_audit_log') req = fakes.HTTPRequestV3.blank('/os-instance_usage_audit_log')
result = self.controller.index(req) result = self.controller.index(req)
self.assertIn('instance_usage_audit_logs', result) self.assertIn('instance_usage_audit_log', result)
logs = result['instance_usage_audit_logs'] logs = result['instance_usage_audit_log']
self.assertEquals(57, logs['total_instances']) self.assertEquals(57, logs['total_instances'])
self.assertEquals(0, logs['total_errors']) self.assertEquals(0, logs['total_errors'])
self.assertEquals(4, len(logs['log'])) self.assertEquals(4, len(logs['log']))
@ -143,8 +144,7 @@ class InstanceUsageAuditLogTest(test.TestCase):
self.assertEquals("ALL hosts done. 0 errors.", logs['overall_status']) self.assertEquals("ALL hosts done. 0 errors.", logs['overall_status'])
def test_show(self): def test_show(self):
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequestV3.blank('/os-instance_usage_audit_log/show')
'/v2/fake/os-instance_usage_audit_log/show')
result = self.controller.show(req, '2012-07-05 10:00:00') result = self.controller.show(req, '2012-07-05 10:00:00')
self.assertIn('instance_usage_audit_log', result) self.assertIn('instance_usage_audit_log', result)
logs = result['instance_usage_audit_log'] logs = result['instance_usage_audit_log']
@ -158,8 +158,7 @@ class InstanceUsageAuditLogTest(test.TestCase):
self.assertEquals("ALL hosts done. 0 errors.", logs['overall_status']) self.assertEquals("ALL hosts done. 0 errors.", logs['overall_status'])
def test_show_with_running(self): def test_show_with_running(self):
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequestV3.blank('/os-instance_usage_audit_log/show')
'/v2/fake/os-instance_usage_audit_log/show')
result = self.controller.show(req, '2012-07-06 10:00:00') result = self.controller.show(req, '2012-07-06 10:00:00')
self.assertIn('instance_usage_audit_log', result) self.assertIn('instance_usage_audit_log', result)
logs = result['instance_usage_audit_log'] logs = result['instance_usage_audit_log']
@ -174,8 +173,7 @@ class InstanceUsageAuditLogTest(test.TestCase):
logs['overall_status']) logs['overall_status'])
def test_show_with_errors(self): def test_show_with_errors(self):
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequestV3.blank('/os-instance_usage_audit_log/show')
'/v2/fake/os-instance_usage_audit_log/show')
result = self.controller.show(req, '2012-07-07 10:00:00') result = self.controller.show(req, '2012-07-07 10:00:00')
self.assertIn('instance_usage_audit_log', result) self.assertIn('instance_usage_audit_log', result)
logs = result['instance_usage_audit_log'] logs = result['instance_usage_audit_log']

View File

@ -164,6 +164,7 @@ policy_data = """
"compute_extension:instance_actions": "", "compute_extension:instance_actions": "",
"compute_extension:instance_actions:events": "is_admin:True", "compute_extension:instance_actions:events": "is_admin:True",
"compute_extension:instance_usage_audit_log": "", "compute_extension:instance_usage_audit_log": "",
"compute_extension:v3:os-instance-usage-audit-log": "",
"compute_extension:keypairs": "", "compute_extension:keypairs": "",
"compute_extension:v3:os-keypairs": "", "compute_extension:v3:os-keypairs": "",
"compute_extension:multinic": "", "compute_extension:multinic": "",

View File

@ -69,6 +69,7 @@ nova.api.v3.extensions =
hypervisors = nova.api.openstack.compute.plugins.v3.hypervisors:Hypervisors hypervisors = nova.api.openstack.compute.plugins.v3.hypervisors:Hypervisors
images = nova.api.openstack.compute.plugins.v3.images:Images images = nova.api.openstack.compute.plugins.v3.images:Images
ips = nova.api.openstack.compute.plugins.v3.ips:IPs ips = nova.api.openstack.compute.plugins.v3.ips:IPs
instance_usage_audit_log = nova.api.openstack.compute.plugins.v3.instance_usage_audit_log:InstanceUsageAuditLog
keypairs = nova.api.openstack.compute.plugins.v3.keypairs:Keypairs keypairs = nova.api.openstack.compute.plugins.v3.keypairs:Keypairs
quota_sets = nova.api.openstack.compute.plugins.v3.quota_sets:QuotaSets quota_sets = nova.api.openstack.compute.plugins.v3.quota_sets:QuotaSets
rescue = nova.api.openstack.compute.plugins.v3.rescue:Rescue rescue = nova.api.openstack.compute.plugins.v3.rescue:Rescue