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