Exemplo n.º 1
0
    def build_environment(self, container):
        """
        Builds a Docker image for the specified container.
        """

        alias = self.config.containers[container]['alias']

        os.mkdir(alias)
        os.chdir(alias)

        # Copy Context Files
        self.helper.copycontext(container)
        self.helper.copysource(container)
        self.helper.copypackages(container)

        # Get Dockerfile
        [baseimage, verbs, arguments] = self.helper.read(container, 'docker')

        # Write Dockerfile
        f = open('Dockerfile', 'w')
        f.write('FROM %s\n' % (baseimage, ))
        for verb, argument in zip(verbs, arguments):
            f.write('%s %s\n' % (
                verb,
                argument,
            ))
        f.close()

        # Build
        sh.run(['docker', 'build', '-t', alias, '.'])
Exemplo n.º 2
0
    def build_environment(self,container):
        """
        Builds a Docker image for the specified container.
        """
        
        alias = self.config.containers[container]['alias']
        
        os.mkdir(alias)
        os.chdir(alias)

        # Copy Context Files
        self.helper.copycontext(container)
        self.helper.copysource(container)
        self.helper.copypackages(container)

        # Get Dockerfile
        [baseimage,verbs,arguments] = self.helper.read(
            container,
            'docker')

        # Write Dockerfile
        f = open('Dockerfile','w')
        f.write('FROM %s\n'%(baseimage,))        
        for verb,argument in zip(verbs,arguments):
            f.write('%s %s\n'%(verb,argument,))
        f.close()

        # Build
        sh.run(['docker','build','-t',alias, '.'])
Exemplo n.º 3
0
    def __install_kernel(self, version):
        """
        Installs the specified kernel in the vagrant box
        """
        logging.info("Rebooting Into New Kernel %s"%(version,))

        # Restart
        sh.run(['vagrant','reload'])
Exemplo n.º 4
0
 def destroy_environment(self, container):
     """
     Removes virtual environment
     """
     for container in self.config.containers:
         alias = self.config.containers[container]['alias']
         sh.run(['docker', 'kill', 'xshop_%s_1' % (alias)])
         sh.run(['docker', 'rm', 'xshop_%s_1' % (alias)])
Exemplo n.º 5
0
 def destroy_environment(self,container):
     """
     Removes virtual environment
     """
     for container in self.config.containers:
         alias = self.config.containers[container]['alias']
         sh.run(['docker','kill','xshop_%s_1'%(alias)])
         sh.run(['docker','rm','xshop_%s_1'%(alias)])
Exemplo n.º 6
0
    def __install_kernel(self, version):
        """
        Installs the specified kernel in the vagrant box
        """
        logging.info("Rebooting Into New Kernel %s" % (version, ))

        # Restart
        sh.run(['vagrant', 'reload'])
Exemplo n.º 7
0
    def destroy_environment(self,container):
        """
        Removes virtual environment
        """
        alias = self.config.containers[container]['alias']

        if os.path.isdir(alias):
            os.chdir(alias)
            sh.run(['vagrant','destroy','-f'])
Exemplo n.º 8
0
    def destroy_environment(self, container):
        """
        Removes virtual environment
        """
        alias = self.config.containers[container]['alias']

        if os.path.isdir(alias):
            os.chdir(alias)
            sh.run(['vagrant', 'destroy', '-f'])
Exemplo n.º 9
0
 def __add(self,files):
     [infile,outfile]= files
     extensions = (".tar.gz",".tar.bz2",".tar.xz",".tar")
     infile = str(infile)
     if infile.endswith(extensions):
         sh.run(['tar','-xf',infile])
         for e in extensions:
             infile = infile.replace(e,"")
     self.__run_command("cp -r /vagrant/%s %s"%(infile, outfile))
Exemplo n.º 10
0
 def __launch_target_image(self):
     box = self.config.target.split(":")[1]
     alias = self.config.containers['target']['alias']
     os.mkdir(alias)
     os.chdir(alias)
     sh.run(['vagrant','init',box])
     self.__write_vagrantfile(box)
     self.helper.copytestfiles()
     sh.run(['vagrant','up'])
     ip = self.__fetch_ip()
     logging.info("IP FOUND %s"%( ip))
     self.config.containers['target']['ip']=ip
     self.__set_environment('target')
Exemplo n.º 11
0
 def __launch_target_image(self):
     box = self.config.target.split(":")[1]
     alias = self.config.containers['target']['alias']
     os.mkdir(alias)
     os.chdir(alias)
     sh.run(['vagrant', 'init', box])
     self.__write_vagrantfile(box)
     self.helper.copytestfiles()
     sh.run(['vagrant', 'up'])
     ip = self.__fetch_ip()
     logging.info("IP FOUND %s" % (ip))
     self.config.containers['target']['ip'] = ip
     self.__set_environment('target')
Exemplo n.º 12
0
    def __add(self,infile, outfile):
        """
        All files in context are included at /vagrant
        This method copies from there to the specified location
        To mimic Docker's idiocy, we have to automatically untar
        any archives.
        """    
        extensions = (".tar.gz",".tar.bz2",".tar.xz",".tar")
        infile = str(infile)
        if infile.endswith(extensions):
            sh.run(['tar','-xf',infile])
            for e in extensions:
                infile = infile.replace(e,"")

        self.__run_command("cp -r /vagrant/%s %s"%(infile, outfile))
Exemplo n.º 13
0
    def __add(self, infile, outfile):
        """
        All files in context are included at /vagrant
        This method copies from there to the specified location
        To mimic Docker's idiocy, we have to automatically untar
        any archives.
        """
        extensions = (".tar.gz", ".tar.bz2", ".tar.xz", ".tar")
        infile = str(infile)
        if infile.endswith(extensions):
            sh.run(['tar', '-xf', infile])
            for e in extensions:
                infile = infile.replace(e, "")

        self.__run_command("cp -r /vagrant/%s %s" % (infile, outfile))
Exemplo n.º 14
0
    def run_function(self,container, function):
        """
        Runs a given function in xshop_test.py inside of a specified
        participant in the test environment. Should return 
        {'ret':return_ code, 'stdout':stdout}
        """
        logging.info("Running %s in %s"%(function,container,))
	os.chdir(self.config.containers[container]['alias'])
        return sh.run(['vagrant','ssh','--',self.environment+'python2 -c "import xshop_test;import sys;sys.exit(xshop_test.%s())"'%(function,)])
Exemplo n.º 15
0
    def build_environment(self, container):
        """
        Constructs a Vagrant managed virtual machine for specified test 
        participant, based on its Dockerfile. 
        """

        alias = self.config.containers[container]['alias']

        logging.info("Building %s:%s" % (container, alias))

        [box, verbs, arguments] = self.helper.read(container, 'vagrant')

        # Build Context
        os.mkdir(alias)
        os.chdir(alias)
        sh.run(['vagrant', 'init', box])

        # Write Custom Vagrantfile
        self.__write_vagrantfile(box)

        # Copy Context
        self.helper.copycontext(container)
        self.helper.copysource(container)
        self.helper.copypackages(container)
        self.helper.copytestfiles()

        # Start Box
        sh.run(['vagrant', 'up'])

        # Find IP
        ip = self.__fetch_ip()
        logging.info("IP FOUND %s" % (ip))
        self.config.containers[container]['ip'] = ip

        # Follow build process with commands
        self.workdir = "/"

        self.__run_dockerfile(verbs, arguments)

        # Set environment
        self.__set_environment(container)
Exemplo n.º 16
0
    def build_environment(self,container):
        """
        Constructs a Vagrant managed virtual machine for specified test 
        participant, based on its Dockerfile. 
        """
        
        alias = self.config.containers[container]['alias']
    
        logging.info("Building %s:%s"%(container, alias))

        [box, verbs, arguments] = self.helper.read(container, 'vagrant') 
         
        # Build Context
        os.mkdir(alias)
        os.chdir(alias)
	sh.run(['vagrant','init',box])

        # Write Custom Vagrantfile
        self.__write_vagrantfile(box)
        
        # Copy Context
        self.helper.copycontext(container)
        self.helper.copysource(container)
        self.helper.copypackages(container)
        self.helper.copytestfiles()

        # Start Box
        sh.run(['vagrant','up'])
        
        # Find IP
        ip = self.__fetch_ip()
        logging.info("IP FOUND %s"%( ip))
        self.config.containers[container]['ip']=ip

        # Follow build process with commands
        self.workdir="/"
    
        self.__run_dockerfile(verbs,arguments)    

        # Set environment
        self.__set_environment(container)
