def start(self):
     # Anything to start?
     am_started = 0
     apps_to_start = self._get_apps_to_start()
     if not apps_to_start:
         return am_started
     # Select how we are going to start it
     run_type = self._fetch_run_type()
     starter = importer.import_entry_point(run_type)(self)
     for app_info in apps_to_start:
         app_name = app_info["name"]
         app_pth = app_info.get("path", app_name)
         app_dir = app_info.get("app_dir", self.get_option('app_dir'))
         # Adjust the program options now that we have real locations
         program_opts = utils.param_replace_list(self._get_app_options(app_name), self._get_param_map(app_name))
         # Start it with the given settings
         LOG.debug("Starting %r using %r", app_name, run_type)
         details_fn = starter.start(app_name, app_pth=app_pth, app_dir=app_dir, opts=program_opts)
         LOG.info("Started %s details are in %s", colorizer.quote(app_name), colorizer.quote(details_fn))
         # This trace is used to locate details about what to stop
         self.tracewriter.app_started(app_name, details_fn, run_type)
         if app_info.get('sleep_time'):
             LOG.info("%s requested a %s second sleep time, please wait...", colorizer.quote(app_name), app_info.get('sleep_time'))
             sh.sleep(app_info.get('sleep_time'))
         am_started += 1
     return am_started
Exemplo n.º 2
0
def retry(attempts, delay, func, *args, **kwargs):
    if delay < 0:
        raise ValueError("delay must be >= 0")
    if attempts < 0:
        raise ValueError("attempts must be >= 1")
    func_name = get_callback_name(func)
    failures = []
    retryable_exceptions = kwargs.pop('retryable_exceptions', [Exception])
    retryable_exceptions = tuple(retryable_exceptions)
    max_attempts = int(attempts) + 1
    for attempt in range(1, max_attempts):
        LOG.debug("Attempt %s for calling '%s'", attempt, func_name)
        kwargs['attempt'] = attempt
        try:
            return func(*args, **kwargs)
        except retryable_exceptions:
            failures.append(sys.exc_info())
            LOG.exception("Calling '%s' failed (retryable)", func_name)
            if attempt < max_attempts and delay > 0:
                LOG.info("Waiting %s seconds before calling '%s' again", delay,
                         func_name)
                sh.sleep(delay)
        except BaseException:
            failures.append(sys.exc_info())
            LOG.exception("Calling '%s' failed (not retryable)", func_name)
            break
    exc_type, exc, exc_tb = failures[-1]
    six.reraise(exc_type, exc, exc_tb)
Exemplo n.º 3
0
def retry(attempts, delay, func, *args, **kwargs):
    if delay < 0:
        raise ValueError("delay must be >= 0")
    if attempts < 0:
        raise ValueError("attempts must be >= 1")
    func_name = "??"
    try:
        func_name = func.__name__
    except AttributeError:
        pass
    failures = []
    max_attempts = int(attempts) + 1
    for attempt in range(1, max_attempts):
        LOG.debug("Attempt %s for calling '%s'", attempt, func_name)
        kwargs['attempt'] = attempt
        try:
            return func(*args, **kwargs)
        except Exception:
            failures.append(sys.exc_info())
            if attempt < max_attempts and delay > 0:
                LOG.info("Waiting %s seconds before calling '%s' again", delay,
                         func_name)
                sh.sleep(delay)
    exc_type, exc, exc_tb = failures[-1]
    six.reraise(exc_type, exc, exc_tb)
