def test_creates_volume(self): results = [] # Check volumes is created for json first containers = fileparser.get_containers(self.docker_def_json) for container in containers: # Remove existing volume mappings from head container container.volumes = [] if container.name == 'head' else container.volumes conts, var = add_networking(containers, self.write_dir) for container in conts: if container.name.startswith('head'): # Check volumes created created = self.run_check(container.volumes, isjson=True) results.append( True) if created and len(container.volumes) is 1 else False # Check volume is created for list containers = fileparser.get_containers(self.docker_def_list) for container in containers: # Remove existing volumes mappings from head container container.volumes = [] if container.name == 'head' else container.volumes conts, var = add_networking(containers, self.write_dir) for container in conts: if container.name.startswith('head'): # Check volumes created created = self.run_check(container.volumes, islist=True) results.append( True) if created and len(container.volumes) is 1 else False assert all(item is True for item in results) and len(results) is 2
def test_03_removing_containers(self): for i in range(3): os.system('docker run -d -v /var/run/docker.sock:/run/docker.sock' ' -p 900' + str(i) + ':22 dgrid:test') hosts = [ self.hostname + ':9000', self.hostname + ':9001', self.hostname + ':9002', self.hostname ] containers = fileparser.get_containers(self.cwd + '/tests/torque/Dockerdef3.json') executor = SSHExecutor(containers, hosts) print executor.containers for x in range(len(executor.containers)): container = executor.containers[x] execute(executor.run_container, container, host=hosts[x]) container.execution_host = hosts[x] executor.terminate_clean() results = [] for x in range(len(executor.containers)): results.append(executor.containers[x].name not in os.popen( "docker ps -a | grep " + executor.containers[x].name + " | awk '{print $1}'").read()) assert all(item is True for item in results)
def test_01_running_remote_containers(self): # Spin up a couple of containers os.system( 'cd ' + self.cwd + '/TestingUtilities/ && docker build --build-arg HOM=$HOME -t dgrid:test .' ) for i in range(3): os.system('docker run -d -v /var/run/docker.sock:/run/docker.sock' ' -p 900' + str(i) + ':22 dgrid:test') # create hostfile hosts = [ self.hostname + ':9000', self.hostname + ':9001', self.hostname + ':9002', self.hostname ] containers = fileparser.get_containers(self.cwd + '/tests/torque/Dockerdef3.json') executor = SSHExecutor(containers, hosts) execute(executor.run_container, containers[0], host=hosts[0]) # Check if container was run result = os.popen("docker ps | grep " + containers[0].name).read() # Clean up os.system( "docker rm -fv $(docker ps -a | grep 'dgrid:test' | awk '{print $1}')" ) os.system( "docker rm -fv $(docker ps -a | grep 'slave' | awk '{print $1}')") assert containers[0].name not in result
def test_check_json_volumes(self): containers = fileparser.get_containers(self.docker_def_json) conts, var = add_networking(containers, self.write_dir) os.system("rm " + self.write_dir + "hostfile.json") for container in conts: if 'head' in container.name: result = self.run_check(container.volumes, isjson=True) assert result is True and len( container.volumes) == 2 and var is True
def test_check_links(self): containers = fileparser.get_containers(self.docker_def_envs) conts, var = add_networking(containers, self.write_dir) for container in conts: if 'tail' in container.name: tail = container.name for container in conts: if 'head' in container.name: result = self.check_envs(container.environment_vars, tail) assert result is True and len( container.environment_vars) == 2 and var is True
def test_check_json(self): containers = fileparser.get_containers(self.docker_def_json) add_networking(containers, self.write_dir) with open(self.write_dir + 'hostfile.json', 'r') as f: data = json.load(f) passes = [] for val in data['green']: passes.append(True) if val.startswith("green") else passes.append( False) for val in data['red']: passes.append(True) if val.startswith("red") else passes.append( False) # Checks that all values are true, and length is correct assert all(item is True for item in passes) and len( data['red']) == 1 and len(data['green']) == 2
def test_02_running_local_container(self): hosts = [ self.hostname + ':9000', self.hostname + ':9001', self.hostname + ':9002', self.hostname ] containers = fileparser.get_containers(self.cwd + '/tests/torque/Dockerdef3.json') executor = SSHExecutor(containers, hosts) # executor.run_int_container() executor.run_int_container() result = os.popen("docker ps -a | grep " + executor.int_container.name).read() # Clean Up os.system( "docker rm -fv $(docker ps -a | grep 'head' | awk '{print $1}')") assert executor.local_pid > 0 and executor.int_container.name in result
def test_check_list(self): containers = fileparser.get_containers(self.docker_def_list) conts, var = add_networking(containers, self.write_dir) expected = [] for container in conts: if container.name.startswith('tail'): expected.append(container.name) with open(self.write_dir + 'hostfile', 'r') as f: lines = f.readlines() results = [] for line in lines: line = line.replace("\n", "") results.append(True) if line in expected else results.append(False) # Check all results are true, and same number of entries in expected as result assert all(item is True for item in results) and len(expected) == len(results)