Commit db98a521 authored by Xavier Thompson's avatar Xavier Thompson

SlapObject: Give each process group its own file

Give each supervisor process group its own separate configuration file.
parent 2a49396e
This diff is collapsed.
...@@ -1077,9 +1077,8 @@ stderr_logfile_backups=1 ...@@ -1077,9 +1077,8 @@ stderr_logfile_backups=1
software_path=software_path, software_path=software_path,
instance_path=instance_path, instance_path=instance_path,
shared_part_list=self.shared_part_list, shared_part_list=self.shared_part_list,
supervisord_partition_configuration_path=os.path.join( supervisord_partition_configuration_dir=(
_getSupervisordConfigurationDirectory(self.instance_root), _getSupervisordConfigurationDirectory(self.instance_root)),
computer_partition_id + '.conf'),
supervisord_socket=self.supervisord_socket, supervisord_socket=self.supervisord_socket,
computer_partition=computer_partition, computer_partition=computer_partition,
computer_id=self.computer_id, computer_id=self.computer_id,
...@@ -1174,9 +1173,8 @@ stderr_logfile_backups=1 ...@@ -1174,9 +1173,8 @@ stderr_logfile_backups=1
software_path=software_path, software_path=software_path,
instance_path=instance_path, instance_path=instance_path,
shared_part_list=self.shared_part_list, shared_part_list=self.shared_part_list,
supervisord_partition_configuration_path=os.path.join( supervisord_partition_configuration_dir=(
_getSupervisordConfigurationDirectory(self.instance_root), '%s.conf' % _getSupervisordConfigurationDirectory(self.instance_root)),
computer_partition_id),
supervisord_socket=self.supervisord_socket, supervisord_socket=self.supervisord_socket,
computer_partition=computer_partition, computer_partition=computer_partition,
computer_id=self.computer_id, computer_id=self.computer_id,
...@@ -1836,9 +1834,8 @@ stderr_logfile_backups=1 ...@@ -1836,9 +1834,8 @@ stderr_logfile_backups=1
instance_path=os.path.join(self.instance_root, instance_path=os.path.join(self.instance_root,
computer_partition.getId()), computer_partition.getId()),
shared_part_list=self.shared_part_list, shared_part_list=self.shared_part_list,
supervisord_partition_configuration_path=os.path.join( supervisord_partition_configuration_dir=(
_getSupervisordConfigurationDirectory(self.instance_root), '%s.conf' % _getSupervisordConfigurationDirectory(self.instance_root)),
computer_partition_id),
supervisord_socket=self.supervisord_socket, supervisord_socket=self.supervisord_socket,
computer_partition=computer_partition, computer_partition=computer_partition,
computer_id=self.computer_id, computer_id=self.computer_id,
......
...@@ -156,17 +156,15 @@ class Manager(object): ...@@ -156,17 +156,15 @@ class Manager(object):
# Generate supervisord configuration with socat processes added # Generate supervisord configuration with socat processes added
partition.generateSupervisorConfiguration() partition.generateSupervisorConfiguration()
group_id = partition.addCustomGroup('socat', partition.partition_id,
[program['name']
for program in socat_programs])
for program in socat_programs: for program in socat_programs:
partition.addProgramToGroup(group_id, program['name'], program['name'], partition.addProgramToGroup('socat', program['name'], program['name'],
program['command'], program['command'],
as_user=program['as_user']) as_user=program['as_user'])
partition.writeSupervisorConfigurationFile() partition.writeSupervisorConfigurationFiles()
# Start processes # Start processes
group_id = partition.getGroupIdFromSuffix('socat')
with partition.getSupervisorRPC() as supervisor: with partition.getSupervisorRPC() as supervisor:
for program in socat_programs: for program in socat_programs:
process_name = '{}:{}'.format(group_id, program['name']) process_name = '{}:{}'.format(group_id, program['name'])
......
...@@ -73,11 +73,9 @@ class Manager(object): ...@@ -73,11 +73,9 @@ class Manager(object):
group_suffix = "prerm" group_suffix = "prerm"
logger.info("Adding pre-delete scripts to supervisord...") logger.info("Adding pre-delete scripts to supervisord...")
partition.generateSupervisorConfiguration() partition.generateSupervisorConfiguration()
partition.addServiceToCustomGroup(group_suffix, partition.addServicesToCustomGroup(
partition_id, group_suffix, wrapper_list, partition.prerm_path)
wrapper_list, partition.writeSupervisorConfigurationFiles()
partition.prerm_path)
partition.writeSupervisorConfigurationFile()
# check the state of all process, if the process is not started yes, start it # check the state of all process, if the process is not started yes, start it
with partition.getSupervisorRPC() as supervisor: with partition.getSupervisorRPC() as supervisor:
......
...@@ -170,8 +170,7 @@ class MasterMixin(BasicMixin, unittest.TestCase): ...@@ -170,8 +170,7 @@ class MasterMixin(BasicMixin, unittest.TestCase):
software_path=software_path, software_path=software_path,
instance_path=instance_path, instance_path=instance_path,
shared_part_list=shared_part_list, shared_part_list=shared_part_list,
supervisord_partition_configuration_path=os.path.join( supervisord_partition_configuration_dir=supervisor_configuration_path,
supervisor_configuration_path, partition_id),
supervisord_socket=os.path.join( supervisord_socket=os.path.join(
supervisor_configuration_path, 'supervisor.sock'), supervisor_configuration_path, 'supervisor.sock'),
computer_partition=slap_computer_partition, computer_partition=slap_computer_partition,
...@@ -507,39 +506,41 @@ class TestPartitionSupervisorConfig(MasterMixin, unittest.TestCase): ...@@ -507,39 +506,41 @@ class TestPartitionSupervisorConfig(MasterMixin, unittest.TestCase):
utils.launchBuildout = FakeCallAndNoop() utils.launchBuildout = FakeCallAndNoop()
def test_grouped_program(self): def test_grouped_program(self):
self.assertEqual(self.partition.supervisor_configuration_group, '') self.partition.addProgramToGroup('test', 'sample-1', 'sample-1', '/bin/ls')
self.assertEqual(self.partition.partition_supervisor_configuration, '') self.partition.writeSupervisorConfigurationFiles()
partition_id = self.partition.partition_id group_id = self.partition.getGroupIdFromSuffix('test')
group_id = self.partition.addCustomGroup('test', partition_id, filepath = os.path.join(
['sample-1']) self.partition.supervisord_partition_configuration_dir,
group_id + '.conf'
self.assertIn('group:{}-test'.format(partition_id), )
self.partition.supervisor_configuration_group)
self.partition.addProgramToGroup(group_id, 'sample-1', 'sample-1', with open(filepath) as f:
'/bin/ls') supervisor_conf = f.read()
self.assertIn('program:{}-test_sample-1'.format(partition_id), self.assertIn('group:' + group_id, supervisor_conf)
self.partition.partition_supervisor_configuration) self.assertIn('program:%s_sample-1' % group_id, supervisor_conf)
def test_simple_service(self): def test_simple_service(self):
self.assertEqual(self.partition.supervisor_configuration_group, '') runners = ['runner-' + str(i) for i in range(3)]
self.assertEqual(self.partition.partition_supervisor_configuration, '') path = os.path.join(self.partition.instance_path, 'etc/run')
self.partition.addServicesToGroup(runners, path)
self.partition.writeSupervisorConfigurationFiles()
partition_id = self.partition.partition_id group_id = self.partition.getGroupIdFromSuffix()
runners = ['runner-{}'.format(i) for i in range(3)] filepath = os.path.join(
path = os.path.join(self.partition.instance_path, 'etc/run') self.partition.supervisord_partition_configuration_dir,
self.partition.addServiceToGroup(partition_id, runners, path) group_id + '.conf'
)
with open(filepath) as f:
supervisor_conf = f.read()
for i in range(3): for i in range(3):
self.assertIn('program:{}_runner-{}'.format(partition_id, i), self.assertIn('program:%s_runner-%s' % (group_id, i), supervisor_conf)
self.partition.partition_supervisor_configuration)
runner_path = os.path.join(self.partition.instance_path, 'etc/run',
'runner-{}'.format(i))
class TestPartitionDestructionLock(MasterMixin, unittest.TestCase): class TestPartitionDestructionLock(MasterMixin, unittest.TestCase):
def setUp(self): def setUp(self):
......
...@@ -3030,13 +3030,17 @@ exit 0 ...@@ -3030,13 +3030,17 @@ exit 0
stat_info = os.stat(partition.partition_path) stat_info = os.stat(partition.partition_path)
uid = stat_info.st_uid uid = stat_info.st_uid
gid = stat_info.st_gid gid = stat_info.st_gid
supervisor_conf_file = os.path.join(self.instance_root, partition_supervisor_conf_file = os.path.join(self.instance_root,
'etc/supervisord.conf.d', 'etc/supervisord.conf.d',
'%s.conf' % partition.name) '%s.conf' % partition.name)
self.assertTrue(os.path.exists(supervisor_conf_file)) prerm_supervisor_conf_file = os.path.join(self.instance_root,
'etc/supervisord.conf.d',
'%s-prerm.conf' % partition.name)
self.assertFalse(os.path.exists(partition_supervisor_conf_file))
self.assertTrue(os.path.exists(prerm_supervisor_conf_file))
regex_user = r"user=(\d+)" regex_user = r"user=(\d+)"
regex_group = r"group=(\d+)" regex_group = r"group=(\d+)"
with open(supervisor_conf_file) as f: with open(prerm_supervisor_conf_file) as f:
config = f.read() config = f.read()
# search user uid in conf file # search user uid in conf file
result = re.search(regex_user, config, re.DOTALL) result = re.search(regex_user, config, re.DOTALL)
...@@ -3113,8 +3117,8 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3113,8 +3117,8 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.computer = self.getTestComputerClass()(self.software_root, self.instance_root) self.computer = self.getTestComputerClass()(self.software_root, self.instance_root)
self.partition = self.computer.instance_list[0] self.partition = self.computer.instance_list[0]
self.instance_supervisord_config_path = os.path.join( self.socat_supervisord_config_path = os.path.join(
self.instance_root, 'etc/supervisord.conf.d/0.conf') self.instance_root, 'etc/supervisord.conf.d/0-socat.conf')
self.port_redirect_path = os.path.join(self.partition.partition_path, self.port_redirect_path = os.path.join(self.partition.partition_path,
slapmanager.portredir.Manager.port_redirect_filename) slapmanager.portredir.Manager.port_redirect_filename)
...@@ -3122,8 +3126,8 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3122,8 +3126,8 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
def _mock_requests(self): def _mock_requests(self):
return httmock.HTTMock(self.computer.request_handler) return httmock.HTTMock(self.computer.request_handler)
def _read_instance_supervisord_config(self): def _read_socat_supervisord_config(self):
with open(self.instance_supervisord_config_path) as f: with open(self.socat_supervisord_config_path) as f:
return f.read() return f.read()
def _setup_instance(self, config): def _setup_instance(self, config):
...@@ -3151,9 +3155,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3151,9 +3155,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
]) ])
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() socat_supervisord_config = self._read_socat_supervisord_config()
self.assertIn('socat-tcp-{}'.format(1234), partition_supervisord_config) self.assertIn('socat-tcp-{}'.format(1234), socat_supervisord_config)
self.assertIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config) self.assertIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', socat_supervisord_config)
def test_ipv6_port_redirection(self): def test_ipv6_port_redirection(self):
with self._mock_requests(): with self._mock_requests():
...@@ -3166,9 +3170,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3166,9 +3170,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
]) ])
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() socat_supervisord_config = self._read_socat_supervisord_config()
self.assertIn('socat-tcp-{}'.format(1234), partition_supervisord_config) self.assertIn('socat-tcp-{}'.format(1234), socat_supervisord_config)
self.assertIn('socat TCP4-LISTEN:1234,fork TCP6:[::1]:4321', partition_supervisord_config) self.assertIn('socat TCP4-LISTEN:1234,fork TCP6:[::1]:4321', socat_supervisord_config)
def test_udp_port_redirection(self): def test_udp_port_redirection(self):
with self._mock_requests(): with self._mock_requests():
...@@ -3182,9 +3186,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3182,9 +3186,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
]) ])
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() socat_supervisord_config = self._read_socat_supervisord_config()
self.assertIn('socat-udp-{}'.format(1234), partition_supervisord_config) self.assertIn('socat-udp-{}'.format(1234), socat_supervisord_config)
self.assertIn('socat UDP4-LISTEN:1234,fork UDP4:127.0.0.1:4321', partition_supervisord_config) self.assertIn('socat UDP4-LISTEN:1234,fork UDP4:127.0.0.1:4321', socat_supervisord_config)
def test_portredir_config_change(self): def test_portredir_config_change(self):
# We want the partition to just get updated, not recreated # We want the partition to just get updated, not recreated
...@@ -3200,9 +3204,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3200,9 +3204,9 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
]) ])
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() socat_supervisord_config = self._read_socat_supervisord_config()
self.assertIn('socat-tcp-{}'.format(1234), partition_supervisord_config) self.assertIn('socat-tcp-{}'.format(1234), socat_supervisord_config)
self.assertIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config) self.assertIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', socat_supervisord_config)
# Remove the port binding from config # Remove the port binding from config
with open(self.port_redirect_path, 'w+') as f: with open(self.port_redirect_path, 'w+') as f:
...@@ -3219,9 +3223,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3219,9 +3223,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertEqual(self.partition.state, 'started') self.assertEqual(self.partition.state, 'started')
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() self.assertFalse(os.path.exists(self.socat_supervisord_config_path))
self.assertNotIn('socat-tcp-{}'.format(1234), partition_supervisord_config)
self.assertNotIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
def test_port_redirection_config_bad_source_port(self): def test_port_redirection_config_bad_source_port(self):
with self._mock_requests(): with self._mock_requests():
...@@ -3234,9 +3236,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3234,9 +3236,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
]) ])
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() self.assertFalse(os.path.exists(self.socat_supervisord_config_path))
self.assertNotIn('socat-tcp-bad', partition_supervisord_config)
self.assertNotIn('socat TCP4-LISTEN:bad,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
def test_port_redirection_config_bad_dest_port(self): def test_port_redirection_config_bad_dest_port(self):
with self._mock_requests(): with self._mock_requests():
...@@ -3249,9 +3249,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3249,9 +3249,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
]) ])
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() self.assertFalse(os.path.exists(self.socat_supervisord_config_path))
self.assertNotIn('socat-tcp-1234', partition_supervisord_config)
self.assertNotIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:wolf', partition_supervisord_config)
def test_port_redirection_config_bad_source_address(self): def test_port_redirection_config_bad_source_address(self):
with self._mock_requests(): with self._mock_requests():
...@@ -3265,9 +3263,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3265,9 +3263,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
]) ])
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() self.assertFalse(os.path.exists(self.socat_supervisord_config_path))
self.assertNotIn('socat-tcp-1234', partition_supervisord_config)
self.assertNotIn('socat TCP4-LISTEN:1234,bind=bad,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
def test_port_redirection_config_bad_dest_address(self): def test_port_redirection_config_bad_dest_address(self):
with self._mock_requests(): with self._mock_requests():
...@@ -3280,9 +3276,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3280,9 +3276,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
]) ])
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() self.assertFalse(os.path.exists(self.socat_supervisord_config_path))
self.assertNotIn('socat-tcp-1234', partition_supervisord_config)
self.assertNotIn('socat TCP4-LISTEN:1234,fork TCP4:wolf:4321', partition_supervisord_config)
def test_port_redirection_config_bad_redir_type(self): def test_port_redirection_config_bad_redir_type(self):
with self._mock_requests(): with self._mock_requests():
...@@ -3296,9 +3290,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase): ...@@ -3296,9 +3290,7 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
]) ])
# Check the socat command # Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config() self.assertFalse(os.path.exists(self.socat_supervisord_config_path))
self.assertNotIn('socat-htcpcp-1234', partition_supervisord_config)
self.assertNotIn('socat HTCPCP4-LISTEN:1234,fork HTCPCP4:127.0.0.1:4321', partition_supervisord_config)
class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase): class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase):
......
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