def _uninstall_touched_files(self): filestouched = self.tracereader.files_touched() if filestouched: LOG.info("Removing %s touched files (%s)", len(filestouched), ", ".join(filestouched)) for fn in filestouched: sh.unlink(fn, run_as_root=True)
def _unconfigure_links(self): symfiles = self.tracereader.symlinks_made() if symfiles: LOG.info("Removing %s symlink files (%s)", len(symfiles), ", ".join(symfiles)) for fn in symfiles: sh.unlink(fn, run_as_root=True)
def _unconfigure_files(self): cfgfiles = self.tracereader.files_configured() if cfgfiles: LOG.info("Removing %s configuration files (%s)", len(cfgfiles), ", ".join(cfgfiles)) for fn in cfgfiles: sh.unlink(fn, run_as_root=True)
def _unconfigure_files(self): cfgfiles = self.tracereader.files_configured() if cfgfiles: LOG.info("Removing %s configuration files (%s)" % (len(cfgfiles), ", ".join(cfgfiles))) for fn in cfgfiles: if fn: sh.unlink(fn)
def _remove_special(self, pkgname, pkginfo): #TODO: maybe this should be a subclass that handles these differences if self.distro == settings.RHEL6 and pkgname in RHEL_RELINKS: #we don't return true here so that #the normal package cleanup happens sh.unlink(RHEL_RELINKS.get(pkgname).get("tgt")) return False
def _uninstall_touched_files(self): filestouched = self.tracereader.files_touched() if filestouched: LOG.info("Removing %s touched files (%s)" % (len(filestouched), ", ".join(filestouched))) for fn in filestouched: if fn: sh.unlink(fn)
def stop(self): to_kill = self._locate_killers() for (app_name, killer) in to_kill: killer.stop(app_name) LOG.debug("Deleting start trace file [%s]", self.tracereader.filename()) sh.unlink(self.tracereader.filename()) return len(to_kill)
def _config_adjust_root(self, contents, fn): params = get_shared_params(self.cfg, self.pw_gen) with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) config.set('DEFAULT', 'admin_token', params['SERVICE_TOKEN']) config.set('DEFAULT', 'admin_port', params['KEYSTONE_AUTH_PORT']) config.set('DEFAULT', 'verbose', True) config.set('DEFAULT', 'debug', True) config.remove_option('DEFAULT', 'log_config') config.set( 'sql', 'connection', db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME, utf8=True)) config.set('catalog', 'template_file', sh.joinpths(self.cfg_dir, CATALOG_CONF)) config.set('catalog', 'driver', "keystone.catalog.backends.templated.TemplatedCatalog") config.set('ec2', 'driver', "keystone.contrib.ec2.backends.sql.Ec2") config.set('filter:s3_extension', 'paste.filter_factory', "keystone.contrib.s3:S3Extension.factory") config.set('pipeline:admin_api', 'pipeline', ( 'token_auth admin_token_auth xml_body ' 'json_body debug ec2_extension s3_extension crud_extension admin_service' )) contents = config.stringify(fn) # FIXME: LP 966670 fixes this in keystone sh.unlink(sh.joinpths(self.app_dir, 'etc', fn)) return contents
def _unconfigure_links(self): sym_files = self.tracereader.symlinks_made() if sym_files: utils.log_iterable(sym_files, logger=LOG, header="Removing %s symlink files" % (len(sym_files))) for fn in sym_files: sh.unlink(fn, run_as_root=True)
def _unconfigure_files(self): cfg_files = self.tracereader.files_configured() if cfg_files: utils.log_iterable(cfg_files, logger=LOG, header="Removing %s configuration files" % (len(cfg_files))) for fn in cfg_files: sh.unlink(fn, run_as_root=True)
def _uninstall_touched_files(self): files_touched = self.tracereader.files_touched() if files_touched: utils.log_iterable(files_touched, logger=LOG, header="Removing %s touched files" % (len(files_touched))) for fn in files_touched: sh.unlink(fn, run_as_root=True)
def _remove_special(self, name, info): if name in RHEL_RELINKS: # Note: we don't return true here so that # the normal package cleanup happens... (_, tgt) = RHEL_RELINKS.get(name) if sh.islink(tgt): sh.unlink(tgt) return False
def _remove(self, pkg): response = yum.YumPackager._remove(self, pkg) if response: options = pkg.get("packager_options", {}) links = options.get("links", []) for (_, tgt) in links: if sh.islink(tgt): sh.unlink(tgt) return response
def _remove(self, pkg): response = yum.YumPackager._remove(self, pkg) if response: options = pkg.get('packager_options', {}) links = options.get('links', []) for (_, tgt) in links: if sh.islink(tgt): sh.unlink(tgt) return response
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)
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)
def stop(self, name, *args, **kargs): with sh.Rooted(kargs.get("run_as_root", True)): trace_dir = kargs.get("trace_dir") if not trace_dir or not sh.isdir(trace_dir): msg = "No trace directory found from which to stop %s" % (name) raise excp.StopException(msg) fn_name = FORK_TEMPL % (name) (pid_file, stderr_fn, stdout_fn) = self._form_file_names(trace_dir, fn_name) trace_fn = tr.trace_fn(trace_dir, fn_name) if sh.isfile(pid_file) and sh.isfile(trace_fn): pid = int(sh.load_file(pid_file).strip()) (killed, attempts) = self._stop_pid(pid) #trash the files if killed: LOG.debug("Killed pid %s after %s attempts" % (pid, attempts)) LOG.debug("Removing pid file %s" % (pid_file)) sh.unlink(pid_file) LOG.debug("Removing stderr file %s" % (stderr_fn)) sh.unlink(stderr_fn) LOG.debug("Removing stdout file %s" % (stdout_fn)) sh.unlink(stdout_fn) LOG.debug("Removing %s trace file %s" % (name, trace_fn)) sh.unlink(trace_fn) else: msg = "Could not stop %s after %s attempts" % (name, attempts) raise excp.StopException(msg) else: msg = "No pid or trace file could be found to stop %s in directory %s" % (name, trace_dir) raise excp.StopException(msg)
def stop(self, app_name): with sh.Rooted(ROOT_GO): if not sh.isdir(self.trace_dir): msg = "No trace directory found from which to stop %s" % (app_name) raise excp.StopException(msg) fn_name = FORK_TEMPL % (app_name) (pid_file, stderr_fn, stdout_fn) = self._form_file_names(fn_name) trace_fn = tr.trace_fn(self.trace_dir, fn_name) if sh.isfile(pid_file) and sh.isfile(trace_fn): pid = int(sh.load_file(pid_file).strip()) (killed, attempts) = self._stop_pid(pid) # Trash the files if it worked if killed: LOG.debug("Killed pid %s after %s attempts" % (pid, attempts)) LOG.debug("Removing pid file %s" % (pid_file)) sh.unlink(pid_file) LOG.debug("Removing stderr file %s" % (stderr_fn)) sh.unlink(stderr_fn) LOG.debug("Removing stdout file %s" % (stdout_fn)) sh.unlink(stdout_fn) LOG.debug("Removing %s trace file %s" % (app_name, trace_fn)) sh.unlink(trace_fn) else: msg = "Could not stop %s after %s attempts" % (app_name, attempts) raise excp.StopException(msg) else: msg = "No pid or trace file could be found to stop %s in directory %s" % (app_name, self.trace_dir) raise excp.StopException(msg)
def _config_adjust(self, contents, name): # Even bother opening?? if name not in READ_CONFIGS: return contents # Use config parser and # then extract known configs that # will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) if config.getboolean('default', 'image_cache_enabled'): cache_dir = config.get('default', "image_cache_datadir") if cache_dir: LOG.info("Ensuring image cache data directory %s exists "\ "(and is empty)" % (cache_dir)) # Destroy then recreate the image cache directory sh.deldir(cache_dir) self.tracewriter.dirs_made(*sh.mkdirslist(cache_dir)) if config.get('default', 'default_store') == 'file': file_dir = config.get('default', 'filesystem_store_datadir') if file_dir: LOG.info( "Ensuring file system store directory %s exists and is empty." % (file_dir)) # Delete existing images # and recreate the image directory sh.deldir(file_dir) self.tracewriter.dirs_made(*sh.mkdirslist(file_dir)) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.dirs_made(*sh.mkdirslist(log_dir)) # Destroy then recreate it (the log file) sh.unlink(log_filename) self.tracewriter.file_touched(sh.touch_file(log_filename)) if config.getboolean('default', 'delayed_delete'): data_dir = config.get('default', 'scrubber_datadir') if data_dir: LOG.info( "Ensuring scrubber data dir %s exists and is empty." % (data_dir)) # Destroy then recreate the scrubber data directory sh.deldir(data_dir) self.tracewriter.dirs_made(*sh.mkdirslist(data_dir)) # Nothing modified so just return the original return contents
def post_start(self): tgt_fn = sh.joinpths(self.bin_dir, MANAGE_DATA_CONF) if sh.isfile(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 (%s) command to initialize keystone." % (" ".join(setup_cmd))) sh.execute(*setup_cmd, env_overrides=env, run_as_root=False) LOG.debug("Removing (%s) file since we successfully initialized keystone." % (tgt_fn)) sh.unlink(tgt_fn)
def _config_adjust(self, contents, name): #even bother opening?? if name not in READ_CONFIGS: return contents #use config parser and #then extract known configs that #will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) if config.getboolean('default', 'image_cache_enabled'): cache_dir = config.get('default', "image_cache_datadir") if cache_dir: LOG.info("Ensuring image cache data directory %s exists "\ "(and is empty)" % (cache_dir)) #destroy then recreate the image cache directory sh.deldir(cache_dir) self.tracewriter.make_dir(cache_dir) if config.get('default', 'default_store') == 'file': file_dir = config.get('default', 'filesystem_store_datadir') if file_dir: LOG.info("Ensuring file system store directory %s exists and is empty." % (file_dir)) #delete existing images #and recreate the image directory sh.deldir(file_dir) self.tracewriter.make_dir(file_dir) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.make_dir(log_dir) #destroy then recreate it (the log file) sh.unlink(log_filename) sh.touch_file(log_filename) self.tracewriter.file_touched(log_filename) if config.getboolean('default', 'delayed_delete'): data_dir = config.get('default', 'scrubber_datadir') if data_dir: LOG.info("Ensuring scrubber data dir %s exists and is empty." % (data_dir)) #destroy then recreate the scrubber data directory sh.deldir(data_dir) self.tracewriter.make_dir(data_dir) #we might need to handle more in the future... #nothing modified so just return the original return contents
def _setup_network_init(self): tgt_fn = sh.joinpths(self.bindir, NET_INIT_CONF) if sh.isfile(tgt_fn): LOG.info("Creating your nova network to be used with instances.") #still there, run it #these environment additions are important #in that they eventually affect how this script runs if utils.service_enabled(settings.QUANTUM, self.instances, False): LOG.info("Waiting %s seconds so that quantum can start up before running first time init." % (WAIT_ONLINE_TO)) time.sleep(WAIT_ONLINE_TO) env = dict() env['ENABLED_SERVICES'] = ",".join(self.instances.keys()) setup_cmd = NET_INIT_CMD_ROOT + [tgt_fn] LOG.info("Running (%s) command to initialize nova's network." % (" ".join(setup_cmd))) sh.execute(*setup_cmd, env_overrides=env, run_as_root=False) LOG.debug("Removing (%s) file since we successfully initialized nova's network." % (tgt_fn)) sh.unlink(tgt_fn)
def stop(self): #ensure it was installed if not self._was_installed(): msg = "Can not stop %s since it was not installed" % (self.component_name) raise excp.StopException(msg) #we can only stop what has a started trace start_traces = self.starttracereader.apps_started() killedam = 0 for mp in start_traces: #extract the apps name and where its trace is fn = mp.get('trace_fn') name = mp.get('name') #missing some key info, skip it if fn is None or name is None: continue #figure out which class will stop it contents = tr.parse_fn(fn) killcls = None runtype = None for (cmd, action) in contents: if cmd == "TYPE": runtype = action killcls = self._getstoppercls(runtype) break #did we find a class that can do it? if killcls: #we can try to stop it LOG.info("Stopping %s of run type %s" % (name, runtype)) #create an instance of the killer class and attempt to stop killer = killcls() killer.stop(name, trace_dir=self.tracedir) killedam += 1 else: #TODO raise error?? pass #if we got rid of them all get rid of the trace if killedam == len(start_traces): fn = self.starttracereader.trace_fn LOG.info("Deleting trace file %s" % (fn)) sh.unlink(fn) return killedam
def _config_adjust_root(self, contents, fn): params = get_shared_params(self.cfg, self.pw_gen) with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) config.set('DEFAULT', 'admin_token', params['SERVICE_TOKEN']) config.set('DEFAULT', 'admin_port', params['KEYSTONE_AUTH_PORT']) config.set('DEFAULT', 'verbose', True) config.set('DEFAULT', 'debug', True) config.remove_option('DEFAULT', 'log_config') config.set('sql', 'connection', db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME, utf8=True)) config.set('catalog', 'template_file', sh.joinpths(self.cfg_dir, CATALOG_CONF)) config.set('catalog', 'driver', "keystone.catalog.backends.templated.TemplatedCatalog") config.set('ec2', 'driver', "keystone.contrib.ec2.backends.sql.Ec2") config.set('filter:s3_extension', 'paste.filter_factory', "keystone.contrib.s3:S3Extension.factory") config.set('pipeline:admin_api', 'pipeline', ('token_auth admin_token_auth xml_body ' 'json_body debug ec2_extension s3_extension crud_extension admin_service')) contents = config.stringify(fn) # FIXME: LP 966670 fixes this in keystone sh.unlink(sh.joinpths(self.app_dir, 'etc', fn)) return contents
def post_start(self): tgt_fn = sh.joinpths(self.bin_dir, MANAGE_DATA_CONF) if sh.isfile(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 (%s) command to initialize keystone." % (" ".join(setup_cmd))) sh.execute(*setup_cmd, env_overrides=env, run_as_root=False) LOG.debug( "Removing (%s) file since we successfully initialized keystone." % (tgt_fn)) sh.unlink(tgt_fn)
def _setup_network_init(self): tgt_fn = sh.joinpths(self.bin_dir, NET_INIT_CONF) if sh.isfile(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.instances.keys()) setup_cmd = NET_INIT_CMD_ROOT + [tgt_fn] LOG.info("Running (%s) command to initialize nova's network." % (" ".join(setup_cmd))) sh.execute(*setup_cmd, env_overrides=env, run_as_root=False) LOG.debug( "Removing (%s) file since we successfully initialized nova's network." % (tgt_fn)) sh.unlink(tgt_fn)
def _config_adjust(self, contents, name): if name == ROOT_CONF: # Use config parser and # then extract known configs that # ill need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.dirs_made(*sh.mkdirslist(log_dir)) # Destroy then recreate it (the log file) sh.unlink(log_filename) self.tracewriter.file_touched(sh.touch_file(log_filename)) elif name == CATALOG_CONF: nlines = list() if 'swift' in self.options: mp = dict() mp['SERVICE_HOST'] = self.cfg.get('host', 'ip') nlines.append("# Swift additions") nlines.extend(utils.param_replace_list(SWIFT_TEMPL_ADDS, mp)) nlines.append("") if 'quantum' in self.options: mp = dict() mp['SERVICE_HOST'] = self.cfg.get('host', 'ip') nlines.append("# Quantum additions") nlines.extend(utils.param_replace_list(QUANTUM_TEMPL_ADDS, mp)) nlines.append("") if nlines: nlines.insert(0, contents) contents = cfg.add_header(name, utils.joinlinesep(*nlines)) return contents
def _config_adjust(self, contents, name): if name == ROOT_CONF: #use config parser and #then extract known configs that #will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.make_dir(log_dir) #destroy then recreate it (the log file) sh.unlink(log_filename) sh.touch_file(log_filename) self.tracewriter.file_touched(log_filename) elif name == CATALOG_CONF: nlines = list() if utils.service_enabled(settings.SWIFT, self.instances): mp = dict() mp['SERVICE_HOST'] = self.cfg.get('host', 'ip') nlines.append("# Swift additions") nlines.extend(utils.param_replace_list(SWIFT_TEMPL_ADDS, mp)) nlines.append("") if utils.service_enabled(settings.QUANTUM, self.instances) or \ utils.service_enabled(settings.QUANTUM_CLIENT, self.instances): mp = dict() mp['SERVICE_HOST'] = self.cfg.get('host', 'ip') nlines.append("# Quantum additions") nlines.extend(utils.param_replace_list(QUANTUM_TEMPL_ADDS, mp)) nlines.append("") if nlines: nlines.insert(0, contents) contents = cfg.add_header(name, utils.joinlinesep(*nlines)) return contents
def _config_adjust(self, contents, name): if name not in CONFIGS: return contents #use config parser and #then extract known configs that #will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) log_filename = config.get('log_file', CFG_SECTION) if log_filename: LOG.info("Ensuring log file %s exists and is empty" % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists" % (log_dir)) self.tracewriter.make_dir(log_dir) #destroy then recreate it (the log file) sh.unlink(log_filename) sh.touch_file(log_filename) self.tracewriter.file_touched(log_filename) #we might need to handle more in the future... #nothing modified so just return the original return contents
def _delete_templates(self): for t in ['object', 'container', 'account']: sh.unlink(sh.joinpths(self.cfg_dir, '%s-server.conf' % t))
def _remove_special(self, pkgname, pkginfo): if self.distro == settings.RHEL6 and pkgname in RHEL_RELINKS: #we don't return true here so that #the normal package cleanup happens sh.unlink(RHEL_RELINKS.get(pkgname).get("tgt")) return False
def stop(self, app_name): trace_fn = tr.trace_fn(self.trace_dir, SCREEN_TEMPL % (app_name)) session_id = self._find_session(app_name, trace_fn) self._do_stop(app_name, session_id) sh.unlink(trace_fn)
def _cleanup(self): if self.tmp_folder: shell.deldir(self.tmp_folder) shell.unlink(self.download_file_name)