From adec6c4e21c1fa1e71df11b398b60449a5fde564 Mon Sep 17 00:00:00 2001 From: "paul@openstack.org" <> Date: Wed, 14 Sep 2011 12:10:33 -0500 Subject: [PATCH 01/11] exporting auth to keystone (users, projects/tenants, roles, credentials) --- bin/nova-manage | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/bin/nova-manage b/bin/nova-manage index 089b2eea..5f0c5471 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -61,6 +61,7 @@ import math import netaddr from optparse import OptionParser import os +import StringIO import sys import time @@ -274,6 +275,50 @@ class ShellCommands(object): arguments: path""" exec(compile(open(path).read(), path, 'exec'), locals(), globals()) + @args('--filename', dest='filename', metavar='', help='Export path') + def export(self, filename): + """Export Nova users into a file that can be consumed by Keystone""" + def create_file(filename): + data = generate_file() + with open(filename, 'w') as f: + f.write(data.getvalue()) + + def tenants(data, am): + for project in am.get_projects(): + print >> data, ("tenant add '%s'" % + (project.name)) + for u in project.member_ids: + user = am.get_user(u) + print >> data, ("user add '%s' '%s' '%s'" % + (user.name, user.access, project.name)) + print >> data, ("credentials add 'EC2' '%s' '%s'" % + (user.access, user.secret)) + + def roles(data, am): + for role in am.get_roles(): + print >> data, ("role add '%s'" % (role)) + + def grant_roles(data, am): + roles = am.get_roles() + for project in am.get_projects(): + for u in project.member_ids: + user = am.get_user(u) + for role in roles: + if user.has_role(role): + print >> data, ("role grant '%s', '%s', '%s')," % + (user.name, role, project.name)) + print >> data, footer + + def generate_file(): + data = StringIO.StringIO() + am = manager.AuthManager() + tenants(data, am) + roles(data, am) + data.seek(0) + return data + + create_file(filename) + class RoleCommands(object): """Class for managing roles.""" From f6017c07ff27e403d94ed5a37d63a539cba0985a Mon Sep 17 00:00:00 2001 From: "paul@openstack.org" <> Date: Wed, 14 Sep 2011 13:20:16 -0500 Subject: [PATCH 02/11] minor changes to credentials for the correct format --- bin/nova-manage | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 5f0c5471..60799024 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -286,13 +286,13 @@ class ShellCommands(object): def tenants(data, am): for project in am.get_projects(): print >> data, ("tenant add '%s'" % - (project.name)) + (project.name)) for u in project.member_ids: user = am.get_user(u) print >> data, ("user add '%s' '%s' '%s'" % - (user.name, user.access, project.name)) - print >> data, ("credentials add 'EC2' '%s' '%s'" % - (user.access, user.secret)) + (user.name, user.access, project.name)) + print >> data, ("credentials add 'EC2' '%s:%s' '%s' '%s'" % + (user.access, project.id, user.secret, project.id)) def roles(data, am): for role in am.get_roles(): From a9d9f5d1f6486fe8370ac5e845a1b6bf6cee305c Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 15 Sep 2011 14:09:14 -0500 Subject: [PATCH 03/11] Added a unit test. --- nova/tests/test_virt_drivers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index 440d3401..8e20e999 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -176,6 +176,10 @@ class _VirtDriverTestCase(test.TestCase): def test_poll_rescued_instances(self): self.connection.poll_rescued_instances(10) + @catch_notimplementederror + def test_poll_unconfirmed_resizes(self): + self.connection.poll_unconfirmed_resizes(10) + @catch_notimplementederror def test_migrate_disk_and_power_off(self): instance_ref = test_utils.get_test_instance() From 4dc2a091bd9d503aee8b89ea5cb4dfd8ece0f0ab Mon Sep 17 00:00:00 2001 From: "paul@openstack.org" <> Date: Fri, 16 Sep 2011 21:12:50 -0500 Subject: [PATCH 04/11] fixed grant user, added stdout support --- bin/nova-manage | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 60799024..4e930727 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -275,11 +275,13 @@ class ShellCommands(object): arguments: path""" exec(compile(open(path).read(), path, 'exec'), locals(), globals()) - @args('--filename', dest='filename', metavar='', help='Export path') + @args('--filename', dest='filename', metavar='', default=False, + help='Export file path') def export(self, filename): """Export Nova users into a file that can be consumed by Keystone""" + def create_file(filename): - data = generate_file() + data = generate_data() with open(filename, 'w') as f: f.write(data.getvalue()) @@ -303,21 +305,27 @@ class ShellCommands(object): for project in am.get_projects(): for u in project.member_ids: user = am.get_user(u) - for role in roles: - if user.has_role(role): - print >> data, ("role grant '%s', '%s', '%s')," % - (user.name, role, project.name)) - print >> data, footer + for role in db.user_get_roles_for_project(ctxt, u, + project.id): + print >> data, ("role grant '%s', '%s', '%s')," % + (user.name, role, project.name)) + print >> data - def generate_file(): + def generate_data(): data = StringIO.StringIO() am = manager.AuthManager() tenants(data, am) roles(data, am) + grant_roles(data, am) data.seek(0) return data - create_file(filename) + ctxt = context.get_admin_context() + if filename: + create_file(filename) + else: + data = generate_data() + print data.getvalue() class RoleCommands(object): From ccc25f83f4068a10a2edb28deb8c35a73ebadd13 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Mon, 19 Sep 2011 11:58:20 -0500 Subject: [PATCH 05/11] Added unit test. --- nova/tests/test_db_api.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 60d7abd8..c99709ff 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -18,6 +18,8 @@ """Unit tests for the DB API""" +import datetime + from nova import test from nova import context from nova import db @@ -95,3 +97,26 @@ class DbApiTestCase(test.TestCase): self.assertEqual(result[0].id, inst2.id) self.assertEqual(result[1].id, inst1.id) self.assertTrue(result[1].deleted) + + def test_migration_get_all_unconfirmed(self): + ctxt = context.get_admin_context() + + # Ensure no migrations are returned. + results = db.migration_get_all_unconfirmed(ctxt, 10) + self.assertEqual(0, len(results)) + + # Ensure one migration older than 10 seconds is returned. + updated_at = datetime.datetime(2000, 01, 01, 12, 00, 00) + values = {"status": "FINISHED", "updated_at": updated_at} + migration = db.migration_create(ctxt, values) + results = db.migration_get_all_unconfirmed(ctxt, 10) + self.assertEqual(1, len(results)) + db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"}) + + # Ensure the new migration is not returned. + updated_at = datetime.datetime.utcnow() + values = {"status": "FINISHED", "updated_at": updated_at} + migration = db.migration_create(ctxt, values) + results = db.migration_get_all_unconfirmed(ctxt, 10) + self.assertEqual(0, len(results)) + db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"}) From f2a25f938b50fdac3931a936f6af27d5d5f7ddc4 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 19 Sep 2011 15:56:42 -0500 Subject: [PATCH 06/11] now raising instead of setting bridge to br100 and warning as was noted --- bin/nova-manage | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 089b2eea..4d90dd1b 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -710,16 +710,7 @@ class NetworkCommands(object): bridge_required = ['nova.network.manager.FlatManager', 'nova.network.manager.FlatDHCPManager'] if FLAGS.network_manager in bridge_required: - # TODO(tr3buchet) - swap print statement and following line for - # raise statement in diablo 4 - print _('--bridge parameter required or FLAG ' - 'flat_network_bridge must be set to create networks\n' - 'WARNING! ACHTUNG! Setting the bridge to br100 ' - 'automatically is deprecated and will be removed in ' - 'Diablo milestone 4. Prepare yourself accordingly.') - time.sleep(10) - bridge = 'br100' - #raise exception.NetworkNotCreated(req='--bridge') + raise exception.NetworkNotCreated(req='--bridge') bridge_interface = bridge_interface or FLAGS.flat_interface or \ FLAGS.vlan_interface From 78e068ca2d2235bd5b7fb75b9a56b95f90e7b1f9 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 19 Sep 2011 14:53:17 -0700 Subject: [PATCH 07/11] Removed the extra code added to support filtering instances by instance uuids. Instead, added 'uuid' to the list of exact_filter_match names. Updated the caller to add 'uuid: uuid_list' to the filters dictionary, instead of passing it in as another argument. Updated the ID to UUID mapping code to return a dictionary, which allows the caller to be more efficient... It removes an extra loop there. A couple of typo fixes. --- nova/tests/test_compute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 4ef57b76..948c7ad4 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1033,8 +1033,8 @@ class ComputeTestCase(test.TestCase): 'get_instance_uuids_by_ip_filter', network_manager.get_instance_uuids_by_ip_filter) self.stubs.Set(network_manager.db, - 'instance_get_uuids_by_ids', - db.instance_get_uuids_by_ids) + 'instance_get_id_to_uuid_mapping', + db.instance_get_id_to_uuid_mapping) instance_id1 = self._create_instance({'display_name': 'woot', 'id': 0}) From d2f78b1b708b4c5de0ecf68ce3246a14163383b0 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 19 Sep 2011 15:08:25 -0700 Subject: [PATCH 08/11] fix a test where list order was assumed --- nova/tests/test_db_api.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 5ebab9cc..aaf5212d 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -92,6 +92,9 @@ class DbApiTestCase(test.TestCase): db.instance_destroy(self.context, inst1.id) result = db.instance_get_all_by_filters(self.context.elevated(), {}) self.assertEqual(2, len(result)) - self.assertEqual(result[0].id, inst1.id) - self.assertEqual(result[1].id, inst2.id) - self.assertTrue(result[0].deleted) + self.assertIn(inst1.id, [result[0].id, result[1].id]) + self.assertIn(inst2.id, [result[0].id, result[1].id]) + if inst1.id == result[0].id: + self.assertTrue(result[0].deleted) + else: + self.assertTrue(result[1].deleted) From 6c2e48f447962cd76a59f33f1eec35c1e5fa8029 Mon Sep 17 00:00:00 2001 From: "Brad McConnell bmcconne@rackspace.com" <> Date: Mon, 19 Sep 2011 21:35:47 -0500 Subject: [PATCH 09/11] Fixed --uuid network command in nova-manage to desc to "uuid" instead of "net_uuid" --- bin/nova-manage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/nova-manage b/bin/nova-manage index 4e930727..8a1a8537 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -738,7 +738,7 @@ class NetworkCommands(object): help='Multi host') @args('--dns1', dest="dns1", metavar="", help='First DNS') @args('--dns2', dest="dns2", metavar="", help='Second DNS') - @args('--uuid', dest="net_uuid", metavar="", + @args('--uuid', dest="uuid", metavar="", help='Network UUID') @args('--project_id', dest="project_id", metavar="", help='Project id') From e2b5dcd3316fde1a06b27e8724a9cef39b778a95 Mon Sep 17 00:00:00 2001 From: "Brad McConnell bmcconne@rackspace.com" <> Date: Mon, 19 Sep 2011 22:21:10 -0500 Subject: [PATCH 10/11] added to authors cuz trey said I cant patch otherwise! --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 4e084869..8d6837ea 100644 --- a/Authors +++ b/Authors @@ -12,6 +12,7 @@ Armando Migliaccio Arvind Somya Bilal Akhtar Brad Hall +Brad McConnell Brian Lamar Brian Schott Brian Waldon