示例#1
0
    def status(self, status):
        has_status = hasattr(self, '_status')
        if has_status:
            if status not in self.valid_state_targets[self._status]:
                kw = {'cur_status': self._status, 'new_status': status}
                e = exception.InvalidImageStatusTransition(**kw)
                LOG.debug(e)
                raise e

            if self._status == 'queued' and status in ('saving', 'active'):
                missing = [
                    k for k in ['disk_format', 'container_format']
                    if not getattr(self, k)
                ]
                if len(missing) > 0:
                    if len(missing) == 1:
                        msg = _('Property %s must be set prior to '
                                'saving data.')
                    else:
                        msg = _('Properties %s must be set prior to '
                                'saving data.')
                    raise ValueError(msg % ', '.join(missing))
        # NOTE(flwang): Image size should be cleared as long as the image
        # status is updated to 'queued'
        if status == 'queued':
            self.size = None
            self.virtual_size = None
        self._status = status
示例#2
0
 def test_upload_data_exists(self):
     request = unit_test_utils.get_fake_request()
     image = FakeImage()
     exc = exception.InvalidImageStatusTransition(cur_status='active',
                                                  new_status='queued')
     image.set_data = Raise(exc)
     self.image_repo.result = image
     self.assertRaises(webob.exc.HTTPConflict, self.controller.upload,
                       request, unit_test_utils.UUID1, 'YYYY', 4)
 def test_image_stage_invalid_image_transition(self, mock_store_add):
     image_id = str(uuid.uuid4())
     request = unit_test_utils.get_fake_request()
     image = FakeImage(image_id=image_id)
     self.image_repo.result = image
     self.controller.stage(request, image_id, 'YYYY', 4)
     self.assertEqual('uploading', image.status)
     self.assertEqual(0, image.size)
     # try staging again
     mock_store_add.side_effect = exception.InvalidImageStatusTransition(
         cur_status='uploading', new_status='uploading')
     self.assertRaises(webob.exc.HTTPConflict, self.controller.stage,
                       request, image_id, 'YYYY', 4)
示例#4
0
 def test_image_stage_invalid_image_transition(self, mock_store_add):
     image_id = str(uuid.uuid4())
     request = unit_test_utils.get_fake_request()
     image = FakeImage(image_id=image_id)
     self.image_repo.result = image
     with mock.patch.object(filesystem.Store, 'add') as mock_add:
         mock_add.return_value = ('foo://bar', 4, 'ident', {})
         self.controller.stage(request, image_id, 'YYYY', 4)
     self.assertEqual('uploading', image.status)
     self.assertEqual(4, image.size)
     # try staging again
     mock_store_add.side_effect = exception.InvalidImageStatusTransition(
         cur_status='uploading', new_status='uploading')
     self.assertRaises(webob.exc.HTTPConflict, self.controller.stage,
                       request, image_id, 'YYYY', 4)