def verify(self, entry, modlist): """Verify device entry.""" ondisk = self._exists(entry) if not ondisk: return False # attempt to verify device properties as specified in config rv = True dev_type = entry.get('dev_type') if dev_type in ['block', 'char']: major = int(entry.get('major')) minor = int(entry.get('minor')) if major != os.major(ondisk.st_rdev): msg = ("Major number for device %s is incorrect. " "Current major is %s but should be %s" % (entry.get("name"), os.major(ondisk.st_rdev), major)) self.logger.debug('POSIX: ' + msg) entry.set('qtext', entry.get('qtext', '') + "\n" + msg) rv = False if minor != os.minor(ondisk.st_rdev): msg = ("Minor number for device %s is incorrect. " "Current minor is %s but should be %s" % (entry.get("name"), os.minor(ondisk.st_rdev), minor)) self.logger.debug('POSIX: ' + msg) entry.set('qtext', entry.get('qtext', '') + "\n" + msg) rv = False return POSIXTool.verify(self, entry, modlist) and rv
def verify(self, entry, modlist): ondisk = self._exists(entry) if not ondisk: return False if not stat.S_ISDIR(ondisk[stat.ST_MODE]): self.logger.info("POSIX: %s is not a directory" % entry.get('name')) return False pruneTrue = True if entry.get('prune', 'false').lower() == 'true': # check for any extra entries when prune='true' attribute is set try: extras = [os.path.join(entry.get('name'), ent) for ent in os.listdir(entry.get('name')) if os.path.join(entry.get('name'), ent) not in modlist] if extras: pruneTrue = False msg = "Directory %s contains extra entries: %s" % \ (entry.get('name'), "; ".join(extras)) self.logger.info("POSIX: " + msg) entry.set('qtext', entry.get('qtext', '') + '\n' + msg) for extra in extras: Bcfg2.Client.XML.SubElement(entry, 'Prune', path=extra) except OSError: pruneTrue = True return POSIXTool.verify(self, entry, modlist) and pruneTrue
def install(self, entry): ondisk = self._exists(entry, remove=True) if ondisk: self.logger.info("POSIX: Symlink %s cleanup failed" % entry.get('name')) try: os.symlink(entry.get('to'), entry.get('name')) rv = True except OSError: err = sys.exc_info()[1] self.logger.error("POSIX: Failed to create symlink %s to %s: %s" % (entry.get('name'), entry.get('to'), err)) rv = False return POSIXTool.install(self, entry) and rv
def install(self, entry): """Install device entries.""" if not os.path.exists(os.path.dirname(entry.get('name'))): if not self._makedirs(entry, path=os.path.dirname(entry.get('name'))): return False newfile = self._write_tmpfile(entry) if not newfile: return False rv = self._set_perms(entry, path=newfile) if not self._rename_tmpfile(newfile, entry): return False return POSIXTool.install(self, entry) and rv
def verify(self, entry, modlist): rv = True try: if not os.path.samefile(entry.get('name'), entry.get('to')): msg = "Hardlink %s is incorrect" % entry.get('name') self.logger.debug("POSIX: " + msg) entry.set('qtext', "\n".join([entry.get('qtext', ''), msg])) rv = False except OSError: self.logger.debug("POSIX: %s %s does not exist" % (entry.tag, entry.get("name"))) entry.set('current_exists', 'false') return False return POSIXTool.verify(self, entry, modlist) and rv
def install(self, entry): """Install device entries.""" fmode = self._exists(entry) if fmode and not stat.S_ISDIR(fmode[stat.ST_MODE]): self.logger.info("POSIX: Found a non-directory entry at %s, " "removing" % entry.get('name')) try: os.unlink(entry.get('name')) fmode = False except OSError: err = sys.exc_info()[1] self.logger.error("POSIX: Failed to unlink %s: %s" % (entry.get('name'), err)) return False elif fmode: self.logger.debug("POSIX: Found a pre-existing directory at %s" % entry.get('name')) rv = True if not fmode: rv &= self._makedirs(entry) if entry.get('prune', 'false') == 'true': ulfailed = False for pent in entry.findall('Prune'): pname = pent.get('path') ulfailed = False if os.path.isdir(pname): rm = shutil.rmtree else: rm = os.unlink try: self.logger.debug("POSIX: Removing %s" % pname) rm(pname) except OSError: err = sys.exc_info()[1] self.logger.error("POSIX: Failed to unlink %s: %s" % (pname, err)) ulfailed = True if ulfailed: # even if prune failed, we still want to install the # entry to make sure that we get permissions and # whatnot set rv = False return POSIXTool.install(self, entry) and rv
def install(self, entry): if not self._exists(entry, remove=True): try: dev_type = entry.get('dev_type') mode = device_map[dev_type] | int(entry.get('perms'), 8) if dev_type in ['block', 'char']: major = int(entry.get('major')) minor = int(entry.get('minor')) device = os.makedev(major, minor) os.mknod(entry.get('name'), mode, device) else: os.mknod(entry.get('name'), mode) except (KeyError, OSError, ValueError): err = sys.exc_info()[1] self.logger.error('POSIX: Failed to install %s: %s' % (entry.get('name'), err)) return False return POSIXTool.install(self, entry)
def verify(self, entry, modlist): rv = True try: sloc = os.readlink(entry.get('name')) if sloc != entry.get('to'): entry.set('current_to', sloc) msg = ("Symlink %s points to %s, should be %s" % (entry.get('name'), sloc, entry.get('to'))) self.logger.debug("POSIX: " + msg) entry.set('qtext', "\n".join([entry.get('qtext', ''), msg])) rv = False except OSError: self.logger.debug("POSIX: %s %s does not exist" % (entry.tag, entry.get("name"))) entry.set('current_exists', 'false') return False return POSIXTool.verify(self, entry, modlist) and rv
def verify(self, entry, modlist): ondisk = self._exists(entry) tempdata, is_binary = self._get_data(entry) different = False content = None if not ondisk: # first, see if the target file exists at all; if not, # they're clearly different different = True content = "" elif len(tempdata) != ondisk[stat.ST_SIZE]: # next, see if the size of the target file is different # from the size of the desired content different = True else: # finally, read in the target file and compare them # directly. comparison could be done with a checksum, # which might be faster for big binary files, but slower # for everything else try: content = open(entry.get('name')).read() except IOError: self.logger.error("POSIX: Failed to read %s: %s" % (entry.get("name"), sys.exc_info()[1])) return False different = content != tempdata if different: self.logger.debug("POSIX: %s has incorrect contents" % entry.get("name")) self._get_diffs( entry, interactive=self.setup['interactive'], sensitive=entry.get('sensitive', 'false').lower() == 'true', is_binary=is_binary, content=content) return POSIXTool.verify(self, entry, modlist) and not different