Exemplo n.º 1
0
 def _setup_vol_groups(self):
     LOG.info("Attempting to setup volume groups for nova volume management.")
     mp = dict()
     backing_file = self.cfg.getdefaulted('nova', 'volume_backing_file', sh.joinpths(self.app_dir, 'nova-volumes-backing-file'))
     vol_group = self.cfg.getdefaulted('nova', 'volume_group', 'nova-volumes')
     backing_file_size = utils.to_bytes(self.cfg.getdefaulted('nova', 'volume_backing_file_size', '2052M'))
     mp['VOLUME_GROUP'] = vol_group
     mp['VOLUME_BACKING_FILE'] = backing_file
     mp['VOLUME_BACKING_FILE_SIZE'] = backing_file_size
     try:
         utils.execute_template(*VG_CHECK_CMD, params=mp)
         LOG.warn("Volume group already exists: %s" % (vol_group))
     except exceptions.ProcessExecutionError as err:
         # Check that the error from VG_CHECK is an expected error
         if err.exit_code != 5:
             raise
         LOG.info("Need to create volume group: %s" % (vol_group))
         sh.touch_file(backing_file, die_if_there=False, file_size=backing_file_size)
         vg_dev_result = utils.execute_template(*VG_DEV_CMD, params=mp)
         if vg_dev_result and vg_dev_result[0]:
             LOG.debug("VG dev result: %s" % (vg_dev_result))
             # Strip the newlines out of the stdout (which is in the first
             # element of the first (and only) tuple in the response
             (sysout, _) = vg_dev_result[0]
             mp['DEV'] = sysout.replace('\n', '')
             utils.execute_template(*VG_CREATE_CMD, params=mp)
     # One way or another, we should have the volume group, Now check the
     # logical volumes
     self._process_lvs(mp)
     # Finish off by restarting tgt, and ignore any errors
     cmdrestart = self.distro.get_command('iscsi', 'restart', quiet=True)
     if cmdrestart:
         sh.execute(*cmdrestart, run_as_root=True, check_exit_code=False)
Exemplo n.º 2
0
 def restart(self):
     LOG.info("Restarting your database.")
     restartcmd = self._get_run_actions('restart', excp.RestartException)
     sh.execute(*restartcmd, run_as_root=True)
     LOG.info("Please wait %s seconds while it restarts." % START_WAIT_TIME)
     time.sleep(START_WAIT_TIME)
     return 1
Exemplo n.º 3
0
 def stop(self):
     if self.status() == comp.STATUS_STARTED:
         stopcmd = self._get_run_actions('stop', excp.StopException)
         sh.execute(*stopcmd, run_as_root=True)
         return 1
     else:
         return 0
Exemplo n.º 4
0
 def post_install(self):
     parent_result = comp.PkgInstallComponent.post_install(self)
     #extra actions to ensure we are granted access
     dbtype = self.cfg.get("db", "type")
     dbactions = DB_ACTIONS.get(dbtype)
     if dbactions and dbactions.get('grant_all'):
         #update the DB to give user 'USER'@'%' full control of the all databases:
         grant_cmd = dbactions.get('grant_all')
         params = self._get_param_map(None)
         cmds = list()
         cmds.append({
             'cmd': grant_cmd,
             'run_as_root': False,
         })
         #shell seems to be needed here
         #since python escapes this to much...
         utils.execute_template(*cmds, params=params, shell=True)
     #special mysql actions
     if dbactions and dbtype == MYSQL:
         cmd = dbactions.get('host_adjust')
         if cmd:
             sh.execute(*cmd, run_as_root=True, shell=True)
     #restart it to make sure all good
     self.runtime.restart()
     return parent_result
Exemplo n.º 5
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.º 6
0
 def start(self):
     if self.status() == comp.STATUS_STOPPED:
         startcmd = self._gettypeactions('start', excp.StartException)
         sh.execute(*startcmd, run_as_root=True)
         return 1
     else:
         return 0
Exemplo n.º 7
0
 def _uninstall_python(self):
     pylisting = self.tracereader.py_listing()
     if pylisting:
         LOG.info("Uninstalling %s python setups" % (len(pylisting)))
         for entry in pylisting:
             where = entry.get('where')
             sh.execute(*PY_UNINSTALL, cwd=where, run_as_root=True)
