Ejemplo n.º 1
0
    def test_drain_one(self):
        key = lease_management.MachineType(target_size=0, ).put()
        key = lease_management.MachineLease(
            id='%s-0' % key.id(),
            machine_type=key,
        ).put()

        lease_management.drain_excess()

        self.assertEqual(lease_management.MachineLease.query().count(), 1)
        self.assertTrue(key.get().drained)
Ejemplo n.º 2
0
    def test_drain_batched(self):
        key = lease_management.MachineType(
            enabled=False,
            target_size=2,
        ).put()
        lease_management.MachineLease(
            id='%s-0' % key.id(),
            machine_type=key,
        ).put()
        lease_management.MachineLease(
            id='%s-1' % key.id(),
            machine_type=key,
        ).put()
        key = lease_management.MachineType(
            enabled=False,
            target_size=2,
        ).put()
        lease_management.MachineLease(
            id='%s-0' % key.id(),
            machine_type=key,
        ).put()
        lease_management.MachineLease(
            id='%s-1' % key.id(),
            machine_type=key,
        ).put()
        key = lease_management.MachineType(target_size=0, ).put()
        lease_management.MachineLease(
            id='%s-0' % key.id(),
            machine_type=key,
        ).put()

        # Choice of 2, 2, 1 above and 3 here ensures at least one batch contains
        # MachineLease entities created for two different MachineTypes.
        lease_management.drain_excess(max_concurrent=3)

        self.assertEqual(lease_management.MachineLease.query().count(), 5)
        for machine_lease in lease_management.MachineLease.query():
            self.assertTrue(machine_lease.drained)
Ejemplo n.º 3
0
    def test_drain_all(self):
        key = lease_management.MachineType(
            enabled=False,
            target_size=3,
        ).put()
        lease_management.MachineLease(
            id='%s-0' % key.id(),
            machine_type=key,
        ).put()
        lease_management.MachineLease(
            id='%s-1' % key.id(),
            machine_type=key,
        ).put()
        lease_management.MachineLease(
            id='%s-2' % key.id(),
            machine_type=key,
        ).put()

        lease_management.drain_excess()

        self.assertEqual(lease_management.MachineLease.query().count(), 3)
        for machine_lease in lease_management.MachineLease.query():
            self.assertTrue(machine_lease.drained)
Ejemplo n.º 4
0
    def test_no_machine_types(self):
        lease_management.drain_excess()

        self.failIf(lease_management.MachineLease.query().count())