def is_fb_running(cls):
        result = False

        if PlatformHelper.is_Linux():
            cmd = "service filebeat status"
            cmd_output = CmdHelper.run(cmd)
            LogHelper.debug(cmd_output)
            if cmd_output.find("running") >= 0:
                result = True

        if PlatformHelper.is_mac():
            cmd = "ps aux | grep 'filebeat -c' | grep -v 'grep'"
            output = CmdHelper.run(cmd)
            if output.find("filebeat") >= 0:
                result = True

        if PlatformHelper.is_win():
            cmd = "sc query filebeat"
            output = CmdHelper.run(cmd)
            if output.find("RUNNING") >= 0:
                result = True

        if result:
            LogHelper.debug("filebeat is running")
        else:
            LogHelper.info("filebeat is not running")

        return result
    def start_fb(cls):

        if PlatformHelper.is_mac():
            fb_binary_dir = os.path.join(cls.config_path,
                                         cls.package_name.split(".tar.gz")[0])
            os.chdir(fb_binary_dir)
            cmd = "./filebeat -c filebeat.yml &"
            output = os.system(cmd)

        if PlatformHelper.is_Linux():
            cmd = "service filebeat start"
            output = CmdHelper.run(cmd)

        if PlatformHelper.is_win():
            cmd = "sc start filebeat"

            # This is to make sure filebeat service can be started after install
            time.sleep(1)
            output = CmdHelper.run(cmd)

            # service = "Get-WmiObject -ClassWin32_Service-Filter name='filebeat'"
            # service.StartService()
            # service.StopService()

        LogHelper.info("start filebeat result %s" % output)
        return output
    def kill_fb(cls):
        """
        kill file beat process
        :return:
        """
        result = False

        if PlatformHelper.is_mac() or PlatformHelper.is_Linux():
            cmd = "ps aux | grep 'filebeat -c' | grep -v 'grep'"
            output = CmdHelper.run(cmd)
            process_id = output.split()[1]
            kill_fb_cmd = "kill -9 %s" % process_id
            output = CmdHelper.run(kill_fb_cmd)

        if PlatformHelper.is_win():
            cmd = "sc stop filebeat"
            output = CmdHelper.run(cmd)

        LogHelper.debug(output)
        if cls.is_fb_running():
            LogHelper.error(
                "filebeat service CAN NOT be stopped successfully.")
        else:
            LogHelper.info("filebeat service is stopped")
            result = True

        return result
 def get_log_path(cls):
     if PlatformHelper.is_Linux():
         logger_path = ConfigAdapter.log_path("LINUX")
     elif PlatformHelper.is_win():
         logger_path = ConfigAdapter.log_path("WINDOWS")
     elif PlatformHelper.is_mac():
         logger_path = ConfigAdapter.log_path("MAC")
     return logger_path
Пример #5
0
    def __create_default_logger(cls):
        if PlatformHelper.is_Linux():
            logger_path = os.path.join("/", "tmp")
        elif PlatformHelper.is_win():
            logger_path = os.path.join("c:", "tmp")
        elif PlatformHelper.is_mac():
            logger_path = os.path.join("/", "tmp")

        log_filepath = os.path.join(logger_path, "automation.log")

        return cls.create_logger(log_filepath)
