Ejemplo n.º 1
0
    def testToHosts(self):
        from Exscript.util.cast import to_hosts
        self.assertRaises(TypeError, to_hosts, None)

        result = to_hosts([])
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 0)

        result = to_hosts('localhost')
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 1)
        self.assertIsInstance(result[0], Host)

        result = to_hosts(Host('localhost'))
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 1)
        self.assertIsInstance(result[0], Host)

        hosts = ['localhost', Host('1.2.3.4')]
        result = to_hosts(hosts)
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 2)
        self.assertIsInstance(result[0], Host)
        self.assertIsInstance(result[1], Host)
Ejemplo n.º 2
0
    def testToHosts(self):
        from Exscript.util.cast import to_hosts
        self.assertRaises(TypeError, to_hosts, None)

        result = to_hosts([])
        self.assertTrue(isinstance(result, list))
        self.assertTrue(len(result) == 0)

        result = to_hosts('localhost')
        self.assertTrue(isinstance(result, list))
        self.assertTrue(len(result) == 1)
        self.assertTrue(isinstance(result[0], Host))

        result = to_hosts(Host('localhost'))
        self.assertTrue(isinstance(result, list))
        self.assertTrue(len(result) == 1)
        self.assertTrue(isinstance(result[0], Host))

        hosts  = ['localhost', Host('1.2.3.4')]
        result = to_hosts(hosts)
        self.assertTrue(isinstance(result, list))
        self.assertTrue(len(result) == 2)
        self.assertTrue(isinstance(result[0], Host))
        self.assertTrue(isinstance(result[1], Host))
Ejemplo n.º 3
0
    def testToHosts(self):
        from Exscript.util.cast import to_hosts
        self.assertRaises(TypeError, to_hosts, None)

        result = to_hosts([])
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 0)

        result = to_hosts('localhost')
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 1)
        self.assertIsInstance(result[0], Host)

        result = to_hosts(Host('localhost'))
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 1)
        self.assertIsInstance(result[0], Host)

        hosts = ['localhost', Host('1.2.3.4')]
        result = to_hosts(hosts)
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 2)
        self.assertIsInstance(result[0], Host)
        self.assertIsInstance(result[1], Host)
Ejemplo n.º 4
0
    def _run(self, hosts, callback, queue_function, *args):
        hosts = to_hosts(hosts, default_domain=self.domain)
        self.total += len(hosts)
        callback = _prepare_connection(callback)
        task = Task(self.workqueue)
        for host in hosts:
            name = host.get_name()
            data = {"host": host}
            job_id = queue_function(callback, name, *args, data=data)
            if job_id is not None:
                task.add_job_id(job_id)

        if task.is_completed():
            self._dbg(2, "No jobs enqueued.")
            return None

        self._dbg(2, "All jobs enqueued.")
        return task
Ejemplo n.º 5
0
    def _run(self, hosts, callback, queue_function, *args):
        hosts = to_hosts(hosts, default_domain=self.domain)
        self.total += len(hosts)
        callback = _prepare_connection(callback)
        task = Task(self.workqueue)
        for host in hosts:
            name = host.get_name()
            data = {'host': host}
            job_id = queue_function(callback, name, *args, data=data)
            if job_id is not None:
                task.add_job_id(job_id)

        if task.is_completed():
            self._dbg(2, 'No jobs enqueued.')
            return None

        self._dbg(2, 'All jobs enqueued.')
        return task