def test_rollback_route_change(db, client, faker, test_application_name,
                               admin_token, action_type, cluster_name,
                               dest_application_name, destination_cluster_name,
                               zk):
    action = action_creator.make_action(
        action_type,
        application_name=test_application_name,
        cluster_name=cluster_name,
        intent='direct',
        dest_application_name=dest_application_name,
        dest_cluster_name=destination_cluster_name)
    audit_log = AuditLog.create(0, faker.ipv4(), action)
    db.close()

    rm = RouteManagement(huskar_client, test_application_name, cluster_name)
    prev_destination_cluster = faker.uuid4()[:8]
    for cluster in [destination_cluster_name, prev_destination_cluster]:
        path = '/huskar/service/%s/%s/fo' % (dest_application_name, cluster)
        zk.ensure_path(path)
    rm.set_route(dest_application_name, prev_destination_cluster)

    r = client.put('/api/audit-rollback/%s/%s' %
                   (test_application_name, audit_log.id),
                   headers={'Authorization': admin_token})
    assert_response_ok(r)
    if action_type == action_types.DELETE_ROUTE:
        result = [(dest_application_name, 'direct', destination_cluster_name)]
    else:
        result = []
    assert list(rm.list_route()) == result
Exemple #2
0
 def _put(self, application_name, cluster_name, dest_application_name):
     dest_cluster_name = request.form['cluster_name'].strip()
     check_cluster_name(dest_cluster_name, dest_application_name)
     intent = self._get_intent()
     facade = RouteManagement(huskar_client, application_name, cluster_name)
     try:
         facade.set_route(dest_application_name, dest_cluster_name, intent)
     except EmptyClusterError as e:
         abort(400, unicode(e))
     audit_log.emit(audit_log.types.UPDATE_ROUTE,
                    application_name=application_name,
                    cluster_name=cluster_name,
                    intent=intent,
                    dest_application_name=dest_application_name,
                    dest_cluster_name=dest_cluster_name)
Exemple #3
0
def rollback_route_action(action_type, action_data):
    application_name = action_data['application_name']
    cluster_name = action_data['cluster_name']
    intent = action_data['intent']
    dest_application_name = action_data['dest_application_name']
    dest_cluster_name = action_data.get('dest_cluster_name')
    rm = RouteManagement(huskar_client, application_name, cluster_name)
    if action_type == action_types.DELETE_ROUTE:
        rm.set_route(dest_application_name, dest_cluster_name)
        new_action_type = action_types.UPDATE_ROUTE
    else:
        rm.discard_route(dest_application_name)
        new_action_type = action_types.DELETE_ROUTE
    return new_action_type, {
        'application_name': application_name,
        'cluster_name': cluster_name,
        'intent': intent,
        'dest_application_name': dest_application_name,
        'dest_cluster_name': dest_cluster_name
    }