Exemplo n.º 8
0
 def restart(self):
     curr_status = self.status()
     if curr_status == comp.STATUS_STARTED:
         sh.execute(*APACHE_RESTART_CMD,
             run_as_root=True)
         return 1
     return 0
Exemplo n.º 9
0
 def stop(self):
     curr_status = self.status()
     if curr_status == comp.STATUS_STARTED:
         sh.execute(*APACHE_STOP_CMD,
             run_as_root=True)
         return 1
     return 0
Exemplo n.º 10
0
 def stop(self):
     if self.status() != comp.STATUS_STOPPED:
         stopcmd = self._get_run_actions('stop', excp.StopException)
         sh.execute(*stopcmd, run_as_root=True, check_exit_code=True)
         return 1
     else:
         return 0
Exemplo n.º 11
0
 def start(self):
     curr_status = self.status()
     if curr_status == comp.STATUS_STARTED:
         # restart it ?
         return self.restart()
     else:
         sh.execute(*APACHE_START_CMD, run_as_root=True)
         return 1
Exemplo n.º 12
0
 def _setup_pw(self):
     LOG.info("Setting up your rabbit-mq guest password.")
     self.runtime.restart()
     passwd = self.pw_gen.get_password("rabbit", PW_USER_PROMPT)
     cmd = self.distro.get_command('rabbit-mq', 'change_password') + [passwd]
     sh.execute(*cmd, run_as_root=True)
     LOG.info("Restarting so that your rabbit-mq guest password is reflected.")
     self.runtime.restart()
Exemplo n.º 13
0
 def _setup_pw(self):
     LOG.info("Setting up your rabbit-mq guest password.")
     self.runtime.restart()
     passwd = self.cfg.get("passwords", "rabbit")
     cmd = PWD_CMD + [passwd]
     sh.execute(*cmd, run_as_root=True)
     LOG.info("Restarting so that your rabbit-mq guest password is reflected.")
     self.runtime.restart()
Exemplo n.º 14
0
 def _setup_pw(self):
     LOG.info("Setting up your rabbit-mq guest password.")
     self.runtime.restart()
     passwd = self.pw_gen.get_password("rabbit", PW_USER_PROMPT)
     cmd = self.distro.get_command('rabbit-mq', 'change_password') + [passwd]
     sh.execute(*cmd, run_as_root=True)
     LOG.info("Restarting so that your rabbit-mq guest password is reflected.")
     self.runtime.restart()
Exemplo n.º 15
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.º 16
0
 def start(self):
     if self.status() == comp.STATUS_STOPPED:
         startcmd = self._get_run_actions('start', excp.StartException)
         sh.execute(*startcmd, run_as_root=True)
         LOG.info("Please wait %s seconds while it starts up." % START_WAIT_TIME)
         time.sleep(START_WAIT_TIME)
         return 1
     else:
         return 0
Exemplo n.º 17
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.º 18
0
 def stop(self):
     if self.status() != comp.STATUS_STOPPED:
         stopcmd = self._get_run_actions('stop', excp.StopException)
         sh.execute(*stopcmd,
             run_as_root=True,
             check_exit_code=True)
         return 1
     else:
         return 0
Exemplo n.º 19
0
 def pre_uninstall(self):
     try:
         self.runtime.restart()
         LOG.info("Attempting to reset the rabbit-mq guest password to \"%s\"", RESET_BASE_PW)
         cmd = PWD_CMD + [RESET_BASE_PW]
         sh.execute(*cmd, run_as_root=True)
     except IOError:
         LOG.warn(("Could not reset the rabbit-mq password. You might have to manually "
                   "reset the password to \"%s\" before the next install") % (RESET_BASE_PW))
Exemplo n.º 20
0
 def pre_uninstall(self):
     try:
         self.runtime.restart()
         LOG.info("Attempting to reset the rabbit-mq guest password to %r", RESET_BASE_PW)
         cmd = self.distro.get_command('rabbit-mq', 'change_password') + [RESET_BASE_PW]
         sh.execute(*cmd, run_as_root=True)
     except IOError:
         LOG.warn(("Could not reset the rabbit-mq password. You might have to manually "
                   "reset the password to %r before the next install") % (RESET_BASE_PW))
