Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA-386281 CIFS username can be omitted in ISO SR #663

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions drivers/ISOSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,12 @@ def appendCIFSMountOptions(self, mountcmd):

if not cifutils.containsCredentials(self.dconf, prefix="cifs"):
options.append('guest')
domain = None
else:
_, domain = cifutils.splitDomainAndUsername(self.dconf['username'])

options.append(self.getSMBVersion())

username, domain = (
cifutils.splitDomainAndUsername(self.dconf['username'])
)

if domain:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just move this up into the else clause ?

Copy link
Contributor Author

@rdn32 rdn32 Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I thought I did. Is the diff somehow showing back-to-front?
Oh, you're talking about the if domain. No, that has to be kept, because domain can come back None from splitDomainAndUsername.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might have been better if the stuff with the SMB version didn't come between the conditional blocks. But the unit tests are sensitive to the order in which options come - I toyed with making them less sensitive, but it seems like quite a lot of faff.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I thought I did. Is the diff somehow showing back-to-front? Oh, you're talking about the if domain. No, that has to be kept, because domain can come back None from splitDomainAndUsername.

Well, yes, but we know that there can never be a domain in the positive case of the if so making the else be

else: 
    _, domain = cifutils.splitDomainAndUsername(self.dconf['username'])
    if domain:
         options.append('domain=' + domain)

would then remove the need for the domain=None in the guest handling side of the branch.

Maybe we should do this as a future improvement to avoid the sensitivity of the UTs to the order of the provided options.

options.append('domain=' + domain)
except:
Expand Down
13 changes: 5 additions & 8 deletions tests/test_ISOSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,14 @@ class TestISOSR_overSMB(unittest.TestCase):

def create_smbisosr(self, location='\\aServer\aLocation', atype=None,
sr_uuid='asr_uuid', server='\\aServer',
serverpath='/aServerpath', username='aUsername',
password='aPassword', vers=None, options='',
serverpath='/aServerpath',
vers=None, options='',
dconf_update={}):
srcmd = mock.Mock()
srcmd.dconf = {
'location': location,
'server': server,
'serverpath': serverpath,
'username': username,
'password': password,
'options': options
}
if vers:
Expand Down Expand Up @@ -252,15 +250,15 @@ def test_attach_with_smb_credentials(self, context, _checkmount, pread,
Positive case, over XC/XE CLI with version 1.0.
"""
context.setup_error_codes()
update = {'cifspassword': 'winter2019'}
update = {'username': 'dot', 'cifspassword': 'winter2019'}
smbsr = self.create_smbisosr(atype='cifs', vers='1.0',
dconf_update=update)
_checkmount.side_effect = [False, True]
smbsr.attach(None)
pread.assert_called_with(['mount.cifs', '\\aServer\x07Location',
'/var/run/sr-mount/asr_uuid', '-o',
'cache=none,vers=1.0'], True,
new_env={'PASSWD': 'winter2019', 'USER': 'aUsername'})
new_env={'PASSWD': 'winter2019', 'USER': 'dot'})

@testlib.with_context
@mock.patch('util.makedirs')
Expand All @@ -274,9 +272,8 @@ def test_attach_with_smb_credentials_domain(self, context,
Positive case, over XC/XE CLI with version 1.0.
"""
context.setup_error_codes()
update = {'cifspassword': 'winter2019'}
update = {'username': r'citrix\jsmith', 'cifspassword': 'winter2019'}
smbsr = self.create_smbisosr(atype='cifs', vers='1.0',
username=r'citrix\jsmith',
dconf_update=update)
_checkmount.side_effect = [False, True]
smbsr.attach(None)
Expand Down