Exemplo n.º 4
0
 def _do_network_init(self):
     ran_fn = sh.joinpths(self.get_option("trace_dir"), NET_INITED_FN)
     if not sh.isfile(ran_fn) and self.net_enabled:
         LOG.info("Creating your nova network to be used with instances.")
         # Figure out the commands to run
         mp = {}
         cmds = []
         mp["CFG_FILE"] = sh.joinpths(self.get_option("cfg_dir"), API_CONF)
         mp["BIN_DIR"] = sh.joinpths(self.get_option("app_dir"), BIN_DIR)
         if self.cfg.getboolean("nova", "enable_fixed"):
             # Create a fixed network
             mp["FIXED_NETWORK_SIZE"] = self.cfg.getdefaulted("nova", "fixed_network_size", "256")
             mp["FIXED_RANGE"] = self.cfg.getdefaulted("nova", "fixed_range", "10.0.0.0/24")
             cmds.extend(FIXED_NET_CMDS)
         if not self.get_option("quantum"):
             if self.cfg.getboolean("nova", "enable_floating"):
                 # Create a floating network + test floating pool
                 cmds.extend(FLOATING_NET_CMDS)
                 mp["FLOATING_RANGE"] = self.cfg.getdefaulted("nova", "floating_range", "172.24.4.224/28")
                 mp["TEST_FLOATING_RANGE"] = self.cfg.getdefaulted("nova", "test_floating_range", "192.168.253.0/29")
                 mp["TEST_FLOATING_POOL"] = self.cfg.getdefaulted("nova", "test_floating_pool", "test")
         else:
             LOG.info("Not creating floating IPs (not supported by quantum server)")
             LOG.info(
                 "Waiting %s seconds so that quantum can start up before running first time init." % (self.wait_time)
             )
             sh.sleep(self.wait_time)
         # Anything to run??
         if cmds:
             utils.execute_template(*cmds, params=mp)
         # Writing this makes sure that we don't init again
         cmd_mp = {"cmds": cmds, "replacements": mp}
         sh.write_file(ran_fn, utils.prettify_yaml(cmd_mp))
         LOG.info("If you wish to re-run initialization, delete %s", colorizer.quote(ran_fn))
Exemplo n.º 5
0
Arquivo: utils.py Projeto: jzako/anvil
def retry(attempts, delay, func, *args, **kwargs):
    if delay < 0:
        raise ValueError("delay must be >= 0")
    if attempts < 0:
        raise ValueError("attempts must be >= 1")
    func_name = get_callback_name(func)
    failures = []
    retryable_exceptions = kwargs.pop("retryable_exceptions", [Exception])
    retryable_exceptions = tuple(retryable_exceptions)
    max_attempts = int(attempts) + 1
    for attempt in range(1, max_attempts):
        LOG.debug("Attempt %s for calling '%s'", attempt, func_name)
        kwargs["attempt"] = attempt
        try:
            return func(*args, **kwargs)
        except retryable_exceptions:
            failures.append(sys.exc_info())
            LOG.exception("Calling '%s' failed (retryable)", func_name)
            if attempt < max_attempts and delay > 0:
                LOG.info("Waiting %s seconds before calling '%s' again", delay, func_name)
                sh.sleep(delay)
        except BaseException:
            failures.append(sys.exc_info())
            LOG.exception("Calling '%s' failed (not retryable)", func_name)
            break
    exc_type, exc, exc_tb = failures[-1]
    six.reraise(exc_type, exc, exc_tb)
Exemplo n.º 6
0
 def restart(self):
     LOG.info("Restarting your qpid daemon.")
     restart_cmd = self.distro.get_command('qpid', 'restart')
     sh.execute(*restart_cmd, run_as_root=True, check_exit_code=True)
     LOG.info("Please wait %s seconds while it restarts." % self.wait_time)
     sh.sleep(self.wait_time)
     return 1
Exemplo n.º 7
0
 def restart(self):
     LOG.info("Restarting your database.")
     restartcmd = self._get_run_actions('restart', excp.RestartException)
     sh.execute(*restartcmd, run_as_root=True, check_exit_code=True)
     LOG.info("Please wait %s seconds while it restarts." % self.wait_time)
     sh.sleep(self.wait_time)
     return 1
Exemplo n.º 8
0
def retry(attempts, delay, func, *args, **kwargs):
    if delay < 0:
        raise ValueError("delay must be >= 0")
    if attempts < 0:
        raise ValueError("attempts must be >= 1")
    func_name = "??"
    try:
        func_name = func.__name__
    except AttributeError:
        pass
    failures = []
    max_attempts = int(attempts) + 1
    for attempt in range(1, max_attempts):
        LOG.debug("Attempt %s for calling '%s'", attempt, func_name)
        kwargs['attempt'] = attempt
        try:
            return func(*args, **kwargs)
        except Exception:
            failures.append(sys.exc_info())
            if attempt < max_attempts and delay > 0:
                LOG.info("Waiting %s seconds before calling '%s' again",
                         delay, func_name)
                sh.sleep(delay)
    exc_type, exc, exc_tb = failures[-1]
    six.reraise(exc_type, exc, exc_tb)