Exemplo n.º 21
0
 def pre_uninstall(self):
     try:
         self.runtime.restart()
         LOG.info("Attempting to reset the rabbit-mq guest password to %r", RESET_BASE_PW)
         cmd = self.distro.get_command('rabbit-mq', 'change_password') + [RESET_BASE_PW]
         sh.execute(*cmd, run_as_root=True)
     except IOError:
         LOG.warn(("Could not reset the rabbit-mq password. You might have to manually "
                   "reset the password to %r before the next install") % (RESET_BASE_PW))
Exemplo n.º 22
0
 def _uninstall_python(self):
     py_listing = self.tracereader.py_listing()
     if py_listing:
         py_listing_dirs = set()
         for (_, where) in py_listing:
             py_listing_dirs.add(where)
         utils.log_iterable(py_listing_dirs, logger=LOG,
             header="Uninstalling %s python setups" % (len(py_listing_dirs)))
         for where in py_listing_dirs:
             sh.execute(*PY_UNINSTALL, cwd=where, run_as_root=True)
Exemplo n.º 23
0
def _gitdownload(storewhere, uri, branch=None):
    dirsmade = sh.mkdirslist(storewhere)
    LOG.info("Downloading from %s to %s" % (uri, storewhere))
    cmd = ["git", "clone"] + [uri, storewhere]
    sh.execute(*cmd)
    if branch and branch != GIT_MASTER_BRANCH:
        LOG.info("Adjusting git branch to %s" % (branch))
        cmd = ['git', 'checkout'] + [branch]
        sh.execute(*cmd, cwd=storewhere)
    return dirsmade
Exemplo n.º 24
0
 def _run_cmd(self, cmd):
     #this seems to fix one of the bugs with rabbit mq starting and stopping
     #not cool, possibly connected to the following bugs:
     #https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878597
     #https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878600
     #
     #rhel seems to have this bug also...
     with TemporaryFile() as f:
         sh.execute(*cmd, run_as_root=True,
                     stdout_fh=f, stderr_fh=f)
Exemplo n.º 25
0
 def start(self):
     if self.status() != comp.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.º 26
0
 def start(self):
     if self.status() != comp.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.º 27
0
def install(pip, distro):
    name = pip['name']
    root_cmd = distro.get_command_config('pip')
    LOG.audit("Installing python package %r using pip command %s" % (name, root_cmd))
    name_full = _make_pip_name(name, pip.get('version'))
    real_cmd = [root_cmd, 'install'] + PIP_INSTALL_CMD_OPTS
    options = pip.get('options')
    if options:
        LOG.debug("Using pip options: %s" % (options))
        real_cmd += [str(options)]
    real_cmd += [name_full]
    sh.execute(*real_cmd, run_as_root=True)
Exemplo n.º 28
0
 def _clean_it(self):
     # These environment additions are important
     # in that they eventually affect how this script runs
     env = dict()
     env['ENABLED_SERVICES'] = ",".join(self.desired_subsystems)
     env['BIN_DIR'] = self.bin_dir
     env['VOLUME_NAME_PREFIX'] = self.cfg.getdefaulted('nova', 'volume_name_prefix', DEF_VOL_PREFIX)
     cleaner_fn = sh.joinpths(self.bin_dir, CLEANER_DATA_CONF)
     if sh.isfile(cleaner_fn):
         LOG.info("Cleaning up your system by running nova cleaner script [%s]." % (cleaner_fn))
         cmd = CLEANER_CMD_ROOT + [cleaner_fn]
         sh.execute(*cmd, run_as_root=True, env_overrides=env)
Exemplo n.º 29
0
def install(pip, distro):
    name = pip['name']
    root_cmd = distro.get_command_config('pip')
    LOG.audit("Installing python package %r using pip command %s" %
              (name, root_cmd))
    name_full = _make_pip_name(name, pip.get('version'))
    real_cmd = [root_cmd, 'install'] + PIP_INSTALL_CMD_OPTS
    options = pip.get('options')
    if options:
        LOG.debug("Using pip options: %s" % (options))
        real_cmd += [str(options)]
    real_cmd += [name_full]
    sh.execute(*real_cmd, run_as_root=True)
