'Server.iter_pid_files is kinda boring, test the
Server.pid_files stuff here as well'

def test_iter_pid_files(self):

    pid_files = (('proxy-server.pid', 1), ('auth-server.pid', 'blah'), ('object-replicator/1.pid', 11), ('object-replicator/2.pid', 12))
    (files, contents) = zip(*pid_files)
    with temptree(files, contents) as t:
        manager.RUN_DIR = t
        server = manager.Server('proxy', run_dir=t)
        iterator = server.iter_pid_files()
        (pid_file, pid) = next(iterator)
        self.assertEqual(pid_file, self.join_run_dir('proxy-server.pid'))
        self.assertEqual(pid, 1)
        self.assertRaises(StopIteration, next, iterator)
        server = manager.Server('auth', run_dir=t)
        (pid_file, pid) = next(server.iter_pid_files())
        self.assertIsNone(pid)
        server = manager.Server('object', run_dir=t)
        self.assertRaises(StopIteration, next, server.iter_pid_files())
        server = manager.Server('object-replicator', run_dir=t)
        real_map = {11: self.join_run_dir('object-replicator/1.pid'), 12: self.join_run_dir('object-replicator/2.pid')}
        pid_map = {}
        for (pid_file, pid) in server.iter_pid_files():
            pid_map[pid] = pid_file
        self.assertEqual(pid_map, real_map)
    conf_files = ('object-server/1.conf', 'object-server/2.conf', 'object-server/3.conf', 'object-server/4.conf')
    pid_files = (('object-server/1.pid', 1), ('object-server/2.pid', 2), ('object-server/5.pid', 5))
    with temptree(conf_files) as swift_dir:
        manager.SWIFT_DIR = swift_dir
        (files, pids) = zip(*pid_files)
        with temptree(files, pids) as t:
            manager.RUN_DIR = t
            server = manager.Server('object', run_dir=t)
            real_map = {1: self.join_run_dir('object-server/1.pid'), 2: self.join_run_dir('object-server/2.pid'), 5: self.join_run_dir('object-server/5.pid')}
            pid_map = {}
            for (pid_file, pid) in server.iter_pid_files():
                pid_map[pid] = pid_file
            self.assertEqual(pid_map, real_map)
            pids = list(server.iter_pid_files(number=2))
            self.assertEqual(len(pids), 1)
            (pid_file, pid) = pids[0]
            self.assertEqual(pid, 2)
            pid_two = self.join_run_dir('object-server/2.pid')
            self.assertEqual(pid_file, pid_two)
            pids = list(server.iter_pid_files(number=3))
            self.assertFalse(pids)
            pids = list(server.iter_pid_files(number=5))
            self.assertFalse(pids)
    conf_files = ('object-server/1.conf', 'object-server/2.conf', 'object-server/3.conf', 'object-server/4.conf')
    pid_files = (('object-server/1.pid', 1), ('object-server/2.pid', 2), ('object-server/5.pid', 5))
    with temptree(conf_files) as swift_dir:
        manager.SWIFT_DIR = swift_dir
        (files, pids) = zip(*pid_files)
        with temptree(files, pids) as t:
            manager.RUN_DIR = t
            server = manager.Server('object.2', run_dir=t)
            pids = list(server.iter_pid_files())
            self.assertEqual(len(pids), 1)
            (pid_file, pid) = pids[0]
            self.assertEqual(pid, 2)
            pid_two = self.join_run_dir('object-server/2.pid')
            self.assertEqual(pid_file, pid_two)
