From 6b3b5e706e9cb63035a1ab4fcc501dc2ac01f018 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sat, 30 May 2020 02:25:37 +0200
Subject: [PATCH] jenkins-community-slave: use requests library to download
 slave.jar

Do not mix two different HTTP libraries in one script. This fixes a
warning:

/var/lib/jenkins/slave.py:82: DeprecationWarning: URLopener style of invoking requests is deprecated. Use newer urlopen functions/methods

This simple implementation has the disadvantage that it stores the whole
file in RAM, but this isn't an issue for the 1.5MB slave.jar.
---
 contrib/ci/jenkins-community-slave/slave.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/ci/jenkins-community-slave/slave.py b/contrib/ci/jenkins-community-slave/slave.py
index fdb61f6ef..7efa1f2e4 100644
--- a/contrib/ci/jenkins-community-slave/slave.py
+++ b/contrib/ci/jenkins-community-slave/slave.py
@@ -2,7 +2,6 @@ from jenkins import Jenkins, JenkinsError, NodeLaunchMethod
 import os
 import signal
 import sys
-import urllib.request
 import subprocess
 import shutil
 import requests
@@ -34,8 +33,9 @@ def slave_download(target):
     if os.path.isfile(slave_jar):
         os.remove(slave_jar)
 
-    loader = urllib.request.URLopener()
-    loader.retrieve(os.environ['JENKINS_URL'] + '/jnlpJars/slave.jar', '/var/lib/jenkins/slave.jar')
+    r = requests.get(os.environ['JENKINS_URL'] + '/jnlpJars/slave.jar')
+    with open('/var/lib/jenkins/slave.jar', 'wb') as f:
+        f.write(r.content)
 
 def slave_run(slave_jar, jnlp_url):
     params = [ 'java', '-jar', slave_jar, '-jnlpUrl', jnlp_url ]
-- 
GitLab