Exemplo n.º 30
0
 def stop(self, app_name):
     fn_name = UPSTART_TEMPL % (app_name)
     trace_fn = tr.trace_fn(self.trace_dir, fn_name)
     # Emit the start, keep track and only do one per component name
     component_event = self.component_name + STOP_EVENT_SUFFIX
     if component_event in self.events:
         LOG.debug("Already emitted event: %s" % (component_event))
     else:
         LOG.info("About to emit event: %s" % (component_event))
         cmd = EMIT_BASE_CMD + [component_event]
         sh.execute(*cmd, run_as_root=True)
         self.events.add(component_event)
     sh.unlink(trace_fn)
Exemplo n.º 31
0
 def stop(self, app_name):
     fn_name = UPSTART_TEMPL % (app_name)
     trace_fn = tr.trace_fn(self.trace_dir, fn_name)
     # Emit the start, keep track and only do one per component name
     component_event = self.component_name + STOP_EVENT_SUFFIX
     if component_event in self.events:
         LOG.debug("Already emitted event: %s" % (component_event))
     else:
         LOG.debug("About to emit event: %s" % (component_event))
         cmd = EMIT_BASE_CMD + [component_event]
         sh.execute(*cmd, run_as_root=True)
         self.events.add(component_event)
     sh.unlink(trace_fn)
Exemplo n.º 32
0
def virt_ok(virt_type, distro):
    virt_protocol = LIBVIRT_PROTOCOL_MAP.get(virt_type)
    if not virt_protocol:
        return False
    #ensure we can do this
    restart(distro)
    #this is our sanity check to ensure that we can actually use that virt technology
    cmd = ['virsh', '-c', virt_protocol, 'uri']
    try:
        sh.execute(*cmd, run_as_root=True)
        return True
    except excp.ProcessExecutionError:
        return False
Exemplo n.º 33
0
def uninstall(pip, distro, skip_errors=True):
    root_cmd = distro.get_command('pip')
    try:
        # Versions don't seem to matter here...
        name = _make_pip_name(pip['name'], None)
        LOG.audit("Uninstalling python package %r using pip command %s" % (name, root_cmd))
        cmd = [root_cmd, 'uninstall'] + PIP_UNINSTALL_CMD_OPTS + [name]
        sh.execute(*cmd, run_as_root=True)
    except excp.ProcessExecutionError:
        if skip_errors:
            LOG.debug(("Ignoring execution error that occured when uninstalling pip %r!"
                " (this may be ok if it was uninstalled by a previous component)") % (name))
        else:
            raise
Exemplo n.º 34
0
def uninstall(pips, distro, skip_errors=True):
    pipnames = sorted(pips.keys())
    root_cmd = PIP_CMD_NAMES[distro]
    LOG.info("Uninstalling python packages (%s) using command (%s)" % (", ".join(pipnames), root_cmd))
    for name in pipnames:
        try:
            LOG.debug("Uninstall python package (%s)" % (name))
            cmd = [root_cmd, 'uninstall'] + PIP_UNINSTALL_CMD_OPTS + [str(name)]
            sh.execute(*cmd, run_as_root=True)
        except excp.ProcessExecutionError:
            if skip_errors:
                LOG.warn("Ignoring execution error that occured when uninstalling pip %s!" % (name))
            else:
                raise
Exemplo n.º 35
0
 def _do_screen_init(self):
     LOG.debug("Creating a new screen session named [%s]" % (SESSION_NAME))
     session_init_cmd = self._gen_cmd(SESSION_INIT)
     sh.execute(*session_init_cmd,
             shell=True,
             run_as_root=ROOT_GO,
             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=ROOT_GO,
             env_overrides=self._get_env())
Exemplo n.º 36
0
 def _clean_it(self):
     # These environment additions are important
     # in that they eventually affect how this script runs
     env = dict()
     env['ENABLED_SERVICES'] = ",".join(self.desired_subsystems)
     env['BIN_DIR'] = self.bin_dir
     env['VOLUME_NAME_PREFIX'] = self.cfg.getdefaulted(
         'nova', 'volume_name_prefix', DEF_VOL_PREFIX)
     cleaner_fn = sh.joinpths(self.bin_dir, CLEANER_DATA_CONF)
     if sh.isfile(cleaner_fn):
         LOG.info(
             "Cleaning up your system by running nova cleaner script %r" %
             (cleaner_fn))
         cmd = CLEANER_CMD_ROOT + [cleaner_fn]
         sh.execute(*cmd, run_as_root=True, env_overrides=env)
