Beispiel #1
0
    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)
Beispiel #2
0
  def testUpdateNoMaster(self):
    """An update skips updating the master map, and approprate sub maps."""
    source_entry1 = automount.AutomountMapEntry()
    source_entry2 = automount.AutomountMapEntry()
    source_entry1.key = '/home'
    source_entry2.key = '/auto'
    source_entry1.location = 'ou=auto.home,ou=automounts'
    source_entry2.location = 'ou=auto.auto,ou=automounts'
    source_master = automount.AutomountMap([source_entry1, source_entry2])

    local_entry1 = automount.AutomountMapEntry()
    local_entry2 = automount.AutomountMapEntry()
    local_entry1.key = '/home'
    local_entry2.key = '/auto'
    local_entry1.location = '/etc/auto.home'
    local_entry2.location = '/etc/auto.null'
    local_master = automount.AutomountMap([local_entry1, local_entry2])

    source_mock = self.mox.CreateMock(source.Source)
    # return the source master map
    source_mock.GetAutomountMasterMap().AndReturn(source_master)

    # the auto.home cache
    cache_home = self.mox.CreateMock(caches.Cache)
    # GetMapLocation() is called, and set to the master map map_entry
    cache_home.GetMapLocation().AndReturn('/etc/auto.home')

    # the auto.auto cache
    cache_auto = self.mox.CreateMock(caches.Cache)
    # GetMapLocation() is called, and set to the master map map_entry
    cache_auto.GetMapLocation().AndReturn('/etc/auto.auto')

    # the auto.master cache, which should not be written to
    cache_master = self.mox.CreateMock(caches.Cache)
    cache_master.GetMap().AndReturn(local_master)

    self.mox.StubOutWithMock(cache_factory, 'Create')
    cache_factory.Create(mox.IgnoreArg(), mox.IgnoreArg(), automount_mountpoint=None).AndReturn(cache_master)
    cache_factory.Create(mox.IgnoreArg(), mox.IgnoreArg(), automount_mountpoint='/home').AndReturn(cache_home)
    cache_factory.Create(mox.IgnoreArg(), mox.IgnoreArg(), automount_mountpoint='/auto').AndReturn(cache_auto)

    skip = map_updater.AutomountUpdater.OPT_LOCAL_MASTER
    updater = map_updater.AutomountUpdater(
        config.MAP_AUTOMOUNT, self.workdir, {skip: 'yes'})

    self.mox.StubOutClassWithMocks(map_updater, 'MapUpdater')
    updater_home = map_updater.MapUpdater(config.MAP_AUTOMOUNT, self.workdir, {'local_automount_master': 'yes'}, automount_mountpoint='/home')
    updater_home.UpdateCacheFromSource(cache_home, source_mock, True, False, 'ou=auto.home,ou=automounts').AndReturn(0)

    self.mox.ReplayAll()

    updater.UpdateFromSource(source_mock)
