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 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 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
    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)
Exemple #6
0
def step_impl(context):
    from lib.platformhelper import PlatformHelper
    if PlatformHelper.is_win():
        from apps.windows.windows_client import Windows_Client
    winclient = Windows_Client(RUNNER_CONFIG.get('OEM_CLIENT', "mozypro"))

    if winclient.gui.status_window.client_is_activated():
        winclient.controller.set_unconfigured_status()
        winclient.controller.reset_reg(RUNNER_CONFIG.get(
            'ENVIRONMENT', "QA12"))
        winclient.controller.restart_services(force=True)
Exemple #7
0
 def get_started(file, start):
     """
     Get the started line number from log.
     :param file: file
     :param start: time after start
     :return: int(line number)
     """
     if PlatformHelper.is_win():
         search_pattern = re.compile("^(.*\s.*)\s.*\.exe.*$", re.IGNORECASE)
     elif PlatformHelper.is_Linux():
         search_pattern = re.compile("^(.*)\.\d{6}.*$", re.IGNORECASE)
     indices = FileHelper.find_text_indices(file, search_pattern)
     return indices[0]
Exemple #8
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
Exemple #11
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())
    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
import os, re, time, subprocess
from lib.platformhelper import PlatformHelper
if PlatformHelper.is_win():
    import win32api
    from pywinauto import application, MatchError
from lib.cmdhelper import CmdHelper
from lib.loghelper import LogHelper
from lib.filehelper import FileHelper
from configuration.fryr.fryr_config_loader import FRYR_CONFIG
from configuration.config_adapter import ConfigAdapter

class WinFryR_LSH_Controller(object):

    app = None
    conn_app = None
    restore_manager = None

    @classmethod
    def launch_lsh_restore_manager(self):
        if self.conn_app is None:
            self.app = application.Application()
            self.app.start("C:\Program Files\Mozy\Mozy Restore Manager\MozyLshRestoreManager.exe")
            time.sleep(2)
            self.conn_app = application.Application(backend="uia").connect(title=u'Mozy Restore Manager', found_index=0)
            self.restore_manager = self.conn_app.Window_(title=u'Mozy Restore Manager', found_index=0)

    @classmethod
    def restore_by_mzdx(self, include_all_version=True, wait_for_export_completed=True):
        subprocess.Popen("cmd /c " + self.get_mzdx_path())
        time.sleep(15)
        self.conn_app = application.Application(backend="uia").connect(title=u'Mozy Restore Manager', found_index=0)