]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Truncate fail_reason to column length
authorVipin Balachandran <vbala@vmware.com>
Thu, 9 Oct 2014 14:05:46 +0000 (19:35 +0530)
committerVipin Balachandran <vbala@vmware.com>
Thu, 9 Oct 2014 14:37:08 +0000 (20:07 +0530)
During create_backup failure handling, backup_update fails with
DataError ("Data too long for column") if the fail_reason is
greater than 255 characters. As a result, backup status is stuck
in 'creating' state. This patch avoids the problem by truncating
fail_reason to 255 characters before update.

Closes-Bug: #1376199
Change-Id: If0d616b81d3869f7ea110caab8cf4140cf5c5c9e

cinder/db/sqlalchemy/models.py
cinder/tests/test_db_api.py

index e5b26c8ca87d8685d15411df38720de60e501228..6ae1505bcd99df340afcb7075571327f04847c3b 100644 (file)
@@ -24,7 +24,7 @@ from oslo.db.sqlalchemy import models
 from sqlalchemy import Column, Integer, String, Text, schema
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy import ForeignKey, DateTime, Boolean
-from sqlalchemy.orm import relationship, backref
+from sqlalchemy.orm import relationship, backref, validates
 
 from cinder.openstack.common import timeutils
 
@@ -478,6 +478,10 @@ class Backup(BASE, CinderBase):
     size = Column(Integer)
     object_count = Column(Integer)
 
+    @validates('fail_reason')
+    def validate_fail_reason(self, key, fail_reason):
+        return fail_reason and fail_reason[:255] or ''
+
 
 class Encryption(BASE, CinderBase):
     """Represents encryption requirement for a volume type.
index 00ee51b414bfe54cb0b81778c99995d927007f83..899a4bc1358c288a8fcd1856f3a4a4d37cdc555a 100644 (file)
@@ -1237,6 +1237,19 @@ class DBAPIBackupTestCase(BaseTest):
         self._assertEqualObjects(updated_values, updated_backup,
                                  self._ignored_keys)
 
+    def test_backup_update_with_fail_reason_truncation(self):
+        updated_values = self._get_values(one=True)
+        fail_reason = '0' * 512
+        updated_values['fail_reason'] = fail_reason
+
+        update_id = self.created[1]['id']
+        updated_backup = db.backup_update(self.ctxt, update_id,
+                                          updated_values)
+
+        updated_values['fail_reason'] = fail_reason[:255]
+        self._assertEqualObjects(updated_values, updated_backup,
+                                 self._ignored_keys)
+
     def test_backup_destroy(self):
         for backup in self.created:
             db.backup_destroy(self.ctxt, backup['id'])