Commit bd28cde2 authored by Xavier Thompson's avatar Xavier Thompson

SlapObject: Refactor supervisord config handling

parent bfe6284c
......@@ -708,7 +708,7 @@ class Partition(object):
logger=self.logger,
debug=self.buildout_debug,
timeout=self.partition_timeout)
self.generateSupervisorConfigurationFile()
self.updateSupervisorConfiguration()
self.createRetentionLockDelay()
self.instance_python = getPythonExecutableFromSoftwarePath(self.software_path)
......@@ -734,8 +734,6 @@ class Partition(object):
if len(runner_list) == 0 and len(service_list) == 0:
self.logger.warning('No runners nor services found for partition %r' %
self.partition_id)
if os.path.exists(self.supervisord_partition_configuration_path):
os.unlink(self.supervisord_partition_configuration_path)
else:
partition_id = self.computer_partition.getId()
group_partition_template = bytes2str(pkg_resources.resource_string(__name__,
......@@ -760,8 +758,21 @@ class Partition(object):
self.supervisor_configuration_group +
self.partition_supervisor_configuration)
self.updateSupervisor()
else:
self.removeSupervisorConfigurationFile()
def removeSupervisorConfigurationFile(self):
"""
Remove supervisord configuration file if it exists and update supervisord
"""
try:
os.unlink(self.supervisord_partition_configuration_path)
except OSError as e:
if e.errno != errno.ENOENT:
raise
self.updateSupervisor()
def generateSupervisorConfigurationFile(self):
def updateSupervisorConfiguration(self):
"""
update supervisord with new processes
"""
......@@ -856,9 +867,7 @@ class Partition(object):
# Cleanup all Data storage location of this partition
if os.path.exists(self.supervisord_partition_configuration_path):
os.remove(self.supervisord_partition_configuration_path)
self.updateSupervisor()
self.removeSupervisorConfigurationFile()
except IOError as exc:
raise IOError("I/O error while freeing partition (%s): %s" % (self.instance_path, exc))
......
......@@ -87,7 +87,7 @@ original_upload_network_cached = networkcache.upload_network_cached
originalBootstrapBuildout = utils.bootstrapBuildout
originalLaunchBuildout = utils.launchBuildout
originalUploadSoftwareRelease = Software.uploadSoftwareRelease
originalPartitionGenerateSupervisorConfigurationFile = Partition.generateSupervisorConfigurationFile
originalPartitionUpdateSupervisorConfiguration = Partition.updateSupervisorConfiguration
class MasterMixin(BasicMixin, unittest.TestCase):
"""
......@@ -378,14 +378,14 @@ class TestPartitionSlapObject(MasterMixin, unittest.TestCase):
def setUp(self):
MasterMixin.setUp(self)
Partition.generateSupervisorConfigurationFile = FakeCallAndNoop()
Partition.updateSupervisorConfiguration = FakeCallAndNoop()
utils.bootstrapBuildout = FakeCallAndNoop()
utils.launchBuildout = FakeCallAndStore()
def tearDown(self):
MasterMixin.tearDown(self)
Partition.generateSupervisorConfigurationFile = originalPartitionGenerateSupervisorConfigurationFile
Partition.updateSupervisorConfiguration = originalPartitionUpdateSupervisorConfiguration
def test_partition_timeout_default(self):
software = self.createSoftware()
......@@ -544,13 +544,13 @@ class TestPartitionSupervisorConfig(MasterMixin, unittest.TestCase):
class TestPartitionDestructionLock(MasterMixin, unittest.TestCase):
def setUp(self):
MasterMixin.setUp(self)
Partition.generateSupervisorConfigurationFile = FakeCallAndNoop()
Partition.updateSupervisorConfiguration = FakeCallAndNoop()
utils.bootstrapBuildout = FakeCallAndNoop()
utils.launchBuildout = FakeCallAndStore()
def tearDown(self):
MasterMixin.tearDown(self)
Partition.generateSupervisorConfigurationFile = originalPartitionGenerateSupervisorConfigurationFile
Partition.updateSupervisorConfiguration = originalPartitionUpdateSupervisorConfiguration
def test_retention_lock_delay_creation(self):
delay = 42
......@@ -640,13 +640,13 @@ class TestPartitionDestructionLock(MasterMixin, unittest.TestCase):
class TestPartitionDestructionUnwritable(MasterMixin, unittest.TestCase):
def setUp(self):
MasterMixin.setUp(self)
Partition.generateSupervisorConfigurationFile = FakeCallAndNoop()
Partition.updateSupervisorConfiguration = FakeCallAndNoop()
utils.bootstrapBuildout = FakeCallAndNoop()
utils.launchBuildout = FakeCallAndStore()
def tearDown(self):
MasterMixin.tearDown(self)
Partition.generateSupervisorConfigurationFile = originalPartitionGenerateSupervisorConfigurationFile
Partition.updateSupervisorConfiguration = originalPartitionUpdateSupervisorConfiguration
def test(self):
software = self.createSoftware()
......
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