Commit fe38481f authored by Lucas Carvalho's avatar Lucas Carvalho

Use utils in the proper way to be able to mock the methods.

If we import the functions directly we are not able to mock the method
it in the proper way as in the previous commit:
 - 2cb7a0f5
parent 2cb7a0f5
...@@ -35,9 +35,7 @@ import tempfile ...@@ -35,9 +35,7 @@ import tempfile
from supervisor import xmlrpc from supervisor import xmlrpc
import xmlrpclib import xmlrpclib
import pwd import pwd
from utils import launchBuildout, getCleanEnvironment,\ import utils
dropPrivileges, bootstrapBuildout, updateFile,\
getSoftwareUrlHash, SlapPopen
from svcbackend import getSupervisorRPC from svcbackend import getSupervisorRPC
from exception import BuildoutFailedError, WrongPermissionError, \ from exception import BuildoutFailedError, WrongPermissionError, \
PathDoesNotExistError PathDoesNotExistError
...@@ -55,7 +53,7 @@ class Software(object): ...@@ -55,7 +53,7 @@ class Software(object):
self.url = url self.url = url
self.software_root = software_root self.software_root = software_root
self.software_path = os.path.join(self.software_root, self.software_path = os.path.join(self.software_root,
getSoftwareUrlHash(self.url)) utils.getSoftwareUrlHash(self.url))
self.buildout = buildout self.buildout = buildout
self.logger = logging.getLogger('BuildoutManager') self.logger = logging.getLogger('BuildoutManager')
self.console = console self.console = console
...@@ -98,10 +96,10 @@ class Software(object): ...@@ -98,10 +96,10 @@ class Software(object):
buildout_option % ('networkcache:', value)) buildout_option % ('networkcache:', value))
buildout_parameter_list.extend(['-c', self.url]) buildout_parameter_list.extend(['-c', self.url])
bootstrapBuildout(self.software_path, self.buildout, utils.bootstrapBuildout(self.software_path, self.buildout,
additional_buildout_parametr_list=buildout_parameter_list, additional_buildout_parametr_list=buildout_parameter_list,
console=self.console) console=self.console)
launchBuildout(self.software_path, utils.launchBuildout(self.software_path,
os.path.join(self.software_path, 'bin', 'buildout'), os.path.join(self.software_path, 'bin', 'buildout'),
additional_buildout_parametr_list=buildout_parameter_list, additional_buildout_parametr_list=buildout_parameter_list,
console=self.console) console=self.console)
...@@ -255,9 +253,9 @@ class Partition(object): ...@@ -255,9 +253,9 @@ class Partition(object):
kw = dict() kw = dict()
if not self.console: if not self.console:
kw.update(stdout=subprocess.PIPE, stderr=subprocess.STDOUT) kw.update(stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
process_handler = SlapPopen(invocation_list, process_handler = utils.SlapPopen(invocation_list,
preexec_fn=lambda: dropPrivileges(uid, gid), cwd=self.instance_path, preexec_fn=lambda: utils.dropPrivileges(uid, gid), cwd=self.instance_path,
env=getCleanEnvironment(pwd.getpwuid(uid).pw_dir), **kw) env=utils.getCleanEnvironment(pwd.getpwuid(uid).pw_dir), **kw)
result_std = process_handler.communicate()[0] result_std = process_handler.communicate()[0]
if self.console: if self.console:
result_std = 'Please consult messages above.' result_std = 'Please consult messages above.'
...@@ -269,12 +267,12 @@ class Partition(object): ...@@ -269,12 +267,12 @@ class Partition(object):
if not os.path.exists(buildout_binary): if not os.path.exists(buildout_binary):
# use own buildout generation # use own buildout generation
bootstrapBuildout(self.instance_path, self.buildout, utils.bootstrapBuildout(self.instance_path, self.buildout,
['buildout:bin-directory=%s'% os.path.join(self.instance_path, ['buildout:bin-directory=%s'% os.path.join(self.instance_path,
'sbin')], console=self.console) 'sbin')], console=self.console)
buildout_binary = os.path.join(self.instance_path, 'sbin', 'buildout') buildout_binary = os.path.join(self.instance_path, 'sbin', 'buildout')
# Launches buildout # Launches buildout
launchBuildout(self.instance_path, utils.launchBuildout(self.instance_path,
buildout_binary, console=self.console) buildout_binary, console=self.console)
# Generates supervisord configuration file from template # Generates supervisord configuration file from template
self.logger.info("Generating supervisord config file from template...") self.logger.info("Generating supervisord config file from template...")
...@@ -314,7 +312,7 @@ class Partition(object): ...@@ -314,7 +312,7 @@ class Partition(object):
HOME=pwd.getpwuid(uid).pw_dir, HOME=pwd.getpwuid(uid).pw_dir,
USER=pwd.getpwuid(uid).pw_name, USER=pwd.getpwuid(uid).pw_name,
) )
updateFile(self.supervisord_partition_configuration_path, utils.updateFile(self.supervisord_partition_configuration_path,
partition_supervisor_configuration) partition_supervisor_configuration)
self.updateSupervisor() self.updateSupervisor()
...@@ -361,9 +359,9 @@ class Partition(object): ...@@ -361,9 +359,9 @@ class Partition(object):
kw = dict() kw = dict()
if not self.console: if not self.console:
kw.update(stdout=subprocess.PIPE, stderr=subprocess.STDOUT) kw.update(stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
process_handler = SlapPopen([destroy_executable_location], process_handler = utils.SlapPopen([destroy_executable_location],
preexec_fn=lambda: dropPrivileges(uid, gid), cwd=self.instance_path, preexec_fn=lambda: utils.dropPrivileges(uid, gid), cwd=self.instance_path,
env=getCleanEnvironment(pwd.getpwuid(uid).pw_dir), **kw) env=utils.getCleanEnvironment(pwd.getpwuid(uid).pw_dir), **kw)
result_std = process_handler.communicate()[0] result_std = process_handler.communicate()[0]
if self.console: if self.console:
result_std = 'Please consult messages above' result_std = 'Please consult messages above'
......
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