Merge lp:~allenap/maas/land-parallel into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 5688
Proposed branch: lp:~allenap/maas/land-parallel
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 160 lines (+29/-31)
3 files modified
Makefile (+10/-6)
src/maastesting/fixtures.py (+7/-10)
src/maastesting/tests/test_fixtures.py (+12/-15)
To merge this branch: bzr merge lp:~allenap/maas/land-parallel
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+316232@code.launchpad.net

Commit message

Gate landings using test.parallel.

Description of the change

A fix was needed to MAASRootFixture, to make it always copy from run-skel instead of the currently defined MAAS_ROOT.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Tested this locally. Just pulled the branch and did "make test", everything worked. So much faster! Thanks for this work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2017-02-02 11:52:19 +0000
3+++ Makefile 2017-02-02 14:26:32 +0000
4@@ -227,7 +227,10 @@
5 test+lxd: lxd $(strip $(test-scripts))
6 utilities/isolated-make-test
7
8-test: $(strip $(test-scripts))
9+test: bin/test.parallel
10+ @bin/test.parallel
11+
12+test-serial: $(strip $(test-scripts))
13 @bin/maas-region makemigrations --dry-run --exit && exit 1 ||:
14 @$(RM) coverage.data .failed
15 $(foreach test,$^,$(test-template);)
16@@ -263,8 +266,8 @@
17 @bin/maas-region makemigrations --dry-run --exit && exit 1 ||:
18 @bin/test.rack --stop
19
20-test+coverage: export NOSE_WITH_COVERAGE = 1
21-test+coverage: test
22+test-serial+coverage: export NOSE_WITH_COVERAGE = 1
23+test-serial+coverage: test-serial
24
25 coverage-report: coverage/index.html
26 sensible-browser $< > /dev/null 2>&1 &
27@@ -280,8 +283,8 @@
28 --title "MAAS r$(revno)" --directory $(@D)
29
30 coverage.data:
31- @$(error Use `$(MAKE) test+coverage` to generate coverage data, \
32- or invoke a test script using the `--with-coverage` flag)
33+ @$(error Use `$(MAKE) test-serial+coverage` to generate coverage \
34+ data, or invoke a test script using the `--with-coverage` flag)
35
36 lint: \
37 lint-py lint-py-complexity lint-py-imports \
38@@ -477,10 +480,11 @@
39 sudoers
40 syncdb
41 test
42- test+coverage
43 test+lxd
44 test-failed
45 test-initial-data
46+ test-serial
47+ test-serial+coverage
48 endef
49
50 #
51
52=== modified file 'src/maastesting/fixtures.py'
53--- src/maastesting/fixtures.py 2017-01-26 15:57:00 +0000
54+++ src/maastesting/fixtures.py 2017-02-02 14:26:32 +0000
55@@ -32,6 +32,7 @@
56
57 import fixtures
58 from fixtures import EnvironmentVariable
59+from maastesting import root
60 from testtools.monkey import MonkeyPatcher
61 from twisted.python.reflect import namedObject
62
63@@ -409,15 +410,11 @@
64 """
65
66 def _setUp(self):
67- super(MAASRootFixture, self)._setUp()
68- maasroot = os.environ.get("MAAS_ROOT")
69- if maasroot is None:
70- raise NotADirectoryError("MAAS_ROOT is not defined.")
71- elif os.path.isdir(maasroot):
72+ skel = Path(root).joinpath("run-skel")
73+ if skel.is_dir():
74 self.path = self.useFixture(TempDirectory()).join("run")
75 # Work only in `run`; reference the old $MAAS_ROOT.
76 etc = Path(self.path).joinpath("etc")
77- src = Path(maasroot)
78 # Create and populate $MAAS_ROOT/run/etc/{ntp,ntp.conf}. The
79 # `.keep` file is not strictly necessary, but it's created for
80 # consistency with the source tree's `run` directory.
81@@ -425,16 +422,16 @@
82 ntp.mkdir(parents=True)
83 ntp.joinpath(".keep").touch()
84 ntp_conf = etc.joinpath("ntp.conf")
85- ntp_conf.write_bytes(src.joinpath("etc", "ntp.conf").read_bytes())
86+ ntp_conf.write_bytes(skel.joinpath("etc", "ntp.conf").read_bytes())
87 # Create and populate $MAAS_ROOT/run/etc/maas.
88 maas = etc.joinpath("maas")
89 maas.mkdir(parents=True)
90 maas.joinpath("drivers.yaml").symlink_to(
91- src.joinpath("etc", "maas", "drivers.yaml").resolve())
92+ skel.joinpath("etc", "maas", "drivers.yaml").resolve())
93 maas.joinpath("templates").symlink_to(
94- src.joinpath("etc", "maas", "templates").resolve())
95+ skel.joinpath("etc", "maas", "templates").resolve())
96 # Update the environment.
97 self.useFixture(EnvironmentVariable("MAAS_ROOT", self.path))
98 else:
99 raise NotADirectoryError(
100- "MAAS_ROOT (%r) is not a directory." % maasroot)
101+ "Skeleton MAAS_ROOT (%s) is not a directory." % skel)
102
103=== modified file 'src/maastesting/tests/test_fixtures.py'
104--- src/maastesting/tests/test_fixtures.py 2017-01-26 15:57:00 +0000
105+++ src/maastesting/tests/test_fixtures.py 2017-02-02 14:26:32 +0000
106@@ -12,7 +12,10 @@
107 from unittest.mock import call
108
109 from fixtures import EnvironmentVariable
110-from maastesting import root
111+from maastesting import (
112+ fixtures as fixtures_module,
113+ root,
114+)
115 from maastesting.factory import factory
116 from maastesting.fixtures import (
117 CaptureStandardIO,
118@@ -256,34 +259,28 @@
119
120 def setUp(self):
121 super(TestMAASRootFixture, self).setUp()
122- self.maasroot = os.path.join(root, "run-skel")
123- self.useFixture(EnvironmentVariable("MAAS_ROOT", self.maasroot))
124+ self.skel = os.path.join(root, "run-skel")
125+ self.useFixture(EnvironmentVariable("MAAS_ROOT", "/"))
126
127 def test_creates_populates_and_removes_new_directory(self):
128 fixture = MAASRootFixture()
129 with fixture:
130 self.assertThat(fixture.path, PathExists())
131- self.assertThat(fixture.path, Not(SamePath(self.maasroot)))
132- files_expected = set(listdirs(self.maasroot))
133+ self.assertThat(fixture.path, Not(SamePath(self.skel)))
134+ files_expected = set(listdirs(self.skel))
135 files_observed = set(listdirs(fixture.path))
136 self.assertThat(files_observed, Equals(files_expected))
137 self.assertThat(fixture.path, Not(PathExists()))
138
139 def test_updates_MAAS_ROOT_in_the_environment(self):
140- self.assertThat(os.environ["MAAS_ROOT"], SamePath(self.maasroot))
141+ self.assertThat(os.environ["MAAS_ROOT"], Not(SamePath(self.skel)))
142 with MAASRootFixture() as fixture:
143 self.assertThat(os.environ["MAAS_ROOT"], SamePath(fixture.path))
144- self.assertThat(os.environ["MAAS_ROOT"], SamePath(self.maasroot))
145-
146- def test_breaks_when_MAAS_ROOT_is_not_defined(self):
147- fixture = MAASRootFixture()
148- del os.environ["MAAS_ROOT"]
149- error = self.assertRaises(NotADirectoryError, fixture._setUp)
150- self.assertThat(str(error), Equals("MAAS_ROOT is not defined."))
151+ self.assertThat(os.environ["MAAS_ROOT"], Not(SamePath(self.skel)))
152
153 def test_breaks_when_MAAS_ROOT_is_not_a_directory(self):
154+ self.patch(fixtures_module, "root", self.make_file())
155 fixture = MAASRootFixture()
156- os.environ["MAAS_ROOT"] = self.make_file()
157 error = self.assertRaises(NotADirectoryError, fixture._setUp)
158 self.assertThat(str(error), DocTestMatches(
159- "MAAS_ROOT (...) is not a directory."))
160+ "Skeleton MAAS_ROOT (...) is not a directory."))