def test__host_draining_resumes_on_hostmgr_recovery(host_affinity_job, maintenance, resmgr, hostmgr): # Pick a host that is UP and start maintenance on it test_host = get_host_in_state(hpb.HOST_STATE_UP) # Set host affinity of the job to the selected host host_affinity_job.job_config.defaultConfig.\ constraint.labelConstraint.label.value = test_host host_affinity_job.create() host_affinity_job.wait_for_state(goal_state='RUNNING') def all_running(): return all(t.state == task.RUNNING for t in host_affinity_job.get_tasks().values()) host_affinity_job.wait_for_condition(all_running) constraint = host_affinity_job.job_config.defaultConfig.constraint test_host = constraint.labelConstraint.label.value # Stop resmgr to ensure maintenance queue is not polled resmgr.stop() resp = maintenance['start']([test_host]) assert resp hostmgr.restart() resmgr.start() # Wait for host to transition to DOWN host.wait_for_host_state(test_host, hpb.HOST_STATE_DOWN)
def test__host_maintenance_lifecycle(host_affinity_job, maintenance): # Pick a host that is UP and start maintenance on it test_host = get_host_in_state(hpb.HOST_STATE_UP) # Set host affinity of the job to the selected host host_affinity_job.job_config.defaultConfig.\ constraint.labelConstraint.label.value = test_host host_affinity_job.create() # Start maintenance on the selected host resp = maintenance['start']([test_host]) assert resp assert host.is_host_in_state(test_host, hpb.HOST_STATE_DRAINING) # Wait for host to transition to DOWN host.wait_for_host_state(test_host, hpb.HOST_STATE_DOWN) # Complete maintenance on the test hosts resp = maintenance['stop']([test_host]) assert resp # Host should no longer be DOWN assert not host.is_host_in_state(test_host, hpb.HOST_STATE_DOWN) host.wait_for_host_state(test_host, hpb.HOST_STATE_UP)
def clean_up(): # kill stateless jobs. This is needed since host draining # is done in SLA aware manner for stateless jobs. for j in stateless_query_jobs(client=client[0]): j.stop() if not draining_hosts: return for h in draining_hosts: wait_for_host_state(h, host_pb2.HOST_STATE_DOWN) stop(draining_hosts)
def clean_up(): if not draining_hosts: return for h in draining_hosts: wait_for_host_state(h, host_pb2.HOST_STATE_DOWN) stop(draining_hosts)