"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "glance/tests/unit/async_/flows/test_api_image_import.py" between
glance-20.0.0.tar.gz and glance-20.0.1.tar.gz

About: OpenStack Glance (Core Service: Image Service) stores and retrieves virtual machine disk images. OpenStack Compute makes use of this during instance provisioning.
The "Ussuri" series (latest release).

test_api_image_import.py  (glance-20.0.0):test_api_image_import.py  (glance-20.0.1)
skipping to change at line 18 skipping to change at line 18
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from unittest import mock from unittest import mock
from glance_store import exceptions as store_exceptions
from oslo_config import cfg from oslo_config import cfg
import glance.async_.flows.api_image_import as import_flow import glance.async_.flows.api_image_import as import_flow
from glance.common.exception import ImportTaskError from glance.common.exception import ImportTaskError
from glance import context from glance import context
from glance import gateway from glance import gateway
import glance.tests.utils as test_utils import glance.tests.utils as test_utils
from cursive import exception as cursive_exception from cursive import exception as cursive_exception
skipping to change at line 167 skipping to change at line 168
img_repo.get.return_value = image img_repo.get.return_value = image
mock_import.set_image_data.side_effect = \ mock_import.set_image_data.side_effect = \
cursive_exception.SignatureVerificationError( cursive_exception.SignatureVerificationError(
"Signature verification failed") "Signature verification failed")
try: try:
image_import.execute() image_import.execute()
self.assertEqual(image.extra_properties['os_glance_failed_import'], self.assertEqual(image.extra_properties['os_glance_failed_import'],
"store1") "store1")
except cursive_exception.SignatureVerificationError: except cursive_exception.SignatureVerificationError:
self.fail("Exception shouldn't be raised") self.fail("Exception shouldn't be raised")
class TestDeleteFromFS(test_utils.BaseTestCase):
def test_delete_with_backends_deletes(self):
task = import_flow._DeleteFromFS(TASK_ID1, TASK_TYPE)
self.config(enabled_backends='file:foo')
with mock.patch.object(import_flow.store_api, 'delete') as mock_del:
task.execute(mock.sentinel.path)
mock_del.assert_called_once_with(
mock.sentinel.path,
'os_glance_staging_store')
def test_delete_with_backends_delete_fails(self):
self.config(enabled_backends='file:foo')
task = import_flow._DeleteFromFS(TASK_ID1, TASK_TYPE)
with mock.patch.object(import_flow.store_api, 'delete') as mock_del:
mock_del.side_effect = store_exceptions.NotFound(image=IMAGE_ID1,
message='Testing')
# If we didn't swallow this we would explode here
task.execute(mock.sentinel.path)
mock_del.assert_called_once_with(
mock.sentinel.path,
'os_glance_staging_store')
# Raise something unexpected and make sure it bubbles up
mock_del.side_effect = RuntimeError
self.assertRaises(RuntimeError,
task.execute, mock.sentinel.path)
@mock.patch('os.path.exists')
@mock.patch('os.unlink')
def test_delete_without_backends_exists(self, mock_unlink, mock_exists):
mock_exists.return_value = True
task = import_flow._DeleteFromFS(TASK_ID1, TASK_TYPE)
task.execute('1234567foo')
# FIXME(danms): I have no idea why the code arbitrarily snips
# the first seven characters from the path. Need a comment or
# *something*.
mock_unlink.assert_called_once_with('foo')
mock_unlink.reset_mock()
mock_unlink.side_effect = OSError(123, 'failed')
# Make sure we swallow the OSError and don't explode
task.execute('1234567foo')
@mock.patch('os.path.exists')
@mock.patch('os.unlink')
def test_delete_without_backends_missing(self, mock_unlink, mock_exists):
mock_exists.return_value = False
task = import_flow._DeleteFromFS(TASK_ID1, TASK_TYPE)
task.execute('foo')
mock_unlink.assert_not_called()
class TestVerifyImageStateTask(test_utils.BaseTestCase):
def test_verify_active_status(self):
fake_img = mock.MagicMock(status='active')
mock_repo = mock.MagicMock()
mock_repo.get.return_value = fake_img
task = import_flow._VerifyImageState(TASK_ID1, TASK_TYPE,
mock_repo, IMAGE_ID1,
'anything!')
task.execute()
fake_img.status = 'importing'
self.assertRaises(import_flow._NoStoresSucceeded,
task.execute)
def test_revert_copy_status_unchanged(self):
fake_img = mock.MagicMock(status='active')
mock_repo = mock.MagicMock()
mock_repo.get.return_value = fake_img
task = import_flow._VerifyImageState(TASK_ID1, TASK_TYPE,
mock_repo, IMAGE_ID1,
'copy-image')
task.revert(mock.sentinel.result)
# If we are doing copy-image, no state update should be made
mock_repo.save_image.assert_not_called()
def test_reverts_state_nocopy(self):
fake_img = mock.MagicMock(status='importing')
mock_repo = mock.MagicMock()
mock_repo.get.return_value = fake_img
task = import_flow._VerifyImageState(TASK_ID1, TASK_TYPE,
mock_repo, IMAGE_ID1,
'glance-direct')
task.revert(mock.sentinel.result)
# Except for copy-image, image state should revert to queued
mock_repo.save_image.assert_called_once()
 End of changes. 2 change blocks. 
0 lines changed or deleted 1 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)