Fix get keyring content failed when ceph auth disabled

When ceph auth diasbled, both 'user' and 'keyring' will be 'None',
and the method _check_or_get_keyring_contents must return strings
for ceph conf file writelines() generation.

Change-Id: Ieafd40ace4f50c1a966c9097c5de270c68b0666b
Closes-Bug: #1817271
changes/08/638608/2
Rui Yuan Dou 4 years ago
parent fb5ebc2f9e
commit a6dff156d7
  1. 13
      os_brick/initiator/connectors/rbd.py
  2. 3
      os_brick/tests/initiator/connectors/test_rbd.py

@ -71,11 +71,14 @@ class RBDConnector(base.BaseLinuxConnector):
def _check_or_get_keyring_contents(self, keyring, cluster_name, user):
try:
if keyring is None and user:
keyring_path = ("/etc/ceph/%s.client.%s.keyring" %
(cluster_name, user))
with open(keyring_path, 'r') as keyring_file:
keyring = keyring_file.read()
if keyring is None:
if user:
keyring_path = ("/etc/ceph/%s.client.%s.keyring" %
(cluster_name, user))
with open(keyring_path, 'r') as keyring_file:
keyring = keyring_file.read()
else:
keyring = ''
return keyring
except IOError:
msg = (_("Keyring path %s is not readable.") % (keyring_path))

@ -123,6 +123,9 @@ class RBDConnectorTestCase(test_connector.ConnectorTestCase):
self.assertEqual(
conn._check_or_get_keyring_contents(keyring, 'cluster',
'user'), keyring_data)
self.assertEqual(
conn._check_or_get_keyring_contents(keyring, 'cluster',
None), '')
def test_keyring_raise_error(self):
conn = rbd.RBDConnector(None)

Loading…
Cancel
Save