Commit 565dab64 authored by Cédric de Saint Martin's avatar Cédric de Saint Martin

Merge branch 'return_value'

parents 08063548 0a349a97
...@@ -71,6 +71,12 @@ MANDATORY_PARAMETER_LIST = [ ...@@ -71,6 +71,12 @@ MANDATORY_PARAMETER_LIST = [
COMPUTER_PARTITION_DESTROYED_STATE = 'destroyed' COMPUTER_PARTITION_DESTROYED_STATE = 'destroyed'
# Global variables about return state of slapgrid
SLAPGRID_SUCCESS = 0
SLAPGRID_FAIL = 1
SLAPGRID_PROMISE_FAIL = 2
# XXX hardcoded watchdog_path # XXX hardcoded watchdog_path
WATCHDOG_PATH = '/opt/slapos/bin/slapos-watchdog' WATCHDOG_PATH = '/opt/slapos/bin/slapos-watchdog'
...@@ -316,23 +322,29 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple): ...@@ -316,23 +322,29 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
def realRun(argument_tuple, method_list): def realRun(argument_tuple, method_list):
clean_run = True
slapgrid_object, option_dict = \ slapgrid_object, option_dict = \
parseArgumentTupleAndReturnSlapgridObject(*argument_tuple) parseArgumentTupleAndReturnSlapgridObject(*argument_tuple)
pidfile = option_dict.get('pidfile') pidfile = option_dict.get('pidfile')
if pidfile: if pidfile:
setRunning(pidfile) setRunning(pidfile)
try: try:
failed = False
failed_promise = False
for method in method_list: for method in method_list:
if not getattr(slapgrid_object, method)(): # Quite complicated way to figure out if everything went fine
clean_run = False return_value = getattr(slapgrid_object, method)()
if return_value == SLAPGRID_FAIL:
failed = True
if return_value == SLAPGRID_PROMISE_FAIL:
failed_promise = True
finally: finally:
if pidfile: if pidfile:
setFinished(pidfile) setFinished(pidfile)
if clean_run: if failed:
sys.exit(0) sys.exit(SLAPGRID_FAIL)
else: if failed_promise:
sys.exit(1) sys.exit(SLAPGRID_PROMISE_FAIL)
sys.exit(SLAPGRID_SUCCESS)
def run(*argument_tuple): def run(*argument_tuple):
...@@ -520,6 +532,7 @@ class Slapgrid(object): ...@@ -520,6 +532,7 @@ class Slapgrid(object):
self.checkEnvironmentAndCreateStructure() self.checkEnvironmentAndCreateStructure()
logger = logging.getLogger('SoftwareReleases') logger = logging.getLogger('SoftwareReleases')
logger.info("Processing software releases...") logger.info("Processing software releases...")
# Boolean to know if every instance has correctly been deployed
clean_run = True clean_run = True
for software_release in self.computer.getSoftwareReleaseList(): for software_release in self.computer.getSoftwareReleaseList():
state = software_release.getState() state = software_release.getState()
...@@ -600,7 +613,11 @@ class Slapgrid(object): ...@@ -600,7 +613,11 @@ class Slapgrid(object):
except NotFoundError: except NotFoundError:
pass pass
logger.info("Finished software releases...") logger.info("Finished software releases...")
return clean_run
# Return success value
if not clean_run:
return SLAPGRID_FAIL
return SLAPGRID_SUCCESS
def _launchSupervisord(self): def _launchSupervisord(self):
...@@ -812,9 +829,8 @@ class Slapgrid(object): ...@@ -812,9 +829,8 @@ class Slapgrid(object):
# If partition has no SR: skip it. # If partition has no SR: skip it.
try: try:
software_url = computer_partition.getSoftwareRelease().getURI() os.path.join(self.software_root, getSoftwareUrlHash(
software_path = os.path.join(self.software_root, computer_partition.getSoftwareRelease().getURI()))
getSoftwareUrlHash(software_url))
except (NotFoundError, TypeError): except (NotFoundError, TypeError):
# This is surely free partition. Check it... # This is surely free partition. Check it...
if os.listdir(computer_partition_path) == []: if os.listdir(computer_partition_path) == []:
...@@ -833,7 +849,6 @@ class Slapgrid(object): ...@@ -833,7 +849,6 @@ class Slapgrid(object):
# Buildout failed: send log but don't print it to output (already done) # Buildout failed: send log but don't print it to output (already done)
except BuildoutFailedError, exception: except BuildoutFailedError, exception:
clean_run = False
try: try:
computer_partition.error(exception) computer_partition.error(exception)
except (SystemExit, KeyboardInterrupt): except (SystemExit, KeyboardInterrupt):
...@@ -845,7 +860,6 @@ class Slapgrid(object): ...@@ -845,7 +860,6 @@ class Slapgrid(object):
# For everything else: log it, send it, continue. # For everything else: log it, send it, continue.
except Exception as exception: except Exception as exception:
clean_run = False
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
try: try:
computer_partition.error(exception) computer_partition.error(exception)
...@@ -867,8 +881,11 @@ class Slapgrid(object): ...@@ -867,8 +881,11 @@ class Slapgrid(object):
# Prepares environment # Prepares environment
self.checkEnvironmentAndCreateStructure() self.checkEnvironmentAndCreateStructure()
self._launchSupervisord() self._launchSupervisord()
# Process Computer Partitions
# Boolean to know if every instance has correctly been deployed
clean_run = True clean_run = True
# Boolean to know if every promises correctly passed
clean_run_promise = True
# Filter all dummy / empty partitions # Filter all dummy / empty partitions
computer_partition_list = self.FilterComputerPartitionList( computer_partition_list = self.FilterComputerPartitionList(
...@@ -888,6 +905,18 @@ class Slapgrid(object): ...@@ -888,6 +905,18 @@ class Slapgrid(object):
computer_partition.error(exception) computer_partition.error(exception)
raise raise
except Slapgrid.PromiseError as exception:
clean_run_promise = False
try:
logger.error(exception)
computer_partition.error(exception)
except (SystemExit, KeyboardInterrupt):
raise
except Exception:
exception = traceback.format_exc()
logger.error('Problem during reporting error, continuing:\n' +
exception)
# Buildout failed: send log but don't print it to output (already done) # Buildout failed: send log but don't print it to output (already done)
except BuildoutFailedError, exception: except BuildoutFailedError, exception:
clean_run = False clean_run = False
...@@ -914,7 +943,13 @@ class Slapgrid(object): ...@@ -914,7 +943,13 @@ class Slapgrid(object):
exception) exception)
logger.info("Finished computer partitions...") logger.info("Finished computer partitions...")
return clean_run
# Return success value
if not clean_run:
return SLAPGRID_FAIL
if not clean_run_promise:
return SLAPGRID_PROMISE_FAIL
return SLAPGRID_SUCCESS
def validateXML(self, to_be_validated, xsd_model): def validateXML(self, to_be_validated, xsd_model):
...@@ -1239,4 +1274,8 @@ class Slapgrid(object): ...@@ -1239,4 +1274,8 @@ class Slapgrid(object):
(computer_partition.getId(), server_error.args[0])) (computer_partition.getId(), server_error.args[0]))
logger.info("Finished usage reports...") logger.info("Finished usage reports...")
return clean_run
# Return success value
if not clean_run:
return SLAPGRID_FAIL
return SLAPGRID_SUCCESS
...@@ -432,14 +432,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase): ...@@ -432,14 +432,14 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
computer = ComputerForTest(self.software_root,self.instance_root,0,0) computer = ComputerForTest(self.software_root,self.instance_root,0,0)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['etc', 'var']) self.assertSortedListEqual(os.listdir(self.instance_root), ['etc', 'var'])
self.assertSortedListEqual(os.listdir(self.software_root), []) self.assertSortedListEqual(os.listdir(self.software_root), [])
def test_one_partition(self): def test_one_partition(self):
computer = ComputerForTest(self.software_root,self.instance_root) computer = ComputerForTest(self.software_root,self.instance_root)
instance = computer.instance_list[0] instance = computer.instance_list[0]
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
partition = os.path.join(self.instance_root, '0') partition = os.path.join(self.instance_root, '0')
...@@ -458,7 +458,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase): ...@@ -458,7 +458,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
""" """
computer = ComputerForTest(self.software_root,self.instance_root) computer = ComputerForTest(self.software_root,self.instance_root)
instance = computer.instance_list[0] instance = computer.instance_list[0]
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
partition = os.path.join(self.instance_root, '0') partition = os.path.join(self.instance_root, '0')
...@@ -478,7 +478,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase): ...@@ -478,7 +478,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
software_amount = 0) software_amount = 0)
partition = computer.instance_list[0] partition = computer.instance_list[0]
partition.requested_state = 'destroyed' partition.requested_state = 'destroyed'
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0','etc', 'var']) self.assertSortedListEqual(os.listdir(self.instance_root), ['0','etc', 'var'])
self.assertSortedListEqual(os.listdir(partition.partition_path), []) self.assertSortedListEqual(os.listdir(partition.partition_path), [])
self.assertSortedListEqual(os.listdir(self.software_root), []) self.assertSortedListEqual(os.listdir(self.software_root), [])
...@@ -489,7 +489,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase): ...@@ -489,7 +489,7 @@ class TestSlapgridCPWithMaster(MasterMixin, unittest.TestCase):
partition = computer.instance_list[0] partition = computer.instance_list[0]
partition.requested_state = 'started' partition.requested_state = 'started'
partition.software.setBuildout(WRAPPER_CONTENT) partition.software.setBuildout(WRAPPER_CONTENT)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
self.assertSortedListEqual(os.listdir(partition.partition_path), self.assertSortedListEqual(os.listdir(partition.partition_path),
...@@ -533,7 +533,7 @@ HEREDOC ...@@ -533,7 +533,7 @@ HEREDOC
)> etc/run/wrapper && )> etc/run/wrapper &&
chmod 755 etc/run/wrapper chmod 755 etc/run/wrapper
""" % dict(python = sys.executable)) """ % dict(python = sys.executable))
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
self.assertSortedListEqual(os.listdir(instance.partition_path), ['.0_wrapper.log', self.assertSortedListEqual(os.listdir(instance.partition_path), ['.0_wrapper.log',
...@@ -556,7 +556,7 @@ chmod 755 etc/run/wrapper ...@@ -556,7 +556,7 @@ chmod 755 etc/run/wrapper
computer.sequence = [] computer.sequence = []
instance.requested_state = 'stopped' instance.requested_state = 'stopped'
self.assertTrue(self.launchSlapgrid()) self.assertEqual(self.launchSlapgrid(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), self.assertSortedListEqual(os.listdir(self.instance_root),
['0', 'etc', 'var']) ['0', 'etc', 'var'])
self.assertSortedListEqual( self.assertSortedListEqual(
...@@ -582,7 +582,7 @@ chmod 755 etc/run/wrapper ...@@ -582,7 +582,7 @@ chmod 755 etc/run/wrapper
instance = computer.instance_list[0] instance = computer.instance_list[0]
instance.requested_state = 'stopped' instance.requested_state = 'stopped'
instance.software.setBuildout(WRAPPER_CONTENT) instance.software.setBuildout(WRAPPER_CONTENT)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
...@@ -598,7 +598,7 @@ chmod 755 etc/run/wrapper ...@@ -598,7 +598,7 @@ chmod 755 etc/run/wrapper
instance.requested_state = 'started' instance.requested_state = 'started'
computer.sequence = [] computer.sequence = []
self.assertTrue(self.launchSlapgrid()) self.assertEqual(self.launchSlapgrid(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
partition = os.path.join(self.instance_root, '0') partition = os.path.join(self.instance_root, '0')
...@@ -634,7 +634,7 @@ chmod 755 etc/run/wrapper ...@@ -634,7 +634,7 @@ chmod 755 etc/run/wrapper
dummy_file.write('dummy') dummy_file.write('dummy')
dummy_file.close() dummy_file.close()
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
...@@ -680,7 +680,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase): ...@@ -680,7 +680,7 @@ class TestSlapgridCPWithMasterWatchdog(MasterMixin, unittest.TestCase):
partition.requested_state = 'started' partition.requested_state = 'started'
partition.software.setBuildout(DAEMON_CONTENT) partition.software.setBuildout(DAEMON_CONTENT)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
self.assertSortedListEqual( self.assertSortedListEqual(
...@@ -730,7 +730,7 @@ touch worked ...@@ -730,7 +730,7 @@ touch worked
partition.requested_state = 'started' partition.requested_state = 'started'
partition.software.setBuildout(self.RUN_CONTENT) partition.software.setBuildout(self.RUN_CONTENT)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
self.assertSortedListEqual(os.listdir(partition.partition_path), self.assertSortedListEqual(os.listdir(partition.partition_path),
...@@ -825,7 +825,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -825,7 +825,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
timestamp = str(int(time.time())) timestamp = str(int(time.time()))
instance.timestamp = timestamp instance.timestamp = timestamp
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
partition = os.path.join(self.instance_root, '0') partition = os.path.join(self.instance_root, '0')
...@@ -835,7 +835,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -835,7 +835,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
os.listdir(self.software_root), [instance.software.software_hash]) os.listdir(self.software_root), [instance.software.software_hash])
timestamp_path = os.path.join(instance.partition_path, '.timestamp') timestamp_path = os.path.join(instance.partition_path, '.timestamp')
self.setSlapgrid() self.setSlapgrid()
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertTrue(timestamp in open(timestamp_path,'r').read()) self.assertTrue(timestamp in open(timestamp_path,'r').read())
self.assertEqual(instance.sequence, self.assertEqual(instance.sequence,
['availableComputerPartition', ['availableComputerPartition',
...@@ -848,7 +848,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -848,7 +848,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
timestamp = str(int(time.time())) timestamp = str(int(time.time()))
instance.timestamp = timestamp instance.timestamp = timestamp
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
partition = os.path.join(self.instance_root, '0') partition = os.path.join(self.instance_root, '0')
...@@ -857,8 +857,9 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -857,8 +857,9 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self.assertSortedListEqual( self.assertSortedListEqual(
os.listdir(self.software_root), [instance.software.software_hash]) os.listdir(self.software_root), [instance.software.software_hash])
self.assertTrue(self.launchSlapgrid(develop=True)) self.assertEqual(self.launchSlapgrid(develop=True),
self.assertTrue(self.launchSlapgrid()) slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(self.launchSlapgrid(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(instance.sequence, self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition', ['availableComputerPartition', 'stoppedComputerPartition',
...@@ -870,7 +871,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -870,7 +871,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
timestamp = str(int(time.time())) timestamp = str(int(time.time()))
instance.timestamp = timestamp instance.timestamp = timestamp
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
partition = os.path.join(self.instance_root, '0') partition = os.path.join(self.instance_root, '0')
...@@ -879,7 +880,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -879,7 +880,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self.assertSortedListEqual(os.listdir(self.software_root), self.assertSortedListEqual(os.listdir(self.software_root),
[instance.software.software_hash]) [instance.software.software_hash])
instance.timestamp = str(int(timestamp) - 1) instance.timestamp = str(int(timestamp) - 1)
self.assertTrue(self.launchSlapgrid()) self.assertEqual(self.launchSlapgrid(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(instance.sequence, self.assertEqual(instance.sequence,
['availableComputerPartition', 'stoppedComputerPartition']) ['availableComputerPartition', 'stoppedComputerPartition'])
...@@ -890,7 +891,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -890,7 +891,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
timestamp = str(int(time.time())) timestamp = str(int(time.time()))
instance.timestamp = timestamp instance.timestamp = timestamp
self.assertTrue(self.launchSlapgrid()) self.assertEqual(self.launchSlapgrid(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
partition = os.path.join(self.instance_root, '0') partition = os.path.join(self.instance_root, '0')
...@@ -899,8 +900,8 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -899,8 +900,8 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self.assertSortedListEqual(os.listdir(self.software_root), self.assertSortedListEqual(os.listdir(self.software_root),
[instance.software.software_hash]) [instance.software.software_hash])
instance.timestamp = str(int(timestamp)+1) instance.timestamp = str(int(timestamp)+1)
self.assertTrue(self.launchSlapgrid()) self.assertEqual(self.launchSlapgrid(), slapgrid.SLAPGRID_SUCCESS)
self.assertTrue(self.launchSlapgrid()) self.assertEqual(self.launchSlapgrid(), slapgrid.SLAPGRID_SUCCESS)
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition', ['getFullComputerInformation', 'availableComputerPartition',
'stoppedComputerPartition', 'getFullComputerInformation', 'stoppedComputerPartition', 'getFullComputerInformation',
...@@ -953,7 +954,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase): ...@@ -953,7 +954,7 @@ class TestSlapgridCPPartitionProcessing (MasterMixin, unittest.TestCase):
self.setSlapgrid() self.setSlapgrid()
self.grid.force_periodicity = True self.grid.force_periodicity = True
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertNotEqual(unwanted_periodicity,self.grid.maximum_periodicity) self.assertNotEqual(unwanted_periodicity,self.grid.maximum_periodicity)
self.assertEqual(computer.sequence, self.assertEqual(computer.sequence,
['getFullComputerInformation', 'availableComputerPartition', ['getFullComputerInformation', 'availableComputerPartition',
...@@ -1104,7 +1105,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -1104,7 +1105,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
instance = computer.instance_list[0] instance = computer.instance_list[0]
instance.requested_state = 'started' instance.requested_state = 'started'
instance.software.setBuildout(WRAPPER_CONTENT) instance.software.setBuildout(WRAPPER_CONTENT)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
self.assertSortedListEqual(os.listdir(instance.partition_path), ['.0_wrapper.log', self.assertSortedListEqual(os.listdir(instance.partition_path), ['.0_wrapper.log',
...@@ -1128,7 +1129,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -1128,7 +1129,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
# Then destroy the instance # Then destroy the instance
computer.sequence = [] computer.sequence = []
instance.requested_state = 'destroyed' instance.requested_state = 'destroyed'
self.assertTrue(self.grid.agregateAndSendUsage()) self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
# Assert partition directory is empty # Assert partition directory is empty
self.assertSortedListEqual(os.listdir(self.instance_root), self.assertSortedListEqual(os.listdir(self.instance_root),
['0', 'etc', 'var']) ['0', 'etc', 'var'])
...@@ -1165,7 +1166,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -1165,7 +1166,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
computer.sequence = [] computer.sequence = []
instance.requested_state = 'destroyed' instance.requested_state = 'destroyed'
self.assertTrue(self.grid.agregateAndSendUsage()) self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
# Assert partition directory is empty # Assert partition directory is empty
self.assertSortedListEqual(os.listdir(self.instance_root), self.assertSortedListEqual(os.listdir(self.instance_root),
['0', 'etc', 'var']) ['0', 'etc', 'var'])
...@@ -1199,7 +1200,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -1199,7 +1200,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
computer.sequence = [] computer.sequence = []
instance.requested_state = 'destroyed' instance.requested_state = 'destroyed'
self.assertTrue(self.grid.agregateAndSendUsage()) self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
# Assert partition directory is empty # Assert partition directory is empty
self.assertSortedListEqual(os.listdir(self.instance_root), self.assertSortedListEqual(os.listdir(self.instance_root),
['0', 'etc', 'var']) ['0', 'etc', 'var'])
...@@ -1227,7 +1228,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -1227,7 +1228,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
instance = computer.instance_list[0] instance = computer.instance_list[0]
instance.requested_state = 'started' instance.requested_state = 'started'
instance.software.setBuildout(WRAPPER_CONTENT) instance.software.setBuildout(WRAPPER_CONTENT)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), self.assertSortedListEqual(os.listdir(self.instance_root),
['0', 'etc', 'var']) ['0', 'etc', 'var'])
self.assertSortedListEqual(os.listdir(instance.partition_path), self.assertSortedListEqual(os.listdir(instance.partition_path),
...@@ -1250,7 +1251,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -1250,7 +1251,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
# Then run usage report and see if it is still working # Then run usage report and see if it is still working
computer.sequence = [] computer.sequence = []
self.assertTrue(self.grid.agregateAndSendUsage()) self.assertEqual(self.grid.agregateAndSendUsage(), slapgrid.SLAPGRID_SUCCESS)
self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc', self.assertSortedListEqual(os.listdir(self.instance_root), ['0', 'etc',
'var']) 'var'])
self.assertSortedListEqual( self.assertSortedListEqual(
...@@ -1288,7 +1289,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase): ...@@ -1288,7 +1289,7 @@ class TestSlapgridUsageReport(MasterMixin, unittest.TestCase):
computer.sequence = [] computer.sequence = []
instance.requested_state = 'destroyed' instance.requested_state = 'destroyed'
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
# Assert partition directory is empty # Assert partition directory is empty
self.assertSortedListEqual(os.listdir(self.instance_root), self.assertSortedListEqual(os.listdir(self.instance_root),
['0', 'etc', 'var']) ['0', 'etc', 'var'])
...@@ -1576,11 +1577,12 @@ class TestSlapgridCPWithMasterPromise(MasterMixin, unittest.TestCase): ...@@ -1576,11 +1577,12 @@ class TestSlapgridCPWithMasterPromise(MasterMixin, unittest.TestCase):
fail = ("""#!/usr/bin/env sh fail = ("""#!/usr/bin/env sh
touch "%(worked_file)s" touch "%(worked_file)s"
exit 127""" % {'worked_file': worked_file}) exit 127""" % {'worked_file': worked_file})
instance.setPromise('fail',fail) instance.setPromise('fail', fail)
self.assertFalse(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(),
slapos.grid.slapgrid.SLAPGRID_PROMISE_FAIL)
self.assertTrue(os.path.isfile(worked_file)) self.assertTrue(os.path.isfile(worked_file))
self.assertTrue(instance.error) self.assertTrue(instance.error)
self.assertNotEqual('started',instance.state) self.assertNotEqual('started', instance.state)
def test_one_succeeding_promise(self): def test_one_succeeding_promise(self):
computer = ComputerForTest(self.software_root,self.instance_root) computer = ComputerForTest(self.software_root,self.instance_root)
...@@ -1591,12 +1593,12 @@ exit 127""" % {'worked_file': worked_file}) ...@@ -1591,12 +1593,12 @@ exit 127""" % {'worked_file': worked_file})
succeed = ("""#!/usr/bin/env sh succeed = ("""#!/usr/bin/env sh
touch "%(worked_file)s" touch "%(worked_file)s"
exit 0""" % {'worked_file': worked_file}) exit 0""" % {'worked_file': worked_file})
instance.setPromise('succeed',succeed) instance.setPromise('succeed', succeed)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
self.assertTrue(os.path.isfile(worked_file)) self.assertTrue(os.path.isfile(worked_file))
self.assertFalse(instance.error) self.assertFalse(instance.error)
self.assertEqual(instance.state,'started') self.assertEqual(instance.state, 'started')
def test_stderr_has_been_sent(self): def test_stderr_has_been_sent(self):
computer = ComputerForTest(self.software_root,self.instance_root) computer = ComputerForTest(self.software_root,self.instance_root)
...@@ -1616,7 +1618,8 @@ touch "%(worked_file)s" ...@@ -1616,7 +1618,8 @@ touch "%(worked_file)s"
echo Error 1>&2 echo Error 1>&2
exit 127""" % {'worked_file': worked_file}) exit 127""" % {'worked_file': worked_file})
os.chmod(succeed, 0777) os.chmod(succeed, 0777)
self.assertFalse(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(),
slapos.grid.slapgrid.SLAPGRID_PROMISE_FAIL)
self.assertTrue(os.path.isfile(worked_file)) self.assertTrue(os.path.isfile(worked_file))
self.assertEqual(instance.error_log, 'Error') self.assertEqual(instance.error_log, 'Error')
...@@ -1641,7 +1644,8 @@ touch "%(worked_file)s" ...@@ -1641,7 +1644,8 @@ touch "%(worked_file)s"
sleep 5 sleep 5
exit 0""" % {'worked_file': worked_file}) exit 0""" % {'worked_file': worked_file})
os.chmod(succeed, 0777) os.chmod(succeed, 0777)
self.assertFalse(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(),
slapos.grid.slapgrid.SLAPGRID_PROMISE_FAIL)
self.assertTrue(os.path.isfile(worked_file)) self.assertTrue(os.path.isfile(worked_file))
self.assertTrue(instance.error) self.assertTrue(instance.error)
...@@ -1661,7 +1665,7 @@ touch "%(worked_file)s" ...@@ -1661,7 +1665,7 @@ touch "%(worked_file)s"
exit 0""" % {'worked_file': worked_file}) exit 0""" % {'worked_file': worked_file})
instance.setPromise('succeed_%s' % i, succeed) instance.setPromise('succeed_%s' % i, succeed)
self.assertTrue(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
for i in range(0,2): for i in range(0,2):
worked_file = os.path.join(instance.partition_path, 'succeed_%s_worked' % i) worked_file = os.path.join(instance.partition_path, 'succeed_%s_worked' % i)
self.assertTrue(os.path.isfile(worked_file)) self.assertTrue(os.path.isfile(worked_file))
...@@ -1687,7 +1691,8 @@ else ...@@ -1687,7 +1691,8 @@ else
exit 127 exit 127
fi""" % {'worked_file': worked_file, 'lockfile': lockfile}) fi""" % {'worked_file': worked_file, 'lockfile': lockfile})
instance.setPromise('promise_%s'%i,promise) instance.setPromise('promise_%s'%i,promise)
self.assertFalse(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(),
slapos.grid.slapgrid.SLAPGRID_PROMISE_FAIL)
self.assertEquals(instance.error, 1) self.assertEquals(instance.error, 1)
self.assertNotEqual('started',instance.state) self.assertNotEqual('started',instance.state)
...@@ -1710,7 +1715,8 @@ fi ...@@ -1710,7 +1715,8 @@ fi
exit 0""" % {'worked_file': worked_file, 'lockfile': lockfile}) exit 0""" % {'worked_file': worked_file, 'lockfile': lockfile})
instance.setPromise('promise_%d' % i, promise) instance.setPromise('promise_%d' % i, promise)
self.assertFalse(self.grid.processComputerPartitionList()) self.assertEqual(self.grid.processComputerPartitionList(),
slapos.grid.slapgrid.SLAPGRID_PROMISE_FAIL)
self.assertEquals(instance.error, 1) self.assertEquals(instance.error, 1)
self.assertNotEqual(instance.state,'started') self.assertNotEqual(instance.state,'started')
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