Beispiel #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, '.'])
Beispiel #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, '.'])
Beispiel #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'])
Beispiel #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)])
Beispiel #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)])
Beispiel #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'])
Beispiel #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'])
Beispiel #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'])
Beispiel #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))
Beispiel #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')
Beispiel #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')
Beispiel #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))
Beispiel #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))
Beispiel #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,)])
Beispiel #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)
Beispiel #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)
Beispiel #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 +
            "())"
        ])
Beispiel #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'])
Beispiel #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'])	
Beispiel #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])
Beispiel #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])
Beispiel #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
         + "())"])
Beispiel #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, )
     ])