<commit_before>import logging
from time import sleep
import traceback
import devops
from devops.model import Environment, Network, Node, Disk, Interface
from devops.helpers import tcp_ping, wait, ssh, http_server, os
from helpers import load, write_config
from settings import controllers, computes
from root import root
import os

logger = logging.getLogger('ci')

class Ci:
    def __init__(self, image=None, name='recipes'):
        self.base_image = image
        self.environment = None
        self.environment_name = os.environ.get('ENV_NAME', name)
        try:
            self.environment = devops.load(self.environment_name)
            logger.info("Successfully loaded existing environment")
        except Exception, e:
            logger.info("Failed to load existing %s environment: " % self.environment_name + str(e) + "\n" + traceback.format_exc())
            pass

    def get_environment(self):
        return self.environment

    def add_nmap_yum(self, remote):
        remote.sudo.ssh.execute('yum -y install nmap')

    def add_epel_repo(self, remote):
        remote.sudo.ssh.execute('rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm')

    def add_puppetlab_repo(self, remote):
        remote.sudo.ssh.execute('rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-5.noarch.rpm')

    def setup_puppet_client_yum(self, remote):
        self.add_puppetlab_repo(remote)
        remote.sudo.ssh.execute('yum -y install puppet-2.7.19')

    def start_puppet_master(self, remote):
        remote.sudo.ssh.execute('puppet resource service puppetmaster ensure=running enable=true')

    def start_puppet_agent(self, remote):
        remote.sudo.ssh.execute('puppet resource service puppet ensure=running enable=true')

    def sign_all_node_certificates(self, remote):
        remote.sudo.ssh.execute('puppet cert sign --all')

    def request_cerificate(self, remote):
        remote.sudo.ssh.execute('puppet agent --waitforcert 0')

    def switch_off_ip_tables(self, remote):
        remote.sudo.ssh.execute('iptables -F')

    def setup_puppet_master_yum(self, remote):
        self.add_puppetlab_repo(remote)
        remote.sudo.ssh.execute('yum -y install puppet-server-2.7.19 mysql mysql-server mysql-devel rubygems ruby-devel make gcc')
        remote.sudo.ssh.execute('gem install rails -v 3.0.10')
        remote.sudo.ssh.execute('gem install mysql')
        remote.sudo.ssh.execute('chkconfig mysql on')
        remote.sudo.ssh.execute('service mysqld start')
        remote.sudo.ssh.execute('mysql -u root -e "create database puppet; grant all privileges on puppet.* to puppet@localhost identified by \'password\'; "')
        remote.sudo.ssh.execute('gem uninstall activerecord')
        remote.sudo.ssh.execute('gem install activerecord -v 3.0.10')
        remote.sudo.ssh.execute('setenforce 0')

    def change_host_name(self, remote, short, long):
        remote.sudo.ssh.execute('hostname %s' % long)
        remote.sudo.ssh.execute('echo HOSTNAME=%s >> /etc/sysconfig/network' % short)
        self.add_to_hosts(remote, '127.0.0.1', short, short)

    def add_to_hosts(self, remote, ip, short, long):
        remote.sudo.ssh.execute('echo %s %s %s >> /etc/hosts' % (ip, long, short))

    def get_environment_or_create(self):
        if self.get_environment():
            return self.get_environment()
        self.setup_environment()
        return self.environment

    def describe_node(self, name, networks, memory=1024):
        node = Node(name)
        node.memory = memory
        node.vnc = True<commit_msg>Remove puppetlab repo after puppet installation<commit_after>import logging
from time import sleep
import traceback
import devops
from devops.model import Environment, Network, Node, Disk, Interface
from devops.helpers import tcp_ping, wait, ssh, http_server, os
from helpers import load, write_config
from settings import controllers, computes
from root import root
import os

logger = logging.getLogger('ci')

class Ci:
    def __init__(self, image=None, name='recipes'):
        self.base_image = image
        self.environment = None
        self.environment_name = os.environ.get('ENV_NAME', name)
        try:
            self.environment = devops.load(self.environment_name)
            logger.info("Successfully loaded existing environment")
        except Exception, e:
            logger.info("Failed to load existing %s environment: " % self.environment_name + str(e) + "\n" + traceback.format_exc())
            pass

    def get_environment(self):
        return self.environment

    def add_nmap_yum(self, remote):
        remote.sudo.ssh.execute('yum -y install nmap')

    def add_epel_repo(self, remote):
        remote.sudo.ssh.execute('rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm')

    def add_puppetlab_repo(self, remote):
        remote.sudo.ssh.execute('rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-5.noarch.rpm')

    def remove_puppetlab_repo(self, remote):
        remote.sudo.ssh.execute('rpm --erase puppetlabs-release-6-5.noarch')

    def setup_puppet_client_yum(self, remote):
        self.add_puppetlab_repo(remote)
        remote.sudo.ssh.execute('yum -y install puppet-2.7.19')
        self.remove_puppetlab_repo(remote)

    def start_puppet_master(self, remote):
        remote.sudo.ssh.execute('puppet resource service puppetmaster ensure=running enable=true')

    def start_puppet_agent(self, remote):
        remote.sudo.ssh.execute('puppet resource service puppet ensure=running enable=true')

    def sign_all_node_certificates(self, remote):
        remote.sudo.ssh.execute('puppet cert sign --all')

    def request_cerificate(self, remote):
        remote.sudo.ssh.execute('puppet agent --waitforcert 0')

    def switch_off_ip_tables(self, remote):
        remote.sudo.ssh.execute('iptables -F')

    def setup_puppet_master_yum(self, remote):
        self.add_puppetlab_repo(remote)
        remote.sudo.ssh.execute('yum -y install puppet-server-2.7.19 mysql mysql-server mysql-devel rubygems ruby-devel make gcc')
        self.remove_puppetlab_repo(remote)
        remote.sudo.ssh.execute('gem install rails -v 3.0.10')
        remote.sudo.ssh.execute('gem install mysql')
        remote.sudo.ssh.execute('chkconfig mysql on')
        remote.sudo.ssh.execute('service mysqld start')
        remote.sudo.ssh.execute('mysql -u root -e "create database puppet; grant all privileges on puppet.* to puppet@localhost identified by \'password\'; "')
        remote.sudo.ssh.execute('gem uninstall activerecord')
        remote.sudo.ssh.execute('gem install activerecord -v 3.0.10')
        remote.sudo.ssh.execute('setenforce 0')

    def change_host_name(self, remote, short, long):
        remote.sudo.ssh.execute('hostname %s' % long)
        remote.sudo.ssh.execute('echo HOSTNAME=%s >> /etc/sysconfig/network' % short)
        self.add_to_hosts(remote, '127.0.0.1', short, short)

    def add_to_hosts(self, remote, ip, short, long):
        remote.sudo.ssh.execute('echo %s %s %s >> /etc/hosts' % (ip, long, short))

    def get_environment_or_create(self):
        if self.get_environment():
            return self.get_environment()
        self.setup_environment()
        return self.environment

    def describe_node(self, name, networks, memory=1024):
        node = Node(name)
        node.memory = memory
        node.vnc = True
{'fraction_non_alphanumeric': 0.1159866220735786, 'fraction_numerical': 0.011237458193979933, 'mean_word_length': 3.238095238095238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4961429', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2283, 'n_words': 516}