From 82f3de6e19878d7fa337da6c0ca2d4444e1930b3 Mon Sep 17 00:00:00 2001 From: Ivan Tyagov <ivan@nexedi.com> Date: Tue, 8 Nov 2011 14:10:29 +0200 Subject: [PATCH] Make test node run slapgrid-cp in order to suppert the case when one partition can request another. --- erp5/util/testnode/SlapOSControler.py | 68 ++++++++++++++++----------- erp5/util/testnode/testnode.py | 15 ++---- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/erp5/util/testnode/SlapOSControler.py b/erp5/util/testnode/SlapOSControler.py index 9ec4384994..05442332f0 100644 --- a/erp5/util/testnode/SlapOSControler.py +++ b/erp5/util/testnode/SlapOSControler.py @@ -30,6 +30,8 @@ import subprocess import time import xml_marshaller +MAX_PARTIONS = 10 + class SlapOSControler(object): def __init__(self, config, log, process_group_pid_set=None, @@ -59,28 +61,30 @@ class SlapOSControler(object): self.software_profile, computer_guid=config['computer_id']) computer = slap.registerComputer(config['computer_id']) - # create partition and configure computer - partition_reference = config['partition_reference'] - partition_path = os.path.join(config['instance_root'], partition_reference) - if not os.path.exists(partition_path): - os.mkdir(partition_path) - os.chmod(partition_path, 0750) - computer.updateConfiguration(xml_marshaller.xml_marshaller.dumps({ - 'address': config['ipv4_address'], - 'instance_root': config['instance_root'], - 'netmask': '255.255.255.255', - 'partition_list': [{'address_list': [{'addr': config['ipv4_address'], - 'netmask': '255.255.255.255'}, - {'addr': config['ipv6_address'], - 'netmask': 'ffff:ffff:ffff::'}, - ], - 'path': partition_path, - 'reference': partition_reference, - 'tap': {'name': partition_reference}, - } - ], - 'reference': config['computer_id'], - 'software_root': config['software_root']})) + for i in range(0, MAX_PARTIONS): + # create partition and configure computer + # XXX: at the moment all partitions do share same virtual interface address + # this is not a problem as usually all services are on different ports + partition_reference = '%s-%s' %(config['partition_reference'], i) + partition_path = os.path.join(config['instance_root'], partition_reference) + if not os.path.exists(partition_path): + os.mkdir(partition_path) + os.chmod(partition_path, 0750) + computer.updateConfiguration(xml_marshaller.xml_marshaller.dumps({ + 'address': config['ipv4_address'], + 'instance_root': config['instance_root'], + 'netmask': '255.255.255.255', + 'partition_list': [{'address_list': [{'addr': config['ipv4_address'], + 'netmask': '255.255.255.255'}, + {'addr': config['ipv6_address'], + 'netmask': 'ffff:ffff:ffff::'},], + 'path': partition_path, + 'reference': partition_reference, + 'tap': {'name': partition_reference}, + } + ], + 'reference': config['computer_id'], + 'software_root': config['software_root']})) def runSoftwareRelease(self, config, environment, process_group_pid_set=None, stdout=None, stderr=None): @@ -112,19 +116,27 @@ class SlapOSControler(object): stdout=None, stderr=None): self.log("SlapOSControler.runComputerPartition") slap = slapos.slap.slap() + # cloudooo-json is required but this is a hack which should be removed + config['instance_dict']['cloudooo-json'] = "{}" slap.registerOpenOrder().request(self.software_profile, partition_reference='testing partition', partition_parameter_kw=config['instance_dict']) command = [config['slapgrid_partition_binary'], config['slapos_config'], '-c', '-v'] - slapgrid = subprocess.Popen(command, - stdout=stdout, stderr=stderr, - close_fds=True, preexec_fn=os.setsid) - process_group_pid_set.add(slapgrid.pid) - slapgrid.wait() + + # try to run for all partitions as one partition may in theory request another one + # this not always is required but curently no way to know how "tree" of partitions + # may "expand" + for runs in range(0, MAX_PARTIONS): + slapgrid = subprocess.Popen(command, + stdout=stdout, stderr=stderr, + close_fds=True, preexec_fn=os.setsid) + process_group_pid_set.add(slapgrid.pid) + slapgrid.wait() + process_group_pid_set.remove(slapgrid.pid) + stdout.seek(0) stderr.seek(0) - process_group_pid_set.remove(slapgrid.pid) status_dict = {'status_code':slapgrid.returncode, 'command': repr(command), 'stdout':stdout.read(), diff --git a/erp5/util/testnode/testnode.py b/erp5/util/testnode/testnode.py index 1589b3935f..378211629c 100644 --- a/erp5/util/testnode/testnode.py +++ b/erp5/util/testnode/testnode.py @@ -32,7 +32,7 @@ import subprocess import sys import time import xmlrpclib - +import glob import SlapOSControler class SubprocessError(EnvironmentError): @@ -247,15 +247,10 @@ branch = %(branch)s retry_software = True raise SubprocessError(status_dict) - run_test_suite_path = config['runTestSuite'] - if not os.path.exists(run_test_suite_path): - raise SubprocessError({ - 'command': 'os.path.exists(run_test_suite_path)', - 'status_code': 1, - 'stdout': '', - 'stderr': 'File does not exist: %r' % (run_test_suite_path, ), - }) - + run_test_suite_path_list = glob.glob("%s/*/bin/runTestSuite" %config['instance_root']) + if not len(run_test_suite_path_list): + raise ValueError('No runTestSuite provided in installed partitions.') + run_test_suite_path = run_test_suite_path_list[0] run_test_suite_revision = revision if isinstance(revision, tuple): revision = ','.join(revision) -- 2.30.9