Merge ~ack/maas:1922433-machine-resources-path-snap into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Alberto Donato
Approved revision: 26e66eef80809fef43d9480560cd183cb22dcdca
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:1922433-machine-resources-path-snap
Merge into: maas:master
Diff against target: 78 lines (+32/-4)
2 files modified
src/provisioningserver/rackdservices/http.py (+7/-2)
src/provisioningserver/rackdservices/tests/test_http.py (+25/-2)
Reviewer Review Type Date Requested Status
Björn Tillenius Approve
Review via email: mp+400623@code.launchpad.net

Commit message

LP #1922433 - snap: fix machine-resources path in nginx config

To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1

review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/provisioningserver/rackdservices/http.py b/src/provisioningserver/rackdservices/http.py
2index cc35ff6..e888c51 100644
3--- a/src/provisioningserver/rackdservices/http.py
4+++ b/src/provisioningserver/rackdservices/http.py
5@@ -7,6 +7,7 @@
6 from collections import defaultdict
7 from datetime import timedelta
8 import os
9+from pathlib import Path
10 import sys
11
12 import attr
13@@ -170,13 +171,17 @@ class RackHTTPService(TimerService):
14 def _configure(self, upstream_http):
15 """Update the HTTP configuration for the rack."""
16 template = load_template("http", "rackd.nginx.conf.template")
17+ machine_resources_prefix = snap.SnapPaths.from_environ().snap or Path(
18+ "/"
19+ )
20 try:
21 rendered = template.substitute(
22 {
23 "upstream_http": list(sorted(upstream_http)),
24 "resource_root": self._resource_root,
25- "machine_resources": snap.SnapPaths.from_environ().snap
26- or "/usr/share/maas",
27+ "machine_resources": str(
28+ machine_resources_prefix / "usr/share/maas"
29+ ),
30 }
31 )
32 except NameError as error:
33diff --git a/src/provisioningserver/rackdservices/tests/test_http.py b/src/provisioningserver/rackdservices/tests/test_http.py
34index 95e7e17..4d3069e 100644
35--- a/src/provisioningserver/rackdservices/tests/test_http.py
36+++ b/src/provisioningserver/rackdservices/tests/test_http.py
37@@ -1,9 +1,9 @@
38 # Copyright 2018 Canonical Ltd. This software is licensed under the
39 # GNU Affero General Public License version 3 (see the file LICENSE).
40
41-"""Tests for `provisioningserver.rackdservices.http`."""
42-
43
44+import os
45+from pathlib import Path
46 import random
47 from unittest.mock import ANY, Mock
48
49@@ -102,6 +102,29 @@ class TestRackHTTPService(MAASTestCase):
50 service.call = (service._tryUpdate, tuple(), {})
51 return service
52
53+ def test_configure_not_snap(self):
54+ tempdir = self.make_dir()
55+ nginx_conf = Path(tempdir) / "rackd.nginx.conf"
56+ service = self.make_startable_RackHTTPService(tempdir, None, reactor)
57+ self.patch(http, "compose_http_config_path").return_value = str(
58+ nginx_conf
59+ )
60+ service._configure(["region1.maas", "region2.maas"])
61+ self.assertIn("root /usr/share/maas;", nginx_conf.read_text())
62+
63+ def test_configure_in_snap(self):
64+ self.patch(os, "environ", {"SNAP": "/snap/maas/123"})
65+ tempdir = self.make_dir()
66+ nginx_conf = Path(tempdir) / "rackd.nginx.conf"
67+ service = self.make_startable_RackHTTPService(tempdir, None, reactor)
68+ self.patch(http, "compose_http_config_path").return_value = str(
69+ nginx_conf
70+ )
71+ service._configure(["region1.maas", "region2.maas"])
72+ self.assertIn(
73+ "root /snap/maas/123/usr/share/maas;", nginx_conf.read_text()
74+ )
75+
76 @inlineCallbacks
77 def test_getConfiguration_returns_configuration_object(self):
78 rpc_service, protocol = yield prepareRegion(self)

Subscribers

People subscribed via source and target branches