def cleanup_forgotten_down(): """Clean up hosts forgotten down""" log.debug("Cleaning up hosts forgotten down") hosts_forgotten_down = get_hosts_forgotten_down(grace=seconds_to_nanoseconds(10 * 60)) if hosts_forgotten_down: up(hostnames=hosts_forgotten_down) else: log.debug("No hosts forgotten down")
def paasta_maintenance(): """Manipulate the maintenance state of a PaaSTA host. :returns: None """ args = parse_args() if args.verbose >= 2: logging.basicConfig(level=logging.DEBUG) elif args.verbose == 1: logging.basicConfig(level=logging.INFO) else: logging.basicConfig(level=logging.WARNING) action = args.action hostnames = args.hostname if action != 'status' and not hostnames: paasta_print("You must specify one or more hostnames") return start = args.start duration = args.duration ret = "Done" if action == 'drain': mesos_maintenance.drain(hostnames, start, duration) elif action == 'undrain': mesos_maintenance.undrain(hostnames) elif action == 'down': mesos_maintenance.down(hostnames) elif action == 'up': mesos_maintenance.up(hostnames) elif action == 'status': ret = mesos_maintenance.friendly_status() elif action == 'cluster_status': ret = mesos_maintenance.status() elif action == 'schedule': ret = mesos_maintenance.schedule() elif action == 'is_safe_to_drain': ret = is_safe_to_drain(hostnames[0]) elif action == 'is_safe_to_kill': ret = is_safe_to_kill(hostnames[0]) elif action == 'is_host_drained': ret = mesos_maintenance.is_host_drained(hostnames[0]) elif action == 'is_host_down': ret = mesos_maintenance.is_host_down(hostnames[0]) elif action == 'is_host_draining': ret = mesos_maintenance.is_host_draining(hostnames[0]) elif action == 'is_host_past_maintenance_start': ret = mesos_maintenance.is_host_past_maintenance_start(hostnames[0]) elif action == 'is_host_past_maintenance_end': ret = mesos_maintenance.is_host_past_maintenance_end(hostnames[0]) else: raise NotImplementedError("Action: '%s' is not implemented." % action) paasta_print(ret) return ret
def test_up(mock_build_maintenance_payload, mock_operator_api): fake_payload = [{"fake_schedule": "fake_value"}] mock_build_maintenance_payload.return_value = fake_payload up(hostnames=["some-host"]) assert mock_build_maintenance_payload.call_count == 1 assert mock_build_maintenance_payload.call_args == mock.call( ["some-host"], "stop_maintenance") assert mock_operator_api.call_count == 1 assert mock_operator_api.return_value.call_count == 1 expected_args = mock.call(data=fake_payload) assert mock_operator_api.return_value.call_args == expected_args
def test_up( mock_build_maintenance_payload, mock_operator_api, ): fake_payload = [{'fake_schedule': 'fake_value'}] mock_build_maintenance_payload.return_value = fake_payload up(hostnames=['some-host']) assert mock_build_maintenance_payload.call_count == 1 assert mock_build_maintenance_payload.call_args == mock.call(['some-host'], 'stop_maintenance') assert mock_operator_api.call_count == 1 assert mock_operator_api.return_value.call_count == 1 expected_args = mock.call(data=fake_payload) assert mock_operator_api.return_value.call_args == expected_args
def test_up( mock_build_start_maintenance_payload, mock_master_api, ): fake_payload = [{'fake_schedule': 'fake_value'}] mock_build_start_maintenance_payload.return_value = fake_payload up(hostnames=['some-host']) assert mock_build_start_maintenance_payload.call_count == 1 assert mock_build_start_maintenance_payload.call_args == mock.call(['some-host']) assert mock_master_api.call_count == 1 assert mock_master_api.return_value.call_count == 1 expected_args = mock.call(method="POST", endpoint="/machine/up", data=json.dumps(fake_payload)) assert mock_master_api.return_value.call_args == expected_args