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 download_and_install(cls, build, job):

        volume_name = cls.get_subdir()
        if volume_name is not None:
            CmdHelper.run("diskutil eject '" + volume_name + "'")

        LogHelper.info(
            "Prepare download Mozy Restore Manager from jenkins, build number is "
            + job)
        jh = JenkinsHelper(GLOBAL_CONFIG["JENKINS"]["URL"],
                           GLOBAL_CONFIG["JENKINS"]["USERNAME"],
                           GLOBAL_CONFIG["JENKINS"]["KEY"])
        dest = ConfigAdapter.get_installer_path('MACFRYR')

        LogHelper.info('Clean up existing files')
        for file in FileHelper.find_file(dest, '*'):
            LogHelper.debug('Delete file %s' % file)
            FileHelper.delete_file(file)
        pattern = 'mozy-fryr'
        packages = jh.download_packages(jh.get_packages(job, build, pattern),
                                        dest=dest)

        TARGET_APP = '/Applications/Mozy Restore Manager.app'
        if os.path.exists(TARGET_APP):
            shutil.rmtree(TARGET_APP)
        image_path = packages[0]

        mount_cmd = 'sudo hdiutil attach {package}'.format(package=image_path)
        CmdHelper.run(mount_cmd)

        volume_name = cls.get_subdir()
        ORIGIN_APP = '/Volumes/' + volume_name + '/Mozy Restore Manager.app'
        shutil.copytree(ORIGIN_APP, TARGET_APP)
Пример #3
0
    def wait_state(self, state, timeout=None, granularity=None):
        """
        :param state:
        :param timeout:
        :param granularity:
        :return:
        """
        result = True

        if timeout is None:
            timeout = GLOBAL_CONFIG["TIMEOUT"]
        if granularity is None:
            granularity = GLOBAL_CONFIG["GRANULARITY"]

        expected_state = []

        if type(state) == str:
            expected_state.append(state)
        else:
            expected_state = state

        current = self.current_state()
        elapsed = 0
        while (current.upper() not in expected_state) and elapsed <= timeout:
            LogHelper.debug("current state is %s" % current)
            time.sleep(granularity)
            elapsed += granularity
            current = self.current_state()
        if current.upper() not in expected_state:
            LogHelper.error("wait %s failed" % expected_state)
            raise Exception("Expected Result %s is not shownup" %
                            expected_state)

        return result
    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 check_md5(target1, target2):
     string1 = FileHelper.md5(target1)
     string2 = FileHelper.md5(target2)
     LogHelper.debug(target1 + " md5: " + string1)
     LogHelper.debug(target2 + " md5: " + string2)
     if string1 == string2:
         return True
     return False
Пример #6
0
 def get_email(self):
     email = None
     account_str = self.get_account()
     account_dict = self.parse_account_to_dict(account_str)
     if account_dict.get("EMAIL"):
         email = account_dict["EMAIL"]
     LogHelper.debug(email)
     return email
Пример #7
0
def step_impl(context, expected_state):
    expected_state.upper()
    LogHelper.debug("expected status is %s" % expected_state)
    actual_status = LinuxGUIClient.state_cmd.current_state().upper()
    LogHelper.debug("actual_status status is %s" % actual_status)
    try:
        expected_state.upper().should.equal(actual_status.upper())
    except AssertionError as e:
        LogHelper.error(e.message)
        raise e
def step_impl(context, folder):
    testdata_root = os.path.expanduser("~/{folder}".format(folder=folder))

    for row in context.table.rows:
        if "file_folder" in row.headings or "file_dir" in row.headings:
            testdata_dir = os.path.join(
                testdata_root,
                row.get('file_folder') or row.get('file_dir') or '')

            LogHelper.debug("Delete dirs " + testdata_dir)
            FileHelper.delete_directory(testdata_dir)