Exemplo n.º 37
0
 def post_start(self):
     tgt_fn = sh.joinpths(self.bin_dir, MANAGE_DATA_CONF)
     if sh.is_executable(tgt_fn):
         # If its still there, run it
         # these environment additions are important
         # in that they eventually affect how this script runs
         LOG.info("Waiting %s seconds so that keystone can start up before running first time init." % (self.wait_time))
         sh.sleep(self.wait_time)
         env = dict()
         env['ENABLED_SERVICES'] = ",".join(self.instances.keys())
         env['BIN_DIR'] = self.bin_dir
         setup_cmd = MANAGE_CMD_ROOT + [tgt_fn]
         LOG.info("Running %r command to initialize keystone." % (" ".join(setup_cmd)))
         sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
         utils.mark_unexecute_file(tgt_fn, env)
Exemplo n.º 38
0
 def _setup_data(self):
     LOG.info("Configuring data setup template %s", MANAGE_DATA_CONF)
     (src_fn, contents) = utils.load_template(self.component_name, MANAGE_DATA_CONF)
     params = self._get_param_map(MANAGE_DATA_CONF)
     contents = utils.param_replace(contents, params, True)
     tgt_fn = sh.joinpths(self.bindir, MANAGE_DATA_CONF)
     sh.write_file(tgt_fn, contents)
     # This environment additions are important
     # in that they eventually affect how this script runs
     env = dict()
     env['ENABLED_SERVICES'] = ",".join(self.instances.keys())
     env['BIN_DIR'] = self.bindir
     setup_cmd = MANAGER_CMD_ROOT + [tgt_fn]
     LOG.info("Running (%s) command to setup keystone." % (" ".join(setup_cmd)))
     sh.execute(*setup_cmd, env_overrides=env)
Exemplo n.º 39
0
 def _start(self, app_name, program, program_args):
     run_trace = tr.TraceWriter(tr.trace_fn(self.trace_dir, UPSTART_TEMPL % (app_name)))
     run_trace.trace(TYPE, RUN_TYPE)
     run_trace.trace(NAME, app_name)
     run_trace.trace(ARGS, json.dumps(program_args))
     # Emit the start, keep track and only do one per component name
     component_event = self.component_name + START_EVENT_SUFFIX
     if component_event in self.events:
         LOG.debug("Already emitted event: %s" % (component_event))
     else:
         LOG.debug("About to emit event: %s" % (component_event))
         cmd = EMIT_BASE_CMD + [component_event]
         sh.execute(*cmd, run_as_root=True)
         self.events.add(component_event)
     return run_trace.filename()
Exemplo n.º 40
0
 def _run_cmd(self, cmd, check_exit=True):
     # This seems to fix one of the bugs with rabbit mq starting and stopping
     # not cool, possibly connected to the following bugs:
     #
     # See: https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878597
     # See: https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878600
     #
     # RHEL seems to have this bug also...
     if self.redir_out:
         with TemporaryFile() as f:
             return sh.execute(*cmd, run_as_root=True,
                         stdout_fh=f, stderr_fh=f,
                         check_exit_code=check_exit)
     else:
         return sh.execute(*cmd, run_as_root=True,
                             check_exit_code=check_exit)
Exemplo n.º 41
0
 def _do_screen_init(self):
     LOG.debug("Creating a new screen session named [%s]" % (SESSION_NAME))
     session_init_cmd = self._gen_cmd(SESSION_INIT)
     sh.execute(*session_init_cmd,
                shell=True,
                run_as_root=ROOT_GO,
                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=ROOT_GO,
                env_overrides=self._get_env())
Exemplo n.º 42
0
 def _start(self, app_name, program, program_args):
     run_trace = tr.TraceWriter(
         tr.trace_fn(self.trace_dir, UPSTART_TEMPL % (app_name)))
     run_trace.trace(TYPE, RUN_TYPE)
     run_trace.trace(NAME, app_name)
     run_trace.trace(ARGS, json.dumps(program_args))
     # Emit the start, keep track and only do one per component name
     component_event = self.component_name + START_EVENT_SUFFIX
     if component_event in self.events:
         LOG.debug("Already emitted event: %s" % (component_event))
     else:
         LOG.debug("About to emit event: %s" % (component_event))
         cmd = EMIT_BASE_CMD + [component_event]
         sh.execute(*cmd, run_as_root=True)
         self.events.add(component_event)
     return run_trace.filename()
