Exemple #1
0
    def test_create_service_read(self):
        """Test parsing of LongRunning service data.
        """
        mock_svc_dir = os.path.join(self.root, 'my_svc')
        os.mkdir(mock_svc_dir)
        with io.open(os.path.join(mock_svc_dir, 'type'), 'w') as f:
            f.write('longrun')
        with io.open(os.path.join(mock_svc_dir, 'run'), 'w') as f:
            f.write('mock run script')
        with io.open(os.path.join(mock_svc_dir, 'down'), 'w') as f:
            pass
        with io.open(os.path.join(mock_svc_dir, 'notification-fd'), 'w') as f:
            f.write('42')
        os.mkdir(os.path.join(mock_svc_dir, 'data'))
        os.mkdir(os.path.join(mock_svc_dir, 'env'))
        with io.open(os.path.join(mock_svc_dir, 'env', 'HOME'), 'w') as f:
            f.write(u'/my/home\n')
        with io.open(os.path.join(mock_svc_dir, 'env', 'FOO'), 'w') as f:
            f.write(u'bar\n')

        mock_svc = s6.create_service(self.root, 'my_svc',
                                     _service_base.ServiceType.LongRun)

        self.assertEqual(mock_svc.type, _service_base.ServiceType.LongRun)
        self.assertEqual(mock_svc.run_script, 'mock run script')
        self.assertEqual(mock_svc.default_down, True)
        self.assertEqual(mock_svc.notification_fd, 42)
        self.assertEqual(mock_svc.data_dir,
                         os.path.join(self.root, 'my_svc', 'data'))
        self.assertEqual(mock_svc.env_dir,
                         os.path.join(self.root, 'my_svc', 'env'))
        self.assertEqual(mock_svc.environ, {
            'FOO': 'bar',
            'HOME': '/my/home',
        })
Exemple #2
0
    def test_new(self):
        """Test service factory.
        """
        mock_svc = s6.create_service(
            self.root, 'mock', _service_base.ServiceType.LongRun,
            run_script='test'
        )

        self.assertIsNotNone(mock_svc)
        s6.services.LongrunService.assert_called_with(
            self.root, 'mock', run_script='test'
        )