Пример #9
0
 def clear_restore_folder(folder_name):
     directory = os.path.expanduser('~/Documents/' + folder_name)
     if platform.system() == "Windows":
         directory = "C:/" + folder_name
     for file in FileHelper.find_file(directory, '*'):
         LogHelper.debug('Delete file %s' % file)
         os.remove(file)
     for folder in FileHelper.find_dir(directory, '*'):
         LogHelper.debug('Delete folder %s' % folder)
         try:
             shutil.rmtree(folder)
         except:
             pass
    def __unmount_image(cls, image_path):
        result = False
        unmount_cmd = "diskutil unmountDisk force \"{image_path}\"".format(
            image_path=image_path)
        output = CmdHelper.run(unmount_cmd)
        LogHelper.debug(output)
        if output.find('successful') > 0:
            LogHelper.debug("install successfull")
            result = True
        else:
            LogHelper.error("install failed")

        return result
 def __find_mounted_volume(cls, pattern):
     mounted_volumes = []
     ls_cmd = 'ls /Volumes'
     output = CmdHelper.run(ls_cmd)
     LogHelper.debug(
         "volume under /Volumes have {output}".format(output=output))
     mounted_volumes = [
         volume for volume in output.splitlines()
         if re.compile(pattern).match(volume)
     ]
     mounted_volumes = map(lambda x: "/Volumes/{volume}".format(volume=x),
                           mounted_volumes)
     return mounted_volumes
Пример #12
0
 def clear_download_folder():
     directory = ConfigAdapter.get_installer_path('MACFRYR')
     if platform.system() == "Windows":
         directory = "C:/" + ConfigAdapter.get_testdata_path(
             'WINFRYR').split('\\\\')[1]
     for file in FileHelper.find_file(directory, '*'):
         LogHelper.debug('Delete file %s' % file)
         os.remove(file)
     for folder in FileHelper.find_dir(directory, '*'):
         LogHelper.debug('Delete folder %s' % folder)
         try:
             shutil.rmtree(folder)
         except:
             pass
    def install_package(cls, package):
        """
        package: local dmg path
        :return: result
        """
        volume = cls.__mount_image(package)
        pkg_path = os.path.join(volume, 'MozyPro Installer.pkg')

        result = cls.__silent_install(pkg_path)

        LogHelper.debug("un-mount volume")
        cls.__unmount_image(volume)

        return result
Пример #14
0
def run_automation(task):
    """
    run automation tasks
    :param task:
    :return:
    """
    try:
        LogHelper.debug("Received task to run automation task {0}".format(task))
        output = CmdHelper.run(task)
        LogHelper.info(output)
        return output

    except SoftTimeLimitExceeded:
        raise SoftTimeLimitExceeded('timeout when execute testcase')
 def get_subdir():
     ls_cmd = 'ls /Volumes'
     output = CmdHelper.run(ls_cmd)
     LogHelper.debug(
         "volume under /Volumes have {output}".format(output=output))
     mounted_volumes = [
         volume for volume in output.splitlines()
         if volume.find('Restore Manager') != -1
     ]
     result = None
     if len(mounted_volumes) != 0:
         result = mounted_volumes[0]
     # print result
     return result
Пример #16
0
def step_impl(context, number):
    if context.change_processed_before is not None:
        expected_number = int(context.change_processed_before) + int(number)
    else:
        raise ValueError('unexpected ')

    current_change_process = LinuxGUIClient.history_cmd.get_continuous_mode_summary().get('changes_processed') or -1
    current_change_process = int(current_change_process)
    LogHelper.info("current changes process is %d" % current_change_process)
    delta = expected_number - int(current_change_process)
    try:
        LogHelper.debug("check changes process number")
        delta.should.be.greater_than_or_equal_to(0)
    except AssertionError as e:
        LogHelper.error(e.message)
        raise e
    def __silent_install(cls, pkg_path):
        LogHelper.info("start to install")
        install_cmd = MacController.prefix_for_sudo(
        ) + "sudo -S /usr/sbin/installer -pkg \"{path}\" -target {dest}".format(
            path=pkg_path, dest="/")
        output = CmdHelper.run(install_cmd)

        LogHelper.debug(output)
        if output.find('successful') > 0:
            LogHelper.debug("Install successfully")
            result = True
        else:
            LogHelper.error("Install failed")
            result = False

        return result
