protractor - Remove docker container at the end of each test -


i'm using docker scale test infrastructure / browsers based on number of requests received in jenkins.

created python script identify total number of spec files , browser type, , spin-up many docker containers. python code has logic determine how many nodes in use, stale , determines required number of containers.

i want programmatically delete container / de-register selenium node @ end of each spec file (docker --rm flag not helping me).so next test clean browser , environment.

the selenium grid runs on same box jenkins is. once invoke protractor protractor.conf.js (step 3), selenium grid start distributing tests containers created in step 1.

when '--rm' not helping, mean after step3 communication between selenium hub , nodes. i'm finding difficult determine node / container used selenium grid execute test , remove container before grid sends test container.

-- jenkins build stage -- shell:

   # step 1    python ./create_test_machine.py ${no_of_containers} # spin-up selenium nodes     # step 2    npm install  # install node modules     # step 3    protractor protractor.conf.js # run protractor tests 

--python code spin containers - create_test_machine.py--

python script:

import sys import docker import docker.utils import requests import json import time  c = docker.client(base_url='unix://var/run/docker.sock', version='1.23') my_envs = {'hub_port_4444_tcp_addr' :'172.17.0.1', 'hub_port_4444_tcp_port' : 4444}  def check_available_machines(no_of_machines):        t = c.containers()     noof_running_containers = len(t)     if noof_running_containers == 0:         print("0 containers running. creating " + str(no_of_machines) + "new containers...")         spinup_test_machines(no_of_machines)     else:                out_of_stock = 0         obj_container in t:             print(obj_container)             container_ip_addr = obj_container['networksettings']['networks']['bridge']['ipaddress']             container_state = obj_container['state']                     res = requests.get('http://' + container_ip_addr + ':5555/wd/hub/sessions')                      obj = json.loads(res.content)                        node_inuse = len(obj['value'])             if node_inuse != 0:                  noof_running_containers -= 1         if noof_running_containers < no_of_machines:             spinup_test_machines(no_of_machines - noof_running_containers)     return        def spinup_test_machines(no_of_machines):     '''         parameter : number of test nodes spin      '''     print("creating " + str(no_of_machines) + " new containers...")     # my_envs = docker.utils.parse_env_file('docker.env')      in range(0,no_of_machines):         new_container = c.create_container(image='selenium/node-chrome', environment=my_envs)         response = c.start(container=new_container.get('id'))         print(new_container, response)     return  if len(sys.argv) - 1 == 1:     no_of_machines = int(sys.argv[1]) + 2        check_available_machines(no_of_machines)     time.sleep(30) else:     print("invalid number of parameters") 

here difference can seen when docker run -d , --rm

using -doption

c:\users\apps>docker run -d --name testso alpine /bin/echo 'hello world' 5d447b558ae6bf58ff6a2147da8bdf25b526bd1c9f39117498fa017f8f71978b 

check logs

c:\users\apps>docker logs testso 'hello world' 

check last run containers

c:\users\apps>docker ps -a container id        image               command                  created             status                      ports               names 5d447b558ae6        alpine              "/bin/echo 'hello wor"   35 hours ago        exited (0) 11 seconds ago                       testso 

finally user have remove explicity

c:\users\apps>docker rm -f testso testso 

using --rm, container vanished including logs process run inside container completed. no trace of container more.

c:\users\apps>docker run --rm --name testso alpine /bin/echo 'hello world' 'hello world'  c:\users\apps>docker logs testso error: no such container: testso  c:\users\apps>docker ps -a container id        image               command             created             status              ports               names 

i believe clear, how run container , leaving no trace after process finished inside of container.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -