예제 #1
0
    def start(self, **kwargs):
        """
        Start the plugin
        Return -1 if the plugin has found a fatal error, 0 otherwise.
        """
        host = kwargs['session']
        pkg_path = kwargs['repository']
        if (not pkg_path):
            aulog.error(
                "Couldn't ping, package repository path is not provided")
            return -1
        try:
            host.expect_exact("#", timeout=30)

        except:
            pass
        pat = re.compile('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
        ipaddr = re.findall(pat, pkg_path)
        protocol = ['tftp:', 'sftp:', 'ftp:']
        list = [' ']
        list = pkg_path.split('/')
        if not len(ipaddr):
            aulog.error("Invalid TFTP address ")
            return -1

        if (len(list[0]) if list[0] else list[1] in protocol):
            cmd = "ping " + ipaddr[0]
            aulog.info(cmd)
            host.sendline(cmd)
            try:
                status = host.expect_exact(
                    [INVALID_INPUT, MORE, "#", PROMPT, EOF], timeout=tout_cmd)
            except:
                aulog.warning(
                    """Command: Timed out, before considering this as failure.
                                 Please check consolelog file for details""")
                return 0

        out = host.before
        if (out.find('Success rate is 0') != -1
                or out.find('Bad hostname or protocol not running') != -1
                or out.find('UUUUU') != -1):
            aulog.warning("TFTP server %s is not reachable from device" %
                          (ipaddr))
            return 0
        return 0
예제 #2
0
파일: ping_test.py 프로젝트: plajjan/aut
    def start(self, **kwargs):
        """
        Start the plugin
        Return -1 if the plugin has found a fatal error, 0 otherwise.
        """
        host = kwargs['session']
        pkg_path = kwargs['repository']
        if (not pkg_path):
           aulog.error("Couldn't ping, package repository path is not provided")
           return -1 
        try :
            host.expect_exact("#", timeout=30)
            
        except :
            pass
        pat = re.compile('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
        ipaddr = re.findall(pat, pkg_path)
        protocol =['tftp:', 'sftp:', 'ftp:']
        list = [' '];
        list = pkg_path.split('/')
        if not len(ipaddr) :
            aulog.error("Invalid TFTP address ") 
            return -1

        if ( len(list[0]) if list[0] else list[1] in protocol):
            cmd = "ping "+ipaddr[0]
            aulog.info(cmd)
            host.sendline(cmd)
            try :
                status = host.expect_exact( [INVALID_INPUT, MORE, "#", PROMPT, EOF], timeout = tout_cmd)
            except :
	        aulog.warning("""Command: Timed out, before considering this as failure.
                                 Please check consolelog file for details""")
                return 0

        out = host.before
        if (out.find('Success rate is 0') != -1 or
            out.find('Bad hostname or protocol not running') != -1 or 
            out.find('UUUUU') != -1):
            aulog.warning("TFTP server %s is not reachable from device"%(ipaddr)) 
            return 0
        return 0
예제 #3
0
    def VerifyClass(self,class_a,class_b):
        """ Ensure that all plugins have Iplugin class and  have defined minimum attribute 

        Al attributes / methos in IPlugin class above are mandatory for each plugins
        e.g. :
            name       = " Name of the Plugin " 
            short_name = "ShortName" # this name will be used in logs to identify from where a log is comming
            version    = "Version" # A X.Y format version used
            method "start" # This will be starting point of this plugin.

        Optional Attributes :    
            load_after_plugin  = "ShortName of another Plugin" # This Plugin to be started after the given plugin 
                                                          # If the given plugin does not exist , this attribute 
                                                          # is ignored

        """
        members_a = [ a[0] for a in inspect.getmembers(class_a) if a[0][0] != '_' ]
        members_b = [ a[0] for a in inspect.getmembers(class_b) if a[0][0] != '_' ]
        not_in_b  = [ a for a in members_a if a not in members_b ] 

        if not_in_b :
            aulog.error("Mandatory attribute %s not found"%("_".join(not_in_b)))
        return 
예제 #4
0
def print_failure(str):
    aulog.error(str)
예제 #5
0
def print_failure(str):
    aulog.error(str)
예제 #6
0
    def start(self, **kwargs):
        """
        Starts all the plugins in order

        @throw PluginError when a plugin could not be initialized
        """
        # holds status of all plugins we run
        results={}

        # common parameters we pass to all plugins
        host = kwargs['session']
        option = kwargs['options']
        kwargs['results']= results
        plugin_type =""

        if len(self.plugins) != 0:
            self.sequence_plugins(option)
            #self.load_plugins()



        if option.preupgradeset:
           plugin_type = "PreUpgrade"
           if option.upgradeset:
               plugin_type =""
        elif option.postupgradeset:
              plugin_type="PostUpgrade"
        elif option.upgradeset:
              plugin_type="Upgrade"
            

        host.sendline("terminal len 0")
        try :
           status = host.expect_exact( [INVALID_INPUT, MORE, "#",
                                         LOGIN_PROMPT_ERR, EOF], timeout=20) 
        except:
           pass
        try :
          status=1
          status = host.expect_exact( ['#'], timeout=20)
        except:
          pass

        #print "Setting term len to zero", status 
        pno = 1;
        for (name, i) in self.plugins:
            aulog.info("++++"*5+ bcolors.HEADER +" (%d) (%s) Check "%(pno, i.plugin_type)+ bcolors.ENDC+"++++"*5)
            aulog.info("\nStarting => %s...."%(i.plugin_name))
            status = i.start(**kwargs)
            return_status = {i.plugin_name:status}
            results.update(return_status)
             
            if status == SUCCESS or status == SYSTEM_RELOADED or status == INSTALL_METHOD_PROCESS_RESTART :
                aulog.info(bcolors.OKGREEN +"\nPassed => %s\n"%(i.plugin_name)+ bcolors.ENDC)
            elif status == IGNORE:
                aulog.info(bcolors.WARNING +"\nIgnoring => %s\n"%(i.plugin_name)+ bcolors.ENDC)
            else :
                if not option.ignore_fail:
                    aulog.error(bcolors.FAIL+"\nFailed => %s\n"%(i.plugin_name)+ bcolors.ENDC)
                else :
                    aulog.ignore_error(bcolors.FAIL+"\nFailed => %s\n"%(i.plugin_name)+ bcolors.ENDC)

            self.active.append((name, i))
            pno = pno + 1
            sleep(1)

        if pno == 1:
              aulog.info(bcolors.HEADER + "++++"*5+" Notice "+"++++"*5 + bcolors.ENDC)
              aulog.info(bcolors.WARNING +"Didn't find any plugins of type ** %s **"%(plugin_type))

        aulog.info(bcolors.HEADER + "++++"*5+" Done "+"++++"*5 + bcolors.ENDC)
        return status