Пример #18
0
 def parse_history(cls, str, skip_continuous=True):
     result = []
     for line in str.splitlines():
         LogHelper.debug("process line %s" % line)
         if re.match("^\d", line):
             tokens = map(lambda x: x.lstrip().rstrip(),
                          re.split(r'\t', line))
             try:
                 result.append(
                     HistoryResultObj(tokens[0], tokens[1], tokens[2],
                                      tokens[3], tokens[4], tokens[5],
                                      tokens[6], tokens[7]))
             except:
                 raise Exception('Invalid history result, failed to parse')
         else:
             continue
     return result
    def uninstall_package(cls, removeconfig=True):
        """
        :return:
        """
        result = False
        uninstall_cmd = MacController.prefix_for_sudo(
        ) + "sudo -S MozyProBackup uninstall"

        if removeconfig:
            uninstall_cmd += " --removeconfig"

        output = CmdHelper.run(uninstall_cmd)
        if output.find('Uninstall thread done') > 0:
            result = True
            LogHelper.debug("Uninstall mozypro successfully")
        else:
            LogHelper.error("something went wrong with uninstall")

        return result
def delete_test_files(context, params):
    testdata_root = ConfigAdapter.get_testdata_path()
    for row in context.table.rows:
        if "file_folder" in row.headings or "file_dir" in row.headings:
            testdata_dir = os.path.join(
                testdata_root,
                row.get('file_folder') or row.get('file_dir') or '')

        if params.upper() == "DIRS":
            LogHelper.debug("Delete dirs " + testdata_dir)
            FileHelper.delete_directory(testdata_dir)
            return

        if params.upper() == "FILES":
            pattern = row.get('pattern') or '*'
            file_list = FileHelper.find_file(testdata_dir, pattern)
            for file in file_list:
                LogHelper.debug("delete file %s" % file)
                FileHelper.delete_file(file)
            return
Пример #21
0
def prepare_testrun(senddb=False):
    start_time = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())

    id_timestamp = start_time.replace(":","_").replace("-","_")
    if options.testrun:
        id = "%s_%s" % (options.testrun, id_timestamp)
    else:
        id = "%s_%s_%s_%s" % (options.product, options.oem_client, options.environment, id_timestamp)

    id = id.upper()

    tr = TestRun(id, start_time, qa_env=options.environment,
                 build=options.build, client=options.product, oem=options.oem_client,
                 branch=options.job, runby="*****@*****.**")

    if senddb:
        LogHelper.debug("Start to write TestRun to ES")
        tr.save_to_elasticsearch()
        LogHelper.debug("Finish to write TestRun to ES")

    return tr
Пример #22
0
def step_impl(context, file_path, is_changed):
    testdata_root = ConfigAdapter.get_testdata_path()

    full_file_path = os.path.join(testdata_root, file_path)
    current_vesion = LinuxGUIClient.info_cmd.get_last_version(full_file_path)
    LogHelper.info(
        "current version is {version}".format(version=current_vesion))

    if is_changed.upper() == "UNCHANGED":
        current_vesion.should.equal(context.version_before)
    if is_changed.upper() == 'CHANGED':
        #Check whether linux client is running at conntinous mode or manual mode
        current_mode = LinuxGUIClient.continuous_cmd.get_mode()
        if current_mode == LinuxGUIClient.continuous_cmd.ON_DEMAND:
            LogHelper.debug("On demand mode, check version...")
            current_vesion.shouldnot.eql(context.version_before)
        if current_mode == LinuxGUIClient.continuous_cmd.CONTINUOUS:
            LogHelper.debug(
                "On continous mode, wait a new version with 300 second")

            if current_vesion != context.version_before:
                is_version_changed = True
            else:
                is_version_changed = False

            eslapsed_time = 0
            wait_time = 10
            while (not is_version_changed) and eslapsed_time <= 300:
                time.sleep(wait_time)
                eslapsed_time += wait_time
                current_vesion = LinuxGUIClient.info_cmd.get_last_version(
                    full_file_path)
                if current_vesion != context.version_before:
                    is_version_changed = True

                else:
                    LogHelper.info("Current version is %s, it is same as %s" %
                                   (current_vesion, context.version_before))

            is_version_changed.should.be(True)
    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
 def download_and_install(cls, build, job):
     # pass
     WinFryR_Installer.uninstall(False)
     LogHelper.info(
         "Prepare download Mozy Restore Manager from jenkins, build number is "
         + job)
     jh = JenkinsHelper(GLOBAL_CONFIG["JENKINS"]["URL"],
                        GLOBAL_CONFIG["JENKINS"]["USERNAME"],
                        GLOBAL_CONFIG["JENKINS"]["KEY"])
     dest = ConfigAdapter.get_installer_path('WINFRYR')
     LogHelper.info('Clean up existing files')
     for file in FileHelper.find_file(dest, '*'):
         LogHelper.debug('Delete file %s' % file)
         FileHelper.delete_file(file)
     pattern = 'mozy-fryr'
     packages = jh.download_packages(jh.get_packages(job, build, pattern),
                                     dest=dest)
     for package in packages:
         if str(package).endswith('setup.exe'):
             LogHelper.info("Prepare to install Mozy Restore Manager.")
             install_cmd = "%s" % (package)
             CmdHelper.run(install_cmd)
             break