Пример #6
0
    def get_backup_start(file):
        search_pattern = "start backup"
        if PlatformHelper.is_win():
            search_pattern = "Starting backup:"
        elif PlatformHelper.is_Linux():
            search_pattern = "Executing : start"
        elif PlatformHelper.is_mac():
            search_pattern = "Starting backup:"
        else:
            pass

        indices = FileHelper.find_text_indices(file, search_pattern)
        if indices:
            return indices[-1]
    def install_fb(cls):
        installer = cls.download_fb()
        LogHelper.info("start to install")

        if PlatformHelper.is_Linux() and PlatformHelper.get_arch() == "deb-64":
            install_cmd = "dpkg -i %s" % installer
            cls.__set_fb_path("/etc/filebeat/")

        if PlatformHelper.is_Linux() and PlatformHelper.get_arch() == "deb-32":
            install_cmd = "rpm -vi %s" % installer
            cls.__set_fb_path("/etc/filebeat/")

        if PlatformHelper.is_win():
            import zipfile
            win_fb_dir = "C:\\filebeat"
            target = os.path.join(win_fb_dir, "filebeat-5.2.0-windows-x86_64")
            installcommnd = os.path.join(target,
                                         "install-service-filebeat.ps1")

            zip_ref = zipfile.ZipFile(installer, 'r')
            zip_ref.extractall(win_fb_dir)
            zip_ref.close()
            # FileHelper.rename()

            install_cmd = "powershell.exe %s" % (installcommnd)

            cls.__set_fb_path(target)

            cmd_output = CmdHelper.runas_admin(install_cmd)
            return cmd_output
            # # TODO: Unzip to start" service
            # install_cmd = "to be implemented"
            # win_fb_dir = "C:\\filebeat"
            # if not FileHelper.dir_exist(win_fb_dir):
            #     FileHelper.create_directory(win_fb_dir)
            # cls.__set_fb_path(win_fb_dir)
            # install_cmd = "unzip %s -C %s" % (installer, win_fb_dir)

        if PlatformHelper.is_mac():
            mac_fb_dir = "/filebeat"
            if not FileHelper.dir_exist(mac_fb_dir):
                FileHelper.create_directory(mac_fb_dir)

            cls.__set_fb_path(mac_fb_dir)

            install_cmd = "tar xzvf %s -C %s" % (installer, mac_fb_dir)

        cmd_output = CmdHelper.run(install_cmd)
        LogHelper.info(cmd_output)
    def config_fb(cls, new_config={}):
        if PlatformHelper.is_mac():
            cls.filebeat_config = os.path.join(
                cls.config_path,
                cls.package_name.split(".tar.gz")[0], "filebeat.yml")

        if PlatformHelper.is_Linux() or PlatformHelper.is_win():
            cls.filebeat_config = os.path.join(cls.config_path, 'filebeat.yml')

        # yaml_file = open(cls.filebeat_config, 'r')
        # config = yaml.load(yaml_file)
        # print config

        with open(cls.filebeat_config, 'w') as f:
            config_dict = yaml.dump(new_config, f)

            return config_dict
Пример #9
0
    def get_kpis(file, starttime=0):
        """
        Get service KPIs
        :param file: Mozy backup log
        :param starttime: Only analyse latest log
        :return: Key Service KPI.  e.g.["/client/sync": response time, "/batch": response time]
        """
        kpi = None

        with open(file, "r") as f:
            for line_no, line in enumerate(f.readlines()):
                if PlatformHelper.is_win():
                    KPIHelper.get_windows_kpi(kpi, line, starttime)  #datetime.datetime.strptime(starttime, '%d%b%Y %H:%M:%S').strftime('%Y-%m-%dT%H:%M:%SZ'))

                elif PlatformHelper.is_Linux():
                    KPIHelper.get_linux_kpi(kpi, line.strip(), starttime)

                elif PlatformHelper.is_mac():
                    KPIHelper.get_mac_kpis(file, line.strip())
Пример #10
0
def step_impl(context, restore_dir, backup_dir):
    testdata_root = ConfigAdapter.get_testdata_path()
    output_root = ConfigAdapter.get_output_path()
    restore_file_path = os.path.join(output_root, restore_dir)
    backup_file_path = os.path.join(testdata_root, backup_dir)
    LogHelper.info('restore_file_path is {0}'.format(restore_file_path))
    LogHelper.info('backup_file_path is {0}'.format(backup_file_path))
    if PlatformHelper.is_mac():
        result = FileHelper.is_dir_same(restore_file_path,
                                        backup_file_path,
                                        exclude_pattern='.DS_Store')
    else:
        result = FileHelper.is_dir_same(restore_file_path, backup_file_path)

    if result:
        for diff in result:
            LogHelper.error("diff files found {path}".format(path=diff))
    try:
        len(result).should.equal(0)
    except AssertionError as e:
        LogHelper.error(e.message)
        raise e
    def is_fb_installed(cls):
        result = False

        if PlatformHelper.is_Linux():
            cmd = "service filebeat status"

        if PlatformHelper.is_mac():
            cmd = "ps aux | grep 'filebeat -c' | grep -v 'grep'"

        if PlatformHelper.is_win():
            cmd = "sc query filebeat"

        output = CmdHelper.run(cmd)
        LogHelper.debug(output)
        match = re.search(r"(FAILED)", output, re.IGNORECASE)

        if match:
            LogHelper.info("filebeat is not installed")
        else:
            result = True
            LogHelper.debug("filebeat is installed")

        return result
Пример #12
0
import time
import re

from lib.platformhelper import PlatformHelper
if PlatformHelper.is_mac():
    from atomac._a11y import ErrorCannotComplete, Error
    from atomac import AXKeyboard
    from atomac import AXKeyCodeConstants

from lib.singleton import Singleton
from lib.loghelper import LogHelper
from configuration.mac.mac_config_loader import MAC_CONFIG
from lib.cmdhelper import CmdHelper


class MacUIUtils(object):

    __metaclass__ = Singleton

    @staticmethod
    def wait_element(search_from,
                     timeout=None,
                     sleep_time=None,
                     method='findFirstR',
                     **matcher):
        """
        :param search_from:
        :param timeout:
        :param sleep_time:
        :param method:
        :param matcher: