def is_safe_to_kill(hostname): """Checks if a host has drained or reached its maintenance window :param hostname: hostname to check :returns: True or False """ return mesos_maintenance.is_host_drained(hostname) or \ mesos_maintenance.is_host_past_maintenance_start(hostname)
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 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 = "%s" % mesos_maintenance.status() elif action == 'schedule': ret = "%s" % 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_is_host_drained(mock_is_host_draining, mock_get_count_running_tasks_on_slave): mock_get_count_running_tasks_on_slave.side_effect = ( sideeffect_mock_get_count_running_tasks_on_slave) mock_is_host_draining.return_value = True assert not is_host_drained("host1") mock_get_count_running_tasks_on_slave.assert_called_with("host1") mock_is_host_draining.assert_called_with(hostname="host1") mock_is_host_draining.return_value = True assert is_host_drained("host2") mock_is_host_draining.return_value = False assert not is_host_drained("host1") mock_is_host_draining.return_value = False assert not is_host_drained("host2") assert not is_host_drained("host3") mock_is_host_draining.return_value = True assert is_host_drained("host3")
def test_is_host_drained( mock_is_host_draining, mock_get_count_running_tasks_on_slave, ): mock_get_count_running_tasks_on_slave.side_effect = sideeffect_mock_get_count_running_tasks_on_slave mock_is_host_draining.return_value = True assert not is_host_drained('host1') mock_get_count_running_tasks_on_slave.assert_called_with('host1') mock_is_host_draining.assert_called_with(hostname='host1') mock_is_host_draining.return_value = True assert is_host_drained('host2') mock_is_host_draining.return_value = False assert not is_host_drained('host1') mock_is_host_draining.return_value = False assert not is_host_drained('host2') assert not is_host_drained('host3') mock_is_host_draining.return_value = True assert is_host_drained('host3')