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)
 def launch_restore_manager(self):
     db_file = os.path.expanduser(
         '~/AppData/Local/Mozy Restore Manager/MozyRestoreManager.db')
     LogHelper.info("Deleting db file at " + db_file)
     FileHelper.delete_file(db_file)
     self.app = application.Application()
     self.app.start(
         "C:\Program Files\Mozy\Mozy Restore Manager\MozyRestoreManager.exe"
     )
     time.sleep(2)
示例#3
0
    def delete_json_file(filename=None, conf_dir=None):
        if not conf_dir:
            conf_dir = LynxCtrl.conf_dir

        if not filename:
            filename = "*.json"

        files = FileHelper.find_file(conf_dir, filename)

        for file_to_delete in files:
            FileHelper.delete_file(file_to_delete)

        return files
示例#4
0
def capture_worker_info(sender, instance, **kwargs):
    """
    dump worker infomation whenever worker is connected
    """
    info = PlatformHelper.get_platform_info()
    info['worker_name']='{0}'.format(sender)
    filename = os.path.join(os.path.dirname(__file__), "worker_info.yaml")
    if FileHelper.file_exist(filename):
        LogHelper.info("delete config file %s" % filename)
        FileHelper.delete_file(filename)
    data = dict((k.upper(), v) for k, v in info.items())
    with open(filename, 'w') as outfile:
        yaml.dump(data, outfile, default_flow_style=False)
示例#5
0
    def apply_conf(dict,
                   conf_file="qa_automation.conf",
                   keep_old_conf_file=True):

        if not conf_file.endswith(".conf"):
            conf_file += ".conf"

        conf_file_path = os.path.join(LynxCtrl.conf_dir, conf_file)

        if not keep_old_conf_file:
            FileHelper.delete_file(conf_file_path)

        for (key, value) in dict.items():
            LynxCtrl.add_conf(key, value, conf_file, True)

        LynxCtrl.restart()
示例#6
0
    def add_conf(key,
                 value,
                 conf_file="qa_automation.conf",
                 keep_old_conf_file=True):
        if not conf_file.endswith(".conf"):
            conf_file += ".conf"

        conf_file_path = os.path.join(LynxCtrl.conf_dir, conf_file)

        if not keep_old_conf_file:
            FileHelper.delete_file(conf_file_path)

        line = "%s = %s\n" % (key, value)

        with open(conf_file_path, 'aw') as f:
            f.write(line)
示例#7
0
def step_impl(context, db):
    database_dir = LinuxClient().controller.config_db_dir

    state_db = os.path.join(database_dir,
                            LinuxClient().controller.state_database)

    if FileHelper.file_exist(state_db):
        FileHelper.delete_file(state_db)
    metric_db = os.path.join(database_dir,
                             LinuxClient().controller.metrics_database)
    if FileHelper.file_exist(metric_db):
        FileHelper.delete_file(metric_db)
    # config_db = LinuxClient().controller.config_database
    # if FileHelper.file_exist(config_db):
    #     FileHelper.delete_file(config_db)

    context.execute_steps(unicode('When I restart Linux Client'))
    def download_fb(
        cls,
        product=None,
        dry_run=False,
    ):

        current_platform = PlatformHelper.get_system()
        fb_site = "https://artifacts.elastic.co/downloads/beats/filebeat/"
        package_name = ""

        if current_platform == "Linux" and PlatformHelper.get_arch(
        ) == "deb-64":
            package_name = 'filebeat-5.2.0-amd64.deb'

        if current_platform == "Linux" and PlatformHelper.get_arch(
        ) == "deb-32":
            package_name = 'filebeat-5.2.0-i386.deb'

        if current_platform == "Windows":
            package_name = 'filebeat-5.2.0-windows-x86_64.zip'

        if current_platform == "Darwin":
            package_name = 'filebeat-5.2.0-darwin-x86_64.tar.gz'

        installer_dir = ConfigAdapter.get_installer_path(product)

        cls.package_name = package_name
        installer_path = os.path.join(installer_dir, package_name)
        url = fb_site + package_name
        LogHelper.info("installer_path is " + installer_path)
        LogHelper.info("package url is " + url)

        if not FileHelper.dir_exist(installer_dir):
            FileHelper.create_directory(installer_dir)

        if FileHelper.file_exist(installer_path):
            FileHelper.delete_file(installer_path)

        if not dry_run:
            downloaded_package = urllib2.urlopen(url)
            LogHelper.info("download result is %s" % downloaded_package)
            with open(installer_path, 'wb') as output:
                output.write(downloaded_package.read())

        return installer_path
    def download_package(cls, job, build, pattern):
        """

        :return:
        """

        jh = JenkinsHelper(GLOBAL_CONFIG["JENKINS"]["URL"],
                           GLOBAL_CONFIG["JENKINS"]["USERNAME"],
                           GLOBAL_CONFIG["JENKINS"]["KEY"])
        dest = ConfigAdapter.get_installer_path(product='MAC')

        # Delete existing images before downloading
        import glob
        images = glob.glob(dest + '/*.dmg')
        for path in images:
            FileHelper.delete_file(path)

        package = jh.get_packages(job, build, pattern)
        return jh.download_packages(package, dest=dest)
