[Server-devel] [PATCH] ds_backup.py: Implement server availability check

Michael Stone michael at laptop.org
Wed Jun 25 00:43:00 EDT 2008


On Tue, Jun 24, 2008 at 08:18:22PM -0400, martin.langhoff at gmail.com wrote:
> +def check_server_available(server, xo_serial):
> +
>      try:
...
> +        ret = urllib2.urlopen(server + '/available/%s' % xo_serial).read()
> +        return 200
> +    except HTTPError, e:
> +        # server is there, did not fullfull req
> +        #  expect 404, 403, 503 as e[1]
> +        return e.code
> +    except URLError, e:
> +        # log it?
> +        # print e.reason
> +        return -1

Why not just propagate the exceptions?

>  def rsync_to_xs(from_path, to_path, keyfile, user):
>  
> @@ -71,7 +61,7 @@ def rsync_to_xs(from_path, to_path, keyfile, user):
>      if not re.compile('/$').search(from_path):
>          from_path = from_path + '/'
>  
> -    ssh = '/usr/bin/ssh -F /dev/null -o "PasswordAuthentication no" -i "%s" -l "%s"' \
> +    ssh = '/usr/bin/ssh -F /dev/null -o "PasswordAuthentication no" -o "StrictHostKeyChecking no" -i "%s" -l "%s"' \

What's the justification for turning off host key checking?

> +    for n in range(1,7):
> +        sstatus = check_server_available(backup_url, sn)
> +        if (sstatus == 200):
> +            # cleared to run
> +            rsync_to_xs(ds_path, 'schoolserver:datastore', pk_path, sn)
> +            # this marks success to the controlling script...
> +            os.system('touch ~/.sugar/default/ds_backup-done')
> +            exit(0)
> +        elif (sstatus == 503):
> +            # exponenxtial backoff
> +            time.sleep(60 * 2**n)
> +        elif (sstatus == -1):
> +            # could not connect - XS is not there
> +            exit(1)
> +        else:
> +            # 500, 404, 403, or other unexpected value
> +            exit(1)

Perhaps we should return either appropriate errno values or the HTTP
error numbers on error conditions?

Thanks,

Michael



More information about the Server-devel mailing list