Close connection to ceph after cinder bakcup

If we don't close connection to ceph cluster,
The connection count increases with cinder bakcup until exceed max open files.
Then rise OSError: [Errno 24] Too many open files

This patch is to close connection to ceph cluster after cinder backup.

Change-Id: I2fb243d2a57771dc3589e96db54e998e2c1c8ef7
Closes-bug: #1628626
(cherry picked from commit 1d51eb64ac)
This commit is contained in:
cheng 2016-09-28 18:03:31 +00:00 committed by Eric Harney
parent 816e212e3b
commit 376638513d
2 changed files with 18 additions and 7 deletions

View File

@ -112,15 +112,18 @@ class RBDVolume(object):
self.client = client
def __enter__(self):
return self
def __exit__(self, type_, value, traceback):
def close(self):
try:
self.image.close()
finally:
self.client.disconnect()
def __enter__(self):
return self
def __exit__(self, type_, value, traceback):
self.close()
def __getattr__(self, attrib):
return getattr(self.image, attrib)
@ -229,4 +232,4 @@ class RBDVolumeIOWrapper(io.RawIOBase):
# in this case is unwanted since the rbd image may have been closed prior
# to the autoclean - currently triggering a segfault in librbd.
def close(self):
pass
self.rbd_image.close()

View File

@ -146,5 +146,13 @@ class RBDVolumeIOWrapperTestCase(base.TestCase):
def test_fileno(self):
self.assertRaises(IOError, self.mock_volume_wrapper.fileno)
def test_close(self):
self.mock_volume_wrapper.close()
@mock.patch('os_brick.initiator.linuxrbd.rbd')
@mock.patch('os_brick.initiator.linuxrbd.rados')
@mock.patch.object(linuxrbd.RBDClient, 'disconnect')
def test_close(self, rbd_disconnect, mock_rados, mock_rbd):
rbd_client = linuxrbd.RBDClient('user', 'pool')
rbd_volume = linuxrbd.RBDVolume(rbd_client, 'volume')
rbd_handle = linuxrbd.RBDVolumeIOWrapper(
linuxrbd.RBDImageMetadata(rbd_volume, 'pool', 'user', None))
rbd_handle.close()
self.assertEqual(1, rbd_disconnect.call_count)