Beispiel #3
0
  def testUpdate(self):
    """An update gets a master map and updates each entry."""
    map_entry1 = automount.AutomountMapEntry()
    map_entry2 = automount.AutomountMapEntry()
    map_entry1.key = '/home'
    map_entry2.key = '/auto'
    map_entry1.location = 'ou=auto.home,ou=automounts'
    map_entry2.location = 'ou=auto.auto,ou=automounts'
    master_map = automount.AutomountMap([map_entry1, map_entry2])

    source_mock = self.mox.CreateMock(source.Source)
    # return the master map
    source_mock.GetAutomountMasterMap().AndReturn(master_map)

    # the auto.home cache
    cache_home = self.mox.CreateMock(caches.Cache)
    # GetMapLocation() is called, and set to the master map map_entry
    cache_home.GetMapLocation().AndReturn('/etc/auto.home')

    # the auto.auto cache
    cache_auto = self.mox.CreateMock(caches.Cache)
    # GetMapLocation() is called, and set to the master map map_entry
    cache_auto.GetMapLocation().AndReturn('/etc/auto.auto')

    # the auto.master cache
    cache_master = self.mox.CreateMock(caches.Cache)

    self.mox.StubOutWithMock(cache_factory, 'Create')
    cache_factory.Create(mox.IgnoreArg(), 'automount', automount_mountpoint='/home').AndReturn(cache_home)
    cache_factory.Create(mox.IgnoreArg(), 'automount', automount_mountpoint='/auto').AndReturn(cache_auto)
    cache_factory.Create(mox.IgnoreArg(), 'automount', automount_mountpoint=None).AndReturn(cache_master)

    updater = map_updater.AutomountUpdater(
        config.MAP_AUTOMOUNT, self.workdir, {})

    self.mox.StubOutClassWithMocks(map_updater, 'MapUpdater')
    updater_home = map_updater.MapUpdater(config.MAP_AUTOMOUNT, self.workdir, {}, automount_mountpoint='/home')
    updater_home.UpdateCacheFromSource(cache_home, source_mock, True, False, 'ou=auto.home,ou=automounts').AndReturn(0)
    updater_auto = map_updater.MapUpdater(config.MAP_AUTOMOUNT, self.workdir, {}, automount_mountpoint='/auto')
    updater_auto.UpdateCacheFromSource(cache_auto, source_mock, True, False, 'ou=auto.auto,ou=automounts').AndReturn(0)
    updater_master = map_updater.MapUpdater(config.MAP_AUTOMOUNT, self.workdir, {})
    updater_master.FullUpdateFromMap(cache_master, master_map).AndReturn(0)

    self.mox.ReplayAll()

    updater.UpdateFromSource(source_mock)

    self.assertEqual(map_entry1.location, '/etc/auto.home')
    self.assertEqual(map_entry2.location, '/etc/auto.auto')
Beispiel #4
0
 def __init__(self, obj):
     """Set some default avalible data for testing."""
     super(TestAutomountMap, self).__init__(obj)
     self._good_entry = automount.AutomountMapEntry()
     self._good_entry.key = 'foo'
     self._good_entry.options = '-tcp'
     self._good_entry.location = 'nfsserver:/mah/stuff'
Beispiel #5
0
    def testGetAutomountMapMetadata(self):
        # need to stub out GetSingleMapMetadata (tested above) and then
        # stub out cache_factory.Create to return a cache mock that spits
        # out an iterable map for the function to use.

        # stub out GetSingleMapMetadata
        class DummyStatus(command.Status):

            def GetSingleMapMetadata(self,
                                     unused_map_name,
                                     unused_conf,
                                     automount_mountpoint=None,
                                     epoch=False):
                return {
                    'map': 'map_name',
                    'last-modify-timestamp': 'foo',
                    'last-update-timestamp': 'bar'
                }

        # the master map to loop over
        master_map = automount.AutomountMap()
        master_map.Add(
            automount.AutomountMapEntry({
                'key': '/home',
                'location': '/etc/auto.home'
            }))
        master_map.Add(
            automount.AutomountMapEntry({
                'key': '/auto',
                'location': '/etc/auto.auto'
            }))

        # mock out a cache to return the master map
        cache_mock = self.mox.CreateMock(caches.Cache)
        cache_mock.GetMap().AndReturn(master_map)

        self.mox.StubOutWithMock(cache_factory, 'Create')
        cache_factory.Create(self.conf.options[config.MAP_AUTOMOUNT].cache,
                             config.MAP_AUTOMOUNT,
                             automount_mountpoint=None).AndReturn(cache_mock)

        self.mox.ReplayAll()

        c = DummyStatus()
        value_list = c.GetAutomountMapMetadata(self.conf)

        self.assertEqual(9, len(value_list))
Beispiel #6
0
 def testInit(self):
     """Construct an empty and seeded AutomountMapEntry."""
     self.assertTrue(automount.AutomountMapEntry(),
                     msg='Could not create empty AutomountMapEntry')
     seed = {'key': 'foo', 'location': '/dev/sda1'}
     entry = automount.AutomountMapEntry(seed)
     self.assertTrue(entry.Verify(),
                     msg='Could not verify seeded AutomountMapEntry')
     self.assertEqual(entry.key,
                      'foo',
                      msg='Entry returned wrong value for name')
     self.assertEqual(entry.options,
                      None,
                      msg='Entry returned wrong value for options')
     self.assertEqual(entry.location,
                      '/dev/sda1',
                      msg='Entry returned wrong value for location')