def step_impl(context, credential):
    context.execute_steps(u"""When I wait for sock ready""")
    # logic to parse credential
    cre_with_oc = re.sub(r"{oemclient}", RUNNER_CONFIG.get('OEM_CLIENT'),
                         credential)
    cre_with_oc_env = re.sub(r"{env}", RUNNER_CONFIG.get('ENVIRONMENT'),
                             cre_with_oc)
    expected_credential = LYNX_CONFIG.get('CREDENTIAL').get(cre_with_oc_env)
    username = expected_credential.get('USERNAME')
    LogHelper.debug("username: %s" % username)
    password = expected_credential.get('PASSWORD')
    pk = expected_credential.get('PERSONALKEY') or None
    context.user = UserHelper(username=username)
    to_activate = False
    if not LinuxGUIClient.account_cmd.is_activate():
        to_activate = True
    else:
        current_email = LinuxGUIClient.account_cmd.get_email()
        LogHelper.debug('%s is not the as  %s' % (current_email, username))
        if not current_email.upper() == username.upper():
            to_activate = True

    if to_activate:
        LogHelper.info("change user account")
        LinuxGUIClient.unlink_cmd.unlink()
        context.execute_steps(
            unicode('When I cleanup local state|metric database'))
        context.execute_steps(unicode('When I restart Linux Client'))
        if pk:
            result = LinuxGUIClient.activate_cmd.activate(
                email=username,
                password=password,
                customkeytext=pk,
                force_encryption_change=None)
        else:
            result = LinuxGUIClient.activate_cmd.activate(
                email=username,
                password=password,
                force_encryption_change=None)

        LogHelper.debug(result)
    def __mount_image(cls, image_path):
        LogHelper.debug("check that package is existed")
        if not FileHelper.file_exist(image_path):
            raise StandardError(
                'file {package} is not existed'.format(package=image_path))

        LogHelper.debug("mount dmg")
        mount_cmd = MacController.prefix_for_sudo(
        ) + 'sudo -S hdiutil attach {package}'.format(package=image_path)
        output = CmdHelper.run(mount_cmd)
        LogHelper.debug("mount result is {output}".format(output=output))

        mounted_volumes = cls.__find_mounted_volume(pattern='.*MozyPro.*')

        if len(mounted_volumes) > 1:
            LogHelper.error(
                "More than one volume deteched, something went wrong")

        mounted_volume = mounted_volumes[-1]

        return mounted_volume
Пример #27
0
def step_impl(context, expected_status):
    LogHelper.debug("checked expected be one of %s" %expected_status)
    expected = [state.strip().strip() for state in re.split(r",|;|:", expected_status.upper())]
    LinuxClient().cli.state_cmd.wait_state(expected)