Exemplo n.º 9
0
 def post_start(self):
     comp.PythonRuntime.post_start(self)
     if self.get_option('create-cidr'):
         LOG.info("Waiting %s seconds so that the melange server can start up before cidr range creation." % (self.wait_time))
         sh.sleep(self.wait_time)
         mp = dict()
         mp['CIDR_RANGE'] = self.cfg.getdefaulted('melange', 'm_mac_range', DEF_CIDR_RANGE)
         utils.execute_template(*CIDR_CREATE_CMD, params=mp)
Exemplo n.º 10
0
 def start(self):
     if self._status() != constants.STATUS_STARTED:
         start_cmd = self.distro.get_command('qpid', 'start')
         sh.execute(*start_cmd, run_as_root=True, check_exit_code=True)
         LOG.info("Please wait %s seconds while it starts up." % self.wait_time)
         sh.sleep(self.wait_time)
         return 1
     else:
         return 0
Exemplo n.º 11
0
 def start(self):
     if self._status() != constants.STATUS_STARTED:
         startcmd = self._get_run_actions('start', excp.StartException)
         sh.execute(*startcmd, run_as_root=True, check_exit_code=True)
         LOG.info("Please wait %s seconds while it starts up." % self.wait_time)
         sh.sleep(self.wait_time)
         return 1
     else:
         return 0
Exemplo n.º 12
0
 def post_start(self):
     comp.PythonRuntime.post_start(self)
     if self.do_upload:
         # Install any images that need activating...
         LOG.info("Waiting %s seconds so that glance can start up before image install." % (self.wait_time))
         sh.sleep(self.wait_time)
         params = {}
         params['glance'] = ghelper.get_shared_params(self.cfg)
         params['keystone'] = khelper.get_shared_params(self.cfg, 'glance')
         ghelper.UploadService(params).install(self._get_image_urls())
Exemplo n.º 13
0
 def wait_active(self):
     # TODO(harlowja) fix this by using the component wait active...
     started = False
     for _i in range(0, self.wait_attempts):
         (st, output) = self._service_status()
         if st != _ALIVE:
             LOG.info("Please wait %s seconds until libvirt is started.", self.wait_time)
             sh.sleep(self.wait_time)
         else:
             started = True
     if not started:
         raise excp.StartException("Unable to start the libvirt daemon due to: %s" % (output))
Exemplo n.º 14
0
def wait_for_url(url,
                 max_attempts=5,
                 on_start=None,
                 on_wait=None,
                 on_success=None):
    if max_attempts <= 0:
        raise ValueError("Wait maximum attempts must be > 0")

    def log_start():
        LOG.info("Waiting for url %s to become active (max_attempts=%s)",
                 colorizer.quote(url), max_attempts)

    def log_wait(sleep_secs):
        LOG.info("Sleeping for %s seconds, %s is still not active.",
                 sleep_secs, colorizer.quote(url))
        return sleep_secs

    def log_success(attempts):
        LOG.info("Url %s became active after %s attempts!",
                 colorizer.quote(url), attempts)

    if not on_wait:
        on_wait = log_wait
    if not on_success:
        on_success = log_success
    if not on_start:
        on_start = log_start

    failures = []
    for i, sleep_time in enumerate(ExponentialBackoff(attempts=max_attempts)):
        if i == 0:
            on_start()
        try:
            with contextlib.closing(urllib2.urlopen(
                    urllib2.Request(url))) as req:
                req.read()
                on_success(i + 1)
                return url
        except urllib2.HTTPError as e:
            failures.append(sys.exc_info())
            if e.code in range(200, 600):
                # Should be ok, at least its responding...
                # although potentially incorrectly...
                on_success(i + 1)
                return url
            else:
                sh.sleep(on_wait(sleep_time))
        except IOError:
            failures.append(sys.exc_info())
            sh.sleep(on_wait(sleep_time))
    exc_type, exc, exc_tb = failures[-1]
    six.reraise(exc_type, exc, exc_tb)
Exemplo n.º 15
0
 def wait_active(self):
     # TODO(harlowja) fix this by using the component wait active...
     started = False
     for _i in range(0, self.wait_attempts):
         (st, output) = self._service_status()
         if st != _ALIVE:
             LOG.info("Please wait %s seconds until libvirt is started.",
                      self.wait_time)
             sh.sleep(self.wait_time)
         else:
             started = True
     if not started:
         raise excp.StartException(
             "Unable to start the libvirt daemon due to: %s" % (output))
