os-xenapi: Exception Error logs shown in Citrix XenServer CI

There are many errors in the patchs which passed our XenServer CI,
it is because when run tempest, test case will ask nova sevice to
do snapshotting, then delete image before snapshotting done. Then
nova compute service couldn't find the image when do image upload
and raise an exception.
Normally the exception can be consumed by nova service. But the
exception generated by os-xenapi can't be recognized by nova, so
the error logs come out.
Add a exception in os_xenapi/client to mark image not found
exception and convert it to another exception which computer
service can process in nova/virt/xenapi.

Change-Id: I16d199e93f615e4f374d49948dceeb4d1d600aa9
Depends-On: Ibe30a76f278264e0ddd1fc29d533fdeaab0a13a5
Closes-Bug: 1700926
This commit is contained in:
naichuans 2017-07-05 08:20:40 +00:00
parent 7ac84ec31d
commit d674b83624
3 changed files with 110 additions and 2 deletions

View File

@ -51,5 +51,9 @@ class PluginRetriesExceeded(OsXenApiException):
msg_fmt = _("Number of retries to plugin (%(num_retries)d) exceeded.")
class PluginImageNotFound(OsXenApiException):
msg_fmt = _("Image (%(image_id)s) not found.")
class SessionLoginTimeout(OsXenApiException):
msg_fmt = _("Unable to log in to XenAPI (is the Dom0 disk full?)")

View File

@ -12,6 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from os_xenapi.client import exception
from os_xenapi.client import XenAPI
def download_vhd(session, num_retries, callback, retry_cb, image_id, sr_path,
extra_headers, uuid_stack=''):
@ -26,5 +29,12 @@ def upload_vhd(session, num_retries, callback, retry_cb, image_id, sr_path,
args = {'image_id': image_id, 'sr_path': sr_path,
'extra_headers': extra_headers, 'vdi_uuids': vdi_uuids,
'properties': properties}
return session.call_plugin_serialized_with_retry(
'glance.py', 'upload_vhd2', num_retries, callback, retry_cb, **args)
try:
session.call_plugin_serialized_with_retry(
'glance.py', 'upload_vhd2', num_retries,
callback, retry_cb, **args)
except XenAPI.Failure as exc:
if (len(exc.details) == 4 and exc.details[3] == 'ImageNotFound'):
raise exception.PluginImageNotFound(image_id=image_id)
else:
raise

View File

@ -0,0 +1,94 @@
# Copyright 2017 Citrix Systems
#
# 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 mock
from os_xenapi.client import exception
from os_xenapi.client import host_glance
from os_xenapi.client import XenAPI
from os_xenapi.tests import base
class HostGlanceTestCase(base.TestCase):
def test_upload_vhd(self):
session = mock.Mock()
num_retries = 'fake_num_retries'
callback = 'fake_callback'
retry_cb = 'fake_retry_cb'
image_id = 'fake_image_id'
sr_path = 'fake_sr_path'
extra_headers = 'fake_extra_headers'
vdi_uuids = 'fake_vdi_uuids'
properties = {}
args = {'image_id': image_id, 'sr_path': sr_path,
'extra_headers': extra_headers, 'vdi_uuids': vdi_uuids,
'properties': properties}
host_glance.upload_vhd(session, num_retries, callback, retry_cb,
image_id, sr_path, extra_headers, vdi_uuids,
properties)
session.call_plugin_serialized_with_retry.assert_called_with(
'glance.py', 'upload_vhd2', num_retries, callback, retry_cb, **args
)
def test_upload_vhd_xenapi_failure_image_not_found(self):
session = mock.Mock()
num_retries = 'fake_num_retries'
callback = 'fake_callback'
retry_cb = 'fake_retry_cb'
image_id = 'fake_image_id'
sr_path = 'fake_sr_path'
extra_headers = 'fake_extra_headers'
vdi_uuids = 'fake_vdi_uuids'
properties = {}
args = {'image_id': image_id, 'sr_path': sr_path,
'extra_headers': extra_headers, 'vdi_uuids': vdi_uuids,
'properties': properties}
session.call_plugin_serialized_with_retry.side_effect = XenAPI.Failure(
('XENAPI_PLUGIN_FAILURE', 'upload_vhd2',
'PluginError', 'ImageNotFound')
)
self.assertRaises(exception.PluginImageNotFound,
host_glance.upload_vhd, session, num_retries,
callback, retry_cb, image_id, sr_path, extra_headers,
vdi_uuids, properties)
session.call_plugin_serialized_with_retry.assert_called_with(
'glance.py', 'upload_vhd2', num_retries, callback, retry_cb, **args
)
def test_upload_vhd_xenapi_failure_reraise(self):
session = mock.Mock()
num_retries = 'fake_num_retries'
callback = 'fake_callback'
retry_cb = 'fake_retry_cb'
image_id = 'fake_image_id'
sr_path = 'fake_sr_path'
extra_headers = 'fake_extra_headers'
vdi_uuids = 'fake_vdi_uuids'
properties = {}
args = {'image_id': image_id, 'sr_path': sr_path,
'extra_headers': extra_headers, 'vdi_uuids': vdi_uuids,
'properties': properties}
session.call_plugin_serialized_with_retry.side_effect = XenAPI.Failure(
('untouch')
)
self.assertRaises(XenAPI.Failure, host_glance.upload_vhd, session,
num_retries, callback, retry_cb, image_id, sr_path,
extra_headers, vdi_uuids, properties)
session.call_plugin_serialized_with_retry.assert_called_with(
'glance.py', 'upload_vhd2', num_retries, callback, retry_cb, **args
)