Commit 14da52c3 authored by Sebastien Robin's avatar Sebastien Robin Committed by Sebastien Robin

erp5-util/testnode : add test to check deletion of software

parent 4f02cf8c
......@@ -310,7 +310,7 @@ branch = foo
return []
test_node = self.getTestNode()
test_node.slapos_controler = SlapOSControler(self.working_directory,
test_node.config)
test_node.config, self.log)
node_test_suite = test_node.getNodeTestSuite('foo')
self.updateNodeTestSuiteData(node_test_suite)
node_test_suite.revision = 'dummy'
......@@ -457,3 +457,16 @@ branch = foo
process_manager = ProcessManager(log=self.log, max_timeout=1)
_checkCorrectStatus(0, *['sleep','0'])
_checkCorrectStatus(-15, *['sleep','2'])
def test_13_SlaposControlerResetSoftware(self):
test_node = self.getTestNode()
controler = SlapOSControler(self.working_directory,
test_node.config, self.log)
os.mkdir(controler.software_root)
file_name = 'AC_Ra\xc3\xadzertic\xc3\xa1ma'
non_ascii_file = open(os.path.join(controler.software_root, file_name), 'w')
non_ascii_file.close()
self.assertEquals([file_name], os.listdir(controler.software_root))
controler.software_root = unicode(controler.software_root)
controler._resetSoftware()
self.assertEquals([], os.listdir(controler.software_root))
......@@ -42,14 +42,24 @@ def createFolder(folder):
class SlapOSControler(object):
def __init__(self, working_directory, config):
def __init__(self, working_directory, config, log):
self.config = config
self.software_root = os.path.join(working_directory, 'soft')
self.instance_root = os.path.join(working_directory, 'inst')
self.slapos_config = os.path.join(working_directory, 'slapos.cfg')
self.proxy_database = os.path.join(working_directory, 'proxy.db')
self.log = log
def _resetSoftware(self):
self.log('SlapOSControler : GOING TO RESET ALL SOFTWARE : %r' %
(self.software_root,))
if os.path.exists(self.software_root):
shutil.rmtree(self.software_root)
os.mkdir(self.software_root)
os.chmod(self.software_root, 0750)
def initializeSlapOSControler(self, log, slapproxy_log=None, process_manager=None,
def initializeSlapOSControler(self, slapproxy_log=None, process_manager=None,
reset_software=False, software_path_list=None):
self.log = log
self.process_manager = process_manager
......@@ -91,11 +101,7 @@ class SlapOSControler(object):
computer = slap.registerComputer(config['computer_id'])
# Reset all previously generated software if needed
if reset_software:
log('SlapOSControler : GOING TO RESET ALL SOFTWARE : %r' % (self.software_root,))
if os.path.exists(self.software_root):
shutil.rmtree(self.software_root)
os.mkdir(self.software_root)
os.chmod(self.software_root, 0750)
self._resetSoftware()
instance_root = self.instance_root
if os.path.exists(instance_root):
# delete old paritions which may exists in order to not get its data
......
......@@ -81,6 +81,9 @@ def main(*args):
for key in ('slapos_directory', 'working_directory', 'test_suite_directory',
'log_directory', 'run_directory'):
d = CONFIG[key]
if isinstance(d, unicode):
d = d.encode('utf8')
CONFIG[key] = d
if not os.path.isdir(d):
raise ValueError('Directory %r does not exists.' % d)
CONFIG['master_url'] = 'http://%s:%s' % (CONFIG['proxy_host'],
......
......@@ -230,8 +230,8 @@ branch = %(branch)s
self.log('testnode, retry_software_count : %r' % \
slapos_instance.retry_software_count)
self.slapos_controler = SlapOSControler.SlapOSControler(
working_directory, self.config)
self.slapos_controler.initializeSlapOSControler(log=self.log, slapproxy_log=slapproxy_log,
working_directory, self.config, self.log)
self.slapos_controler.initializeSlapOSControler(slapproxy_log=slapproxy_log,
process_manager=self.process_manager, reset_software=reset_software,
software_path_list=software_path_list)
self.process_manager.supervisord_pid_file = os.path.join(\
......
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