Log shade inner exceptions

With the dependent change, shade now stores inner
exceptions if they occur.  Wrap our use of shade
with a context manager that logs the inner exceptions
in nodepool's own logging context.

Change-Id: I6be2422aa0352ee9f0ff7429ee6e66384c2b5d57
Depends-On: I33269743a8f62b863569130aba3cc9b5a8539aa0
This commit is contained in:
James E. Blair 2015-09-18 15:59:19 -07:00 committed by Yolanda Robla
parent eed395d637
commit afdd58c10a
2 changed files with 33 additions and 8 deletions

View File

@ -19,6 +19,7 @@
import json
import logging
import paramiko
from contextlib import contextmanager
import threading
import time
@ -125,6 +126,15 @@ def make_image_dict(image):
return d
@contextmanager
def shade_inner_exceptions():
try:
yield
except shade.OpenStackCloudException as e:
e.log_error()
raise
class NotFound(Exception):
pass
@ -574,14 +584,15 @@ class ProviderManager(TaskManager):
# block for our v1 clouds anyway, so we might as well
# have the interface be the same and treat faking-out
# a shade-level fake-async interface later
image = self._client.create_image(
name=image_name,
filename='%s.%s' % (filename, disk_format),
is_public=False,
disk_format=disk_format,
container_format=container_format,
wait=True,
**meta)
with shade_inner_exceptions():
image = self._client.create_image(
name=image_name,
filename='%s.%s' % (filename, disk_format),
is_public=False,
disk_format=disk_format,
container_format=container_format,
wait=True,
**meta)
return image.id
def listExtensions(self):

View File

@ -12,12 +12,16 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
import os
import fixtures
import shade
import testtools
import yaml
from nodepool import tests
from nodepool.provider_manager import shade_inner_exceptions
class TestShadeIntegration(tests.IntegrationTestCase):
@ -86,3 +90,13 @@ class TestShadeIntegration(tests.IntegrationTestCase):
pool.updateConfig()
provider_manager = pool.config.provider_managers['fake-provider']
self.assertEqual(provider_manager._client.auth, auth_data)
def test_exceptions(self):
log = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
with testtools.ExpectedException(shade.OpenStackCloudException):
with shade_inner_exceptions():
try:
raise Exception("inner test")
except:
raise shade.OpenStackCloudException("outer test")
self.assertTrue('Exception("inner test")' in log.output)