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