Exemplo n.º 43
0
def uninstall(pip, distro, skip_errors=True):
    root_cmd = distro.get_command('pip')
    try:
        # Versions don't seem to matter here...
        name = _make_pip_name(pip['name'], None)
        LOG.audit("Uninstalling python package %r using pip command %s" %
                  (name, root_cmd))
        cmd = [root_cmd, 'uninstall'] + PIP_UNINSTALL_CMD_OPTS + [name]
        sh.execute(*cmd, run_as_root=True)
    except excp.ProcessExecutionError:
        if skip_errors:
            LOG.debug((
                "Ignoring execution error that occured when uninstalling pip %r!"
                " (this may be ok if it was uninstalled by a previous component)"
            ) % (name))
        else:
            raise
Exemplo n.º 44
0
 def post_start(self):
     tgt_fn = sh.joinpths(self.bin_dir, MANAGE_DATA_CONF)
     if sh.is_executable(tgt_fn):
         # If its still there, run it
         # these environment additions are important
         # in that they eventually affect how this script runs
         LOG.info(
             "Waiting %s seconds so that keystone can start up before running first time init."
             % (self.wait_time))
         sh.sleep(self.wait_time)
         env = dict()
         env['ENABLED_SERVICES'] = ",".join(self.instances.keys())
         env['BIN_DIR'] = self.bin_dir
         setup_cmd = MANAGE_CMD_ROOT + [tgt_fn]
         LOG.info("Running %r command to initialize keystone." %
                  (" ".join(setup_cmd)))
         sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
         utils.mark_unexecute_file(tgt_fn, env)
Exemplo n.º 45
0
 def _setup_network_init(self):
     tgt_fn = sh.joinpths(self.bin_dir, NET_INIT_CONF)
     if sh.is_executable(tgt_fn):
         LOG.info("Creating your nova network to be used with instances.")
         # If still there, run it
         # these environment additions are important
         # in that they eventually affect how this script runs
         if 'quantum' in self.options:
             LOG.info(
                 "Waiting %s seconds so that quantum can start up before running first time init."
                 % (self.wait_time))
             sh.sleep(self.wait_time)
         env = dict()
         env['ENABLED_SERVICES'] = ",".join(self.options)
         setup_cmd = NET_INIT_CMD_ROOT + [tgt_fn]
         LOG.info("Running %r command to initialize nova's network." %
                  (" ".join(setup_cmd)))
         sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
         utils.mark_unexecute_file(tgt_fn, env)
Exemplo n.º 46
0
 def _service_status(self):
     cmd = self.distro.get_command('libvirt', 'status')
     (stdout, stderr) = sh.execute(*cmd,
                                   run_as_root=True,
                                   check_exit_code=False)
     combined = (stdout + stderr).lower()
     if combined.find("running") != -1 or combined.find('start') != -1:
         return _ALIVE
     else:
         return _DEAD
Exemplo n.º 47
0
 def _do_stop(self, app_name, session_id):
     mp = dict()
     mp['SESSION_NAME'] = session_id
     mp['NAME'] = app_name
     LOG.debug(
         "Stopping program running in session [%s] in window named [%s]." %
         (session_id, app_name))
     kill_cmd = self._gen_cmd(CMD_KILL, mp)
     sh.execute(*kill_cmd,
                shell=True,
                run_as_root=ROOT_GO,
                env_overrides=self._get_env(),
                check_exit_code=False)
     # We have really no way of knowing if it worked or not, screen sux...
     wipe_cmd = self._gen_cmd(CMD_WIPE, mp)
     sh.execute(*wipe_cmd,
                shell=True,
                run_as_root=ROOT_GO,
                env_overrides=self._get_env(),
                check_exit_code=False)
