Commit 2a49396e authored by Xavier Thompson's avatar Xavier Thompson

SlapObject: Refactor supervisord config handling

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