예제 #1
0
 def _setup_test(self) :
     try :
         super()._setup_test()
         test = "/tmp/tests/" + self._name
         deploy = "/tmp/tests/" + self._name + "/kubernetes.yml"
         example_data = "./examples/" + self._name + "/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-kubernetes.sh"
         if isfile(setup) :
             proc = run("sudo ./setup-kubernetes.sh", cwd=test, shell=True)
             if proc.returncode != 0 :
                 raise(Exception("setup-kubernetes failed"))
         # if isdir(example_data) :
             # for cp_dir in listdir(example_data) :
                 # if isdir(join(example_data, cp_dir)) :
                     # copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
         proc = run("sudo kubectl apply -f kubernetes.yml", shell=True, cwd=test)
         if proc.returncode != 0 :
             raise(Exception("kubectl apply failed"))
     except :
         log("KUBERNETES", "❌", "exception while running KubernetesTest._setup_test()\n" + format_exc())
         self._cleanup_test()
         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 _setup_test(self):
     try:
         super()._setup_test()
         test = "/tmp/tests/" + self._name
         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"))
         proc = LinuxTest.docker_cp(self.__distro, test,
                                    "/opt/" + self._name)
         if proc.returncode != 0:
             raise (Exception("docker cp failed (test)"))
         setup = test + "/setup-linux.sh"
         if isfile(setup):
             proc = LinuxTest.docker_exec(
                 self.__distro,
                 "cd /opt/" + self._name + " && ./setup-linux.sh")
             if proc.returncode != 0:
                 raise (Exception("docker exec setup failed (test)"))
         proc = LinuxTest.docker_exec(
             self.__distro,
             "cp /opt/" + self._name + "/variables.env /opt/bunkerweb")
         if proc.returncode != 0:
             raise (Exception("docker exec cp variables.env failed (test)"))
         proc = LinuxTest.docker_exec(
             self.__distro,
             "systemctl stop bunkerweb ; systemctl start bunkerweb")
         if proc.returncode != 0:
             raise (Exception(
                 "docker exec systemctl restart failed (linux stack)"))
     except:
         log(
             "LINUX", "❌",
             "exception while running LinuxTest._setup_test()\n" +
             format_exc())
         self._debug_fail()
         self._cleanup_test()
         return False
     return True
예제 #4
0
 def _setup_test(self):
     try:
         super()._setup_test()
         test = "/tmp/tests/" + self._name
         compose = "/tmp/tests/" + self._name + "/swarm.yml"
         example_data = "./examples/" + self._name + "/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-swarm.sh"
         if isfile(setup):
             proc = run("sudo ./setup-swarm.sh", cwd=test, shell=True)
             if proc.returncode != 0:
                 raise (Exception("setup-swarm failed"))
         # if isdir(example_data) :
         # for cp_dir in listdir(example_data) :
         # if isdir(join(example_data, cp_dir)) :
         # if isdir(join("/tmp/bw-data", cp_dir)) :
         # run("sudo rm -rf " + join("/tmp/bw-data", cp_dir), shell=True)
         # copytree(join(example_data, cp_dir), join("/tmp/bw-data", cp_dir))
         proc = run('docker stack deploy -c swarm.yml "' + self._name + '"',
                    shell=True,
                    cwd=test)
         if proc.returncode != 0:
             raise (Exception("docker stack deploy failed"))
         i = 0
         healthy = False
         while i < self._timeout:
             proc = run('docker stack services --format "{{ .Name }}" ' +
                        self._name,
                        cwd="/tmp/swarm",
                        shell=True,
                        capture_output=True)
             if proc.returncode != 0:
                 raise (
                     Exception("swarm stack is not healthy (cmd1 failed)"))
             all_healthy = True
             for service in proc.stdout.decode().splitlines():
                 proc2 = run(
                     'docker service ps --format "{{ .CurrentState }}" ' +
                     service,
                     cwd="/tmp/swarm",
                     shell=True,
                     capture_output=True)
                 if proc2.returncode != 0:
                     raise (Exception(
                         "swarm stack is not healthy (cmd2 failed)"))
                 if not "Running" in proc2.stdout.decode():
                     all_healthy = False
                     break
             if all_healthy:
                 healthy = True
                 break
             sleep(1)
             i += 1
         if not healthy:
             raise (Exception("swarm stack is not healthy"))
     except:
         log(
             "SWARM", "❌",
             "exception while running SwarmTest._setup_test()\n" +
             format_exc())
         self._cleanup_test()
         return False
     return True