Merge "Robust md creation/ending"

This commit is contained in:
Zuul 2022-02-14 22:38:27 +00:00 committed by Gerrit Code Review
commit 3475113d0e
2 changed files with 26 additions and 11 deletions

View File

@ -783,6 +783,19 @@ class NVMeOFConnector(base.BaseLinuxConnector):
LOG.debug('[!] cmd = ' + str(cmd))
NVMeOFConnector.run_mdadm(executor, cmd)
# sometimes under load, md is not created right away so we wait
for i in range(60):
try:
is_exist = os.path.exists("/dev/md/" + name)
LOG.debug("[!] md is_exist = %s", is_exist)
if is_exist:
return
time.sleep(1)
except Exception:
LOG.debug('[!] Exception_wait_raid!')
msg = _("md: /dev/md/%s not found.") % name
LOG.error(msg)
raise exception.NotFound(message=msg)
@staticmethod
def end_raid(executor, device_path):
@ -791,12 +804,11 @@ class NVMeOFConnector(base.BaseLinuxConnector):
for i in range(10):
try:
cmd_out = NVMeOFConnector.stop_raid(
executor, device_path)
executor, device_path, True)
if not cmd_out:
break
except Exception:
break
time.sleep(1)
time.sleep(1)
try:
is_exist = os.path.exists(device_path)
LOG.debug("[!] is_exist = %s", is_exist)
@ -807,10 +819,10 @@ class NVMeOFConnector(base.BaseLinuxConnector):
LOG.debug('[!] Exception_stop_raid!')
@staticmethod
def stop_raid(executor, md_path):
def stop_raid(executor, md_path, raise_exception=False):
cmd = ['mdadm', '--stop', md_path]
LOG.debug("[!] cmd = " + str(cmd))
cmd_out = NVMeOFConnector.run_mdadm(executor, cmd)
cmd_out = NVMeOFConnector.run_mdadm(executor, cmd, raise_exception)
return cmd_out
@staticmethod

View File

@ -666,8 +666,10 @@ class NVMeOFConnectorTestCase(test_connector.ConnectorTestCase):
['mdadm', '--assemble', '--run', '/dev/md/md1', '-o', '/dev/sda'],
True)
@mock.patch.object(os.path, 'exists')
@mock.patch.object(nvmeof.NVMeOFConnector, 'run_mdadm')
def test_create_raid_cmd_simple(self, mock_run_mdadm):
def test_create_raid_cmd_simple(self, mock_run_mdadm, mock_os):
mock_os.return_value = True
self.assertIsNone(self.connector.create_raid(
self.connector, ['/dev/sda'], '1', 'md1', 'name', True))
mock_run_mdadm.assert_called_with(
@ -675,6 +677,7 @@ class NVMeOFConnectorTestCase(test_connector.ConnectorTestCase):
['mdadm', '-C', '-o', 'md1', '-R', '-N', 'name', '--level', '1',
'--raid-devices=1', '--bitmap=internal', '--homehost=any',
'--failfast', '--assume-clean', '/dev/sda'])
mock_os.assert_called_with('/dev/md/name')
@mock.patch.object(nvmeof.NVMeOFConnector, 'stop_raid')
@mock.patch.object(nvmeof.NVMeOFConnector, 'is_raid_exists')
@ -684,7 +687,7 @@ class NVMeOFConnectorTestCase(test_connector.ConnectorTestCase):
self.assertIsNone(self.connector.end_raid(
self.connector, '/dev/md/md1'))
mock_raid_exists.assert_called_with(self.connector, '/dev/md/md1')
mock_stop_raid.assert_called_with(self.connector, '/dev/md/md1')
mock_stop_raid.assert_called_with(self.connector, '/dev/md/md1', True)
@mock.patch.object(os.path, 'exists')
@mock.patch.object(nvmeof.NVMeOFConnector, 'stop_raid')
@ -696,7 +699,7 @@ class NVMeOFConnectorTestCase(test_connector.ConnectorTestCase):
self.assertIsNone(self.connector.end_raid(
self.connector, '/dev/md/md1'))
mock_raid_exists.assert_called_with(self.connector, '/dev/md/md1')
mock_stop_raid.assert_called_with(self.connector, '/dev/md/md1')
mock_stop_raid.assert_called_with(self.connector, '/dev/md/md1', True)
mock_os.assert_called_with('/dev/md/md1')
@mock.patch.object(os.path, 'exists')
@ -709,16 +712,16 @@ class NVMeOFConnectorTestCase(test_connector.ConnectorTestCase):
self.assertIsNone(self.connector.end_raid(
self.connector, '/dev/md/md1'))
mock_raid_exists.assert_called_with(self.connector, '/dev/md/md1')
mock_stop_raid.assert_called_with(self.connector, '/dev/md/md1')
mock_stop_raid.assert_called_with(self.connector, '/dev/md/md1', True)
mock_os.assert_called_with('/dev/md/md1')
@mock.patch.object(nvmeof.NVMeOFConnector, 'run_mdadm')
def test_stop_raid_simple(self, mock_run_mdadm):
mock_run_mdadm.return_value = 'mdadm output'
self.assertEqual(self.connector.stop_raid(
self.connector, '/dev/md/md1'), 'mdadm output')
self.connector, '/dev/md/md1', True), 'mdadm output')
mock_run_mdadm.assert_called_with(
self.connector, ['mdadm', '--stop', '/dev/md/md1'])
self.connector, ['mdadm', '--stop', '/dev/md/md1'], True)
@mock.patch.object(nvmeof.NVMeOFConnector, 'run_mdadm')
def test_remove_raid_simple(self, mock_run_mdadm):