Beispiel #1
0
    def test_execute_pid1_aborted(self):
        """Test shutting down of the node.
        """
        mock_tm_env_class = collections.namedtuple(
            'MockTMEnv', ['running_dir', 'cleanup_dir'])
        mock_tm_env = mock_tm_env_class(os.path.join(self.root, 'running'),
                                        os.path.join(self.root, 'cleanup'))

        service_dir = os.path.join(mock_tm_env.running_dir, 'mock_service')
        fs.mkdir_safe(service_dir)

        with io.open(os.path.join(service_dir, 'type'), 'w') as f:
            f.write('longrun')

        mock_container_cleanup_action =\
            monitor.MonitorContainerCleanup(mock_tm_env, {})

        res = mock_container_cleanup_action.execute({
            'signal': 6,
            'id': 'mock_service',
        })

        # This MonitorContainerCleanup stops the monitor.
        self.assertEqual(res, True)

        treadmill.appcfg.abort.flag_aborted.assert_called_with(
            os.path.join(service_dir, 'data'),
            why=treadmill.appcfg.abort.AbortedReason.PID1)
        os.replace.assert_called()

        supervisor.control_svscan.assert_called_with(
            os.path.join(self.root, 'running'), [
                supervisor.SvscanControlAction.alarm,
                supervisor.SvscanControlAction.nuke
            ])
Beispiel #2
0
 def containers(approot, scan_dir):
     """Setup a monitor for the running containers.
     """
     tm_env = appenv.AppEnvironment(root=approot)
     mon = monitor.Monitor(
         scan_dirs=scan_dir,
         service_dirs=None,
         policy_impl=monitor.MonitorRestartPolicy,
         down_action=monitor.MonitorContainerCleanup(tm_env))
     mon.run()