예제 #1
0
def register_commands(c: Type[TestBase]):
    """
    Registers the default subcommands to the test class c.
    """
    class TestSetup(c):
        def main(self):
            self.setup()

    class TestRun(c):
        def main(self):
            self._run()

    class TestTeardown(c):
        def main(self):
            self.teardown()

    class TestBrowse(c):
        def main(self):
            self.browse()

    log.init_log()
    c.subcommand("setup", TestSetup)
    c.subcommand("run", TestRun)
    c.subcommand("teardown", TestTeardown)
    c.subcommand("browse", TestBrowse)
예제 #2
0
def main(test_class):
    log.init_log()

    class _TestMain(test_class, cli.Application):
        __doc__ = test_class.__doc__
        CALL_MAIN_IF_NESTED_COMMAND = False

        def main(self):
            self.init()
            try:
                self.setup()
                self._run()
            except Exception:
                traceback.print_exc()
                return 1
            finally:
                self.teardown()

    class _TestSetup(test_class, cli.Application):
        def main(self):
            self.init()
            try:
                self.setup()
            except Exception:
                traceback.print_exc()
                return 1

    class _TestRun(test_class, cli.Application):
        def main(self):
            self.init()
            try:
                self._run()
            except Exception:
                traceback.print_exc()
                return 1

    class _TestTeardown(test_class, cli.Application):
        def main(self):
            self.init()
            try:
                self.teardown()
            except Exception:
                traceback.print_exc()
                return 1

    _TestMain.subcommand("setup", _TestSetup)
    _TestMain.subcommand("run", _TestRun)
    _TestMain.subcommand("teardown", _TestTeardown)
    _TestMain.run()
예제 #3
0
파일: test.py 프로젝트: sciontime/scion
    def _http_endpoint(self, cs_config: LocalPath):
        with open(cs_config, 'r') as f:
            cfg = toml.load(f)
            return cfg['metrics']['prometheus']

    def _extract_skid(self, file: LocalPath):
        cert = local['openssl']['x509', '-in', file, '-noout', '-text']
        grep = local['grep']['-A1', 'Subject Key Identifier']
        search = cert | grep
        return search().split()[-1].replace(':', ' ').upper()

    def _disp_ip(self, cs_name: str):
        with open('gen/scion-dc.yml') as f:
            dc = yaml.load(f, Loader=yaml.FullLoader)
            networks = dc['services']['scion_disp_%s' % cs_name]['networks']
            for _, network in networks.items():
                if 'ipv6_address' in network:
                    return network['ipv6_address']
                return network['ipv4_address']


def rel(path: LocalPath):
    return path.relative_to(local.path('.'))


if __name__ == '__main__':
    init_log()
    Test.test_state = TestState(SCIONDocker(), DC())
    Test.run()
예제 #4
0
파일: test.py 프로젝트: chaehni/scion
    def _teardown(self):
        logs = self._docker_compose("logs")
        with open(self.test_state.artifacts / "logs" / "docker-compose.log",
                  "w") as f:
            f.write(logs)
        print(self._docker_compose("down", "-v"))


@Test.subcommand("setup")
class TestSetup(Test):
    def main(self):
        self._setup()


@Test.subcommand("run")
class TestRun(Test):
    def main(self):
        self._run()


@Test.subcommand("teardown")
class TestTeardown(Test):
    def main(self):
        self._teardown()


if __name__ == "__main__":
    log.init_log()
    Test.test_state = base.TestState(scion.SCIONDocker(), tools.DC())
    Test.run()