<commit_before>import logging
import pexpect
import time

from teuthology import lockstatus as ls

from ..exceptions import ConsoleError

import remote

try:
    import libvirt
except ImportError:
    libvirt = None

log = logging.getLogger(__name__)


class PhysicalConsole():
    """
    Physical Console (set from getRemoteConsole)
    """
    def __init__(self, name, ipmiuser, ipmipass, ipmidomain, logfile=None,
                 timeout=20):
        self.name = name
        self.shortname = remote.getShortName(name)
        self.timeout = timeout
        self.logfile = None
        self.ipmiuser = ipmiuser
        self.ipmipass = ipmipass
        self.ipmidomain = ipmidomain

    def _pexpect_spawn(self, cmd):
        """
        Run the cmd specified using ipmitool.
        """
        if not self.ipmiuser or not self.ipmipass or not self.ipmidomain:
            log.error('Must set ipmi_user, ipmi_password, and ipmi_domain in .teuthology.yaml')  # noqa
        full_command = self._build_command(cmd)
        log.debug('pexpect command: %s', full_command)
        child = pexpect.spawn(full_command)
        if self.logfile:
            child.logfile = self.logfile
        return child

    def _build_command(self, subcommand):
        template = \
            'ipmitool -H {s}.{dn} -I lanplus -U {ipmiuser} -P {ipmipass} {cmd}'
        return template.format(
            cmd=subcommand,
            s=self.shortname,
            dn=self.ipmidomain,
            ipmiuser=self.ipmiuser,
            ipmipass=self.ipmipass,
        )

    def _exit_session(self, child, timeout=None):
        child.send('~.')
        t = timeout or self.timeout
        r = child.expect(
            ['terminated ipmitool', pexpect.TIMEOUT, pexpect.EOF], timeout=t)
        if r != 0:
            self._pexpect_spawn('sol deactivate')

    def _wait_for_login(self, timeout=None, attempts=2):
        """
        Wait for login.  Retry if timeouts occur on commands.
        """
        t = timeout or self.timeout<commit_msg>PhysicalConsole._pexpect_spawn(): pass logfile arg<commit_after>import logging
import pexpect
import time

from teuthology import lockstatus as ls

from ..exceptions import ConsoleError

import remote

try:
    import libvirt
except ImportError:
    libvirt = None

log = logging.getLogger(__name__)


class PhysicalConsole():
    """
    Physical Console (set from getRemoteConsole)
    """
    def __init__(self, name, ipmiuser, ipmipass, ipmidomain, logfile=None,
                 timeout=20):
        self.name = name
        self.shortname = remote.getShortName(name)
        self.timeout = timeout
        self.logfile = None
        self.ipmiuser = ipmiuser
        self.ipmipass = ipmipass
        self.ipmidomain = ipmidomain

    def _pexpect_spawn(self, cmd):
        """
        Run the cmd specified using ipmitool.
        """
        if not self.ipmiuser or not self.ipmipass or not self.ipmidomain:
            log.error('Must set ipmi_user, ipmi_password, and ipmi_domain in .teuthology.yaml')  # noqa
        full_command = self._build_command(cmd)
        log.debug('pexpect command: %s', full_command)
        child = pexpect.spawn(
            full_command,
            logfile=self.logfile,
        )
        return child

    def _build_command(self, subcommand):
        template = \
            'ipmitool -H {s}.{dn} -I lanplus -U {ipmiuser} -P {ipmipass} {cmd}'
        return template.format(
            cmd=subcommand,
            s=self.shortname,
            dn=self.ipmidomain,
            ipmiuser=self.ipmiuser,
            ipmipass=self.ipmipass,
        )

    def _exit_session(self, child, timeout=None):
        child.send('~.')
        t = timeout or self.timeout
        r = child.expect(
            ['terminated ipmitool', pexpect.TIMEOUT, pexpect.EOF], timeout=t)
        if r != 0:
            self._pexpect_spawn('sol deactivate')

    def _wait_for_login(self, timeout=None, attempts=2):
        """
        Wait for login.  Retry if timeouts occur on commands.
        """
        t = timeout or self.timeout
{'fraction_non_alphanumeric': 0.09427032321253673, 'fraction_numerical': 0.0019588638589618022, 'mean_word_length': 2.1989036805011746, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6865033', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1268, 'n_words': 312}