~andreserl/maas/lp1665143

« back to all changes in this revision

Viewing changes to src/maastesting/fixtures.py

Merged specify_scripts_commissioning into test_api.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
import fixtures
34
34
from fixtures import EnvironmentVariable
 
35
from maastesting import root
35
36
from testtools.monkey import MonkeyPatcher
36
37
from twisted.python.reflect import namedObject
37
38
 
409
410
    """
410
411
 
411
412
    def _setUp(self):
412
 
        super(MAASRootFixture, self)._setUp()
413
 
        maasroot = os.environ.get("MAAS_ROOT")
414
 
        if maasroot is None:
415
 
            raise NotADirectoryError("MAAS_ROOT is not defined.")
416
 
        elif os.path.isdir(maasroot):
 
413
        skel = Path(root).joinpath("run-skel")
 
414
        if skel.is_dir():
417
415
            self.path = self.useFixture(TempDirectory()).join("run")
418
416
            # Work only in `run`; reference the old $MAAS_ROOT.
419
417
            etc = Path(self.path).joinpath("etc")
420
 
            src = Path(maasroot)
421
418
            # Create and populate $MAAS_ROOT/run/etc/{ntp,ntp.conf}. The
422
419
            # `.keep` file is not strictly necessary, but it's created for
423
420
            # consistency with the source tree's `run` directory.
425
422
            ntp.mkdir(parents=True)
426
423
            ntp.joinpath(".keep").touch()
427
424
            ntp_conf = etc.joinpath("ntp.conf")
428
 
            ntp_conf.write_bytes(src.joinpath("etc", "ntp.conf").read_bytes())
 
425
            ntp_conf.write_bytes(skel.joinpath("etc", "ntp.conf").read_bytes())
429
426
            # Create and populate $MAAS_ROOT/run/etc/maas.
430
427
            maas = etc.joinpath("maas")
431
428
            maas.mkdir(parents=True)
432
429
            maas.joinpath("drivers.yaml").symlink_to(
433
 
                src.joinpath("etc", "maas", "drivers.yaml").resolve())
 
430
                skel.joinpath("etc", "maas", "drivers.yaml").resolve())
434
431
            maas.joinpath("templates").symlink_to(
435
 
                src.joinpath("etc", "maas", "templates").resolve())
 
432
                skel.joinpath("etc", "maas", "templates").resolve())
436
433
            # Update the environment.
437
434
            self.useFixture(EnvironmentVariable("MAAS_ROOT", self.path))
438
435
        else:
439
436
            raise NotADirectoryError(
440
 
                "MAAS_ROOT (%r) is not a directory." % maasroot)
 
437
                "Skeleton MAAS_ROOT (%s) is not a directory." % skel)