示例#10
0
def dump_options_to_config(filename="runner_config.yaml"):
    """
    dump options dict to a yaml file
    :return:
    """
    LogHelper.info("start to dump runner options to %s" % filename)
    if not filename.endswith(".yaml"):
        filename = filename + ".yaml"

    config_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "configuration"))
    config_file = os.path.join(config_dir, filename)

    if FileHelper.file_exist(config_file):
        LogHelper.info("delete config file %s" % config_file)
        FileHelper.delete_file(config_file)

    data = dict((k.upper(), v) for k, v in options.__dict__.items())

    with open(config_file, 'w') as outfile:
        yaml.dump(data, outfile, default_flow_style=False)
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
 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 activate_linux_client(context):
    for row in context.table.rows:
        email_raw = row.get('email') or row.get('username')
        password = row.get('password')
        customkeytext = row.get('customkeytext')
        password_file = row.get('password_file')
        #TODO: add other parameters

    regex = re.match(r"{env}_{oemclient}_?.*", email_raw)
    if regex:
        cre_with_oc = re.sub(r"{oemclient}", RUNNER_CONFIG.get('OEM_CLIENT'),
                             email_raw)
        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)

        email = expected_credential.get('USERNAME')
        password_correct = expected_credential.get('PASSWORD')
    else:
        email = email_raw

    kargs = {}

    if email:
        kargs['email'] = email

    if password:
        kargs['password'] = password

    if password_file and password_file.upper() == "VALID":

        password_file_path = os.path.join(LYNX_CONFIG.get('TMP_PATH'),
                                          "password.txt")
        FileHelper.delete_file(password_file_path)

        if FileHelper.file_exist(password_file_path):
            FileHelper.delete_file(password_file_path)

        with open(password_file_path, "w") as text_file:
            text_file.write(password_correct)
        kargs['password-file'] = password_file_path

    if password_file and password_file.upper() == "INVALID":

        password_file_path = os.path.join(LYNX_CONFIG.get('TMP_PATH'),
                                          "wrong_password.txt")

        if FileHelper.file_exist(password_file_path):
            FileHelper.delete_file(password_file_path)

        with open(password_file_path, "w") as text_file:
            text_file.write(
                "{password}_wrong".format(password=password_correct))

        kargs['password-file'] = password_file_path

    if customkeytext:
        kargs['customkeytext'] = customkeytext

    kargs['force_encryption_change'] = None

    output = LinuxGUIClient.activate_cmd.activate(**kargs)
    LogHelper.info("activate output is %s" % output)
示例#14
0
 def __remove_db(self, db_name):
     file_full_path = os.path.join(self.app_support_dir, db_name)
     FileHelper.delete_file(file_full_path)
示例#15
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)
示例#16
0
 def clear_config(self):
     if FileHelper.file_exist(self.config_database):
         FileHelper.delete_file(self.config_database)
     if FileHelper.file_exist(self.state_database):
         FileHelper.delete_file(self.state_database)
def step_impl(context, number):
    LogHelper.info("start to judge whether to create files")
    testdata_config = ConfigAdapter.get_testdata_pros()
    testdata_root = ConfigAdapter.get_testdata_path()
    testdata_dir = testdata_root
    file_size = 0
    for row in context.table:
        if "file_folder" in row.headings:
            testdata_dir = os.path.join(testdata_root, row.get('file_folder'))
        elif "file_dir" in row.headings:
            testdata_dir = os.path.join(testdata_root, row.get('file_dir'))

    if not FileHelper.dir_exist(testdata_dir):
        FileHelper.create_directory(testdata_dir)

    if not FileHelper.get_file_count_in_dir(testdata_dir) == int(number):
        FileHelper.delete_file(testdata_dir)
        for row in context.table:
            for i in range(0, int(number)):
                file_prefix = row.get("file_prefix") or testdata_config.get(
                    "FILE_PREFIX") or "td"
                file_txt = row.get("file_ext") or testdata_config.get(
                    "FILE_EXT") or "txt"
                name = row.get('file_name') or testdata_config.get(
                    "FILE_NAME") or None
                if name:
                    file_name = "%s_%s_%s.%s" % (file_prefix, name, i,
                                                 file_txt)
                else:
                    file_name = "%s_%s.%s" % (file_prefix, i, file_txt)
                file_size = row.get("file_size") or testdata_config.get(
                    "FILE_SIZE") or 0

                DataHelper.create_testfile(file_name, testdata_dir,
                                           int(file_size))

        context.file_size = file_size

    else:
        for row in context.table:
            length = row.get('length') or testdata_config.get(
                "FILE_SIZE") or 10
            length = int(length)
            size = row.get('file_size') or testdata_config.get("FILE_SIZE")
            pattern = row.get('content') or 'random'

            testdatas = FileHelper.find_file(testdata_dir, '*')
            patch_method = row.get('patch_method')
            if patch_method == "append":
                for testdata in testdatas:
                    LogHelper.info("Patch test files with %s %s %d %s" %
                                   (patch_method, testdata, length, pattern))
                    FileHelper.append_file_content(testdata, length, pattern)
            elif patch_method == "truncate":
                for testdata in testdatas:
                    LogHelper.info("Patch test files with %s %s %d %s" %
                                   (patch_method, testdata, length, pattern))
                    FileHelper.truncate_file(testdata, length)
            elif patch_method == "insert":
                for testdata in testdatas:
                    LogHelper.info("Patch test files with %s %s %d %s" %
                                   (patch_method, testdata, length, pattern))
                    size_offset = random.randrange(1, size)
                    FileHelper.insert_file_content(testdata, size_offset,
                                                   length, pattern)