예제 #1
0
    def __init__(
        self,
        start_scripts: List[str],
        vlans: List[int],
        tests: str,
        out_dir: Path,
        keep_vm_state: bool = False,
    ):
        self.tests = tests
        self.out_dir = out_dir

        tmp_dir = get_tmp_dir()

        with rootlog.nested("start all VLans"):
            self.vlans = [VLan(nr, tmp_dir) for nr in vlans]

        def cmd(scripts: List[str]) -> Iterator[NixStartScript]:
            for s in scripts:
                yield NixStartScript(s)

        self.polling_conditions = []

        self.machines = [
            Machine(
                start_command=cmd,
                keep_vm_state=keep_vm_state,
                name=cmd.machine_name,
                tmp_dir=tmp_dir,
                callbacks=[self.check_polling_conditions],
                out_dir=self.out_dir,
            ) for cmd in cmd(start_scripts)
        ]
예제 #2
0
    def __init__(
        self,
        start_scripts: List[str],
        vlans: List[int],
        tests: str,
        keep_vm_state: bool = False,
    ):
        self.tests = tests

        tmp_dir = Path(os.environ.get("TMPDIR", tempfile.gettempdir()))
        tmp_dir.mkdir(mode=0o700, exist_ok=True)

        with rootlog.nested("start all VLans"):
            self.vlans = [VLan(nr, tmp_dir) for nr in vlans]

        def cmd(scripts: List[str]) -> Iterator[NixStartScript]:
            for s in scripts:
                yield NixStartScript(s)

        self.polling_conditions = []

        self.machines = [
            Machine(
                start_command=cmd,
                keep_vm_state=keep_vm_state,
                name=cmd.machine_name,
                tmp_dir=tmp_dir,
                callbacks=[self.check_polling_conditions],
            ) for cmd in cmd(start_scripts)
        ]
예제 #3
0
 def subtest(self, name: str) -> Iterator[None]:
     """Group logs under a given test name"""
     with rootlog.nested(name):
         try:
             yield
             return True
         except Exception as e:
             rootlog.error(f'Test "{name}" failed with error: "{e}"')
             raise e
예제 #4
0
파일: machine.py 프로젝트: rick68/nixpkgs
 def nested(self,
            msg: str,
            attrs: Dict[str, str] = {}) -> _GeneratorContextManager:
     my_attrs = {"machine": self.name}
     my_attrs.update(attrs)
     return rootlog.nested(msg, my_attrs)
예제 #5
0
 def __exit__(self, *_: Any) -> None:
     with rootlog.nested("cleanup"):
         for machine in self.machines:
             machine.release()
예제 #6
0
 def join_all(self) -> None:
     """Wait for all machines to shut down"""
     with rootlog.nested("wait for all VMs to finish"):
         for machine in self.machines:
             machine.wait_for_shutdown()
예제 #7
0
 def start_all(self) -> None:
     """Start all machines"""
     with rootlog.nested("start all VMs"):
         for machine in self.machines:
             machine.start()
예제 #8
0
 def test_script(self) -> None:
     """Run the test script"""
     with rootlog.nested("run the VM test script"):
         symbols = self.test_symbols()  # call eagerly
         exec(self.tests, symbols, None)