Exemplo n.º 48
0
 def _setup_vol_groups(self):
     LOG.info(
         "Attempting to setup volume groups for nova volume management.")
     mp = dict()
     backing_file = self.cfg.getdefaulted(
         'nova', 'volume_backing_file',
         sh.joinpths(self.app_dir, 'nova-volumes-backing-file'))
     vol_group = self.cfg.getdefaulted('nova', 'volume_group',
                                       'nova-volumes')
     backing_file_size = utils.to_bytes(
         self.cfg.getdefaulted('nova', 'volume_backing_file_size', '2052M'))
     mp['VOLUME_GROUP'] = vol_group
     mp['VOLUME_BACKING_FILE'] = backing_file
     mp['VOLUME_BACKING_FILE_SIZE'] = backing_file_size
     try:
         utils.execute_template(*VG_CHECK_CMD, params=mp)
         LOG.warn("Volume group already exists: %r" % (vol_group))
     except exceptions.ProcessExecutionError as err:
         # Check that the error from VG_CHECK is an expected error
         if err.exit_code != 5:
             raise
         LOG.info("Need to create volume group: %r" % (vol_group))
         sh.touch_file(backing_file,
                       die_if_there=False,
                       file_size=backing_file_size)
         vg_dev_result = utils.execute_template(*VG_DEV_CMD, params=mp)
         if vg_dev_result and vg_dev_result[0]:
             LOG.debug("VG dev result: %s" % (vg_dev_result))
             # Strip the newlines out of the stdout (which is in the first
             # element of the first (and only) tuple in the response
             (sysout, _) = vg_dev_result[0]
             mp['DEV'] = sysout.replace('\n', '')
             utils.execute_template(*VG_CREATE_CMD, params=mp)
     # One way or another, we should have the volume group, Now check the
     # logical volumes
     self._process_lvs(mp)
     # Finish off by restarting tgt, and ignore any errors
     cmdrestart = self.distro.get_command('iscsi', 'restart', quiet=True)
     if cmdrestart:
         sh.execute(*cmdrestart, run_as_root=True, check_exit_code=False)
Exemplo n.º 49
0
 def _active_sessions(self):
     knowns = list()
     list_cmd = self._gen_cmd(LIST_CMD)
     (sysout, _) = sh.execute(*list_cmd,
                              check_exit_code=False,
                              run_as_root=ROOT_GO,
                              env_overrides=self._get_env())
     if sysout.lower().find("No Sockets found") != -1:
         return knowns
     for line in sysout.splitlines():
         mtch = SESSION_NAME_MTCHER.match(line)
         if mtch:
             knowns.append(mtch.group(1))
     return knowns
Exemplo n.º 50
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 [%s] in session [%s]" %
               (prog_name, session))
     sh.execute(*init_cmd,
                shell=True,
                run_as_root=ROOT_GO,
                env_overrides=self._get_env())
     LOG.debug(
         "Waiting %s seconds before we attempt to run command [%s] 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=ROOT_GO,
                env_overrides=self._get_env())
Exemplo n.º 51
0
 def status(self):
     statuscmd = self._get_run_actions('status', excp.StatusException)
     run_result = sh.execute(*statuscmd,
                             run_as_root=True,
                             check_exit_code=False)
     if not run_result:
         return comp.STATUS_UNKNOWN
     (sysout, stderr) = run_result
     combined = (str(sysout) + str(stderr)).lower()
     if combined.find("running") != -1:
         return comp.STATUS_STARTED
     elif combined.find("stop") != -1 or \
          combined.find('unrecognized') != -1:
         return comp.STATUS_STOPPED
     else:
         return comp.STATUS_UNKNOWN
Exemplo n.º 52
0
 def download(self):
     dirsmade = list()
     if sh.isdir(self.store_where):
         LOG.info("Updating using git: located at %r" % (self.store_where))
         cmd = list(self.distro.get_command('git', 'checkout'))
         cmd += [GIT_MASTER_BRANCH]
         sh.execute(*cmd, cwd=self.store_where)
         cmd = self.distro.get_command('git', 'pull')
         sh.execute(*cmd, cwd=self.store_where)
     else:
         LOG.info("Downloading using git: %r to %r" % (self.uri, self.store_where))
         dirsmade.extend(sh.mkdirslist(self.store_where))
         cmd = list(self.distro.get_command('git', 'clone'))
         cmd += [self.uri, self.store_where]
         sh.execute(*cmd)
     if self.branch and self.branch != GIT_MASTER_BRANCH:
         LOG.info("Adjusting branch using git: %r" % (self.branch))
         cmd = list(self.distro.get_command('git', 'checkout'))
         cmd += [self.branch]
         sh.execute(*cmd, cwd=self.store_where)
     return dirsmade
