예제 #1
0
 def init():
     try:
         if not Test.init():
             return False
         proc = run("sudo chown -R root:root /tmp/bw-data", shell=True)
         if proc.returncode != 0:
             raise (Exception("chown failed (autoconf stack)"))
         if isdir("/tmp/autoconf"):
             rmtree("/tmp/autoconf")
         copytree("./integrations/autoconf", "/tmp/autoconf")
         compose = "/tmp/autoconf/docker-compose.yml"
         Test.replace_in_file(compose, r"bunkerity/bunkerweb:.*$",
                              "10.20.1.1:5000/bw-tests:latest")
         Test.replace_in_file(compose, r"bunkerity/bunkerweb-autoconf:.*$",
                              "10.20.1.1:5000/bw-autoconf-tests:latest")
         Test.replace_in_file(compose, r"\./bw\-data:/", "/tmp/bw-data:/")
         proc = run("docker-compose pull", cwd="/tmp/autoconf", shell=True)
         if proc.returncode != 0:
             raise (
                 Exception("docker-compose pull failed (autoconf stack)"))
         proc = run("docker-compose up -d", cwd="/tmp/autoconf", shell=True)
         if proc.returncode != 0:
             raise (Exception("docker-compose up failed (autoconf stack)"))
         i = 0
         healthy = False
         while i < 30:
             proc = run(
                 'docker inspect --format "{{json .State.Health }}" autoconf_mybunker_1',
                 cwd="/tmp/autoconf",
                 shell=True,
                 capture_output=True)
             if proc.returncode != 0:
                 raise (Exception(
                     "docker-compose inspect failed (autoconf stack)"))
             if "healthy" in proc.stdout.decode():
                 healthy = True
                 break
             sleep(1)
             i += 1
         if not healthy:
             raise (Exception("autoconf stack is not healthy"))
     except:
         log("AUTOCONF", "❌",
             "exception while running AutoconfTest.init()\n" + format_exc())
         return False
     return True
예제 #2
0
 def _setup_test(self):
     try:
         super()._setup_test()
         test = "/tmp/tests/" + self._name
         compose = "/tmp/tests/" + self._name + "/autoconf.yml"
         example_data = "/tmp/tests/" + self._name + "/bw-data"
         Test.replace_in_file(compose, r"bunkerity/bunkerweb:.*$",
                              "10.20.1.1:5000/bw-tests:latest")
         Test.replace_in_file(compose, r"\./bw\-data:/", "/tmp/bw-data:/")
         Test.replace_in_file(compose, r"\- bw_data:/", "- /tmp/bw-data:/")
         for ex_domain, test_domain in self._domains.items():
             Test.replace_in_files(test, ex_domain, test_domain)
             Test.rename(test, ex_domain, test_domain)
         Test.replace_in_files(test, "example.com", getenv("ROOT_DOMAIN"))
         setup = test + "/setup-autoconf.sh"
         if isfile(setup):
             proc = run("sudo ./setup-autoconf.sh", cwd=test, shell=True)
             if proc.returncode != 0:
                 raise (Exception("setup-autoconf failed"))
         if isdir(example_data) and not self._no_copy_container:
             proc = run("sudo bash -c 'cp -rp " + example_data +
                        "/* /tmp/bw-data'",
                        shell=True)
             if proc.returncode != 0:
                 raise (Exception("cp bw-data failed"))
         proc = run("docker-compose -f autoconf.yml pull",
                    shell=True,
                    cwd=test)
         if proc.returncode != 0:
             raise (Exception("docker-compose pull failed"))
         proc = run("docker-compose -f autoconf.yml up -d",
                    shell=True,
                    cwd=test)
         if proc.returncode != 0:
             raise (Exception("docker-compose up failed"))
     except:
         log(
             "AUTOCONF", "❌",
             "exception while running AutoconfTest._setup_test()\n" +
             format_exc())
         self._cleanup_test()
         return False
     return True
예제 #3
0
 def init():
     try:
         if not Test.init():
             return False
         proc = run("sudo chown -R root:root /tmp/bw-data", shell=True)
         if proc.returncode != 0:
             raise (Exception("chown failed (swarm stack)"))
         if isdir("/tmp/swarm"):
             rmtree("/tmp/swarm")
         copytree("./integrations/swarm", "/tmp/swarm")
         compose = "/tmp/swarm/stack.yml"
         Test.replace_in_file(compose, r"bunkerity/bunkerweb:.*$",
                              "10.20.1.1:5000/bw-tests:latest")
         Test.replace_in_file(compose, r"bunkerity/bunkerweb-autoconf:.*$",
                              "10.20.1.1:5000/bw-autoconf-tests:latest")
         Test.replace_in_file(compose, r"bw\-data:/", "/tmp/bw-data:/")
         proc = run("docker stack deploy -c stack.yml bunkerweb",
                    cwd="/tmp/swarm",
                    shell=True)
         if proc.returncode != 0:
             raise (Exception("docker stack deploy failed (swarm stack)"))
         i = 0
         healthy = False
         while i < 45:
             proc = run(
                 'docker stack ps --no-trunc --format "{{ .CurrentState }}" bunkerweb | grep -v "Running"',
                 cwd="/tmp/swarm",
                 shell=True,
                 capture_output=True)
             if "" == proc.stdout.decode():
                 healthy = True
                 break
             sleep(1)
             i += 1
         if not healthy:
             raise (Exception("swarm stack is not healthy"))
         sleep(60)
     except:
         log("SWARM", "❌",
             "exception while running SwarmTest.init()\n" + format_exc())
         return False
     return True
예제 #4
0
 def init() :
     try :
         if not Test.init() :
             return False
         proc = run("sudo chown -R root:root /tmp/bw-data", shell=True)
         if proc.returncode != 0 :
             raise(Exception("chown failed (k8s stack)"))
         if isdir("/tmp/kubernetes") :
             rmtree("/tmp/kubernetes")
         copytree("./integrations/kubernetes", "/tmp/kubernetes")
         copy("./tests/utils/k8s.yml", "/tmp/kubernetes")
         deploy = "/tmp/kubernetes/bunkerweb.yml"
         Test.replace_in_file(deploy, r"bunkerity/bunkerweb:.*$", "10.20.1.1:5000/bw-tests:latest")
         Test.replace_in_file(deploy, r"bunkerity/bunkerweb-autoconf:.*$", "10.20.1.1:5000/bw-autoconf-tests:latest")
         Test.replace_in_file(deploy, r"ifNotPresent", "Always")
         proc = run("sudo kubectl apply -f k8s.yml", cwd="/tmp/kubernetes", shell=True)
         if proc.returncode != 0 :
             raise(Exception("kubectl apply k8s failed (k8s stack)"))
         proc = run("sudo kubectl apply -f rbac.yml", cwd="/tmp/kubernetes", shell=True)
         if proc.returncode != 0 :
             raise(Exception("kubectl apply rbac failed (k8s stack)"))
         proc = run("sudo kubectl apply -f bunkerweb.yml", cwd="/tmp/kubernetes", shell=True)
         if proc.returncode != 0 :
             raise(Exception("kubectl apply bunkerweb failed (k8s stack)"))
         healthy = False
         i = 0
         while i < 30 :
             proc = run('sudo kubectl get pods | grep bunkerweb | grep -v Running', shell=True, capture_output=True)
             if "" == proc.stdout.decode() :
                 healthy = True
                 break
             sleep(1)
             i += 1
         if not healthy :
             raise(Exception("k8s stack is not healthy"))
         sleep(60)
     except :
         log("KUBERNETES", "❌", "exception while running KubernetesTest.init()\n" + format_exc())
         return False
     return True