def _setup_vol_groups(self): LOG.info("Attempting to setup volume groups for nova volume management.") mp = dict() backing_file = self.cfg.get('nova', 'volume_backing_file') # check if we need to have a default backing file if not backing_file: backing_file = sh.joinpths(self.appdir, 'nova-volumes-backing-file') vol_group = self.cfg.get('nova', 'volume_group') backing_file_size = utils.to_bytes(self.cfg.get('nova', 'volume_backing_file_size')) 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 utils.execute_template(*RESTART_TGT_CMD, check_exit_code=False)
def _start(self): if self.started: return else: trace_dirs = sh.mkdirslist(sh.dirname(self.trace_fn)) sh.touch_file(self.trace_fn) self.trace(TRACE_VERSION, str(TRACE_VER)) self.started = True self.dirs_made(*trace_dirs)
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 _fix_quantum(self): if not (utils.service_enabled(settings.QUANTUM_CLIENT, self.instances, False)): #make the fake quantum (apparently needed so imports don't fail???) #TODO remove this... quantum_dir = sh.joinpths(self.dash_dir, 'quantum') if not sh.isdir(quantum_dir): self.tracewriter.dirs_made(*sh.mkdirslist(quantum_dir)) for fn in FAKE_QUANTUM_FILES: self.tracewriter.file_touched(sh.touch_file(sh.joinpths(quantum_dir, fn)))
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)
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): # 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 _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 _setup_vol_groups(self): LOG.debug("Attempt to setup vol groups") mp = dict() backing_file = self.cfg.get('nova', 'volume_backing_file') # check if we need to have a default backing file if not backing_file: backing_file = sh.joinpths(self.appdir, 'nova-volumes-backing-file') backing_file_size = self.cfg.get('nova', 'volume_backing_file_size') if backing_file_size[-1].upper() == 'M': backing_file_size = int(backing_file_size[:-1]) * 1024 ** 2 elif backing_file_size[-1].upper() == 'K': backing_file_size = int(backing_file_size[:-1]) * 1024 elif backing_file_size[-1].upper() == 'B': backing_file_size = int(backing_file_size[:-1]) LOG.debug("backing_file_size:%s" % (backing_file_size)) mp['VOLUME_GROUP'] = self.cfg.get('nova', 'volume_group') mp['VOLUME_BACKING_FILE'] = backing_file mp['VOLUME_BACKING_FILE_SIZE'] = backing_file_size LOG.debug("params for setup vol group: %s" % (mp)) try: utils.execute_template(*VG_CHECK_CMD, params=mp) LOG.debug("Vol group exists") except exceptions.ProcessExecutionError as err: LOG.debug("Caught expected exception:%s" % (err)) LOG.info("Need to create vol groups") 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) LOG.debug("vg dev result:%s" % (vg_dev_result)) # String the newlines out of the stdout (which is in the first # element of the first (and only) tuple in the response mp['DEV'] = vg_dev_result[0][0].replace('\n', '') utils.execute_template(*VG_CREATE_CMD, params=mp, tracewriter=self.tracewriter) # TODO Now need to check the headings, etc... # Finish off by restarting tgt utils.execute_template(*RESTART_TGT_CMD, check_exit_code=False, tracewriter=self.tracewriter)
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 touch_trace(rootdir, name): tracefn = trace_fn(rootdir, name) sh.touch_file(tracefn) return tracefn
def touch_file(self, path): self._start() sh.touch_file(path) self.file_touched(path) return path