Exemplo n.º 53
0
 def status(self):
     # This has got to be the worst status output.
     #
     # I have ever seen (its like a weird mix json+crap)
     run_result = sh.execute(
         *self.distro.get_command('rabbit-mq', 'status'),
         check_exit_code=False,
         run_as_root=True)
     if not run_result:
         return comp.STATUS_UNKNOWN
     (sysout, stderr) = run_result
     combined = str(sysout) + str(stderr)
     combined = combined.lower()
     if combined.find('nodedown') != -1 or \
        combined.find("unable to connect to node") != -1 or \
        combined.find('unrecognized') != -1:
         return comp.STATUS_STOPPED
     elif combined.find('running_applications') != -1:
         return comp.STATUS_STARTED
     else:
         return comp.STATUS_UNKNOWN
Exemplo n.º 54
0
 def _install_python_setups(self):
     pydirs = self._get_python_directories()
     if pydirs:
         LOG.info("Setting up %s python directories (%s)", len(pydirs),
                  pydirs)
         for (name, wkdir) in pydirs.items():
             working_dir = wkdir or self.app_dir
             self.tracewriter.dirs_made(*sh.mkdirslist(working_dir))
             self.tracewriter.py_installed(name, working_dir)
             (stdout, stderr) = sh.execute(*PY_INSTALL,
                                           cwd=working_dir,
                                           run_as_root=True)
             py_trace_name = "%s-%s" % (tr.PY_TRACE, name)
             py_writer = tr.TraceWriter(
                 tr.trace_fn(self.trace_dir, py_trace_name))
             # Format or json encoding isn't really needed here since this is
             # more just for information output/lookup if desired.
             py_writer.trace("CMD", " ".join(PY_INSTALL))
             py_writer.trace("STDOUT", stdout)
             py_writer.trace("STDERR", stderr)
             self.tracewriter.file_touched(py_writer.filename())
Exemplo n.º 55
0
def execute_template(*cmds, **kargs):
    params_replacements = kargs.pop('params', None)
    ignore_missing = kargs.pop('ignore_missing', False)
    cmd_results = list()
    for cmdinfo in cmds:
        cmd_to_run_templ = cmdinfo["cmd"]
        cmd_to_run = param_replace_list(cmd_to_run_templ, params_replacements,
                                        ignore_missing)
        stdin_templ = cmdinfo.get('stdin')
        stdin = None
        if stdin_templ:
            stdin_full = param_replace_list(stdin_templ, params_replacements,
                                            ignore_missing)
            stdin = joinlinesep(*stdin_full)
        exec_result = sh.execute(*cmd_to_run,
                                 run_as_root=cmdinfo.get('run_as_root', False),
                                 process_input=stdin,
                                 ignore_exit_code=cmdinfo.get(
                                     'ignore_failure', False),
                                 **kargs)
        cmd_results.append(exec_result)
    return cmd_results
Exemplo n.º 56
0
 def post_uninstall(self):
     sh.execute(*RSYSLOG_SERVICE_RESTART, run_as_root=True)
     sh.execute(*RSYNC_SERVICE_RESTART, run_as_root=True)
Exemplo n.º 57
0
 def _execute_apt(self, cmd, **kargs):
     full_cmd = APT_GET + cmd
     return sh.execute(*full_cmd, run_as_root=True,
         check_exit_code=True,
         env_overrides=ENV_ADDITIONS,
         **kargs)
Exemplo n.º 58
0
 def _execute_yum(self, cmd, **kargs):
     full_cmd = YUM_CMD + cmd
     return sh.execute(*full_cmd,
                       run_as_root=True,
                       check_exit_code=True,
                       **kargs)
Exemplo n.º 59
0
 def _sync_db(self):
     # Initialize the horizon database (it stores sessions and notices shown to users).
     # The user system is external (keystone).
     LOG.info("Initializing the horizon database.")
     sh.execute(*DB_SYNC_CMD, cwd=self.app_dir)
Exemplo n.º 60
0
 def restart(self):
     swift_restart_cmd = [sh.joinpths(self.bin_dir, SWIFT_INIT)
                          ] + ['all', 'restart']
     sh.execute(*swift_restart_cmd, run_as_root=True)