<commit_before>import logging
from time import sleep
import unittest
from devops.helpers import ssh, os
import re
from ci_helpers import get_environment
from helpers import load, execute, write_config, sync_time
from root import root

class RecipeTestCase(unittest.TestCase):

    def setUp(self):
        self.environment = get_environment()
        master = self.environment.node['master']
        self.revert_snapshot()
        self.master_remote = ssh(master.ip_address, username='root', password='<PASSWORD>')
        self.upload_recipes()
        self.restart_puppet_muster()

    def upload_recipes(self):
        recipes_dir = root('fuel','deployment','puppet')
        for dir in os.listdir(recipes_dir):
            recipe_dir = os.path.join(recipes_dir, dir)
            remote_dir = "/etc/puppet/modules/"
            self.master_remote.mkdir(remote_dir)
            self.master_remote.upload(recipe_dir, remote_dir)

    def revert_snapshot(self):
        for node in self.environment.nodes:
            node.restore_snapshot('empty')
            sleep(4)
            sync_time(ssh(node.ip_address, username='root', password='<PASSWORD>').sudo.ssh)

    def replace(self, template, **kwargs):
        for key in kwargs:
            value=kwargs.get(key)
            template, count = re.subn(
                '^(\$' + str(key) + ')\s*=.*', "\\1 = " + str(value),
                template,
                flags=re.MULTILINE)
            if count == 0:
                raise Exception("Variable ${0:>s} is not found".format(key))
        return template

    def write_site_pp_manifest(self, path, **kwargs):
        site_pp = load(path)
        site_pp = self.replace(site_pp, **kwargs)
        write_config(self.master_remote, '/etc/puppet/manifests/site.pp', site_pp)

    def assertResult(self, result):
        self.assertEqual([], result['stderr'], result['stderr'])<commit_msg>Make yum cache after revert<commit_after>import logging
from time import sleep
import unittest
from devops.helpers import ssh, os
import re
from ci_helpers import get_environment
from helpers import load, execute, write_config, sync_time
from root import root

class RecipeTestCase(unittest.TestCase):

    def setUp(self):
        self.environment = get_environment()
        master = self.environment.node['master']
        self.revert_snapshot()
        self.master_remote = ssh(master.ip_address, username='root', password='<PASSWORD>')
        self.upload_recipes()
        self.restart_puppet_muster()

    def upload_recipes(self):
        recipes_dir = root('fuel','deployment','puppet')
        for dir in os.listdir(recipes_dir):
            recipe_dir = os.path.join(recipes_dir, dir)
            remote_dir = "/etc/puppet/modules/"
            self.master_remote.mkdir(remote_dir)
            self.master_remote.upload(recipe_dir, remote_dir)

    def revert_snapshot(self):
        for node in self.environment.nodes:
            node.restore_snapshot('empty')
            sleep(4)
            remote=ssh(node.ip_address, username='root', password='<PASSWORD>')
            sync_time(remote.sudo.ssh)
            remote.sudo.ssh.execute('yum makecache')

    def replace(self, template, **kwargs):
        for key in kwargs:
            value=kwargs.get(key)
            template, count = re.subn(
                '^(\$' + str(key) + ')\s*=.*', "\\1 = " + str(value),
                template,
                flags=re.MULTILINE)
            if count == 0:
                raise Exception("Variable ${0:>s} is not found".format(key))
        return template

    def write_site_pp_manifest(self, path, **kwargs):
        site_pp = load(path)
        site_pp = self.replace(site_pp, **kwargs)
        write_config(self.master_remote, '/etc/puppet/manifests/site.pp', site_pp)

    def assertResult(self, result):
        self.assertEqual([], result['stderr'], result['stderr'])
{'fraction_non_alphanumeric': 0.12097812097812098, 'fraction_numerical': 0.002059202059202059, 'mean_word_length': 2.66258246936852, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7273957', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1140, 'n_words': 244}