<commit_before># -*- coding: utf-8 -*-

# This file is part of Cockpit.
#
# Copyright (C) 2013 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import fcntl
import os
import re
import select
import socket
import subprocess
import tempfile
import time
import sys
import shutil
from lxml import etree

DEFAULT_FLAVOR="cockpit"
DEFAULT_OS = "fedora-22"
DEFAULT_ARCH = "x86_64"

MEMORY_MB = 1024

SSH_WARNING = re.compile(r'Warning: Permanently added .* to the list of known hosts.*\n')

class Failure(Exception):
    def __init__(self, msg):
        self.msg = msg
    def __str__(self):
        return self.msg

class RepeatThis(Failure):
    pass

class Machine:
    boot_hook = None

    def __init__(self, address=None, flavor=None, system=None, arch=None, verbose=False, label=None):
        self.verbose = verbose
        self.flavor = flavor or DEFAULT_FLAVOR

        conf_file = "%s.conf" % self.flavor
        if os.path.exists(conf_file):
            with open(conf_file, "r") as f:
                self.conf = eval(f.read())
        else:
            self.conf = { }

        self.os = system or self.getconf('os') or os.environ.get("TEST_OS") or DEFAULT_OS
        self.arch = arch or os.environ.get("TEST_ARCH") or DEFAULT_ARCH
        self.image = "%s-%s-%s" % (self.flavor, self.os, self.arch)
        self.test_dir = os.path.abspath(os.path.dirname(__file__))
        self.test_data = os.environ.get("TEST_DATA") or self.test_dir
        self.address = address
        self.mac = None
        self.label = label or "UNKNOWN"

    def getconf(self, key):
        return key in self.conf and self.conf[key]

    def message(self, *args):
        """Prints args if in verbose mode"""
        if not self.verbose:
            return
        print " ".join(args)

    def start(self, maintain=False, macaddr=None):
        """Overridden by machine classes to start the machine"""
        self.message("Assuming machine is already running")

    def stop(self):
        """Overridden by machine classes to stop the machine"""
        self.message("Not shutting down already running machine")

    def wait_ssh(self):
        """Try to connect to self.address on port 22"""
        tries_left = 60
        while (tries_left > 0):
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.settimeout(1)
            try:
                sock.connect((self.address, 22))
                return True
            except:
                pass
            finally:
                sock.close()
            tries_left = tries_left - 1
            time.sleep(1)
        return False

    def wait_user_login(self):
        """Wait until logging in as non-root works.

           Most tests run as the "admin" user, so we make sure that
           user sessions are allowed (and cockit-ws will let "admin"
           in) before declaring a test machine as "booted".
        """
        tries_left = 5
        while (tries_left > 0):
            try:
                self.execute("! test -f /run/nologin")
                return<commit_msg>Test: increase user login wait<commit_after># -*- coding: utf-8 -*-

# This file is part of Cockpit.
#
# Copyright (C) 2013 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import fcntl
import os
import re
import select
import socket
import subprocess
import tempfile
import time
import sys
import shutil
from lxml import etree

DEFAULT_FLAVOR="cockpit"
DEFAULT_OS = "fedora-22"
DEFAULT_ARCH = "x86_64"

MEMORY_MB = 1024

SSH_WARNING = re.compile(r'Warning: Permanently added .* to the list of known hosts.*\n')

class Failure(Exception):
    def __init__(self, msg):
        self.msg = msg
    def __str__(self):
        return self.msg

class RepeatThis(Failure):
    pass

class Machine:
    boot_hook = None

    def __init__(self, address=None, flavor=None, system=None, arch=None, verbose=False, label=None):
        self.verbose = verbose
        self.flavor = flavor or DEFAULT_FLAVOR

        conf_file = "%s.conf" % self.flavor
        if os.path.exists(conf_file):
            with open(conf_file, "r") as f:
                self.conf = eval(f.read())
        else:
            self.conf = { }

        self.os = system or self.getconf('os') or os.environ.get("TEST_OS") or DEFAULT_OS
        self.arch = arch or os.environ.get("TEST_ARCH") or DEFAULT_ARCH
        self.image = "%s-%s-%s" % (self.flavor, self.os, self.arch)
        self.test_dir = os.path.abspath(os.path.dirname(__file__))
        self.test_data = os.environ.get("TEST_DATA") or self.test_dir
        self.address = address
        self.mac = None
        self.label = label or "UNKNOWN"

    def getconf(self, key):
        return key in self.conf and self.conf[key]

    def message(self, *args):
        """Prints args if in verbose mode"""
        if not self.verbose:
            return
        print " ".join(args)

    def start(self, maintain=False, macaddr=None):
        """Overridden by machine classes to start the machine"""
        self.message("Assuming machine is already running")

    def stop(self):
        """Overridden by machine classes to stop the machine"""
        self.message("Not shutting down already running machine")

    def wait_ssh(self):
        """Try to connect to self.address on port 22"""
        tries_left = 15
        while (tries_left > 0):
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.settimeout(1)
            try:
                sock.connect((self.address, 22))
                return True
            except:
                pass
            finally:
                sock.close()
            tries_left = tries_left - 1
            time.sleep(1)
        return False

    def wait_user_login(self):
        """Wait until logging in as non-root works.

           Most tests run as the "admin" user, so we make sure that
           user sessions are allowed (and cockit-ws will let "admin"
           in) before declaring a test machine as "booted".
        """
        tries_left = 60
        while (tries_left > 0):
            try:
                self.execute("! test -f /run/nologin")
                return
{'fraction_non_alphanumeric': 0.0952186905732138, 'fraction_numerical': 0.008014126596033686, 'mean_word_length': 2.3544419134396355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '1147892', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2093, 'n_words': 751}