Exemplo n.º 16
0
 def _do_screen_init(self):
     LOG.debug("Creating a new screen session named %r" % (SESSION_NAME))
     session_init_cmd = self._gen_cmd(SESSION_INIT)
     sh.execute(*session_init_cmd,
             shell=True,
             run_as_root=True,
             env_overrides=self._get_env())
     LOG.debug("Waiting %s seconds before we attempt to set the title bar for that session." % (self.wait_time))
     sh.sleep(self.wait_time)
     bar_init_cmd = self._gen_cmd(BAR_INIT)
     sh.execute(*bar_init_cmd,
             shell=True,
             run_as_root=True,
             env_overrides=self._get_env())
Exemplo n.º 17
0
def wait_for_url(url, max_attempts=5,
                 on_start=None, on_wait=None, on_success=None):
    if max_attempts <= 0:
        raise ValueError("Wait maximum attempts must be > 0")

    def log_start():
        LOG.info("Waiting for url %s to become active (max_attempts=%s)",
                 colorizer.quote(url), max_attempts)

    def log_wait(sleep_secs):
        LOG.info("Sleeping for %s seconds, %s is still not active.", sleep_secs, colorizer.quote(url))
        return sleep_secs

    def log_success(attempts):
        LOG.info("Url %s became active after %s attempts!", colorizer.quote(url), attempts)

    if not on_wait:
        on_wait = log_wait
    if not on_success:
        on_success = log_success
    if not on_start:
        on_start = log_start

    failures = []
    for i, sleep_time in enumerate(ExponentialBackoff(attempts=max_attempts)):
        if i == 0:
            on_start()
        try:
            with contextlib.closing(urllib2.urlopen(urllib2.Request(url))) as req:
                req.read()
                on_success(i + 1)
                return url
        except urllib2.HTTPError as e:
            failures.append(sys.exc_info())
            if e.code in range(200, 600):
                # Should be ok, at least its responding...
                # although potentially incorrectly...
                on_success(i + 1)
                return url
            else:
                sh.sleep(on_wait(sleep_time))
        except IOError:
            failures.append(sys.exc_info())
            sh.sleep(on_wait(sleep_time))
    exc_type, exc, exc_tb = failures[-1]
    six.reraise(exc_type, exc, exc_tb)
Exemplo n.º 18
0
 def post_start(self):
     if not sh.isfile(self.init_fn):
         LOG.info("Waiting %s seconds so that keystone can start up before running first time init." % (self.wait_time))
         sh.sleep(self.wait_time)
         LOG.info("Running commands to initialize keystone.")
         LOG.debug("Initializing with %s", self.init_what)
         initial_cfg = dict()
         initial_cfg['glance'] = ghelper.get_shared_params(self.cfg)
         initial_cfg['keystone'] = khelper.get_shared_params(self.cfg)
         initial_cfg['nova'] = nhelper.get_shared_params(self.cfg)
         initial_cfg['quantum'] = qhelper.get_shared_params(self.cfg)
         initial_cfg['swift'] = shelper.get_shared_params(self.cfg)
         init_what = utils.param_replace_deep(copy.deepcopy(self.init_what), initial_cfg)
         khelper.Initializer(initial_cfg['keystone']).initialize(**init_what)
         # Writing this makes sure that we don't init again
         sh.write_file(self.init_fn, utils.prettify_yaml(init_what))
         LOG.info("If you wish to re-run initialization, delete %s", colorizer.quote(self.init_fn))
Exemplo n.º 19
0
    def start(self):
        def is_active():
            status = self.statii()[0].status
            if status == bruntime.STATUS_STARTED:
                return True
            return False

        if is_active():
            return 1

        self._run_action('start')
        for sleep_secs in utils.ExponentialBackoff():
            LOG.info("Sleeping for %s seconds, rabbit-mq is still not active.",
                     sleep_secs)
            sh.sleep(sleep_secs)
            if is_active():
                return 1
        raise RuntimeError('Failed to start rabbit-mq')
