Skip to content

Commit

Permalink
CA-388811 Don't tell xapi whether SR supports hard links when there's…
Browse files Browse the repository at this point in the history
… no session

Signed-off-by: Robin Newton <[email protected]>
  • Loading branch information
Robin Newton authored and Wescoeur committed Apr 10, 2024
1 parent 513eff9 commit bd5698b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
24 changes: 13 additions & 11 deletions drivers/FileSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,21 +1103,23 @@ def _check_hardlinks(self):
self._raise_hardlink_error)

os.link(test_name, link_name)
self.session.xenapi.SR.remove_from_sm_config(
self.sr_ref, SharedFileSR.NO_HARDLINK_SUPPORT)
if self.session:
self.session.xenapi.SR.remove_from_sm_config(
self.sr_ref, SharedFileSR.NO_HARDLINK_SUPPORT)
except OSError:
msg = "File system for SR %s does not support hardlinks, crash " \
"consistency of snapshots cannot be assured" % self.uuid
util.SMlog(msg, priority=util.LOG_WARNING)
try:
self.session.xenapi.SR.add_to_sm_config(
self.sr_ref, SharedFileSR.NO_HARDLINK_SUPPORT, 'True')
self.session.xenapi.message.create(
"sr_does_not_support_hardlinks", 2, "SR", self.uuid,
msg)
except XenAPI.Failure:
# Might already be set and checking has TOCTOU issues
pass
if self.session:
try:
self.session.xenapi.SR.add_to_sm_config(
self.sr_ref, SharedFileSR.NO_HARDLINK_SUPPORT, 'True')
self.session.xenapi.message.create(
"sr_does_not_support_hardlinks", 2, "SR", self.uuid,
msg)
except XenAPI.Failure:
# Might already be set and checking has TOCTOU issues
pass
finally:
util.force_unlink(link_name)
util.force_unlink(test_name)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_FileSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,13 @@ def create_test_sr(self):
'sr_ref': TestShareFileSR.TEST_SR_REF}
return FakeSharedFileSR(srcmd, self.sr_uuid)

def create_sessionless_test_sr(self):
srcmd = mock.Mock()
srcmd.dconf = {}
srcmd.params = {'command': "some_command",
'sr_ref': TestShareFileSR.TEST_SR_REF}
return FakeSharedFileSR(srcmd, self.sr_uuid)

def test_attach_success(self):
"""
Attach SR on FS with expected features
Expand Down Expand Up @@ -529,6 +536,24 @@ def test_attach_link_fail_already_set(self):
self.mock_session.xenapi.SR.add_to_sm_config.assert_called_with(
TestShareFileSR.TEST_SR_REF, TestShareFileSR.NO_HARDLINKS, 'True')

def test_attach_success_no_session(self):
test_sr = self.create_sessionless_test_sr()

with mock.patch('FileSR.open'):
test_sr.attach(self.sr_uuid)

self.mock_session.xenapi.SR.remove_from_sm_config.assert_not_called()

def test_attach_link_fail_no_session(self):
test_sr = self.create_sessionless_test_sr()
self.mock_link.side_effect = OSError(524, TestShareFileSR.ERROR_524)

with mock.patch('FileSR.open'):
test_sr.attach(self.sr_uuid)

self.mock_session.xenapi.SR.add_to_sm_config.assert_not_called()
self.mock_session.xenapi.message.create.assert_not_called()

def test_attach_fist_active(self):
"""
Attach SR with FIST point active to set no hardlinks
Expand Down

0 comments on commit bd5698b

Please sign in to comment.