def testUpdateMapsTrapsPermissionDenied(self): self.mox.StubOutWithMock(map_updater.MapUpdater, 'UpdateFromSource') map_updater.MapUpdater.UpdateFromSource(mox.IgnoreArg(), incremental=True, force_write=False).AndRaise( error.PermissionDenied) 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_PASSWORD] self.conf.cache = 'dummy' modify_stamp = 1 map_entry = passwd.PasswdMapEntry({'name': 'foo', 'uid': 10, 'gid': 10}) passwd_map = passwd.PasswdMap([map_entry]) passwd_map.SetModifyTimestamp(modify_stamp) source_mock = self.mox.CreateMock(source.Source) 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) self.mox.StubOutWithMock(cache_factory, 'Create') self.mox.ReplayAll() c = command.Update() self.assertEqual( 1, c.UpdateMaps(self.conf, incremental=True, force_write=False))
def testUpdateSingleMaps(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_PASSWORD] self.conf.cache = 'dummy' modify_stamp = 1 map_entry = passwd.PasswdMapEntry({'name': 'foo', 'uid': 10, 'gid': 10}) passwd_map = passwd.PasswdMap([map_entry]) passwd_map.SetModifyTimestamp(modify_stamp) source_mock = self.mox.CreateMock(source.Source) source_mock.GetMap(config.MAP_PASSWORD, location=None).AndReturn(passwd_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.WriteMap(map_data=passwd_map).AndReturn(0) self.mox.StubOutWithMock(cache_factory, 'Create') cache_factory.Create(self.conf.options[config.MAP_PASSWORD].cache, config.MAP_PASSWORD).AndReturn(cache_mock) self.mox.ReplayAll() c = command.Update() self.assertEqual( 0, c.UpdateMaps(self.conf, incremental=True, force_write=False))
def testUpdateMapsWithBadMapName(self): c = command.Update() self.mox.StubOutWithMock(c, '_Lock') c._Lock(force=False, path=None).AndReturn(True) self.mox.ReplayAll() # Create an invalid map name. self.assertEqual( 1, c.Run(self.conf, ['-m', config.MAP_PASSWORD + 'invalid']))
def testRunWithBadParameters(self): c = command.Update() # Trap stderr so the unit test runs clean, # since unit test status is printed on stderr. dev_null = StringIO.StringIO() stderr = sys.stderr sys.stderr = dev_null self.assertEquals(2, c.Run(None, ['--invalid'])) sys.stderr = stderr
def testForceLockFlagCallsUpdateMapsWithForceLockTrue(self): c = command.Update() self.mox.StubOutWithMock(c, 'UpdateMaps') c.UpdateMaps(self.conf, incremental=mox.IgnoreArg(), force_lock=True, force_write=mox.IgnoreArg()).AndReturn(0) self.mox.ReplayAll() self.assertEqual(0, c.Run(self.conf, ['--force-lock']))
def testRunWithNoParameters(self): c = command.Update() self.mox.StubOutWithMock(c, 'UpdateMaps') c.UpdateMaps(self.conf, incremental=True, force_lock=False, force_write=False).AndReturn(0) self.mox.ReplayAll() self.assertEquals(0, c.Run(self.conf, []))
def testUpdateMapsCanForceLock(self): self.mox.StubOutClassWithMocks(lock, 'PidFile') lock_mock = lock.PidFile(filename=None) lock_mock.Lock(force=True).AndReturn(False) lock_mock.Locked().AndReturn(True) lock_mock.Unlock() self.mox.ReplayAll() c = command.Update() self.assertEquals(c.UpdateMaps(self.conf, False, force_lock=True), c.ERR_LOCK)
def testSleep(self): self.mox.StubOutWithMock(time, 'sleep') time.sleep(1) c = command.Update() self.mox.StubOutWithMock(c, 'UpdateMaps') c.UpdateMaps(self.conf, incremental=True, force_lock=mox.IgnoreArg(), force_write=mox.IgnoreArg()).AndReturn(0) self.mox.ReplayAll() c.Run(self.conf, ['-s', '1'])
def testRunWithFlags(self): c = command.Update() self.mox.StubOutWithMock(c, 'UpdateMaps') c.UpdateMaps(self.conf, incremental=False, force_lock=True, force_write=True).AndReturn(0) self.mox.ReplayAll() self.assertEqual( 0, c.Run(self.conf, [ '-m', config.MAP_PASSWORD, '-f', '--force-write', '--force-lock' ])) self.assertEqual(['passwd'], self.conf.maps)
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))
def testForceLockFlag(self): c = command.Update() (options, _) = c.parser.parse_args([]) self.assertEqual(False, options.force_lock) (options, _) = c.parser.parse_args(['--force-lock']) self.assertEqual(True, options.force_lock)
def testForceWriteFlag(self): c = command.Update() (options, _) = c.parser.parse_args([]) self.assertEqual(False, options.force_write) (options, _) = c.parser.parse_args(['--force-write']) self.assertEqual(True, options.force_write)
def testHelp(self): c = command.Update() self.failIfEqual(None, c.Help())
def testConstructor(self): c = command.Update() self.failIfEqual(None, c)
def testHelp(self): c = command.Update() self.assertNotEqual(None, c.Help())
def testConstructor(self): c = command.Update() self.assertNotEqual(None, c)