diff --git a/etc/nova/policy.json b/etc/nova/policy.json index 2558b69e258c..5c3acd2ba3c9 100644 --- a/etc/nova/policy.json +++ b/etc/nova/policy.json @@ -87,6 +87,7 @@ "compute_extension:instance_actions": "", "compute_extension:instance_actions:events": "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:keypairs": "", "compute_extension:v3:os-keypairs:discoverable": "", diff --git a/nova/api/openstack/compute/plugins/v3/instance_usage_audit_log.py b/nova/api/openstack/compute/plugins/v3/instance_usage_audit_log.py index 3c3aa23c0b8d..d74c999153b7 100644 --- a/nova/api/openstack/compute/plugins/v3/instance_usage_audit_log.py +++ b/nova/api/openstack/compute/plugins/v3/instance_usage_audit_log.py @@ -28,9 +28,9 @@ from nova import utils CONF = cfg.CONF CONF.import_opt('compute_topic', 'nova.compute.rpcapi') - +ALIAS = "os-instance-usage-audit-log" authorize = extensions.extension_authorizer('compute', - 'instance_usage_audit_log') + 'v3:' + ALIAS) class InstanceUsageAuditLogController(object): @@ -41,7 +41,7 @@ class InstanceUsageAuditLogController(object): context = req.environ['nova.context'] authorize(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): context = req.environ['nova.context'] @@ -124,14 +124,19 @@ class InstanceUsageAuditLogController(object): log=log) -class Instance_usage_audit_log(extensions.ExtensionDescriptor): +class InstanceUsageAuditLog(extensions.V3APIExtensionBase): """Admin-only Task Log Monitoring.""" - name = "OSInstanceUsageAuditLog" - alias = "os-instance_usage_audit_log" - namespace = "http://docs.openstack.org/ext/services/api/v1.1" - updated = "2012-07-06T01:00:00+00:00" + name = "InstanceUsageAuditLog" + alias = ALIAS + namespace = "http://docs.openstack.org/ext/services/api/v3" + version = 1 def get_resources(self): - ext = extensions.ResourceExtension('os-instance_usage_audit_log', + ext = extensions.ResourceExtension(ALIAS, InstanceUsageAuditLogController()) return [ext] + + def get_controller_extensions(self): + """It's an abstract function V3APIExtensionBase and the extension + will not be loaded without it.""" + return [] diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_instance_usage_audit_log.py b/nova/tests/api/openstack/compute/plugins/v3/test_instance_usage_audit_log.py index 2b2fd1131e79..7c3543131fb7 100644 --- a/nova/tests/api/openstack/compute/plugins/v3/test_instance_usage_audit_log.py +++ b/nova/tests/api/openstack/compute/plugins/v3/test_instance_usage_audit_log.py @@ -15,7 +15,8 @@ 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 db from nova.openstack.common import timeutils @@ -118,7 +119,7 @@ class InstanceUsageAuditLogTest(test.TestCase): return TEST_COMPUTE_SERVICES 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', fake_service_get_all) self.stubs.Set(db, 'task_log_get_all', @@ -129,10 +130,10 @@ class InstanceUsageAuditLogTest(test.TestCase): timeutils.clear_time_override() 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) - self.assertIn('instance_usage_audit_logs', result) - logs = result['instance_usage_audit_logs'] + self.assertIn('instance_usage_audit_log', result) + logs = result['instance_usage_audit_log'] self.assertEquals(57, logs['total_instances']) self.assertEquals(0, logs['total_errors']) self.assertEquals(4, len(logs['log'])) @@ -143,8 +144,7 @@ class InstanceUsageAuditLogTest(test.TestCase): self.assertEquals("ALL hosts done. 0 errors.", logs['overall_status']) def test_show(self): - req = fakes.HTTPRequest.blank( - '/v2/fake/os-instance_usage_audit_log/show') + req = fakes.HTTPRequestV3.blank('/os-instance_usage_audit_log/show') result = self.controller.show(req, '2012-07-05 10:00:00') self.assertIn('instance_usage_audit_log', result) logs = result['instance_usage_audit_log'] @@ -158,8 +158,7 @@ class InstanceUsageAuditLogTest(test.TestCase): self.assertEquals("ALL hosts done. 0 errors.", logs['overall_status']) def test_show_with_running(self): - req = fakes.HTTPRequest.blank( - '/v2/fake/os-instance_usage_audit_log/show') + req = fakes.HTTPRequestV3.blank('/os-instance_usage_audit_log/show') result = self.controller.show(req, '2012-07-06 10:00:00') self.assertIn('instance_usage_audit_log', result) logs = result['instance_usage_audit_log'] @@ -174,8 +173,7 @@ class InstanceUsageAuditLogTest(test.TestCase): logs['overall_status']) def test_show_with_errors(self): - req = fakes.HTTPRequest.blank( - '/v2/fake/os-instance_usage_audit_log/show') + req = fakes.HTTPRequestV3.blank('/os-instance_usage_audit_log/show') result = self.controller.show(req, '2012-07-07 10:00:00') self.assertIn('instance_usage_audit_log', result) logs = result['instance_usage_audit_log'] diff --git a/nova/tests/fake_policy.py b/nova/tests/fake_policy.py index 94433b5ec605..3d7c57e1867f 100644 --- a/nova/tests/fake_policy.py +++ b/nova/tests/fake_policy.py @@ -164,6 +164,7 @@ policy_data = """ "compute_extension:instance_actions": "", "compute_extension:instance_actions:events": "is_admin:True", "compute_extension:instance_usage_audit_log": "", + "compute_extension:v3:os-instance-usage-audit-log": "", "compute_extension:keypairs": "", "compute_extension:v3:os-keypairs": "", "compute_extension:multinic": "", diff --git a/setup.cfg b/setup.cfg index 828f6736e5f8..ce5c9e830d62 100644 --- a/setup.cfg +++ b/setup.cfg @@ -69,6 +69,7 @@ nova.api.v3.extensions = hypervisors = nova.api.openstack.compute.plugins.v3.hypervisors:Hypervisors images = nova.api.openstack.compute.plugins.v3.images:Images 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 quota_sets = nova.api.openstack.compute.plugins.v3.quota_sets:QuotaSets rescue = nova.api.openstack.compute.plugins.v3.rescue:Rescue