#!/usr/bin/env python
"""
Copyright 2018 Open Networking Foundation (ONF)

Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>

TestON is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
( at your option ) any later version.

TestON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with TestON.  If not, see <http://www.gnu.org/licenses/>.
"""

import pexpect
import re
import os
from drivers.common.cli.emulator.scapyclidriver import ScapyCliDriver

class HostDriver( ScapyCliDriver ):
    """
    This class is created as a standalone host driver.
    """
    def __init__( self ):
        super( HostDriver, self ).__init__()
        self.handle = self
        self.name = None
        self.shortName = None
        self.interfaces = []
        self.home = None
        self.inband = False
        self.prompt = "\$"
        self.scapyPrompt = ">>>"
        self.tempRoutes = []

    def connect( self, **connectargs ):
        """
        Creates ssh handle for host.
        NOTE:
        The ip_address would come from the topo file using the host tag, the
        value can be an environment variable as well as a "localhost" to get
        the ip address needed to ssh to the "bench"
        """
        try:
            for key in connectargs:
                vars( self )[ key ] = connectargs[ key ]
            self.name = self.options[ 'name' ]
            self.shortName = self.options[ 'shortName' ]
            self.interfaces.append( { 'ips': [ self.options[ 'ip' ] ],
                                      'isUp': True,
                                      'mac': self.options[ 'mac' ],
                                      'dhcp': self.options.get( 'dhcp', "False" ),
                                      'name': self.options.get( 'ifaceName', None ) } )

            try:
                if os.getenv( str( self.ip_address ) ) is not None:
                    self.ip_address = os.getenv( str( self.ip_address ) )
                else:
                    main.log.info( self.name +
                                   ": Trying to connect to " +
                                   self.ip_address )
            except KeyError:
                main.log.info( "Invalid host name," +
                               " connecting to local host instead" )
                self.ip_address = 'localhost'
            except Exception as inst:
                main.log.error( "Uncaught exception: " + str( inst ) )

            self.handle = super(
                HostDriver,
                self ).connect(
                user_name=self.user_name,
                ip_address=self.ip_address,
                port=None,
                pwd=self.pwd )

            # Update IP of interfaces if using dhcp
            for intf in self.interfaces:
                if intf[ 'dhcp' ].lower() == "true":
                    ip = self.getIPAddress( iface=intf[ 'name' ] )
                    if ip:
                        intf['ips'] = [ ip ]
                    else:
                        main.log.warn( self.name + ": Could not find IP of %s" % intf[ 'name' ] )

            if self.handle:
                main.log.info( "Connection successful to the " +
                               self.user_name +
                               "@" +
                               self.ip_address )
                self.handle.sendline( "" )
                self.handle.expect( self.prompt )
                return main.TRUE
            else:
                main.log.error( "Connection failed to " +
                                self.user_name +
                                "@" +
                                self.ip_address )
                return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def disconnect( self, **connectargs ):
        """
        Called when test is complete to disconnect the handle.
        """
        response = main.TRUE
        try:
            if self.handle:
                self.preDisconnect()
                if self.tempRoutes:
                    for r in self.tempRoutes:
                        self.deleteRoute( *r )
                # Disconnect from the host
                if not self.options.get( 'inband', False ) == 'True':
                    self.handle.sendline( "" )
                    self.handle.expect( self.prompt )
                    self.handle.sendline( "exit" )
                    i = self.handle.expect( [ "closed", pexpect.TIMEOUT ] )
                    if i == 1:
                        main.log.error( self.name + ": timeout when waiting for response" )
                        main.log.error( self.name + ": response: " + str( self.handle.before ) )
                else:
                    self.handle.sendline( "" )
                    i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ], timeout=2 )
                    if i == 1:
                        main.log.warn( self.name + ": timeout when waiting for response" )
                        main.log.warn( self.name + ": response: " + str( self.handle.before ) )
                    self.handle.sendline( "exit" )
                    i = self.handle.expect( [ "closed", pexpect.TIMEOUT ], timeout=2 )
                    if i == 1:
                        main.log.warn( self.name + ": timeout when waiting for response" )
                        main.log.warn( self.name + ": response: " + str( self.handle.before ) )
                return main.TRUE
        except TypeError:
            main.log.exception( self.name + ": Object not as expected" )
            response = main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
        except ValueError:
            main.log.exception( "Exception in disconnect of " + self.name )
            response = main.TRUE
        except Exception:
            main.log.exception( self.name + ": Connection failed to the host" )
            response = main.FALSE
        return response

    def connectInband( self ):
        """
        ssh to the host using its data plane IP
        """
        try:
            if not self.options[ 'inband' ] == 'True':
                main.log.info( "Skip connecting the host via data plane" )
                return main.TRUE
            self.handle.sendline( "" )
            self.handle.expect( self.prompt )
            self.handle.sendline( "ssh {}@{}".format( self.options[ 'username' ],
                                                      self.options[ 'ip' ] ) )
            i = self.handle.expect( [ "password|Password", self.prompt, pexpect.TIMEOUT ], timeout=30 )
            if i == 0:
                self.handle.sendline( self.pwd )
                j = self.handle.expect( [ "password|Password", self.prompt, pexpect.TIMEOUT ], timeout=10 )
                if j != 1:
                    main.log.error( "Incorrect password" )
                    return main.FALSE
            elif i == 1:
                main.log.info( "Password not required logged in" )
            else:
                main.log.error( "Failed to connect to the host" )
                return main.FALSE
            self.inband = True
            return main.TRUE
        except KeyError:
            main.log.error( self.name + ": host component not as expected" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE

    def disconnectInband( self ):
        """
        Terminate the ssh connection to the host's data plane IP
        """
        try:
            if not self.options[ 'inband' ] == 'True':
                main.log.info( "Skip disconnecting the host via data plane" )
                return main.TRUE
            self.handle.sendline( "" )
            self.handle.expect( self.prompt, timeout=2 )
            self.handle.sendline( "exit" )
            i = self.handle.expect( [ "closed", pexpect.TIMEOUT ], timeout=2 )
            if i == 1:
                main.log.error( self.name + ": timeout when waiting for response" )
                main.log.error( self.name + ": response: " + str( self.handle.before ) )
            return main.TRUE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE

    def getRoutes( self ):
        """
        Returns the output of 'ip route show' command
        # TODO: process and return a a list or json object
        """
        try:
            cmd = "ip route show"
            self.handle.sendline( cmd )
            i = self.handle.expect( [ "password|Password", self.prompt ]  )
            if i == 0:
                self.handle.sendline( self.pwd )
                j = self.handle.expect( [ "password|Password", self.prompt ] )
                if j != 1:
                    main.log.error( "Incorrect password" )
                    return main.FALSE
            return self.handle.before
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE

    def addRouteToHost( self, route, gw, interface=None, sudoRequired=True, purgeOnDisconnect=True, cmdPath='/sbin/ip' ):
        """
        Adds a static route to the host
        Arguments:
        * route - String, CIDR notation for the destination subnet
        * gw - String, IP address of gateway
        Optional Arguments:
        * interface - String, The interface to use for this route, defaults to None, or the default interface
        * sudoRequired - Boolean, whether sudo is needed for this command, defaults to True
        * purgeOnDisconnect - Boolean, remove this route before disconnecting from component
        """
        try:
            if cmdPath:
                cmd = cmdPath
            else:
                cmd = "ip"
            cmd += " route add %s via %s" % ( route, gw )
            if sudoRequired:
                cmd = "sudo %s" % cmd
            if interface:
                cmd = "%s dev %s" % ( cmd, interface )
            if purgeOnDisconnect:
                self.tempRoutes.append( (route, gw, interface, sudoRequired ) )
            self.handle.sendline( cmd )
            i = self.handle.expect( [ "password|Password", self.prompt, "Error" ]  )
            output = ""
            if i == 2:
                output += self.handle.before + self.handle.after
                self.handle.expect( self.prompt )
                output += self.handle.before + self.handle.after
                main.log.error( "%s: Erorr in ip route command: %s" % ( self.name, output ) )
                return main.FALSE
            elif i == 0:
                self.handle.sendline( self.pwd )
                j = self.handle.expect( [ "password|Password", self.prompt, "Error" ] )
                if j == 0:
                    main.log.error( "Incorrect password" )
                    return main.FALSE
                elif j == 2:
                    output += self.handle.before + self.handle.after
                    self.handle.expect( self.prompt )
                    output += self.handle.before + self.handle.after
                    main.log.error( "%s: Erorr in ip route command: %s" % ( self.name, output ) )
                    return main.FALSE
            output += self.handle.before + self.handle.after
            main.log.debug( output )
            return main.TRUE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE

    def deleteRoute( self, route, gw, interface=None, sudoRequired=True, cmdPath='/sbin/ip'  ):
        """
        Deletess a static route from the host
        Arguments:
        * route - String, CIDR notation for the destination subnet
        * gw - String, IP address of gateway
        Optional Arguments:
        * interface - String, The interface to use for this route, defaults to None, or the default interface
        * sudoRequired - Boolean, whether sudo is needed for this command, defaults to True
        """
        try:
            if cmdPath:
                cmd = cmdPath
            else:
                cmd = "ip"
            cmd += " route del %s via %s" % ( route, gw )
            if sudoRequired:
                cmd = "sudo %s" % cmd
            if interface:
                cmd = "%s dev %s" % ( cmd, interface )
            self.handle.sendline( cmd )
            i = self.handle.expect( [ "password|Password", self.prompt, "Error" ]  )
            output = ""
            if i == 2:
                output += self.handle.before + self.handle.after
                self.handle.expect( self.prompt )
                output += self.handle.before + self.handle.after
                main.log.error( "%s: Erorr in ip route command: %s" % ( self.name, output ) )
                return main.FALSE
            elif i == 0:
                self.handle.sendline( self.pwd )
                j = self.handle.expect( [ "password|Password", self.prompt, "Error" ] )
                if j == 0:
                    main.log.error( "Incorrect password" )
                    return main.FALSE
                elif j == 2:
                    output += self.handle.before + self.handle.after
                    self.handle.expect( self.prompt )
                    output += self.handle.before + self.handle.after
                    main.log.error( "%s: Erorr in ip route command: %s" % ( self.name, output ) )
                    return main.FALSE
            output += self.handle.before + self.handle.after
            main.log.debug( output )
            return main.TRUE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.log.error( self.name + ":     " + self.handle.before )
            return main.FALSE

    def getIPAddress( self, iface=None, proto='IPV4' ):
        """
        Returns IP address of the host
        """
        cmd = "ifconfig %s" % iface if iface else ""
        response = self.command( cmd )
        if "Command 'ifconfig' not found" in response:
            # ip a show dev
            cmd = "ip addr show %s" % iface if iface else ""
            response = self.command( cmd )
            pattern = ''
            if proto == 'IPV4':
                pattern = "inet\s(\d+\.\d+\.\d+\.\d+)/\d+"
            else:
                pattern = "inet6\s([\w,:]*)/\d+"
        else:
            pattern = ''
            if proto == 'IPV4':
                pattern = "inet\s(\d+\.\d+\.\d+\.\d+)\s\snetmask"
            else:
                pattern = "inet6\s([\w,:]*)/\d+\s\sprefixlen"
        ipAddressSearch = re.search( pattern, response )
        if not ipAddressSearch:
            return None
        main.log.info(
            self.name +
            ": IP-Address is " +
            ipAddressSearch.group( 1 ) )
        return ipAddressSearch.group( 1 )

    def ping( self, dst, ipv6=False, interface=None, wait=3 ):
        """
        Description:
            Ping from this host to another
        Required:
            dst: IP address of destination host
        Optional:
            ipv6: will use ping6 command if True; otherwise use ping command
            interface: Specify which interface to use for the ping
            wait: timeout for ping command
        """
        try:
            command = "ping6" if ipv6 else "ping"
            if interface:
                command += " -I %s " % interface
            command += " -c 1 -i 1 -W " + str( wait ) + " " + str( dst )
            main.log.info( self.name + ": Sending: " + command )
            self.handle.sendline( command )
            i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
                                    timeout=wait + 5 )
            response = self.handle.before
            if i == 1:
                main.log.error(
                    self.name +
                    ": timeout when waiting for response" )
                main.log.error( self.name + ": response: " + str( self.handle.before ) )
            if re.search( ',\s0\%\spacket\sloss', response ):
                main.log.info( self.name + ": no packets lost, host is reachable" )
                return main.TRUE
            else:
                main.log.warn(
                    self.name +
                    ": PACKET LOST, HOST IS NOT REACHABLE" )
                return main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()

    def pingHostSetAlternative( self, dstIPList, wait=1, IPv6=False ):
        """
        Description:
            Ping a set of destination host.
        Params:
            dstIPList is a list of destination ip addresses
        Returns:
            main.TRUE if the destination host is reachable
            main.FALSE otherwise
        """
        isReachable = main.TRUE
        wait = int( wait )
        cmd = "ping"
        if IPv6:
            cmd = cmd + "6"
        cmd = cmd + " -c 1 -i 1 -W " + str( wait )
        try:
            for dstIP in dstIPList:
                pingCmd = cmd + " " + dstIP
                self.handle.sendline( pingCmd )
                i = self.handle.expect( [ self.prompt,
                                          pexpect.TIMEOUT ],
                                        timeout=wait + 5 )
                if i == 0:
                    response = self.handle.before
                    if not re.search( ',\s0\%\spacket\sloss', response ):
                        main.log.debug( "Ping failed between %s and %s" % ( self.name, dstIP ) )
                        isReachable = main.FALSE
                elif i == 1:
                    main.log.error( self.name + ": timeout when waiting for response" )
                    isReachable = main.FALSE
                else:
                    main.log.error( self.name + ": unknown response: " + self.handle.before )
                    isReachable = main.FALSE
        except pexpect.TIMEOUT:
            main.log.exception( self.name + ": TIMEOUT exception" )
            self.exitFromCmd( [ self.prompt ] )
            isReachable = main.FALSE
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": Uncaught exception!" )
            main.cleanAndExit()
        return isReachable

    def ifconfig( self, wait=3 ):
        """
        Run ifconfig command on host and return output
        """
        try:
            command = "ifconfig"
            main.log.info( self.name + ": Sending: " + command )
            self.handle.sendline( command )
            i = self.handle.expect( [ "Command 'ifconfig' not found", self.prompt, pexpect.TIMEOUT ],
                                    timeout=wait + 5 )
            if i == 0:
                response = self.handle.before
                self.handle.expect( [ self.prompt, pexpect.TIMEOUT ] )
                response += str( self.handle.before )
                main.log.error( self.name + ": Error running ifconfig: %s " % response )
                return response
            if i == 2:
                main.log.error(
                    self.name +
                    ": timeout when waiting for response" )
                main.log.error( self.name + ": response: " + str( self.handle.before ) )
            response = self.handle.before
            return response
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": uncaught exception!" )
            main.cleanAndExit()

    def ip( self, options="a", wait=3 ):
        """
        Run ip command on host and return output
        """
        try:
            command = "ip {}".format( options )
            main.log.info( self.name + ": Sending: " + command )
            self.handle.sendline( command )
            i = self.handle.expect( [ self.prompt, pexpect.TIMEOUT ],
                                    timeout=wait + 5 )
            if i == 1:
                main.log.error( self.name + ": timeout when waiting for response" )
                main.log.error( self.name + ": response: " + str( self.handle.before ) )
            response = self.handle.before
            return response
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": uncaught exception!" )
            main.cleanAndExit()

    def command( self, cmd, wait=3, debug=False):
        """
        Run shell command on host and return output
        Required:
            cmd: command to run on the host
        """
        try:
            main.log.info( self.name + ": Sending: " + cmd )
            self.handle.sendline( cmd )
            i = self.handle.expect( [ "password|Password", self.prompt, pexpect.TIMEOUT ],
                                    timeout=wait + 5 )
            response = self.handle.before
            if debug:
                main.log.debug( response )
            if i == 0:
                self.handle.sendline( self.pwd )
                j = self.handle.expect( [ "password|Password", self.prompt, pexpect.TIMEOUT ], timeout=10 )
                if j != 1:
                    main.log.error( "Incorrect password" )
                    return main.FALSE
            if i == 2:
                main.log.error( self.name + ": timeout when waiting for response" )
                main.log.error( self.name + ": response: " + str( response ) )
            main.log.debug( self.prompt )
            return response
        except pexpect.EOF:
            main.log.error( self.name + ": EOF exception found" )
            main.log.error( self.name + ":     " + self.handle.before )
            main.cleanAndExit()
        except Exception:
            main.log.exception( self.name + ": uncaught exception!" )
            main.cleanAndExit()
            self.clearBuffer()
