#!/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.options[ 'password' ] )
                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( [ self.prompt, pexpect.TIMEOUT ],
                                    timeout=wait + 5 )
            response = self.handle.before
            if debug:
                main.log.debug( response )
            if i == 1:
                main.log.error( self.name + ": timeout when waiting for response" )
                main.log.error( self.name + ": response: " + str( response ) )
            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()