Exemplo n.º 20
0
    def start(self):

        def is_active():
            status = self.statii()[0].status
            if status == bruntime.STATUS_STARTED:
                return True
            return False

        if is_active():
            return 1

        self._run_action('start')
        for sleep_secs in utils.ExponentialBackoff():
            LOG.info("Sleeping for %s seconds, rabbit-mq is still not active.",
                     sleep_secs)
            sh.sleep(sleep_secs)
            if is_active():
                return 1
        raise RuntimeError('Failed to start rabbit-mq')
Exemplo n.º 21
0
 def _do_start(self, session, prog_name, cmd):
     init_cmd = list()
     mp = dict()
     run_cmd = " ".join(cmd)
     mp['SESSION_NAME'] = session
     mp['NAME'] = prog_name
     mp['CMD'] = run_cmd
     init_cmd = self._gen_cmd(CMD_INIT, mp)
     LOG.debug("Creating a new screen window named %r in session %r" % (prog_name, session))
     sh.execute(*init_cmd,
         shell=True,
         run_as_root=True,
         env_overrides=self._get_env())
     LOG.debug("Waiting %s seconds before we attempt to run command %r in that window." % (self.wait_time, run_cmd))
     sh.sleep(self.wait_time)
     start_cmd = self._gen_cmd(CMD_START, mp)
     sh.execute(*start_cmd,
         shell=True,
         run_as_root=True,
         env_overrides=self._get_env())
Exemplo n.º 22
0
 def waiter(try_num):
     LOG.info("Waiting %s seconds for component %s programs to start.", between_wait, colorizer.quote(self.name))
     LOG.info("Please wait...")
     sh.sleep(between_wait)
Exemplo n.º 23
0
 def _post_app_start(self, app_info):
     if 'sleep_time' in app_info:
         LOG.info("%s requested a %s second sleep time, please wait...", 
                  colorizer.quote(app_info.get('name')), app_info.get('sleep_time'))
         sh.sleep(int(app_info.get('sleep_time')))
Exemplo n.º 24
0
 def restart_service(self):
     if self._service_status() != _ALIVE:
         cmd = self.distro.get_command('libvirt', 'restart')
         sh.execute(*cmd, run_as_root=True)
         LOG.info("Restarting the libvirt service, please wait %s seconds until its started." % (self.wait_time))
         sh.sleep(self.wait_time)
Exemplo n.º 25
0
 def restart(self):
     LOG.info("Restarting rabbit-mq.")
     self._run_cmd(self.distro.get_command('rabbit-mq', 'restart'))
     LOG.info("Please wait %s seconds while it starts up." % (self.wait_time))
     sh.sleep(self.wait_time)
     return 1
Exemplo n.º 26
0
 def waiter(sleep_secs):
     LOG.info("Sleeping for %s seconds, %s is still not active.", sleep_secs, colorizer.quote(url))
     sh.sleep(sleep_secs)
Exemplo n.º 27
0
 def waiter(sleep_secs):
     LOG.info("Sleeping for %s seconds, %s is still not active.",
              sleep_secs, colorizer.quote(url))
     sh.sleep(sleep_secs)
Exemplo n.º 28
0
 def waiter():
     LOG.info("Sleeping for %s seconds, %s is still not active.", wait_between, colorizer.quote(url))
     sh.sleep(wait_between)
Exemplo n.º 29
0
 def _post_app_start(self, app_info):
     if 'sleep_time' in app_info:
         LOG.info("%s requested a %s second sleep time, please wait...",
                  colorizer.quote(app_info.get('name')), app_info.get('sleep_time'))
         sh.sleep(int(app_info.get('sleep_time')))
Exemplo n.º 30
0
 def waiter(try_num):
     LOG.info("Waiting %s seconds for component %s programs to start.", between_wait, colorizer.quote(rt_name))
     LOG.info("Please wait...")
     sh.sleep(between_wait)
Exemplo n.º 31
0
 def waiter():
     LOG.info("Sleeping for %s seconds, %s is still not active.",
              wait_between, colorizer.quote(url))
     sh.sleep(wait_between)
Exemplo n.º 32
0
 def waiter(between_wait):
     LOG.info(
         "Waiting %.2f seconds for component %s programs to start.",
         between_wait, colorizer.quote(self.name))
     LOG.info("Please wait...")
     sh.sleep(between_wait)