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
diff --git a/src/provisioningserver/rackdservices/http.py b/src/provisioningserver/rackdservices/http.py
index cc35ff6..e888c51 100644
--- a/src/provisioningserver/rackdservices/http.py
+++ b/src/provisioningserver/rackdservices/http.py
@@ -7,6 +7,7 @@
7from collections import defaultdict7from collections import defaultdict
8from datetime import timedelta8from datetime import timedelta
9import os9import os
10from pathlib import Path
10import sys11import sys
1112
12import attr13import attr
@@ -170,13 +171,17 @@ class RackHTTPService(TimerService):
170 def _configure(self, upstream_http):171 def _configure(self, upstream_http):
171 """Update the HTTP configuration for the rack."""172 """Update the HTTP configuration for the rack."""
172 template = load_template("http", "rackd.nginx.conf.template")173 template = load_template("http", "rackd.nginx.conf.template")
174 machine_resources_prefix = snap.SnapPaths.from_environ().snap or Path(
175 "/"
176 )
173 try:177 try:
174 rendered = template.substitute(178 rendered = template.substitute(
175 {179 {
176 "upstream_http": list(sorted(upstream_http)),180 "upstream_http": list(sorted(upstream_http)),
177 "resource_root": self._resource_root,181 "resource_root": self._resource_root,
178 "machine_resources": snap.SnapPaths.from_environ().snap182 "machine_resources": str(
179 or "/usr/share/maas",183 machine_resources_prefix / "usr/share/maas"
184 ),
180 }185 }
181 )186 )
182 except NameError as error:187 except NameError as error:
diff --git a/src/provisioningserver/rackdservices/tests/test_http.py b/src/provisioningserver/rackdservices/tests/test_http.py
index 95e7e17..4d3069e 100644
--- a/src/provisioningserver/rackdservices/tests/test_http.py
+++ b/src/provisioningserver/rackdservices/tests/test_http.py
@@ -1,9 +1,9 @@
1# Copyright 2018 Canonical Ltd. This software is licensed under the1# Copyright 2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Tests for `provisioningserver.rackdservices.http`."""
5
64
5import os
6from pathlib import Path
7import random7import random
8from unittest.mock import ANY, Mock8from unittest.mock import ANY, Mock
99
@@ -102,6 +102,29 @@ class TestRackHTTPService(MAASTestCase):
102 service.call = (service._tryUpdate, tuple(), {})102 service.call = (service._tryUpdate, tuple(), {})
103 return service103 return service
104104
105 def test_configure_not_snap(self):
106 tempdir = self.make_dir()
107 nginx_conf = Path(tempdir) / "rackd.nginx.conf"
108 service = self.make_startable_RackHTTPService(tempdir, None, reactor)
109 self.patch(http, "compose_http_config_path").return_value = str(
110 nginx_conf
111 )
112 service._configure(["region1.maas", "region2.maas"])
113 self.assertIn("root /usr/share/maas;", nginx_conf.read_text())
114
115 def test_configure_in_snap(self):
116 self.patch(os, "environ", {"SNAP": "/snap/maas/123"})
117 tempdir = self.make_dir()
118 nginx_conf = Path(tempdir) / "rackd.nginx.conf"
119 service = self.make_startable_RackHTTPService(tempdir, None, reactor)
120 self.patch(http, "compose_http_config_path").return_value = str(
121 nginx_conf
122 )
123 service._configure(["region1.maas", "region2.maas"])
124 self.assertIn(
125 "root /snap/maas/123/usr/share/maas;", nginx_conf.read_text()
126 )
127
105 @inlineCallbacks128 @inlineCallbacks
106 def test_getConfiguration_returns_configuration_object(self):129 def test_getConfiguration_returns_configuration_object(self):
107 rpc_service, protocol = yield prepareRegion(self)130 rpc_service, protocol = yield prepareRegion(self)

Subscribers

People subscribed via source and target branches