mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-24 00:32:15 +00:00
This patch gets housekeeping to create a uuid file if a path to a uuid file is upplied but the file is missing. Because it import the uuid lib, uuid parameters where renamed. Fixes #1987 Signed-off-by: Amnon Heiman <amnon@scylladb.com> Message-Id: <1483866553-13855-2-git-send-email-amnon@scylladb.com>
129 lines
4.4 KiB
Python
Executable File
129 lines
4.4 KiB
Python
Executable File
#!/usr/bin/python
|
|
#
|
|
# Copyright (C) 2016 ScyllaDB
|
|
#
|
|
|
|
#
|
|
# This file is part of Scylla.
|
|
#
|
|
# Scylla is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Scylla is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
from __future__ import print_function
|
|
|
|
import argparse
|
|
import json
|
|
import urllib
|
|
import urllib2
|
|
import requests
|
|
import ConfigParser
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import uuid
|
|
from pkg_resources import parse_version
|
|
|
|
VERSION = "1.0"
|
|
quiet = False
|
|
# Temporary url for the review
|
|
version_url = "https://i6a5h9l1kl.execute-api.us-east-1.amazonaws.com/prod/check_version"
|
|
|
|
def trace(*vals):
|
|
print(''.join(vals))
|
|
|
|
def traceln(*vals):
|
|
trace(*(vals + ('\n',)))
|
|
|
|
def help(args):
|
|
parser.print_help()
|
|
|
|
def sh_command(*args):
|
|
p = subprocess.Popen(args, stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE)
|
|
out, err = p.communicate()
|
|
if err:
|
|
raise Exception(err)
|
|
return out
|
|
|
|
def get_json_from_url(path):
|
|
data = sh_command("curl", "-s", "-X", "GET", path)
|
|
return json.loads(data)
|
|
|
|
def get_api(path):
|
|
return get_json_from_url("http://localhost:10000" + path)
|
|
|
|
def version_compare(a, b):
|
|
return parse_version(a) < parse_version(b)
|
|
|
|
def create_uuid_file(fl):
|
|
with open(args.uuid_file, 'w') as myfile:
|
|
myfile.write(str(uuid.uuid1()) + "\n")
|
|
|
|
def check_version(ar):
|
|
if config and (not config.has_option("housekeeping", "check-version") or not config.getboolean("housekeeping", "check-version")):
|
|
return
|
|
if ar.version and ar.version != '':
|
|
current_version = ar.version
|
|
else:
|
|
current_version = get_api('/storage_service/scylla_release_version')
|
|
if current_version == "":
|
|
# API is down, nothing to do
|
|
return
|
|
try:
|
|
params = "?version=" + current_version
|
|
if ar.mode:
|
|
# mode would accept any string.
|
|
# use i for install, c (default) for running from the command line
|
|
params = params + "&sts=" + ar.mode
|
|
if uid:
|
|
params = params + "&uu=" + uid
|
|
latest_version = get_json_from_url(version_url + params)["version"]
|
|
except:
|
|
traceln("Unable to retrieve version information")
|
|
return
|
|
if version_compare(current_version, latest_version):
|
|
traceln("A new version was found, current version=", current_version, " latest version=", latest_version)
|
|
|
|
parser = argparse.ArgumentParser(description='ScyllaDB help report tool', conflict_handler="resolve")
|
|
parser.add_argument('-q', '--quiet', action='store_true', default=False, help='Quiet mode')
|
|
parser.add_argument('-c', '--config', default="", help='An optional config file. Specifying a missing file will terminate the script')
|
|
parser.add_argument('--uuid', default="", help='A uuid for the requests')
|
|
parser.add_argument('--uuid-file', default="", help='A uuid file for the requests')
|
|
|
|
subparsers = parser.add_subparsers(help='Available commands')
|
|
parser_help = subparsers.add_parser('help', help='Display help information')
|
|
parser_help.set_defaults(func=help)
|
|
parser_system = subparsers.add_parser('version', help='Check if the current running version is the latest one')
|
|
parser_system.add_argument('--mode', default="c", help='Which mode the version check runs')
|
|
parser_system.add_argument('--version', default="", help='Use a given version to compare to')
|
|
parser_system.set_defaults(func=check_version)
|
|
|
|
args = parser.parse_args()
|
|
quiet = args.quiet
|
|
config = None
|
|
if args.config != "":
|
|
if not os.path.isfile(args.config):
|
|
traceln("Config file ", args.config, " is missing, terminating")
|
|
sys.exit(0)
|
|
config = ConfigParser.SafeConfigParser()
|
|
config.read(args.config)
|
|
uid = None
|
|
if args.uuid != "":
|
|
uid = args.uuid
|
|
if args.uuid_file != "":
|
|
if not os.path.exists(args.uuid_file):
|
|
create_uuid_file(args.uuid_file)
|
|
with open(args.uuid_file, 'r') as myfile:
|
|
uid = myfile.read().replace('\n', '')
|
|
args.func(args)
|