Beispiel #7
0
 def testAttributes(self):
     """Test that we can get and set all expected attributes."""
     entry = automount.AutomountMapEntry()
     entry.key = 'foo'
     self.assertEqual(entry.key, 'foo', msg='Could not set attribute: key')
     entry.options = 'noatime'
     self.assertEqual(entry.options,
                      'noatime',
                      msg='Could not set attribute: options')
     entry.location = '/dev/ipod'
     self.assertEqual(entry.location,
                      '/dev/ipod',
                      msg='Could not set attribute: location')
Beispiel #8
0
    def Transform(self, obj):
        """Transforms an LDAP automount object into an autofs(5) entry."""
        automount_ent = automount.AutomountMapEntry()
        automount_ent.key = obj['cn'][0]

        automount_information = obj['automountInformation'][0]

        if automount_information.startswith('ldap'):
            # we are creating an autmount master map, pointing to other maps in LDAP
            automount_ent.location = automount_information
        else:
            # we are creating normal automount maps, with filesystems and options
            automount_ent.options = automount_information.split(' ')[0]
            automount_ent.location = automount_information.split(' ')[1]

        return automount_ent
Beispiel #9
0
    def testUpdateAutomounts(self):
        self.mox.StubOutClassWithMocks(lock, 'PidFile')
        lock_mock = lock.PidFile(filename=None)
        lock_mock.Lock(force=False).AndReturn(True)
        lock_mock.Locked().AndReturn(True)
        lock_mock.Unlock()

        self.conf.maps = [config.MAP_AUTOMOUNT]
        self.conf.cache = 'dummy'

        modify_stamp = 1
        map_entry = automount.AutomountMapEntry()
        map_entry.key = '/home'
        map_entry.location = 'foo'
        automount_map = automount.AutomountMap([map_entry])
        automount_map.SetModifyTimestamp(modify_stamp)

        source_mock = self.mox.CreateMock(source.Source)
        source_mock.GetAutomountMasterMap().AndReturn(automount_map)
        source_mock.GetMap(config.MAP_AUTOMOUNT,
                           location='foo').AndReturn(automount_map)

        self.mox.StubOutWithMock(source_factory, 'Create')
        source_factory.Create(self.conf.options[
            config.MAP_PASSWORD].source).AndReturn(source_mock)

        cache_mock = self.mox.CreateMock(caches.Cache)
        cache_mock.GetMapLocation().AndReturn('home')
        cache_mock.WriteMap(map_data=automount_map).AndReturn(0)
        cache_mock.WriteMap(map_data=automount_map).AndReturn(0)

        self.mox.StubOutWithMock(cache_factory, 'Create')
        cache_factory.Create(
            self.conf.options[config.MAP_AUTOMOUNT].cache,
            config.MAP_AUTOMOUNT,
            automount_mountpoint='/home').AndReturn(cache_mock)
        cache_factory.Create(self.conf.options[config.MAP_AUTOMOUNT].cache,
                             config.MAP_AUTOMOUNT,
                             automount_mountpoint=None).AndReturn(cache_mock)

        self.mox.ReplayAll()

        c = command.Update()
        self.assertEquals(
            0, c.UpdateMaps(self.conf, incremental=True, force_write=False))
Beispiel #10
0
    def _ReadEntry(self, line):
        """Return an AutomountMapEntry from a record in the target cache.

        Args:
          line: A string from a file cache.

        Returns:
          An AutomountMapEntry if the line is successfully parsed, None otherwise.
        """
        line = line.split()
        map_entry = automount.AutomountMapEntry()
        try:
            map_entry.key = line[0]
            if len(line) > 2:
                map_entry.options = line[1]
                map_entry.location = line[2]
            else:
                map_entry.location = line[1]
        except IndexError:
            return None
        return map_entry
Beispiel #11
0
 def testKey(self):
     """Key() should return the value of the 'key' attribute."""
     entry = automount.AutomountMapEntry()
     entry.key = 'foo'
     self.assertEqual(entry.Key(), entry.key)
Beispiel #12
0
    def testVerify(self):
        """Test that the object can verify it's attributes and itself."""
        entry = automount.AutomountMapEntry()

        # Empty object should bomb
        self.assertFalse(entry.Verify())