Beispiel #1
0
def logs_cmd(args):
    """Retrieves and streams the logs of a service."""
    service_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    try:
        for line in service_api.get_logs(args.service_id):
            if args.timestamps:
                print(line[0], line[1])
            else:
                print(line[1])
    except KeyboardInterrupt:
        print('CTRL-C detected, exiting...')
Beispiel #2
0
def _log_stream_stdout(service_id, timestamps, auth):
    service_api = ZoeServiceAPI(auth['url'], auth['user'], auth['pass'])
    try:
        for line in service_api.get_logs(service_id):
            if timestamps:
                print(line[0], line[1])
            else:
                print(line[1])
    except KeyboardInterrupt:
        print('CTRL-C detected, exiting...')
        return 'interrupt'
    return 'stream_end'
def _log_stream_stdout(service_id, timestamps):
    service_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    try:
        for line in service_api.get_logs(service_id):
            if timestamps:
                print(line[0], line[1])
            else:
                print(line[1])
    except KeyboardInterrupt:
        print('CTRL-C detected, exiting...')
        return 'interrupt'
    return 'stream_end'
class Test:
    def __init__(self, user, pwd, url, name, zapp):
        self.user = user
        self.pwd = pwd
        self.url = url
        self.name = name
        try:
            with open(zapp, 'r') as infile:
                self.zapp = json.load(infile)
        except:
            exit("Unable to load zapp file.")
        self.exec_api = ZoeExecutionsAPI(self.url, self.user, self.pwd)
        self.service_api = ZoeServiceAPI(self.url, self.user, self.pwd)

    def start_exec(self):
        exec_id = self.exec_api.start(self.name, self.zapp)
        return exec_id

    def get_services_id(self, exec_id):
        services = self.exec_api.get(exec_id)
        return services['services']

    def get_submit_service(self, exec_id):
        while len(self.get_services_id(exec_id)) < 4:
            print('waiting')
            time.sleep(0.5)
        for service_id in self.get_services_id(exec_id):
            srv = self.service_api.get(service_id)
            if re.search('submit', srv['name']):
                return srv['id']

    def is_running(self, exec_id):
        return self.exec_api.get(exec_id)['status'] == 'running'

    def run_test(self):
        ts = time.time()
        exec_id = self.start_exec()
        outfilename = './logs/{}'.format(exec_id)
        submit_id = self.get_submit_service(exec_id)
        while not self.is_running(exec_id):
            time.sleep(0.5)
        te = time.time()
        with open(outfilename, 'w') as out:
            out.write("PerfMeasure: Scheduling time: {}".format(te - ts))
            for line in self.service_api.get_logs(submit_id):
                out.write("{}\n".format(line))
        self.exec_api.terminate(exec_id)
        print('Terminated {}'.format(exec_id))