Ejemplo n.º 1
0
def test_add_service_instance_from_container_but_meets_barrier(
        client, test_application_name, zk, add_service, minimal_mode,
        key, value):
    if minimal_mode:
        zk.ensure_path('/huskar/service/%s' % test_application_name)
        sleep(0.1)

    cm = ContainerManagement(huskar_client, key)
    cm.set_barrier()

    args, r = add_service(key, value, cluster_name='stable')
    assert r.status_code == 409
    assert r.json['status'] == 'Conflict'
    assert r.json['message'] == 'this container has been unbound recently'

    assert not zk.exists(
        '/huskar/service/%s/stable/%s' % (test_application_name, key))
    assert cm.lookup() == []
Ejemplo n.º 2
0
    def delete(self, container_id):
        """Reregisters all instances bound to this container.

        The site admin authority is required. See :ref:`site_admin` also.

        :param container_id: The container id (a.k.a CID, Task ID).
        :<header Authorization: Huskar Token (See :ref:`token`)
        :status 409: The container is still using by another one, and who are
                     registering new service instance on it. It is recommended
                     to try again since the container is truly dead.
        :status 200: The request is successful.
        """
        g.auth.require_admin()

        cm = ContainerManagement(huskar_client, container_id)
        cm.set_barrier()

        for application_name, cluster_name in cm.lookup():
            # Deregister current instance
            old_data = service_facade.get_value(
                application_name, cluster_name, container_id)
            service_facade.delete(
                application_name, cluster_name, container_id, strict=False)
            audit_log.emit(
                audit_log.types.DELETE_SERVICE,
                application_name=application_name, cluster_name=cluster_name,
                key=container_id, old_data=old_data)
            # Release container record
            cm.deregister_from(application_name, cluster_name)

        try:
            cm.destroy()
        except NotEmptyError:
            message = 'Container {0} is still registering new instance'.format(
                container_id)
            abort(409, message)

        return api_response()