Commit 9b599b47 authored by Jérome Perrin's avatar Jérome Perrin

testcase: use partition's python for getPromisePluginParameterDict

parent 151be649
Pipeline #17931 failed with stage
in 0 seconds
...@@ -45,7 +45,8 @@ from six.moves.configparser import ConfigParser ...@@ -45,7 +45,8 @@ from six.moves.configparser import ConfigParser
from supervisor import xmlrpc from supervisor import xmlrpc
from slapos.grid.utils import (md5digest, getCleanEnvironment, from slapos.grid.utils import (md5digest, getCleanEnvironment,
SlapPopen, dropPrivileges, updateFile) SlapPopen, dropPrivileges, updateFile,
getPythonExecutableFromSoftwarePath)
from slapos.grid import utils # for methods that could be mocked, access them through the module from slapos.grid import utils # for methods that could be mocked, access them through the module
from slapos.slap.slap import NotFoundError from slapos.slap.slap import NotFoundError
from slapos.grid.svcbackend import getSupervisorRPC from slapos.grid.svcbackend import getSupervisorRPC
...@@ -472,7 +473,7 @@ class Partition(object): ...@@ -472,7 +473,7 @@ class Partition(object):
self.instance_min_free_space = instance_min_free_space self.instance_min_free_space = instance_min_free_space
self.instance_python = self.getInstalledPythonExecutable() self.instance_python = getPythonExecutableFromSoftwarePath(self.software_path)
def check_free_space(self): def check_free_space(self):
...@@ -707,7 +708,7 @@ class Partition(object): ...@@ -707,7 +708,7 @@ class Partition(object):
debug=self.buildout_debug) debug=self.buildout_debug)
self.generateSupervisorConfigurationFile() self.generateSupervisorConfigurationFile()
self.createRetentionLockDelay() self.createRetentionLockDelay()
self.instance_python = self.getInstalledPythonExecutable() self.instance_python = getPythonExecutableFromSoftwarePath(self.software_path)
def generateSupervisorConfiguration(self): def generateSupervisorConfiguration(self):
""" """
...@@ -1046,15 +1047,3 @@ class Partition(object): ...@@ -1046,15 +1047,3 @@ class Partition(object):
return float(date_file_path.read()) return float(date_file_path.read())
else: else:
return None return None
def getInstalledPythonExecutable(self):
"""
Return the path of the python executable installed for the SR of this instance.
"""
try:
with open(os.path.join(self.software_path, 'bin', 'buildout')) as f:
shebang = f.readline()
except OSError:
return
if shebang.startswith('#!'):
return shebang[2:].split(None, 1)[0]
...@@ -164,6 +164,20 @@ def md5digest(url): ...@@ -164,6 +164,20 @@ def md5digest(url):
return hashlib.md5(url.encode('utf-8')).hexdigest() return hashlib.md5(url.encode('utf-8')).hexdigest()
def getPythonExecutableFromSoftwarePath(software_path):
"""
Return the path of the python executable installed for the software release
installed as `software_path`.
"""
try:
with open(os.path.join(software_path, 'bin', 'buildout')) as f:
shebang = f.readline()
except OSError:
return
if shebang.startswith('#!'):
return shebang[2:].split(None, 1)[0]
def getCleanEnvironment(logger, home_path='/tmp'): def getCleanEnvironment(logger, home_path='/tmp'):
changed_env = {} changed_env = {}
removed_env = [] removed_env = []
......
...@@ -41,6 +41,8 @@ from contextlib import closing ...@@ -41,6 +41,8 @@ from contextlib import closing
from six.moves import BaseHTTPServer from six.moves import BaseHTTPServer
from six.moves import urllib_parse from six.moves import urllib_parse
from ..grid.utils import getPythonExecutableFromSoftwarePath
try: try:
import typing import typing
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
...@@ -77,8 +79,12 @@ def getPromisePluginParameterDict(filepath): ...@@ -77,8 +79,12 @@ def getPromisePluginParameterDict(filepath):
This allow to check that monitoring plugin are using a proper config. This allow to check that monitoring plugin are using a proper config.
""" """
executable = getPythonExecutableFromSoftwarePath(
os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(filepath))),
'software_release'))
extra_config_dict_json = subprocess.check_output([ extra_config_dict_json = subprocess.check_output([
sys.executable, executable,
"-c", "-c",
""" """
import json, sys import json, sys
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment