From 8b58c7296ae394772dab82fbb76469722798cc29 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Wed, 25 Aug 2010 16:37:22 -0500 Subject: Moved API tests into a sub-folder of the tests/ and added a stubbed-out test declarations to mirror existing API tickets --- nova/api/test.py | 61 ------------------- nova/tests/api/__init__.py | 0 nova/tests/api/rackspace/__init__.py | 0 nova/tests/api/rackspace/flavors.py | 34 +++++++++++ nova/tests/api/rackspace/images.py | 42 +++++++++++++ nova/tests/api/rackspace/servers.py | 55 +++++++++++++++++ nova/tests/api/rackspace/sharedipgroups.py | 40 +++++++++++++ nova/tests/api/test.py | 59 ++++++++++++++++++ nova/tests/api/test_helper.py | 7 +++ nova/tests/api/wsgi_test.py | 96 ++++++++++++++++++++++++++++++ nova/wsgi_test.py | 96 ------------------------------ 11 files changed, 333 insertions(+), 157 deletions(-) delete mode 100644 nova/api/test.py create mode 100644 nova/tests/api/__init__.py create mode 100644 nova/tests/api/rackspace/__init__.py create mode 100644 nova/tests/api/rackspace/flavors.py create mode 100644 nova/tests/api/rackspace/images.py create mode 100644 nova/tests/api/rackspace/servers.py create mode 100644 nova/tests/api/rackspace/sharedipgroups.py create mode 100644 nova/tests/api/test.py create mode 100644 nova/tests/api/test_helper.py create mode 100644 nova/tests/api/wsgi_test.py delete mode 100644 nova/wsgi_test.py diff --git a/nova/api/test.py b/nova/api/test.py deleted file mode 100644 index 51b114b8e..000000000 --- a/nova/api/test.py +++ /dev/null @@ -1,61 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 OpenStack LLC. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Test for the root WSGI middleware for all API controllers. -""" - -import unittest - -import stubout -import webob -import webob.dec - -from nova import api - - -class Test(unittest.TestCase): - - def setUp(self): # pylint: disable-msg=C0103 - self.stubs = stubout.StubOutForTesting() - - def tearDown(self): # pylint: disable-msg=C0103 - self.stubs.UnsetAll() - - def test_rackspace(self): - self.stubs.Set(api.rackspace, 'API', APIStub) - result = webob.Request.blank('/v1.0/cloud').get_response(api.API()) - self.assertEqual(result.body, "/cloud") - - def test_ec2(self): - self.stubs.Set(api.ec2, 'API', APIStub) - result = webob.Request.blank('/ec2/cloud').get_response(api.API()) - self.assertEqual(result.body, "/cloud") - - def test_not_found(self): - self.stubs.Set(api.ec2, 'API', APIStub) - self.stubs.Set(api.rackspace, 'API', APIStub) - result = webob.Request.blank('/test/cloud').get_response(api.API()) - self.assertNotEqual(result.body, "/cloud") - - -class APIStub(object): - """Class to verify request and mark it was called.""" - - @webob.dec.wsgify - def __call__(self, req): - return req.path_info diff --git a/nova/tests/api/__init__.py b/nova/tests/api/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/nova/tests/api/rackspace/__init__.py b/nova/tests/api/rackspace/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/nova/tests/api/rackspace/flavors.py b/nova/tests/api/rackspace/flavors.py new file mode 100644 index 000000000..fb8ba94a5 --- /dev/null +++ b/nova/tests/api/rackspace/flavors.py @@ -0,0 +1,34 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest + +from nova.api.rackspace import flavors +from nova.tests.api.test_helper import * + +class FlavorsTest(unittest.TestCase): + def setUp(self): + self.stubs = stubout.StubOutForTesting() + + def tearDown(self): + self.stubs.UnsetAll() + + def test_get_flavor_list(self): + pass + + def test_get_flavor_by_id(self): + pass diff --git a/nova/tests/api/rackspace/images.py b/nova/tests/api/rackspace/images.py new file mode 100644 index 000000000..0e3a87051 --- /dev/null +++ b/nova/tests/api/rackspace/images.py @@ -0,0 +1,42 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest + +from nova.api.rackspace import images +from nova.tests.api.test_helper import * + +class ImagesTest(unittest.TestCase): + def setUp(self): + self.stubs = stubout.StubOutForTesting() + + def tearDown(self): + self.stubs.UnsetAll() + + def test_get_image_list(self): + pass + + def test_get_backup_schedule(self): + pass + + def test_delete_image(self): + pass + + def test_create_image(self): + pass + + diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py new file mode 100644 index 000000000..980e69b84 --- /dev/null +++ b/nova/tests/api/rackspace/servers.py @@ -0,0 +1,55 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest + +from nova.api.rackspace import servers +from nova.tests.api.test_helper import * + +class ServersTest(unittest.TestCase): + def setUp(self): + self.stubs = stubout.StubOutForTesting() + + def tearDown(self): + self.stubs.UnsetAll() + + def test_get_server_list(self): + pass + + def test_create_instance(self): + pass + + def test_get_server_by_id(self): + pass + + def test_get_server_details(self): + pass + + def test_get_server_ips(self): + pass + + def test_server_reboot(self): + pass + + def test_server_rebuild(self): + pass + + def test_server_resize(self): + pass + + def test_delete_server_instance(self): + pass diff --git a/nova/tests/api/rackspace/sharedipgroups.py b/nova/tests/api/rackspace/sharedipgroups.py new file mode 100644 index 000000000..b4b281db7 --- /dev/null +++ b/nova/tests/api/rackspace/sharedipgroups.py @@ -0,0 +1,40 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest + +from nova.api.rackspace import sharedipgroups +from nova.tests.api.test_helper import * + +class SharedIpGroupsTest(unittest.TestCase): + def setUp(self): + self.stubs = stubout.StubOutForTesting() + + def tearDown(self): + self.stubs.UnsetAll() + + def test_get_shared_ip_groups(self): + pass + + def test_create_shared_ip_group(self): + pass + + def test_delete_shared_ip_group(self): + pass + + + diff --git a/nova/tests/api/test.py b/nova/tests/api/test.py new file mode 100644 index 000000000..59c4adc3d --- /dev/null +++ b/nova/tests/api/test.py @@ -0,0 +1,59 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Test for the root WSGI middleware for all API controllers. +""" + +import unittest + +import stubout +import webob +import webob.dec + +from nova import api +from nova.tests.api.test_helper import * + +class Test(unittest.TestCase): + + def setUp(self): # pylint: disable-msg=C0103 + self.stubs = stubout.StubOutForTesting() + + def tearDown(self): # pylint: disable-msg=C0103 + self.stubs.UnsetAll() + + def test_rackspace(self): + self.stubs.Set(api.rackspace, 'API', APIStub) + result = webob.Request.blank('/v1.0/cloud').get_response(api.API()) + self.assertEqual(result.body, "/cloud") + + def test_ec2(self): + self.stubs.Set(api.ec2, 'API', APIStub) + result = webob.Request.blank('/ec2/cloud').get_response(api.API()) + self.assertEqual(result.body, "/cloud") + + def test_not_found(self): + self.stubs.Set(api.ec2, 'API', APIStub) + self.stubs.Set(api.rackspace, 'API', APIStub) + result = webob.Request.blank('/test/cloud').get_response(api.API()) + self.assertNotEqual(result.body, "/cloud") + + def test_query_api_version(self): + pass + +if __name__ == '__main__': + unittest.main() diff --git a/nova/tests/api/test_helper.py b/nova/tests/api/test_helper.py new file mode 100644 index 000000000..8151a4af6 --- /dev/null +++ b/nova/tests/api/test_helper.py @@ -0,0 +1,7 @@ +import webob.dec + +class APIStub(object): + """Class to verify request and mark it was called.""" + @webob.dec.wsgify + def __call__(self, req): + return req.path_info diff --git a/nova/tests/api/wsgi_test.py b/nova/tests/api/wsgi_test.py new file mode 100644 index 000000000..786dc1bce --- /dev/null +++ b/nova/tests/api/wsgi_test.py @@ -0,0 +1,96 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# Copyright 2010 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Test WSGI basics and provide some helper functions for other WSGI tests. +""" + +import unittest + +import routes +import webob + +from nova import wsgi + + +class Test(unittest.TestCase): + + def test_debug(self): + + class Application(wsgi.Application): + """Dummy application to test debug.""" + + def __call__(self, environ, start_response): + start_response("200", [("X-Test", "checking")]) + return ['Test result'] + + application = wsgi.Debug(Application()) + result = webob.Request.blank('/').get_response(application) + self.assertEqual(result.body, "Test result") + + def test_router(self): + + class Application(wsgi.Application): + """Test application to call from router.""" + + def __call__(self, environ, start_response): + start_response("200", []) + return ['Router result'] + + class Router(wsgi.Router): + """Test router.""" + + def __init__(self): + mapper = routes.Mapper() + mapper.connect("/test", controller=Application()) + super(Router, self).__init__(mapper) + + result = webob.Request.blank('/test').get_response(Router()) + self.assertEqual(result.body, "Router result") + result = webob.Request.blank('/bad').get_response(Router()) + self.assertNotEqual(result.body, "Router result") + + def test_controller(self): + + class Controller(wsgi.Controller): + """Test controller to call from router.""" + test = self + + def show(self, req, id): # pylint: disable-msg=W0622,C0103 + """Default action called for requests with an ID.""" + self.test.assertEqual(req.path_info, '/tests/123') + self.test.assertEqual(id, '123') + return id + + class Router(wsgi.Router): + """Test router.""" + + def __init__(self): + mapper = routes.Mapper() + mapper.resource("test", "tests", controller=Controller()) + super(Router, self).__init__(mapper) + + result = webob.Request.blank('/tests/123').get_response(Router()) + self.assertEqual(result.body, "123") + result = webob.Request.blank('/test/123').get_response(Router()) + self.assertNotEqual(result.body, "123") + + def test_serializer(self): + # TODO(eday): Placeholder for serializer testing. + pass diff --git a/nova/wsgi_test.py b/nova/wsgi_test.py deleted file mode 100644 index 786dc1bce..000000000 --- a/nova/wsgi_test.py +++ /dev/null @@ -1,96 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# Copyright 2010 OpenStack LLC. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Test WSGI basics and provide some helper functions for other WSGI tests. -""" - -import unittest - -import routes -import webob - -from nova import wsgi - - -class Test(unittest.TestCase): - - def test_debug(self): - - class Application(wsgi.Application): - """Dummy application to test debug.""" - - def __call__(self, environ, start_response): - start_response("200", [("X-Test", "checking")]) - return ['Test result'] - - application = wsgi.Debug(Application()) - result = webob.Request.blank('/').get_response(application) - self.assertEqual(result.body, "Test result") - - def test_router(self): - - class Application(wsgi.Application): - """Test application to call from router.""" - - def __call__(self, environ, start_response): - start_response("200", []) - return ['Router result'] - - class Router(wsgi.Router): - """Test router.""" - - def __init__(self): - mapper = routes.Mapper() - mapper.connect("/test", controller=Application()) - super(Router, self).__init__(mapper) - - result = webob.Request.blank('/test').get_response(Router()) - self.assertEqual(result.body, "Router result") - result = webob.Request.blank('/bad').get_response(Router()) - self.assertNotEqual(result.body, "Router result") - - def test_controller(self): - - class Controller(wsgi.Controller): - """Test controller to call from router.""" - test = self - - def show(self, req, id): # pylint: disable-msg=W0622,C0103 - """Default action called for requests with an ID.""" - self.test.assertEqual(req.path_info, '/tests/123') - self.test.assertEqual(id, '123') - return id - - class Router(wsgi.Router): - """Test router.""" - - def __init__(self): - mapper = routes.Mapper() - mapper.resource("test", "tests", controller=Controller()) - super(Router, self).__init__(mapper) - - result = webob.Request.blank('/tests/123').get_response(Router()) - self.assertEqual(result.body, "123") - result = webob.Request.blank('/test/123').get_response(Router()) - self.assertNotEqual(result.body, "123") - - def test_serializer(self): - # TODO(eday): Placeholder for serializer testing. - pass -- cgit From 0d20ee4894f5f8566b00f7a28fabc630ca3195aa Mon Sep 17 00:00:00 2001 From: Cerberus Date: Thu, 26 Aug 2010 13:38:29 -0500 Subject: Renamed test.py and moved a test as per merge proposal feedback --- nova/tests/api/__init__.py | 59 +++++++++++++++++++++++++++++++++++++ nova/tests/api/rackspace/servers.py | 3 ++ nova/tests/api/test.py | 59 ------------------------------------- 3 files changed, 62 insertions(+), 59 deletions(-) delete mode 100644 nova/tests/api/test.py diff --git a/nova/tests/api/__init__.py b/nova/tests/api/__init__.py index e69de29bb..59c4adc3d 100644 --- a/nova/tests/api/__init__.py +++ b/nova/tests/api/__init__.py @@ -0,0 +1,59 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Test for the root WSGI middleware for all API controllers. +""" + +import unittest + +import stubout +import webob +import webob.dec + +from nova import api +from nova.tests.api.test_helper import * + +class Test(unittest.TestCase): + + def setUp(self): # pylint: disable-msg=C0103 + self.stubs = stubout.StubOutForTesting() + + def tearDown(self): # pylint: disable-msg=C0103 + self.stubs.UnsetAll() + + def test_rackspace(self): + self.stubs.Set(api.rackspace, 'API', APIStub) + result = webob.Request.blank('/v1.0/cloud').get_response(api.API()) + self.assertEqual(result.body, "/cloud") + + def test_ec2(self): + self.stubs.Set(api.ec2, 'API', APIStub) + result = webob.Request.blank('/ec2/cloud').get_response(api.API()) + self.assertEqual(result.body, "/cloud") + + def test_not_found(self): + self.stubs.Set(api.ec2, 'API', APIStub) + self.stubs.Set(api.rackspace, 'API', APIStub) + result = webob.Request.blank('/test/cloud').get_response(api.API()) + self.assertNotEqual(result.body, "/cloud") + + def test_query_api_version(self): + pass + +if __name__ == '__main__': + unittest.main() diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py index 980e69b84..6d628e78a 100644 --- a/nova/tests/api/rackspace/servers.py +++ b/nova/tests/api/rackspace/servers.py @@ -36,6 +36,9 @@ class ServersTest(unittest.TestCase): def test_get_server_by_id(self): pass + def test_get_backup_schedule(self): + pass + def test_get_server_details(self): pass diff --git a/nova/tests/api/test.py b/nova/tests/api/test.py deleted file mode 100644 index 59c4adc3d..000000000 --- a/nova/tests/api/test.py +++ /dev/null @@ -1,59 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 OpenStack LLC. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Test for the root WSGI middleware for all API controllers. -""" - -import unittest - -import stubout -import webob -import webob.dec - -from nova import api -from nova.tests.api.test_helper import * - -class Test(unittest.TestCase): - - def setUp(self): # pylint: disable-msg=C0103 - self.stubs = stubout.StubOutForTesting() - - def tearDown(self): # pylint: disable-msg=C0103 - self.stubs.UnsetAll() - - def test_rackspace(self): - self.stubs.Set(api.rackspace, 'API', APIStub) - result = webob.Request.blank('/v1.0/cloud').get_response(api.API()) - self.assertEqual(result.body, "/cloud") - - def test_ec2(self): - self.stubs.Set(api.ec2, 'API', APIStub) - result = webob.Request.blank('/ec2/cloud').get_response(api.API()) - self.assertEqual(result.body, "/cloud") - - def test_not_found(self): - self.stubs.Set(api.ec2, 'API', APIStub) - self.stubs.Set(api.rackspace, 'API', APIStub) - result = webob.Request.blank('/test/cloud').get_response(api.API()) - self.assertNotEqual(result.body, "/cloud") - - def test_query_api_version(self): - pass - -if __name__ == '__main__': - unittest.main() -- cgit From 58e1886113e6408d502d095d382a250d33fa0195 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Fri, 27 Aug 2010 20:17:30 +0200 Subject: Create console.log ahead of time. This ensures that the user running nova-compute maintains read privileges. --- nova/virt/libvirt_conn.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 524646ee5..ee8efde7f 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -23,7 +23,7 @@ A connection to a hypervisor (e.g. KVM) through libvirt. import json import logging -import os.path +import os import shutil from twisted.internet import defer @@ -218,6 +218,8 @@ class LibvirtConnection(object): f.write(libvirt_xml) f.close() + os.close(os.open(basepath('console.log'), os.O_CREAT | os.O_WRONLY, 0660)) + user = manager.AuthManager().get_user(data['user_id']) project = manager.AuthManager().get_project(data['project_id']) if not os.path.exists(basepath('disk')): -- cgit From c6100bb1b16722807a583eae2312c4d6653e5643 Mon Sep 17 00:00:00 2001 From: Cerberus Date: Mon, 30 Aug 2010 14:04:47 -0500 Subject: Removed get_backup_schedules from the image test --- nova/tests/api/rackspace/images.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/nova/tests/api/rackspace/images.py b/nova/tests/api/rackspace/images.py index 0e3a87051..560d8c898 100644 --- a/nova/tests/api/rackspace/images.py +++ b/nova/tests/api/rackspace/images.py @@ -30,9 +30,6 @@ class ImagesTest(unittest.TestCase): def test_get_image_list(self): pass - def test_get_backup_schedule(self): - pass - def test_delete_image(self): pass -- cgit From 921d9d01d731f2fda05c73775606f87b3be9aba6 Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Tue, 31 Aug 2010 21:17:48 +0200 Subject: Better log formatter for Nova. It's just like gnuchangelog, but logs the author rather than the committer. --- bzrplugins/novalog/__init__.py | 59 ++++++++++++++++++++++++++++++++++++++++++ setup.py | 6 +++-- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 bzrplugins/novalog/__init__.py diff --git a/bzrplugins/novalog/__init__.py b/bzrplugins/novalog/__init__.py new file mode 100644 index 000000000..e16b2e00f --- /dev/null +++ b/bzrplugins/novalog/__init__.py @@ -0,0 +1,59 @@ +# Copyright 2010 OpenStack LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Log format for Nova's changelog.""" + +import bzrlib.log +from bzrlib.osutils import format_date + +# +# This is mostly stolen from bzrlib.log.GnuChangelogLogFormatter +# The difference is that it logs the author rather than the committer +# which for Nova always is Tarmac. +# +class NovaLogFormat(bzrlib.log.GnuChangelogLogFormatter): + preferred_levels = 1 + def log_revision(self, revision): + """Log a revision, either merged or not.""" + to_file = self.to_file + + date_str = format_date(revision.rev.timestamp, + revision.rev.timezone or 0, + self.show_timezone, + date_fmt='%Y-%m-%d', + show_offset=False) + + authors = revision.rev.get_apparent_authors() + to_file.write('%s %s\n\n' % (date_str, ", ".join(authors))) + + if revision.delta is not None and revision.delta.has_changed(): + for c in revision.delta.added + revision.delta.removed + revision.delta.modified: + path, = c[:1] + to_file.write('\t* %s:\n' % (path,)) + for c in revision.delta.renamed: + oldpath,newpath = c[:2] + # For renamed files, show both the old and the new path + to_file.write('\t* %s:\n\t* %s:\n' % (oldpath,newpath)) + to_file.write('\n') + + if not revision.rev.message: + to_file.write('\tNo commit message\n') + else: + message = revision.rev.message.rstrip('\r\n') + for l in message.split('\n'): + to_file.write('\t%s\n' % (l.lstrip(),)) + to_file.write('\n') + +bzrlib.log.register_formatter('novalog', NovaLogFormat) + diff --git a/setup.py b/setup.py index 0fd286f7d..ca23efd7b 100644 --- a/setup.py +++ b/setup.py @@ -29,8 +29,10 @@ class local_sdist(sdist): def run(self): if os.path.isdir('.bzr'): # We're in a bzr branch - log_cmd = subprocess.Popen(["bzr", "log", "--gnu"], - stdout=subprocess.PIPE) + env = os.environ.copy() + env['BZR_PLUGIN_PATH'] = os.path.abspath('./bzrplugins') + log_cmd = subprocess.Popen(["bzr", "log", "--novalog"], + stdout=subprocess.PIPE, env=env) changelog = log_cmd.communicate()[0] with open("ChangeLog", "w") as changelog_file: changelog_file.write(changelog) -- cgit From 7595f752137d13449b4cde5680e722582a36c1de Mon Sep 17 00:00:00 2001 From: Michael Gundlach Date: Wed, 1 Sep 2010 16:27:46 -0400 Subject: Abstractified generalization mechanism --- nova/wsgi.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/nova/wsgi.py b/nova/wsgi.py index bec0a7b1c..543ecb71e 100644 --- a/nova/wsgi.py +++ b/nova/wsgi.py @@ -241,6 +241,9 @@ class Serializer(object): """ self.environ = environ self.metadata = metadata or {} + self._methods = { + 'application/json', self._to_json, + 'application/xml', self._to_xml} def to_content_type(self, data): """ @@ -250,20 +253,20 @@ class Serializer(object): """ mimetype = 'application/xml' # TODO(gundlach): determine mimetype from request - - if mimetype == 'application/json': - import json - return json.dumps(data) - elif mimetype == 'application/xml': - metadata = self.metadata.get('application/xml', {}) - # We expect data to contain a single key which is the XML root. - root_key = data.keys()[0] - from xml.dom import minidom - doc = minidom.Document() - node = self._to_xml_node(doc, metadata, root_key, data[root_key]) - return node.toprettyxml(indent=' ') - else: - return repr(data) + return self._methods.get(mimetype, repr)(data) + + def _to_json(self, data): + import json + return json.dumps(data) + + def _to_xml(self, data): + metadata = self.metadata.get('application/xml', {}) + # We expect data to contain a single key which is the XML root. + root_key = data.keys()[0] + from xml.dom import minidom + doc = minidom.Document() + node = self._to_xml_node(doc, metadata, root_key, data[root_key]) + return node.toprettyxml(indent=' ') def _to_xml_node(self, doc, metadata, nodename, data): """Recursive method to convert data members to XML nodes.""" -- cgit From 89d8fb48628b6ff72a6baff1dca8772d0a7587f8 Mon Sep 17 00:00:00 2001 From: Michael Gundlach Date: Wed, 1 Sep 2010 17:53:39 -0400 Subject: Nurrr --- nova/wsgi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/wsgi.py b/nova/wsgi.py index 543ecb71e..8a4e2a9f4 100644 --- a/nova/wsgi.py +++ b/nova/wsgi.py @@ -242,8 +242,8 @@ class Serializer(object): self.environ = environ self.metadata = metadata or {} self._methods = { - 'application/json', self._to_json, - 'application/xml', self._to_xml} + 'application/json': self._to_json, + 'application/xml': self._to_xml} def to_content_type(self, data): """ -- cgit