alembic-runner 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/PKG-INFO +1 -1
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/pyproject.toml +1 -1
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/src/alembic_runner/__init__.py +1 -1
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/src/alembic_runner/runner.py +9 -3
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/tests/fixtures/fake_alembic.py +1 -1
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/tests/test_pipeline.py +7 -4
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/tests/test_runner.py +16 -4
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/tests/test_units.py +10 -2
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/.gitignore +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/LICENSE +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/README.md +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/src/alembic_runner/backend.py +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/src/alembic_runner/hosting.py +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/src/alembic_runner/pipeline.py +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/src/alembic_runner/plan.py +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/src/alembic_runner/review.py +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/src/alembic_runner/status.py +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/src/alembic_runner/workspace.py +0 -0
- {alembic_runner-0.2.0 → alembic_runner-0.3.0}/tests/fixtures/store_adapter.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: alembic-runner
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: run alembic plan, review and apply from a host application
|
|
5
5
|
Project-URL: Homepage, https://github.com/cyberwitchery/alembic-sot-plugins
|
|
6
6
|
Project-URL: Repository, https://github.com/cyberwitchery/alembic-sot-plugins
|
|
@@ -15,7 +15,7 @@ from .plan import ApplyReport, DocumentError, DriftReport, Plan, sha256
|
|
|
15
15
|
from .workspace import Workspace
|
|
16
16
|
|
|
17
17
|
# pre-1.0, a minor release may break the cli, so the range stops at the next minor.
|
|
18
|
-
SUPPORTED = ((0,
|
|
18
|
+
SUPPORTED = ((0, 12, 0), (0, 13, 0))
|
|
19
19
|
|
|
20
20
|
# what a run inherits from the worker. everything else is built per run, so the
|
|
21
21
|
# host's own secrets (django SECRET_KEY, database passwords) never reach alembic.
|
|
@@ -36,6 +36,9 @@ PASSTHROUGH_ENV = (
|
|
|
36
36
|
|
|
37
37
|
OUTPUT_LIMIT = 1 << 20
|
|
38
38
|
|
|
39
|
+
# what `plan --report` exits with when the target has drifted.
|
|
40
|
+
DRIFT_EXIT = 2
|
|
41
|
+
|
|
39
42
|
_VERSION = re.compile(r"^alembic (\d+)\.(\d+)\.(\d+)\b")
|
|
40
43
|
|
|
41
44
|
|
|
@@ -232,7 +235,9 @@ class Runner:
|
|
|
232
235
|
if sha256(path.read_bytes()) != expected_sha256:
|
|
233
236
|
raise RunnerError("the plan written for apply does not match the approved hash")
|
|
234
237
|
out = ws.run_dir(run) / "apply.json"
|
|
235
|
-
|
|
238
|
+
# the stale check before apply is ours: it compares against the approved
|
|
239
|
+
# plan with the flow's own flags, which alembic's check cannot see.
|
|
240
|
+
args = ["apply", "-p", str(path), "-o", str(out), "--no-stale-check", *config]
|
|
236
241
|
if flow.allow_delete:
|
|
237
242
|
args.append("--allow-delete")
|
|
238
243
|
completed = self._run(flow, args)
|
|
@@ -250,7 +255,8 @@ class Runner:
|
|
|
250
255
|
args = ["plan", "-f", str(inventory), "--report", "-o", str(out)]
|
|
251
256
|
args += config
|
|
252
257
|
completed = self._run(flow, args)
|
|
253
|
-
|
|
258
|
+
# `--report` exits 2 when it finds drift: that is a result, not a failure
|
|
259
|
+
if completed.exit_code not in (0, DRIFT_EXIT):
|
|
254
260
|
return DriftOutcome(completed, error=completed.describe())
|
|
255
261
|
try:
|
|
256
262
|
return DriftOutcome(completed, report=DriftReport.from_bytes(out.read_bytes()))
|
|
@@ -54,7 +54,7 @@ rules:
|
|
|
54
54
|
emit:
|
|
55
55
|
type: dcim.site
|
|
56
56
|
key: { slug: "${key.slug}" }
|
|
57
|
-
attrs: { name: "
|
|
57
|
+
attrs: { name: "m-${key.slug}", slug: "${key.slug}" }
|
|
58
58
|
"""
|
|
59
59
|
|
|
60
60
|
|
|
@@ -194,10 +194,13 @@ class PipelineTests(unittest.TestCase):
|
|
|
194
194
|
self.assertEqual(self.plan("2").status, S.NO_CHANGES)
|
|
195
195
|
|
|
196
196
|
def test_a_map_spec_is_relative_to_the_root(self):
|
|
197
|
-
files = {"schemas/inv.yaml": INVENTORY, "maps/
|
|
198
|
-
planned = self.plan("1", files=files, entry="schemas/inv.yaml", map_spec="maps/
|
|
197
|
+
files = {"schemas/inv.yaml": INVENTORY, "maps/sites.yaml": MAP}
|
|
198
|
+
planned = self.plan("1", files=files, entry="schemas/inv.yaml", map_spec="maps/sites.yaml")
|
|
199
199
|
self.assertEqual(planned.status, S.AWAITING_APPROVAL, planned.fields.get("error"))
|
|
200
|
-
|
|
200
|
+
derived = json.loads(planned.fields["input"][DERIVED_ENTRY])
|
|
201
|
+
self.assertEqual(
|
|
202
|
+
[o["attrs"] for o in derived["objects"]], [{"name": "m-fra1", "slug": "fra1"}]
|
|
203
|
+
)
|
|
201
204
|
|
|
202
205
|
|
|
203
206
|
if __name__ == "__main__":
|
|
@@ -8,6 +8,7 @@ from pathlib import Path
|
|
|
8
8
|
from unittest import mock
|
|
9
9
|
|
|
10
10
|
from alembic_runner import Backend, Flow, Plan, Runner, RunnerError
|
|
11
|
+
from alembic_runner.runner import PASSTHROUGH_ENV
|
|
11
12
|
|
|
12
13
|
FIXTURES = Path(__file__).parent / "fixtures"
|
|
13
14
|
|
|
@@ -56,8 +57,11 @@ class FakeBinaryTests(unittest.TestCase):
|
|
|
56
57
|
with mock.patch.dict(os.environ, {"SECRET_KEY": "django", "DB_PASSWORD": "pw"}):
|
|
57
58
|
self.runner.plan(self.flow, "9", self.inventory)
|
|
58
59
|
env = self.record()["env"]
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
# the interpreter running the fake binary adds its own locale and, on
|
|
61
|
+
# macOS, CoreFoundation variables; anything else must come from the runner.
|
|
62
|
+
platform = {"LC_CTYPE", "__CF_USER_TEXT_ENCODING"}
|
|
63
|
+
allowed = {"HOME", "ALEMBIC_STATE_BACKEND", "NETBOX_TOKEN", *PASSTHROUGH_ENV, *platform}
|
|
64
|
+
self.assertLessEqual(set(env), allowed)
|
|
61
65
|
self.assertEqual(env["NETBOX_TOKEN"], "secret")
|
|
62
66
|
self.assertEqual(env["ALEMBIC_STATE_BACKEND"], "local")
|
|
63
67
|
self.assertEqual(env["HOME"], str(self.tmp / "work" / "flows" / "1"))
|
|
@@ -108,9 +112,17 @@ class FakeBinaryTests(unittest.TestCase):
|
|
|
108
112
|
with self.assertRaises(RunnerError):
|
|
109
113
|
self.runner.apply(self.flow, "9", plan, "0" * 64)
|
|
110
114
|
|
|
115
|
+
def test_apply_leaves_the_stale_check_to_the_runner(self):
|
|
116
|
+
# the runner checks against the approved plan with the flow's flags first
|
|
117
|
+
plan = Plan.from_bytes(b'{"ops": []}')
|
|
118
|
+
self.runner.apply(self.flow, "9", plan, plan.sha256)
|
|
119
|
+
argv = self.record()["argv"]
|
|
120
|
+
self.assertEqual(argv[:3], ["apply", "-p", argv[2]])
|
|
121
|
+
self.assertIn("--no-stale-check", argv)
|
|
122
|
+
|
|
111
123
|
def test_version_range(self):
|
|
112
|
-
self.assertEqual(self.runner.check_version(), "0.
|
|
113
|
-
for text in ("alembic 0.
|
|
124
|
+
self.assertEqual(self.runner.check_version(), "0.12.0")
|
|
125
|
+
for text in ("alembic 0.11.0", "alembic 0.13.0", "something else"):
|
|
114
126
|
self.fake.with_suffix(".version").write_text(text)
|
|
115
127
|
with self.assertRaises(RunnerError, msg=text):
|
|
116
128
|
self.runner.check_version()
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import hashlib
|
|
1
2
|
import json
|
|
2
3
|
import stat
|
|
3
4
|
import tempfile
|
|
@@ -97,7 +98,7 @@ class PlanTests(unittest.TestCase):
|
|
|
97
98
|
|
|
98
99
|
def test_sha256_is_of_the_bytes(self):
|
|
99
100
|
raw = plan_bytes([CREATE])
|
|
100
|
-
self.assertEqual(
|
|
101
|
+
self.assertEqual(Plan.from_bytes(raw).sha256, hashlib.sha256(raw).hexdigest())
|
|
101
102
|
self.assertNotEqual(Plan.from_bytes(raw).sha256, Plan.from_bytes(raw + b" ").sha256)
|
|
102
103
|
|
|
103
104
|
def test_rejects_non_plans(self):
|
|
@@ -172,7 +173,14 @@ class BackendTests(unittest.TestCase):
|
|
|
172
173
|
def test_state_env(self):
|
|
173
174
|
self.assertEqual(StateStore().env("flow-1"), {"ALEMBIC_STATE_BACKEND": "local"})
|
|
174
175
|
pg = StateStore.from_settings({"backend": "postgres", "postgres_url": "postgres://x"})
|
|
175
|
-
self.assertEqual(
|
|
176
|
+
self.assertEqual(
|
|
177
|
+
pg.env("flow-1"),
|
|
178
|
+
{
|
|
179
|
+
"ALEMBIC_STATE_BACKEND": "postgres",
|
|
180
|
+
"ALEMBIC_STATE_POSTGRES_URL": "postgres://x",
|
|
181
|
+
"ALEMBIC_STATE_KEY": "flow-1",
|
|
182
|
+
},
|
|
183
|
+
)
|
|
176
184
|
with self.assertRaises(BackendError):
|
|
177
185
|
StateStore("postgres")
|
|
178
186
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|