'Executes a command with preliminary checks and substitutions.
Before executing any commands, executes the "check" command first
in order to check if pre-requirements are met. If this check fails,
it tries to restore a sane environment before executing the real
command.
Parameters
cmd : str
The command to execute.
aInfo : dictionary
Dynamic properties.
Returns
bool
True if the command succeeded.'

def _processCmd(self, cmd, aInfo=None, conditional=''):

    if (cmd == ''):
        self._logSys.debug('Nothing    to    do')
        return True
    if (conditional == ''):
        conditional = 'family=inet4'
        if allowed_ipv6:
            try:
                ip = aInfo['ip']
                if (ip and asip(ip).isIPv6):
                    conditional = 'family=inet6'
            except KeyError:
                pass
    checkCmd = self.replaceTag('<actioncheck>', self._properties, conditional=conditional, cache=self.__substCache)
    if checkCmd:
        if (not self.executeCmd(checkCmd, self.timeout)):
            self._logSys.error('Invariant    check    failed.    Trying    to    restore    a    sane    environment')
            repairCmd = self.replaceTag('<actionrepair>', self._properties, conditional=conditional, cache=self.__substCache)
            if repairCmd:
                if (not self.executeCmd(repairCmd, self.timeout)):
                    self._logSys.critical('Unable    to    restore    environment')
                    return False
            else:
                self.stop()
                self.start()
            if (not self.executeCmd(checkCmd, self.timeout)):
                self._logSys.critical('Unable    to    restore    environment')
                return False
    realCmd = self.replaceTag(cmd, self._properties, conditional=conditional, cache=self.__substCache)
    if (aInfo is not None):
        realCmd = self.replaceDynamicTags(realCmd, aInfo)
    else:
        realCmd = cmd
    return self.executeCmd(realCmd, self.timeout)
