def testExecuteTasksOnNeighbors(self):
        """test execute tasks on directly connected machines"""
        tmpfile = tempfile.NamedTemporaryFile()

        myhost = my_node()
        cfgparser = load_cfg('topology1.conf')
        neighbor = cfgparser.get('CONFIG', 'NEIGHBOR')
        gateways = cfgparser.get('CONFIG', 'GATEWAYS')
        targets = cfgparser.get('CONFIG', 'TARGETS')

        tmpfile.write('[Main]\n')
        tmpfile.write('%s: %s\n' % (myhost, neighbor))
        tmpfile.write('%s: %s\n' % (neighbor, gateways))
        tmpfile.write('%s: %s\n' % (gateways, targets))
        tmpfile.flush()
        parser = TopologyParser()
        parser.load(tmpfile.name)

        tree = parser.tree(myhost)
        wtree = WorkerTree(NodeSet(targets), None, 0, command='echo ok',
                           topology=tree, newroot=myhost)
        # XXX Need to propagate topology for this to work in tests
        raise RuntimeError

        task = task_self()
        task.set_info('debug', True)
        task.schedule(wtree)
        task.resume()

        for buf, nodes in task.iter_buffers():
            print '-' * 15
            print str(nodes)
            print '-' * 15
            print buf
            print ''
Пример #2
0
    def testExecuteTasksOnNeighbors(self):
        """test execute tasks on directly connected machines"""
        tmpfile = tempfile.NamedTemporaryFile()

        myhost = my_node()
        cfgparser = load_cfg('topology1.conf')
        neighbor = cfgparser.get('CONFIG', 'NEIGHBOR')
        gateways = cfgparser.get('CONFIG', 'GATEWAYS')
        targets = cfgparser.get('CONFIG', 'TARGETS')

        tmpfile.write('[Main]\n')
        tmpfile.write('%s: %s\n' % (myhost, neighbor))
        tmpfile.write('%s: %s\n' % (neighbor, gateways))
        tmpfile.write('%s: %s\n' % (gateways, targets))
        tmpfile.flush()
        parser = TopologyParser()
        parser.load(tmpfile.name)

        tree = parser.tree(myhost)
        wtree = WorkerTree(NodeSet(targets),
                           None,
                           0,
                           command='echo ok',
                           topology=tree,
                           newroot=myhost)
        # XXX Need to propagate topology for this to work in tests
        raise RuntimeError

        task = task_self()
        task.set_info('debug', True)
        task.schedule(wtree)
        task.resume()

        for buf, nodes in task.iter_buffers():
            print '-' * 15
            print str(nodes)
            print '-' * 15
            print buf
            print ''
Пример #3
0
    def testCompletePropagation(self):
        """test a complete command propagation trip"""
        #
        # This test relies on configured parameters (topology2.conf)
        tmpfile = tempfile.NamedTemporaryFile()

        logging.basicConfig(
                level=logging.DEBUG
                )
        logging.debug("STARTING")

        hostname = my_node()
        cfgparser = load_cfg('topology2.conf')
        neighbors = cfgparser.get('CONFIG', 'NEIGHBORS')
        targets = cfgparser.get('CONFIG', 'TARGETS')

        tmpfile.write('[DEFAULT]\n')
        tmpfile.write('%s: %s\n' % (hostname, neighbors))
        tmpfile.write('%s: %s\n' % (neighbors, targets))
        tmpfile.flush()
        parser = TopologyParser()
        parser.load(tmpfile.name)
        tmpfile.close()

        nfs_tmpdir = os.path.expanduser('~/.clustershell/tests/tmp')

        tree = parser.tree(hostname)
        print tree

        ptree = PropagationTree(tree, hostname)
        ptree.upchannel = None
        ptree.edgehandler = DirectHandler()

        ptree.fanout = 20
        ptree.invoke_gateway = \
            'cd %s; PYTHONPATH=../lib python -m ClusterShell/Gateway -Bu' % \
                os.getcwd()
        #print ptree.invoke_gateway

        ## delete remaining files from previous tests
        for filename in os.listdir(nfs_tmpdir):
            if filename.startswith("fortoy"):
                os.remove(os.path.join(nfs_tmpdir, filename))

        dst = NodeSet(targets)
        task = ptree.execute('python -c "import time; print time.time()" > ' + \
                             os.path.join(nfs_tmpdir, '$(hostname)'), dst, 20)
        #task = ptree.execute('sleep 2; echo "output from $(hostname)"', \
        #                      dst, 20)
        self.assert_(task)

        res = NodeSet()
        times = []
        for filename in os.listdir(nfs_tmpdir):
            for k in dst:
                if filename.startswith(str(k)):
                    res.add(k)
                    fd = open(os.path.join(nfs_tmpdir, filename))
                    times.append(float(fd.read()))
                    fd.close()

        self.assertEquals(str(res), str(dst))
        print "Complete propagation time: %fs for %d nodes" % \
                (max(times) - min(times), len(dst))