Example #1
0
def get_log_file(context, service_name):
    def mtime(path):
        try:
            return os.path.getmtime(path)
        except os.error:
            return 0

    data = context.service_data(service_name)
    if "location" in data:
        logs = [
            context.application.workspace + data["location"] +
            "/logs/stdout.txt",
            context.application.workspace + data["location"] +
            "/target/logs/stdout.txt",
            SmPlayService.unzipped_dir_path(context, data["location"]) +
            "/logs/stdout.txt",
        ]
        if not any([os.path.exists(log) for log in logs]):
            raise ServiceManagerException("Cannot find log files for %s" %
                                          service_name)
        else:
            return sorted(logs, key=mtime, reverse=True)[0]
    else:
        raise ServiceManagerException("Cannot find a location for %s" %
                                      service_name)
def _format_healthcheck_status(healthcheck):
    b = BColors()
    if healthcheck == SmServiceStatus.HEALTHCHECK_PASS:
        return b.bold + b.okgreen + "PASS" + b.endc
    elif healthcheck == SmServiceStatus.HEALTHCHECK_BOOT:
        return b.bold + b.warning + "BOOT" + b.endc
    elif healthcheck == SmServiceStatus.HEALTHCHECK_NONE:
        return b.okblue + "NONE" + b.endc
    else:
        raise ServiceManagerException("Unknown healthcheck status: %s" % healthcheck)
Example #3
0
def _wait_for_services(context, service_names, seconds_to_wait):

    waiting_for_services = []

    for service_name in service_names:
        if "healthcheck" in context.service_data(service_name):
            waiting_for_services += [context.get_service(service_name)]

    if not seconds_to_wait:
        seconds_to_wait = 0

    end_time = _now() + seconds_to_wait

    while waiting_for_services and _now() < end_time:

        services_to_check = list(waiting_for_services)

        for service in services_to_check:

            if _now() >= end_time:
                break

            processes = SmProcess.processes_matching(service.pattern)
            if all(map(service.run_healthcheck, processes)):
                print(("Service '%s' has started successfully" %
                       service.service_name))
                waiting_for_services.remove(service)
            else:
                seconds_remaining = end_time - _now()
                if seconds_remaining % 5 == 0 or seconds_remaining < 10:
                    print((
                        "Waiting for %s to start, %s second%s before timeout" %
                        (
                            service.service_name,
                            seconds_remaining,
                            "s" if seconds_to_wait != 1 else "",
                        )))

        if waiting_for_services:
            time.sleep(1)

    if waiting_for_services:
        services_timed_out = []
        for service in waiting_for_services:
            services_timed_out += [service.service_name]
        raise ServiceManagerException("Timed out starting service(s): %s" %
                                      ", ".join(services_timed_out))
 def setUp(self):
     self.context = MagicMock()
     self.context.exception = lambda message: ServiceManagerException(
         message)
     self.context.service_type = lambda x: ""