def testCorrectOpsiDepotShareWithoutFixForSamba4(isSamba4, disableDirCreation): config = [ u"[opsi_depot]\n", u" available = yes\n", u" comment = opsi depot share (ro)\n", u" path = /var/lib/opsi/depot\n", u" oplocks = no\n", u" follow symlinks = yes\n", u" level2 oplocks = no\n", u" writeable = no\n", u" invalid users = root\n", ] if not isSamba4: pytest.skip("Requires Samba 4.") result = Samba._processConfig(config) opsiDepotFound = False for line in result: if line.strip(): if '[opsi_depot]' in line: opsiDepotFound = True elif opsiDepotFound and 'admin users' in line: break elif opsiDepotFound and line.startswith('['): opsiDepotFound = False break else: raise RuntimeError('Did not find "admin users" in opsi_depot share')
def testWritingSambaConfig(pathToSmbConf): config = [ u"[opt_pcbin]\n", u"[opsi_depot]\n", u"[opsi_depot_rw]\n", u"[opsi_images]\n", u"[opsi_workbench]\n", u"[opsi_repository]\n", u"[opsi_logs]\n", ] Samba._writeConfig(config, pathToSmbConf) with open(pathToSmbConf, 'r') as readConfig: assert config == readConfig.readlines()
def testProcessConfigAddsMissingRepositoryShare(isSamba4, disableDirCreation): config = [ u"; load opsi shares\n", u"include = /etc/samba/share.conf\n", u"[opt_pcbin]\n", u"[opsi_depot]\n", u"[opsi_depot_rw]\n", u"[opsi_images]\n", u"[opsi_workbench]\n", u"[opsi_logs]\n", ] result = Samba._processConfig(config) repository = False pathFound = False for line in result: if '[opsi_repository]' in line: repository = True elif repository: if line.strip().startswith('['): # next section break elif line.strip().startswith('path'): assert '/var/lib/opsi/repository' in line pathFound = True break assert repository, "Missing entry 'opsi_repository'" assert pathFound, "Missing 'path' in 'opsi_repository'"
def testConfigureSambaOnUbuntu(isSamba4, workbenchPath, disableDirCreation): result = Samba._processConfig([]) if workbenchPath.endswith('/'): workbenchPath = workbenchPath[:-1] assert any('path = {}'.format(workbenchPath) in line for line in result)
def testSambaConfigureSamba4Share(isSamba4, workbenchPath, disableDirCreation): config = [ u"[opt_pcbin]\n", u"[opsi_depot]\n", u"[opsi_depot_rw]\n", u"[opsi_images]\n", u"[opsi_workbench]\n", u"[opsi_repository]\n", u"[opsi_logs]\n", ] result = Samba._processConfig(config) assert any(line.strip() for line in result)
def testReadingSambaConfig(pathToSmbConf): config = [ u"[opt_pcbin]\n", u"[opsi_depot]\n", u"[opsi_depot_rw]\n", u"[opsi_images]\n", u"[opsi_workbench]\n", u"[opsi_repository]\n", u"[opsi_logs]\n", ] with open(pathToSmbConf, 'w') as fakeSambaConfig: for line in config: fakeSambaConfig.write(line) assert config == Samba._readConfig(pathToSmbConf)
def testProcessConfigDoesNotRemoveComment(isSamba4, disableDirCreation): config = [ u"; load opsi shares\n", u"include = /etc/samba/share.conf\n", u"[opt_pcbin]\n", u"[opsi_depot]\n", u"[opsi_depot_rw]\n", u"[opsi_images]\n", u"[opsi_workbench]\n", u"[opsi_repository]\n", u"[opsi_logs]\n", ] result = Samba._processConfig(config) assert any('; load opsi shares' in line for line in result)
def testAdminUsersAreAddedToExistingOpsiDepotShare(isSamba4, disableDirCreation): config = [ u"[opsi_depot]\n", u" available = yes\n", u" comment = opsi depot share (ro)\n", u" path = /var/lib/opsi/depot\n", u" oplocks = no\n", u" follow symlinks = yes\n", u" level2 oplocks = no\n", u" writeable = no\n", u" invalid users = root\n", ] if not isSamba4: pytest.skip("Requires Samba 4.") result = Samba._processConfig(config) assert any('admin users' in line for line in result), 'Missing Admin Users in Share opsi_depot'
def testCorrectOpsiDepotShareWithSamba4Fix(isSamba4, disableDirCreation): config = [ u"[opt_pcbin]\n", u"[opsi_depot]\n", u" available = yes\n", u" comment = opsi depot share (ro)\n", u" path = /var/lib/opsi/depot\n", u" oplocks = no\n", u" follow symlinks = yes\n", u" level2 oplocks = no\n", u" writeable = no\n", u" invalid users = root\n", u" admin users = @%s\n" % Samba.FILE_ADMIN_GROUP, u"[opsi_depot_rw]\n", u"[opsi_images]\n", u"[opsi_workbench]\n", u"[opsi_repository]\n", u"[opsi_logs]\n", ] if not isSamba4: pytest.skip("Requires Samba 4.") assert config == Samba._processConfig(config)
def testReadingEmptySambaConfig(pathToSmbConf): assert [] == Samba._readConfig(pathToSmbConf)
def testCheckForSamba4DependsOnVersion(versionString, expectedSamba4): with mock.patch('OPSI.Util.Task.Samba.execute', lambda cmd: [versionString]): with mock.patch('OPSI.Util.Task.Samba.which', lambda cmd: cmd): assert Samba.isSamba4() == expectedSamba4
def testCheckForSambaVersionWithoutSMBD(emptyoutput): with mock.patch('OPSI.Util.Task.Samba.execute', lambda cmd: emptyoutput): with mock.patch('OPSI.Util.Task.Samba.which', lambda cmd: None): assert not Samba.isSamba4()
def testWritingEmptySambaConfig(pathToSmbConf): Samba._writeConfig([], pathToSmbConf) with open(pathToSmbConf, 'r') as readConfig: assert [] == readConfig.readlines()