def test_daemon_start_stop(self, wait_for_pidfile, chdir, get_size, supports, java_home, kill): cfg = config.Config() cfg.add(config.Scope.application, "node", "root.dir", "test") cfg.add(config.Scope.application, "mechanic", "keep.running", False) cfg.add(config.Scope.application, "mechanic", "telemetry.devices", []) cfg.add(config.Scope.application, "mechanic", "telemetry.params", None) cfg.add(config.Scope.application, "system", "env.name", "test") ms = get_metrics_store(cfg) proc_launcher = launcher.ProcessLauncher(cfg, ms, paths.races_root(cfg)) node_config = NodeConfiguration(car=Car("default", root_path=None, config_paths=[]), ip="127.0.0.1", node_name="testnode", node_root_path="/tmp", binary_path="/tmp", log_path="/tmp", data_paths="/tmp") nodes = proc_launcher.start([node_config]) self.assertEqual(len(nodes), 1) self.assertEqual(nodes[0].pid, MOCK_PID_VALUE) proc_launcher.stop(nodes) self.assertTrue(kill.called)
def test_daemon_start_stop(self, wait_for_pidfile, chdir, get_size, supports, java_home): cfg = config.Config() cfg.add(config.Scope.application, "node", "root.dir", "test") cfg.add(config.Scope.application, "mechanic", "keep.running", False) cfg.add(config.Scope.application, "telemetry", "devices", []) cfg.add(config.Scope.application, "telemetry", "params", None) cfg.add(config.Scope.application, "system", "env.name", "test") ms = get_metrics_store(cfg) proc_launcher = launcher.ProcessLauncher(cfg) node_configs = [] for node in range(2): node_configs.append( NodeConfiguration(build_type="tar", car_env={}, car_runtime_jdks="12,11", ip="127.0.0.1", node_name="testnode-{}".format(node), node_root_path="/tmp", binary_path="/tmp", data_paths="/tmp")) nodes = proc_launcher.start(node_configs) self.assertEqual(len(nodes), 2) self.assertEqual(nodes[0].pid, MOCK_PID_VALUE) stopped_nodes = proc_launcher.stop(nodes, ms) # all nodes should be stopped self.assertEqual(nodes, stopped_nodes)
def test_starts_container_successfully(self, run_subprocess_with_output, run_subprocess_with_logging): run_subprocess_with_logging.return_value = 0 # Docker container id (from docker-compose ps), Docker container id (from docker ps --filter ...) run_subprocess_with_output.side_effect = [["de604d0d"], ["de604d0d"]] cfg = config.Config() docker = launcher.DockerLauncher(cfg) node_config = NodeConfiguration(build_type="docker", car_env={}, car_runtime_jdks="12,11", ip="127.0.0.1", node_name="testnode", node_root_path="/tmp", binary_path="/bin", data_paths="/tmp") nodes = docker.start([node_config]) self.assertEqual(1, len(nodes)) node = nodes[0] self.assertEqual(0, node.pid) self.assertEqual("/bin", node.binary_path) self.assertEqual("127.0.0.1", node.host_name) self.assertEqual("testnode", node.node_name) self.assertIsNotNone(node.telemetry) run_subprocess_with_logging.assert_called_once_with( "docker-compose -f /bin/docker-compose.yml up -d") run_subprocess_with_output.assert_has_calls([ mock.call("docker-compose -f /bin/docker-compose.yml ps -q"), mock.call( 'docker ps -a --filter "id=de604d0d" --filter "status=running" --filter "health=healthy" -q' ) ])
def test_container_not_started(self, run_subprocess_with_output, run_subprocess_with_logging, sleep): run_subprocess_with_logging.return_value = 0 # Docker container id (from docker-compose ps), but NO Docker container id (from docker ps --filter...) twice run_subprocess_with_output.side_effect = [["de604d0d"], [], []] cfg = config.Config() # ensure we only check the status two times stop_watch = DockerLauncherTests.IterationBasedStopWatch( max_iterations=2) docker = launcher.DockerLauncher( cfg, clock=DockerLauncherTests.TestClock(stop_watch=stop_watch)) node_config = NodeConfiguration(build_type="docker", car_env={}, car_runtime_jdks="12,11", ip="127.0.0.1", node_name="testnode", node_root_path="/tmp", binary_path="/bin", data_paths="/tmp") with self.assertRaisesRegex( exceptions.LaunchError, "No healthy running container after 600 seconds!"): docker.start([node_config])