Ejemplo n.º 1
0
    def test_shrink(self):
        """ test_shrink. test when the pool shrinks. """

        (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION,
                                                       product=PRODUCT)
        defaults = {"resource_max": 3, "template_name": TEMPLATE}
        (pool1, _) = models.Pool.objects.update_or_create(
            name=TEST_POOL, host=host1, defaults=defaults)

        args = FakeArgs()
        server.args_process(args)
        self.assertEqual(server.main(args), 0)

        ##
        # Now shrink the pool to two
        pool1.resource_max = 2
        pool1.save()
        ##

        args = FakeArgs()
        args.setup = False
        server.args_process(args)
        self.assertEqual(server.main(args), 0)
        exts = ext.api_ext_list()

        pool = exts[PRODUCT].pool_get(pool1)
        self.assertEqual(len(pool.list(pool1)), 2)
Ejemplo n.º 2
0
def main():
    """ main entry point. """

    from testpool.core import server

    arg_parser = server.argparser()
    args = arg_parser.parse_args()
    server.args_process(args)
    server.main(args)
Ejemplo n.º 3
0
    def test_create_two(self):
        """ Create one container. """

        (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION,
                                                       product=PRODUCT)
        defaults = {"resource_max": 2, "template_name": TEMPLATE}
        models.Pool.objects.update_or_create(name=TEST_POOL, host=host1,
                                             defaults=defaults)

        args = FakeArgs()
        server.args_process(args)
        self.assertEqual(server.main(args), 0)
Ejemplo n.º 4
0
    def test_setup(self):
        """ test_setup. """

        (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION,
                                                       product=PRODUCT)

        defaults = {"resource_max": 1, "template_name": TEMPLATE}
        (pool1, _) = models.Pool.objects.update_or_create(
            name=TEST_POOL, host=host1, defaults=defaults)

        args = FakeArgs()
        server.args_process(args)
        self.assertEqual(server.main(args), 0)
        self.assertEqual(pool1.resource_set.all().count(), 1)
Ejemplo n.º 5
0
    def test_expiration(self):
        """ test_expiration. """

        resource_max = 3

        (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION,
                                                       product=PRODUCT)
        defaults = {"resource_max": resource_max, "template_name": TEMPLATE}
        (pool1, _) = models.Pool.objects.update_or_create(name=TEST_POOL,
                                                          host=host1,
                                                          defaults=defaults)

        args = FakeArgs()
        server.args_process(args)
        self.assertEqual(server.main(args), 0)

        rsrcs = pool1.resource_set.filter(status=models.Resource.READY)
        self.assertEqual(len(rsrcs), resource_max)

        rsrc = rsrcs[0]

        ##
        # Acquire for 3 seconds.
        rsrc.transition(models.Resource.RESERVED, algo.ACTION_DESTROY, 3)
        time.sleep(5)
        args.setup = False
        args.count = 2
        args.sleep_time = 1
        args.max_sleep_time = 1
        args.min_sleep_time = 1
        server.args_process(args)
        self.assertEqual(server.main(args), 0)
        ##

        exts = ext.api_ext_list()
        server.adapt(exts)

        rsrcs = pool1.resource_set.filter(status=models.Resource.READY)

        ##
        # Check to see if the expiration happens.
        self.assertEqual(rsrcs.count(), 2)
Ejemplo n.º 6
0
    def test_expiration(self):
        """ test_expiration. """

        resource_max = 3

        (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION,
                                                       product=PRODUCT)
        defaults = {"resource_max": resource_max, "template_name": TEMPLATE}
        (pool1, _) = models.Pool.objects.update_or_create(
            name=TEST_POOL, host=host1, defaults=defaults)

        args = FakeArgs()
        server.args_process(args)
        self.assertEqual(server.main(args), 0)

        rsrcs = pool1.resource_set.filter(status=models.Resource.READY)
        self.assertEqual(len(rsrcs), resource_max)

        rsrc = rsrcs[0]

        ##
        # Acquire for 3 seconds.
        rsrc.transition(models.Resource.RESERVED, algo.ACTION_DESTROY, 3)
        time.sleep(5)
        args.setup = False
        args.count = 2
        args.sleep_time = 1
        args.max_sleep_time = 1
        args.min_sleep_time = 1
        server.args_process(args)
        self.assertEqual(server.main(args), 0)
        ##

        exts = ext.api_ext_list()
        server.adapt(exts)

        rsrcs = pool1.resource_set.filter(status=models.Resource.READY)

        ##
        # Check to see if the expiration happens.
        self.assertEqual(rsrcs.count(), 2)
Ejemplo n.º 7
0
    def test_expand(self):
        """ test_expand. Check when pool increases. """

        (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION,
                                                       product=PRODUCT)
        defaults = {"resource_max": 2, "template_name": TEMPLATE}
        (pool1, _) = models.Pool.objects.update_or_create(
            name=TEST_POOL, host=host1, defaults=defaults)

        ##
        #  Now expand to 3
        pool1.resource_max = 3
        pool1.save()
        ##

        args = FakeArgs()
        server.args_process(args)
        self.assertEqual(server.main(args), 0)

        exts = ext.api_ext_list()
        pool = exts[PRODUCT].pool_get(pool1)
        self.assertEqual(len(pool.list(pool1)), 3)