diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2011-05-25 19:05:20 +0000 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2011-05-25 19:05:20 +0000 |
| commit | f2507b3cb77538c1434fea485c4861c11ef3f48b (patch) | |
| tree | dba939e5fb375eb36f55132a49f0a5099ec94255 | |
| parent | b933f90faecaddf7281455f4824577b586e07f0c (diff) | |
| download | nova-f2507b3cb77538c1434fea485c4861c11ef3f48b.tar.gz nova-f2507b3cb77538c1434fea485c4861c11ef3f48b.tar.xz nova-f2507b3cb77538c1434fea485c4861c11ef3f48b.zip | |
fix forever looping on a password reset API call
| -rw-r--r-- | nova/compute/manager.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 0a4064440..d1e01f275 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -406,22 +406,28 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception @checks_instance_lock def set_admin_password(self, context, instance_id, new_pass=None): - """Set the root/admin password for an instance on this host.""" + """Set the root/admin password for an instance on this host. + + This is generally only called by API password resets after an + image has been built. + """ + context = context.elevated() if new_pass is None: # Generate a random password new_pass = utils.generate_password(FLAGS.password_length) - while True: + max_tries = 10 + + for i in xrange(max_tries): instance_ref = self.db.instance_get(context, instance_id) instance_id = instance_ref["id"] instance_state = instance_ref["state"] expected_state = power_state.RUNNING if instance_state != expected_state: - time.sleep(5) - continue + raise exception.Error(_('Instance is not running')) else: try: self.driver.set_admin_password(instance_ref, new_pass) @@ -437,6 +443,12 @@ class ComputeManager(manager.SchedulerDependentManager): except Exception, e: # Catch all here because this could be anything. LOG.exception(e) + if i == max_tries - 1: + # At some point this exception may make it back + # to the API caller, and we don't want to reveal + # too much. The real exception is logged above + raise exception.Error(_('Internal error')) + time.sleep(1) continue @exception.wrap_exception |