Пример #28
0
def run():
    if options.database_enabled:
        id = testrun.upper()+start_time.replace(":", "_").replace("-", "_")
        tr = TestRun(id, start_time, qa_env=options.environment,
                     build=options.build, client=options.product,
                     oem=options.oem_client,
                     branch=options.job, runby="*****@*****.**")

        LogHelper.debug("Start to write TestRun to ES")
        tr.save_to_elasticsearch()
        LogHelper.debug("Finish to write TestRun to ES")

    create_runner_log()
    verify_options()
    if product == 'MAC_MACFRYR':
        LogHelper.debug("MAC_MACFRYR Test Case")
        mac_client = NativeClientFactory.get_client(product='MAC', oem=oem_client)
        if build:
            mac_client.installer.download_and_install(build[0], job[0])
        mac_client.controller.prepare_environment(environment)

        macfryr_client = NativeClientFactory.get_client(product='MACFRYR', oem=oem_client)
        if build:
            macfryr_client.installer.download_and_install(build[1], job[1])
        macfryr_client.controller.prepare_environment(environment)

        LogHelper.info('Install MacFryr Client')
        LogHelper.info('Prepare MacFryr Client Environment')

    elif product == 'WINDOWS_WINFRYR':
        LogHelper.debug("WINDOWS_WINFRYR Test Case")
        win_client = NativeClientFactory.get_client(product='WINDOWS', oem=oem_client)
        LogHelper.info('Load Configuration')
        if build:
            win_client.installer.download_and_install(build[0], job[0])
        win_client.controller.prepare_environment(environment)
        LogHelper.info('Install WINDOWS Client')
        LogHelper.info('Prepare WINDOWS Client Environment')

        winfryr_client = NativeClientFactory.get_client(product='WINFRYR', oem=oem_client)
        if build:
            winfryr_client.installer.download_and_install(build[1], job[1])
        winfryr_client.controller.prepare_environment(environment)
        LogHelper.info('Install WINFRYR Client')
        LogHelper.info('Prepare WINFRYR Client Environment')
    elif product == 'MTS':
        LogHelper.info("No need to install anything to test against MTS.")
    #TODO
    else:
        LogHelper.info("Standalone app ")
        native_client = NativeClientFactory.get_client(product=product, oem=oem_client)
        if build:
            native_client.installer.download_and_install(build, job)
        native_client.controller.prepare_environment(environment)

    dump_options_to_config()

    if options.taskid:
        print ("update task record after execution")
        CeleryHelper.update_task_status(options.taskid, testrun, result='STARTED')

    behave_cmd = "behave %s --no-capture --no-capture-stderr" % features
    LogHelper.info(behave_cmd)
    if options.tags:
        behave_cmd += " --tags %s" %(options.tags)

    dry_run = options.dry_run
    if dry_run:
            behave_cmd += ' --dry-run'

    output = CmdHelper.run(behave_cmd)
    print output

    if options.database_enabled:
        # TestRun Finish.
        tr.end_time = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
        tr.save_to_elasticsearch()


    rerun_failed = options.rerun
    if rerun_failed and FileHelper.file_exist("rerun_failing.features"):
        LogHelper.info('Rerun failed feature')
        behave_cmd = "behave @rerun_failing.features"
    	behave_output = CmdHelper.run(behave_cmd)
    	print behave_output


    final_result = 'COMPLETED'
    if options.taskid:
        LogHelper.debug("update task status in databsae")
        CeleryHelper.update_task_status(options.taskid, testrun, result=final_result)
        time.sleep(2)
        LogHelper.debug("check testrun status")
        query_body = {
            "query": {
                "bool": {
                    "must": [
                        {
                            "match": {
                                "testrun_id": testrun
                            }
                        }
                    ],
                    "must_not": [
                        {
                            "match": {
                                "status": final_result
                            }
                        }
                    ]
                }
            }
        }

        result = ElasticsearchHelper().search_document(index='task', doc_type='task', body=query_body)
        uncompleted_tasks = result.get('hits').get('total')
        LogHelper.debug("%d tasks is uncompleted" % uncompleted_tasks)
        if uncompleted_tasks == 0:
            print "all tasks are completed"
            LogHelper.debug("all tasks are done for testrun %s" % testrun)
            output = CeleryHelper.detach_from_queue(testrun)
            print output
            LogHelper.debug(output)
Пример #29
0
def step_impl(context, text):
    LogHelper.debug(text)
Пример #30
0
 def clear_installer_folder(product_name):
     directory = ConfigAdapter.get_installer_path(product_name)
     for file in FileHelper.find_file(directory, '*'):
         LogHelper.debug('Delete file %s' % file)
         FileHelper.delete_file(file)