def testWriteAutomountEntry(self): """We correctly write a typical entry in /etc/auto.* format.""" cache = files.FilesAutomountMapHandler(self.config) file_mock = self.mox.CreateMock(sys.stdout) file_mock.write('scratch -tcp,rw,intr,bg fileserver:/scratch\n') map_entry = automount.AutomountMapEntry() map_entry.key = 'scratch' map_entry.options = '-tcp,rw,intr,bg' map_entry.location = 'fileserver:/scratch' self.mox.ReplayAll() cache._WriteData(file_mock, map_entry) self.mox.VerifyAll() file_mock = self.mox.CreateMock(sys.stdout) file_mock.write('scratch fileserver:/scratch\n') map_entry = automount.AutomountMapEntry() map_entry.key = 'scratch' map_entry.options = None map_entry.location = 'fileserver:/scratch' self.mox.ReplayAll() cache._WriteData(file_mock, map_entry)
def testAutomountSetsFilename(self): """We set the correct filename based on mountpoint information.""" # also tests GetMapLocation() because it uses it :) conf = {'dir': self.workdir, 'cache_filename_suffix': ''} cache = files.FilesAutomountMapHandler(conf) self.assertEqual(cache.GetMapLocation(), '%s/auto.master' % self.workdir) cache = files.FilesAutomountMapHandler(conf, automount_mountpoint='/home') self.assertEqual(cache.GetMapLocation(), '%s/auto.home' % self.workdir) cache = files.FilesAutomountMapHandler(conf, automount_mountpoint='/usr/meh') self.assertEqual(cache.GetMapLocation(), '%s/auto.usr_meh' % self.workdir)
def testCacheFileDoesNotExist(self): """Make sure we just get an empty map rather than exception.""" conf = {'dir': self.workdir, 'cache_filename_suffix': ''} cache = files.FilesAutomountMapHandler(conf) self.assertFalse( os.path.exists(os.path.join(self.workdir, 'auto.master'))) data = cache.GetMap() self.assertFalse(data)