#!/usr/bin/env python
import requests
import sys
import json
import argparse


def fake_callback(backend_url, lab_name, lab_token, filename):
    headers = {
        "Authorization": lab_token
    }
    print "Looking for file {}".format(filename)
    try:
        json_file = open(filename)
    except (IOError) as err:
        print "Can't find file, error: {}".format(err)
        return
    payload = json.load(json_file)
    url = backend_url + "/callback/lava/boot?lab_name=" + lab_name + "&status=2&status_string=complete"
    response = requests.post(url, headers=headers, json=payload)
    print response


def parse_cmdline():
    parser = argparse.ArgumentParser(
        description="Resend a LAVA v2 callback event from a JSON file",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--url', action='store',
                        help="The backend url to send callbacks to",
                        required=True)
    parser.add_argument('--lab-name', action='store',
                        help="The lab-name as registered in the backend.",
                        required=True)
    parser.add_argument('--token', action='store',
                        help="The token associated to the lab-name",
                        required=True)
    parser.add_argument('--filename', action='store',
                        help="The json file that contains the callback data.",
                        required=True)
    return parser.parse_args()


def main():
    args = parse_cmdline()
    fake_callback(args.url, args.lab_name, args.token, args.filename)


if __name__ == "__main__":
    main()
    sys.exit(0)

@@ -70,16 +70,46 @@
 rgparse%0A
+import urllib%0Aimport urlparse%0A
 %0A%0Adef fa
@@ -457,57 +457,53 @@
     
-url = backend_url + %22/callback/lava/boot?
+params = urllib.urlencode(%7B%0A        '
 lab_name
 =%22 +
@@ -502,12 +502,10 @@
 name
-=%22 +
+':
  lab
@@ -513,22 +513,40 @@
 name
- + %22&status=2&
+,%0A        'status': 2,%0A        '
 stat
@@ -558,17 +558,20 @@
 ring
-=
+': '
 complete
 %22%0A  
@@ -566,17 +566,105 @@
 complete
-%22
+',%0A    %7D)%0A    url = urlparse.urljoin(backend_url, 'callback/lava/boot?%7B%7D'.format(params))
 %0A    res

Fix pep8 error in fake_lava_v2_callback.py