Exemplo n.º 17
0
    def run_function(self, container, function):
        """
        Runs a given function in xshop_test.py inside of a specified
        participant in the test environment.
        """
        alias = self.config.containers[container]['alias']

        return sh.run([
            'docker', 'exec', "xshop_" + alias + "_1", 'python2', '-c',
            "import xshop_test;import sys;sys.exit(xshop_test." + function +
            "())"
        ])
Exemplo n.º 18
0
    def launch_test_environment(self):
        """
        Launches the full test environment, based on information in 
        test_environment.yml	
        """
        # Create Compose Context
        compose_directory = (self.config.project_directory + "/" +
                             self.config.build_directory + "/compose")

        os.mkdir(compose_directory)
        os.chdir(compose_directory)

        for container in self.config.containers:
            self.__create_compose_context(container)
            os.chdir(compose_directory)

        self.__create_compose_file()

        # Launch
        sh.run(['docker-compose', '-p', 'xshop', 'build'])
        sh.run(['docker-compose', '-p', 'xshop', 'up', '-d'])
Exemplo n.º 19
0
    def launch_test_environment(self):
        """
        Launches the full test environment, based on information in 
        test_environment.yml	
        """
        # Create Compose Context
        compose_directory = (self.config.project_directory
            + "/"
            + self.config.build_directory
            + "/compose")

        os.mkdir(compose_directory)
        os.chdir(compose_directory)
        
        for container in self.config.containers:
            self.__create_compose_context(container)
            os.chdir(compose_directory)
       
        self.__create_compose_file()

        # Launch
        sh.run(['docker-compose','-p','xshop','build'])
        sh.run(['docker-compose','-p','xshop','up','-d'])	
Exemplo n.º 20
0
    def __run_command(self,command,test_function=False):
        """
        Runs the specified command in the vagrant box. 
        Throws an error if the command returns nonzero.
	If skip_check is set, the return code is not verified. 
        """
        # We add WORKDIR functionality by wrapping each command
        # In this bash statement
        if not test_function:
            run_command = 'cd '+self.workdir+';sudo '+command

	if test_function:
   	    run_command=command 
        return sh.run(['vagrant','ssh','-c',run_command])
Exemplo n.º 21
0
    def __run_command(self, command, test_function=False):
        """
        Runs the specified command in the vagrant box. 
        Throws an error if the command returns nonzero.
	If skip_check is set, the return code is not verified. 
        """
        # We add WORKDIR functionality by wrapping each command
        # In this bash statement
        if not test_function:
            run_command = 'cd ' + self.workdir + ';sudo ' + command

        if test_function:
            run_command = command
        return sh.run(['vagrant', 'ssh', '-c', run_command])
Exemplo n.º 22
0
 def run_function(self,container, function):
     """
     Runs a given function in xshop_test.py inside of a specified
     participant in the test environment.
     """
     alias = self.config.containers[container]['alias']
 
     return sh.run(['docker',
         'exec',
         "xshop_"+alias+"_1",
         'python2',
         '-c',
         "import xshop_test;import sys;sys.exit(xshop_test." 
         + function
         + "())"])
Exemplo n.º 23
0
 def run_function(self, container, function):
     """
     Runs a given function in xshop_test.py inside of a specified
     participant in the test environment. Should return 
     {'ret':return_ code, 'stdout':stdout}
     """
     logging.info("Running %s in %s" % (
         function,
         container,
     ))
     os.chdir(self.config.containers[container]['alias'])
     return sh.run([
         'vagrant', 'ssh', '--', self.environment +
         'python2 -c "import xshop_test;import sys;sys.exit(xshop_test.%s())"'
         % (function, )
     ])