summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-09-17 08:51:58 +0300
committerLars Wirzenius <liw@liw.fi>2018-09-17 08:51:58 +0300
commite61c54196ead96b7efcdc0794ced2314de26d030 (patch)
treecd1eb6aefae89da0a70ff648fa185b614995a406
parent4519bdb40920bdec5d2d09084da52e37ea4d570d (diff)
downloadick2-e61c54196ead96b7efcdc0794ced2314de26d030.tar.gz
Change: worker-manager gets APT server from controller
-rw-r--r--NEWS7
-rw-r--r--ick2/actions.py19
-rw-r--r--ick2/client.py6
-rw-r--r--ick2/client_tests.py14
-rw-r--r--ick2/controllerapi.py3
-rw-r--r--ick2/versionapi.py5
-rw-r--r--ick2/versionapi_tests.py5
-rw-r--r--ick_controller.py2
-rw-r--r--yarns/900-local.yarn1
9 files changed, 61 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 188c00b..170b67e 100644
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,13 @@ Version 0.53.2+git, not yet released
to make it easier to run commands from Python code. It's a small
wrapper around `subporocess.run()`.
+* The worker-manager now creates a temporary dput configuration file
+ when it runs dput. Previously it expected a global configuration to
+ exist. This change is motivated by wanting to make worker-manager
+ configuration not have a hidden depency on dput configuration. The
+ controller now reports the APT server it expects the workers to use,
+ in the /version endpoint.
+
Version 0.53.2, released 2018-07-18
------------------------------------
diff --git a/ick2/actions.py b/ick2/actions.py
index daab0e5..0c4aa7f 100644
--- a/ick2/actions.py
+++ b/ick2/actions.py
@@ -597,11 +597,28 @@ class DputAction(Action): # pragma: no cover
env = self.get_env()
workspace = env.get_workspace_directory()
- argv = ['sh', '-c', 'dput ick *.changes']
+ apt_server = self._cc.get_apt_server()
+ config = self.configure_dput(apt_server)
+ argv = ['sh', '-c', 'dput -c {} ick *.changes'.format(config)]
exit_code = env.host_runcmd(argv, cwd=workspace)
env.report(exit_code, 'dput finished (exit code %d)\n' % exit_code)
+ os.remove(config)
return exit_code
+ def configure_dput(self, apt_server):
+ fd, filename = tempfile.mkstemp()
+ os.close(fd)
+ with open(filename, 'w') as f:
+ f.write('[ick]\n')
+ f.write('login = incoming\n')
+ f.write('fqdn = {}\n'.format(apt_server))
+ f.write('method = scp\n')
+ f.write('incoming = /srv/apt/incoming\n')
+ f.write('allow_unsigned_uploads = 1\n')
+ f.write('check_version = 0\n')
+ f.write('run_dinstall = 0\n')
+ return filename
+
class NotifyAction(Action): # pragma: no cover
diff --git a/ick2/client.py b/ick2/client.py
index 2d54bc8..e25665c 100644
--- a/ick2/client.py
+++ b/ick2/client.py
@@ -163,6 +163,12 @@ class ControllerClient:
url = self.url('/version')
return self._api.get_dict(url)
+ def get_apt_server(self):
+ version = self.get_version()
+ server = version.get('apt-server')
+ logging.info('APT server: %r', server)
+ return server
+
def get_artifact_store_url(self):
version = self.get_version()
url = version.get('artifact_store')
diff --git a/ick2/client_tests.py b/ick2/client_tests.py
index adba2dc..24b9227 100644
--- a/ick2/client_tests.py
+++ b/ick2/client_tests.py
@@ -174,6 +174,20 @@ class ControllerClientTests(unittest.TestCase):
self.session.response = FakeResponse(200)
self.assertEqual(self.controller.report_work(work), None)
+ def test_get_apt_server_raises_exception_on_error(self):
+ self.session.response = FakeResponse(400)
+ with self.assertRaises(ick2.HttpError):
+ self.controller.get_apt_server()
+
+ def test_get_apt_server_succeeds(self):
+ server = 'apt.example.com'
+ version = {
+ 'apt-server': server,
+ }
+ self.session.response = FakeResponse(
+ 200, body=json.dumps(version), content_type=json_type)
+ self.assertEqual(self.controller.get_apt_server(), server)
+
def test_get_artifact_store_url_raises_exception_on_error(self):
self.session.response = FakeResponse(400)
with self.assertRaises(ick2.HttpError):
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py
index 1bc830d..b28e1f7 100644
--- a/ick2/controllerapi.py
+++ b/ick2/controllerapi.py
@@ -22,6 +22,9 @@ class ControllerAPI:
self._state = state
self._apis = {}
+ def set_apt_server(self, domain): # pragma: no cover
+ self._set_url('set_apt_server', domain)
+
def set_artifact_store_url(self, url): # pragma: no cover
self._set_url('set_artifact_store_url', url)
diff --git a/ick2/versionapi.py b/ick2/versionapi.py
index da8cf62..ec858f5 100644
--- a/ick2/versionapi.py
+++ b/ick2/versionapi.py
@@ -20,10 +20,14 @@ class VersionAPI(ick2.APIbase):
def __init__(self, state):
super().__init__(state)
+ self._apt_server = None
self._artifact_store_url = None
self._auth_url = None
self._notify_url = None
+ def set_apt_server(self, domain):
+ self._apt_server = domain
+
def set_artifact_store_url(self, url):
self._artifact_store_url = url
@@ -46,6 +50,7 @@ class VersionAPI(ick2.APIbase):
def get_version(self, **kwargs):
return {
'version': ick2.__version__,
+ 'apt_server': self._apt_server,
'artifact_store': self._artifact_store_url,
'auth_url': self._auth_url,
'notify_url': self._notify_url,
diff --git a/ick2/versionapi_tests.py b/ick2/versionapi_tests.py
index 76879ed..6dc8f54 100644
--- a/ick2/versionapi_tests.py
+++ b/ick2/versionapi_tests.py
@@ -22,18 +22,23 @@ import ick2
class VersionAPITests(unittest.TestCase):
def test_returns_version_correcly(self):
+ apt = 'apt.example.com'
bloburl = 'https://blobs.example.com'
idpurl = 'https://idp.example.com'
notifyurl = 'https://notify.example.com'
+
api = ick2.VersionAPI(None)
+ api.set_apt_server(apt)
api.set_artifact_store_url(bloburl)
api.set_auth_url(idpurl)
api.set_notify_url(notifyurl)
+
response = api.get_version()
self.assertEqual(
response,
{
'version': ick2.__version__,
+ 'apt_server': apt,
'artifact_store': bloburl,
'auth_url': idpurl,
'notify_url': notifyurl,
diff --git a/ick_controller.py b/ick_controller.py
index 4c952af..2090b4e 100644
--- a/ick_controller.py
+++ b/ick_controller.py
@@ -49,6 +49,7 @@ default_config = {
'artifact-store': None,
'auth-url': None,
'notify-url': None,
+ 'apt-server': None,
}
@@ -96,6 +97,7 @@ def main():
state.set_directory(config['statedir'])
api = ick2.ControllerAPI(state)
+ api.set_apt_server(config['apt-server'])
api.set_artifact_store_url(config['artifact-store'])
api.set_auth_url(config['auth-url'])
api.set_notify_url(config['notify-url'])
diff --git a/yarns/900-local.yarn b/yarns/900-local.yarn
index 6c83ce6..4a315ae 100644
--- a/yarns/900-local.yarn
+++ b/yarns/900-local.yarn
@@ -77,6 +77,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
},
],
'statedir': vars['statedir'],
+ 'apt-server': 'localhost',
'artifact-store': vars['artifact_store'],
'auth-url': vars['auth_url'],
'notify-url': vars['notify_url'],