From d70f915ace8a9bf9b86f73435c98a8afb389cc7f Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Tue, 18 Jan 2011 21:00:28 -0500 Subject: [PATCH 01/16] Completed first pass at converting all localized strings with multiple format substitutions. --- bin/nova-api | 2 +- bin/nova-dhcpbridge | 6 ++-- nova/auth/ldapdriver.py | 4 +-- nova/auth/manager.py | 69 +++++++++++++++++++++++++---------------- nova/fakerabbit.py | 11 ++++--- nova/rpc.py | 19 ++++++------ nova/tests/test_rpc.py | 2 +- 7 files changed, 65 insertions(+), 48 deletions(-) diff --git a/bin/nova-api b/bin/nova-api index 7b4fbeab..605f0067 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -55,7 +55,7 @@ def run_app(paste_config_file): if config is None: LOG.debug(_("No paste configuration for app: %s"), api) continue - LOG.debug(_("App Config: %s\n%r"), api, config) + LOG.debug(_("App Config: %(api)s\n%(config)r") % locals()) wsgi.paste_config_to_flags(config, { "verbose": FLAGS.verbose, "%s_host" % api: config.get('host', '0.0.0.0'), diff --git a/bin/nova-dhcpbridge b/bin/nova-dhcpbridge index 1a994d95..b2c706bd 100755 --- a/bin/nova-dhcpbridge +++ b/bin/nova-dhcpbridge @@ -120,9 +120,9 @@ def main(): mac = argv[2] ip = argv[3] hostname = argv[4] - LOG.debug(_("Called %s for mac %s with ip %s and " - "hostname %s on interface %s"), - action, mac, ip, hostname, interface) + msg = _("Called %(action)s for mac %(mac)s with ip %(ip)s and" + " hostname %(hostname)s on interface %(interface)s") % locals() + LOG.debug(msg) globals()[action + '_lease'](mac, ip, hostname, interface) else: print init_leases(interface) diff --git a/nova/auth/ldapdriver.py b/nova/auth/ldapdriver.py index bc53e0ec..fb9a118b 100644 --- a/nova/auth/ldapdriver.py +++ b/nova/auth/ldapdriver.py @@ -473,8 +473,8 @@ class LdapDriver(object): raise exception.NotFound("The group at dn %s doesn't exist" % group_dn) if self.__is_in_group(uid, group_dn): - raise exception.Duplicate(_("User %s is already a member of " - "the group %s") % (uid, group_dn)) + raise exception.Duplicate(_("User %(uid)s is already a member of " + "the group %(group_dn)s") % locals()) attr = [(self.ldap.MOD_ADD, 'member', self.__uid_to_dn(uid))] self.conn.modify_s(group_dn, attr) diff --git a/nova/auth/manager.py b/nova/auth/manager.py index 1652e24e..450ab803 100644 --- a/nova/auth/manager.py +++ b/nova/auth/manager.py @@ -272,16 +272,22 @@ class AuthManager(object): project = self.get_project(project_id) if project == None: - LOG.audit(_("failed authorization: no project named %s (user=%s)"), - project_id, user.name) + pjid = project_id + uname = user.name + LOG.audit(_("failed authorization: no project named %(pjid)s" + " (user=%(uname)s)") % locals()) raise exception.NotFound(_('No project called %s could be found') % project_id) if not self.is_admin(user) and not self.is_project_member(user, project): - LOG.audit(_("Failed authorization: user %s not admin and not " - "member of project %s"), user.name, project.name) - raise exception.NotFound(_('User %s is not a member of project %s') - % (user.id, project.id)) + uname = user.name + uid = user.id + pjname = project.name + pjid = project.id + LOG.audit(_("Failed authorization: user %(uname)s not admin" + " and not member of project %(pjname)s") % locals()) + raise exception.NotFound(_('User %(uid)s is not a member of' + ' project %(pjid)s') % locals()) if check_type == 's3': sign = signer.Signer(user.secret.encode()) expected_signature = sign.s3_authorization(headers, verb, path) @@ -408,14 +414,16 @@ class AuthManager(object): raise exception.NotFound(_("The %s role can not be found") % role) if project is not None and role in FLAGS.global_roles: raise exception.NotFound(_("The %s role is global only") % role) + uid = User.safe_id(user) + pid = Project.safe_id(project) if project: - LOG.audit(_("Adding role %s to user %s in project %s"), role, - User.safe_id(user), Project.safe_id(project)) + LOG.audit(_("Adding role %(role)s to user %(uid)s" + " in project %(pid)s") % locals()) else: - LOG.audit(_("Adding sitewide role %s to user %s"), role, - User.safe_id(user)) + LOG.audit(_("Adding sitewide role %(role)s to user %(uid)s") + % locals()) with self.driver() as drv: - drv.add_role(User.safe_id(user), role, Project.safe_id(project)) + drv.add_role(uid, role, pid) def remove_role(self, user, role, project=None): """Removes role for user @@ -434,14 +442,16 @@ class AuthManager(object): @type project: Project or project_id @param project: Project in which to remove local role. """ + uid = User.safe_id(user) + pid = Project.safe_id(project) if project: - LOG.audit(_("Removing role %s from user %s on project %s"), - role, User.safe_id(user), Project.safe_id(project)) + LOG.audit(_("Removing role %(role)s from user %(uid)s" + " on project %(pid)s") % locals()) else: - LOG.audit(_("Removing sitewide role %s from user %s"), role, - User.safe_id(user)) + LOG.audit(_("Removing sitewide role %(role)s" + " from user %(uid)s") % locals()) with self.driver() as drv: - drv.remove_role(User.safe_id(user), role, Project.safe_id(project)) + drv.remove_role(uid, role, pid) @staticmethod def get_roles(project_roles=True): @@ -502,8 +512,8 @@ class AuthManager(object): description, member_users) if project_dict: - LOG.audit(_("Created project %s with manager %s"), name, - manager_user) + LOG.audit(_("Created project %(name)s with" + " manager %(manager_user)s") % locals()) project = Project(**project_dict) return project @@ -530,11 +540,12 @@ class AuthManager(object): def add_to_project(self, user, project): """Add user to project""" - LOG.audit(_("Adding user %s to project %s"), User.safe_id(user), - Project.safe_id(project)) + uid = User.safe_id(user) + pid = Project.safe_id(project) + LOG.audit(_("Adding user %(uid)s to project %(pid)s") % locals()) with self.driver() as drv: return drv.add_to_project(User.safe_id(user), - Project.safe_id(project)) + Project.safe_id(project)) def is_project_manager(self, user, project): """Checks if user is project manager""" @@ -550,11 +561,11 @@ class AuthManager(object): def remove_from_project(self, user, project): """Removes a user from a project""" - LOG.audit(_("Remove user %s from project %s"), User.safe_id(user), - Project.safe_id(project)) + uid = User.safe_id(user) + pid = Project.safe_id(project) + LOG.audit(_("Remove user %(uid)s from project %(pid)s") % locals()) with self.driver() as drv: - return drv.remove_from_project(User.safe_id(user), - Project.safe_id(project)) + return drv.remove_from_project(uid, pid) @staticmethod def get_project_vpn_data(project): @@ -634,7 +645,10 @@ class AuthManager(object): user_dict = drv.create_user(name, access, secret, admin) if user_dict: rv = User(**user_dict) - LOG.audit(_("Created user %s (admin: %r)"), rv.name, rv.admin) + rvname = rv.name + rvadmin = rv.admin + LOG.audit(_("Created user %(rvname)s" + " (admin: %(rvadmin)r)") % locals()) return rv def delete_user(self, user): @@ -656,7 +670,8 @@ class AuthManager(object): if secret_key: LOG.audit(_("Secret Key change for user %s"), uid) if admin is not None: - LOG.audit(_("Admin status set to %r for user %s"), admin, uid) + LOG.audit(_("Admin status set to %(admin)r" + " for user %(uid)s") % locals()) with self.driver() as drv: drv.modify_user(uid, access_key, secret_key, admin) diff --git a/nova/fakerabbit.py b/nova/fakerabbit.py index 7c2d7177..dd82a936 100644 --- a/nova/fakerabbit.py +++ b/nova/fakerabbit.py @@ -45,8 +45,9 @@ class Exchange(object): self._routes = {} def publish(self, message, routing_key=None): - LOG.debug(_('(%s) publish (key: %s) %s'), - self.name, routing_key, message) + nm = self.name + LOG.debug(_('(%(nm)s) publish (key: %(routing_key)s)' + ' %(message)s') % locals()) routing_key = routing_key.split('.')[0] if routing_key in self._routes: for f in self._routes[routing_key]: @@ -92,8 +93,8 @@ class Backend(base.BaseBackend): def queue_bind(self, queue, exchange, routing_key, **kwargs): global EXCHANGES global QUEUES - LOG.debug(_('Binding %s to %s with key %s'), - queue, exchange, routing_key) + LOG.debug(_('Binding %(queue)s to %(exchange)s with' + ' key %(routing_key)s') % locals()) EXCHANGES[exchange].bind(QUEUES[queue].push, routing_key) def declare_consumer(self, queue, callback, *args, **kwargs): @@ -117,7 +118,7 @@ class Backend(base.BaseBackend): content_type=content_type, content_encoding=content_encoding) message.result = True - LOG.debug(_('Getting from %s: %s'), queue, message) + LOG.debug(_('Getting from %(queue)s: %(message)s') % locals()) return message def prepare_message(self, message_data, delivery_mode, diff --git a/nova/rpc.py b/nova/rpc.py index 49b11602..68feac6d 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -89,15 +89,16 @@ class Consumer(messaging.Consumer): self.failed_connection = False break except: # Catching all because carrot sucks - LOG.exception(_("AMQP server on %s:%d is unreachable." - " Trying again in %d seconds.") % ( - FLAGS.rabbit_host, - FLAGS.rabbit_port, - FLAGS.rabbit_retry_interval)) + fl_host = FLAGS.rabbit_host + fl_port = FLAGS.rabbit_port + fl_intv = FLAGS.rabbit_retry_interval + LOG.exception(_("AMQP server on %(fl_host)s:%(fl_port)d is" + " unreachable. Trying again in %(fl_intv)d seconds.") + % locals()) self.failed_connection = True if self.failed_connection: LOG.exception(_("Unable to connect to AMQP server " - "after %d tries. Shutting down."), + "after %d tries. Shutting down."), FLAGS.rabbit_max_retries) sys.exit(1) @@ -152,7 +153,7 @@ class TopicConsumer(Consumer): class AdapterConsumer(TopicConsumer): """Calls methods on a proxy object based on method and args""" def __init__(self, connection=None, topic="broadcast", proxy=None): - LOG.debug(_('Initing the Adapter Consumer for %s') % (topic)) + LOG.debug(_('Initing the Adapter Consumer for %s') % topic) self.proxy = proxy super(AdapterConsumer, self).__init__(connection=connection, topic=topic) @@ -167,7 +168,7 @@ class AdapterConsumer(TopicConsumer): Example: {'method': 'echo', 'args': {'value': 42}} """ - LOG.debug(_('received %s') % (message_data)) + LOG.debug(_('received %s') % message_data) msg_id = message_data.pop('_msg_id', None) ctxt = _unpack_context(message_data) @@ -180,7 +181,7 @@ class AdapterConsumer(TopicConsumer): # messages stay in the queue indefinitely, so for now # we just log the message and send an error string # back to the caller - LOG.warn(_('no method for message: %s') % (message_data)) + LOG.warn(_('no method for message: %s') % message_data) msg_reply(msg_id, _('No method for message: %s') % message_data) return diff --git a/nova/tests/test_rpc.py b/nova/tests/test_rpc.py index 85593ab4..9b0b7b14 100644 --- a/nova/tests/test_rpc.py +++ b/nova/tests/test_rpc.py @@ -86,7 +86,7 @@ class RpcTestCase(test.TestCase): @staticmethod def echo(context, queue, value): """Calls echo in the passed queue""" - LOG.debug(_("Nested received %s, %s"), queue, value) + LOG.debug(_("Nested received %(queue)s, %(value)s") % locals()) ret = rpc.call(context, queue, {"method": "echo", From e3bbab66593b70f79f070778bb35fc769743a1b6 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Wed, 19 Jan 2011 15:26:09 -0500 Subject: [PATCH 02/16] Updated trunk changes to work with localization --- nova/tests/test_rpc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_rpc.py b/nova/tests/test_rpc.py index 9b0b7b14..4820e04f 100644 --- a/nova/tests/test_rpc.py +++ b/nova/tests/test_rpc.py @@ -86,7 +86,8 @@ class RpcTestCase(test.TestCase): @staticmethod def echo(context, queue, value): """Calls echo in the passed queue""" - LOG.debug(_("Nested received %(queue)s, %(value)s") % locals()) + LOG.debug(_("Nested received %(queue)s, %(value)s") + % locals()) ret = rpc.call(context, queue, {"method": "echo", From 44face17c3a570058d9fde9aadb13ab188d3e2c9 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Sat, 22 Jan 2011 21:20:09 +0000 Subject: [PATCH 03/16] Use Glance to relate machine image with kernel and ramdisk --- krm_mapping.json.sample | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 krm_mapping.json.sample diff --git a/krm_mapping.json.sample b/krm_mapping.json.sample deleted file mode 100644 index 1ecfba63..00000000 --- a/krm_mapping.json.sample +++ /dev/null @@ -1,3 +0,0 @@ -{ - "machine" : ["kernel", "ramdisk"] -} From 7c147a8dcadac587fd04c2cb909bc2b807660a02 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Sat, 22 Jan 2011 15:14:33 -0800 Subject: [PATCH 05/16] add test and fix describe regions --- nova/flags.py | 2 +- nova/tests/test_cloud.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/nova/flags.py b/nova/flags.py index 81e2e36f..43bc174d 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -218,7 +218,7 @@ def _get_my_ip(): DEFINE_string('my_ip', _get_my_ip(), 'host ip address') DEFINE_list('region_list', [], - 'list of region=url pairs separated by commas') + 'list of region=fqdn pairs separated by commas') DEFINE_string('connection_type', 'libvirt', 'libvirt, xenapi or fake') DEFINE_string('aws_access_key_id', 'admin', 'AWS Access ID') DEFINE_string('aws_secret_access_key', 'admin', 'AWS Access Key') diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 771b1fcc..4d763933 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -87,6 +87,17 @@ class CloudTestCase(test.TestCase): # NOTE(vish): create depends on pool, so just call helper directly return cloud._gen_key(self.context, self.context.user.id, name) + def test_describe_regions(self): + """Makes sure describe regions runs without raising an exception""" + result = self.cloud.describe_regions(self.context) + self.assertEqual(len(result['regionInfo']), 1) + regions = FLAGS.region_list + FLAGS.region_list = ["one=test_host1", "two=test_host2"] + result = self.cloud.describe_regions(self.context) + print result + self.assertEqual(len(result['regionInfo']), 2) + regions = FLAGS.region_list + def test_describe_addresses(self): """Makes sure describe addresses runs without raising an exception""" address = "10.10.10.10" From da8a8c3a9f9d0e98135cf126f17836f6ba6d2f27 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Sat, 22 Jan 2011 15:17:43 -0800 Subject: [PATCH 06/16] remove extra print --- nova/tests/test_cloud.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 4d763933..5e456e61 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -94,7 +94,6 @@ class CloudTestCase(test.TestCase): regions = FLAGS.region_list FLAGS.region_list = ["one=test_host1", "two=test_host2"] result = self.cloud.describe_regions(self.context) - print result self.assertEqual(len(result['regionInfo']), 2) regions = FLAGS.region_list From b2fc578f8d929315cde4d8eefd2255fa338e29dd Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Sat, 22 Jan 2011 17:46:05 -0800 Subject: [PATCH 07/16] fix reversed assignment --- nova/tests/test_cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 5e456e61..445cc6e8 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -95,7 +95,7 @@ class CloudTestCase(test.TestCase): FLAGS.region_list = ["one=test_host1", "two=test_host2"] result = self.cloud.describe_regions(self.context) self.assertEqual(len(result['regionInfo']), 2) - regions = FLAGS.region_list + FLAGS.region_list = regions def test_describe_addresses(self): """Makes sure describe addresses runs without raising an exception""" From b0e9f7757e9225527dcdc65e754369f2e0f69b66 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 24 Jan 2011 12:07:12 -0600 Subject: [PATCH 09/16] changed nova-manage to use named arguments to net_manager.create_networks --- bin/nova-manage | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index a347e86c..1c885f8a 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -473,9 +473,12 @@ class NetworkCommands(object): fixed_range_v6 = FLAGS.fixed_range_v6 net_manager = utils.import_object(FLAGS.network_manager) net_manager.create_networks(context.get_admin_context(), - fixed_range, int(num_networks), - int(network_size), int(vlan_start), - int(vpn_start), fixed_range_v6) + cidr=fixed_range, + num_networks=int(num_networks), + network_size=int(network_size), + vlan_start=int(vlan_start), + vpn_start=int(vpn_start), + cidr_v6=fixed_range_v6) class ServiceCommands(object): From 1fbdb172d36dbc4657a5a15cb80f911d1c32b710 Mon Sep 17 00:00:00 2001 From: Ryan Lane Date: Mon, 24 Jan 2011 19:07:12 +0000 Subject: [PATCH 10/16] Changes __dn_to_uid to return the uid attribute from the user's object. --- nova/auth/ldapdriver.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nova/auth/ldapdriver.py b/nova/auth/ldapdriver.py index a6915ce0..db7b345d 100644 --- a/nova/auth/ldapdriver.py +++ b/nova/auth/ldapdriver.py @@ -585,11 +585,11 @@ class LdapDriver(object): else: return None - @staticmethod - def __dn_to_uid(dn): + def __dn_to_uid(self,dn): """Convert user dn to uid""" - return dn.split(',')[0].split('=')[1] - + query = '(objectclass=novaUser)' + user = self.__find_object(dn,query) + return user[FLAGS.ldap_user_id_attribute][0] class FakeLdapDriver(LdapDriver): """Fake Ldap Auth driver""" From e402c3f0c2c9a2d4d0b8f608552dc68165d979ea Mon Sep 17 00:00:00 2001 From: Ryan Lane Date: Mon, 24 Jan 2011 21:25:13 +0000 Subject: [PATCH 11/16] PEP8 fixes --- nova/auth/ldapdriver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nova/auth/ldapdriver.py b/nova/auth/ldapdriver.py index db7b345d..4562c92e 100644 --- a/nova/auth/ldapdriver.py +++ b/nova/auth/ldapdriver.py @@ -585,12 +585,13 @@ class LdapDriver(object): else: return None - def __dn_to_uid(self,dn): + def __dn_to_uid(self, dn): """Convert user dn to uid""" query = '(objectclass=novaUser)' - user = self.__find_object(dn,query) + user = self.__find_object(dn, query) return user[FLAGS.ldap_user_id_attribute][0] + class FakeLdapDriver(LdapDriver): """Fake Ldap Auth driver""" From 04f4a407093871c2dafa92b3ccb0c40d61505a43 Mon Sep 17 00:00:00 2001 From: John Dewey Date: Mon, 24 Jan 2011 18:31:04 -0800 Subject: [PATCH 12/16] Updated a couple data structures to pass pep8. --- bin/nova-spoolsentry | 6 ++---- nova/tests/test_virt.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/bin/nova-spoolsentry b/bin/nova-spoolsentry index ab20268a..325e9219 100644 --- a/bin/nova-spoolsentry +++ b/bin/nova-spoolsentry @@ -74,10 +74,8 @@ class SpoolSentry(object): return rv def send_data(self, data): - data = { - 'data': base64.b64encode(pickle.dumps(data).encode('zlib')), - 'key': self.key - } + data = {'data': base64.b64encode(pickle.dumps(data).encode('zlib')), + 'key': self.key} req = urllib2.Request(self.sentry_url) res = urllib2.urlopen(req, urllib.urlencode(data)) if res.getcode() != 200: diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py index f6800e3d..0b9b847a 100644 --- a/nova/tests/test_virt.py +++ b/nova/tests/test_virt.py @@ -256,7 +256,7 @@ class IptablesFirewallTestCase(test.TestCase): ':FORWARD ACCEPT [0:0]', ':OUTPUT ACCEPT [349256:75777230]', 'COMMIT', - '# Completed on Tue Jan 18 23:47:56 2011' + '# Completed on Tue Jan 18 23:47:56 2011', ] def test_static_filters(self): From 4983384e3321f14947f7be5d1b22b13598fb0c8c Mon Sep 17 00:00:00 2001 From: John Dewey Date: Mon, 24 Jan 2011 18:39:47 -0800 Subject: [PATCH 13/16] corrected nesting of the data dictionary --- bin/nova-spoolsentry | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/nova-spoolsentry b/bin/nova-spoolsentry index 325e9219..c5348285 100644 --- a/bin/nova-spoolsentry +++ b/bin/nova-spoolsentry @@ -75,7 +75,7 @@ class SpoolSentry(object): def send_data(self, data): data = {'data': base64.b64encode(pickle.dumps(data).encode('zlib')), - 'key': self.key} + 'key': self.key} req = urllib2.Request(self.sentry_url) res = urllib2.urlopen(req, urllib.urlencode(data)) if res.getcode() != 200: From 62b4840f0d5a5e7d8015cc9409d117c5d586d6a3 Mon Sep 17 00:00:00 2001 From: John Dewey Date: Mon, 24 Jan 2011 20:16:09 -0800 Subject: [PATCH 14/16] Added myself (John Dewey) to Authors. --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 608fec52..4b227cc7 100644 --- a/Authors +++ b/Authors @@ -21,6 +21,7 @@ Jay Pipes Jesse Andrews Joe Heck Joel Moore +John Dewey Jonathan Bryce Josh Durgin Josh Kearney From 6f654d49dc3394de254193a8da04cb5b7f643b6e Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Tue, 25 Jan 2011 11:46:24 -0800 Subject: [PATCH 15/16] updated authors since build is failing --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 608fec52..33895be7 100644 --- a/Authors +++ b/Authors @@ -49,6 +49,7 @@ Soren Hansen Thierry Carrez Todd Willey Trey Morris +Tushar Patil Vishvananda Ishaya Youcef Laribi Zhixue Wu