def test_manage_jobs(): """ Verify that it is possible to create, edit and manage jobs via the Python client """ server = kiwibes.KiwibesServer("python-client-token",verify_cert=False) # get the initial list of jobs initial_jobs = sorted(["sleep_10","list_home","hello_world"]) assert initial_jobs == sorted(server.get_all_jobs()) # verify that no jobs are currently scheduled assert [] == server.get_scheduled_jobs() # add a new job, without a schedule assert server.ERROR_NO_ERROR == server.create_job("jobby","",["/bin/ls","-hal"]) assert "jobby" in server.get_all_jobs() # try to add a job with an invalid Cron schedule assert server.ERROR_JOB_SCHEDULE_INVALID == server.create_job("jaba","* * ? 34",["/bin/ls","-hal"]) assert not "jaba" in server.get_all_jobs() # cannot add a job if the name already exists assert server.ERROR_JOB_NAME_TAKEN == server.create_job("jobby","",["/bin/ls","-h"]) # cannot delete a job that does not exist assert server.ERROR_JOB_NAME_UNKNOWN == server.delete_job("ASASASDSDFsf") # can delete a job that exists assert server.ERROR_NO_ERROR == server.delete_job("sleep_10") assert not "sleep_10" in server.get_all_jobs()
def test_invalid_constructor_params(): """ Give wrong parameters to the client constructor """ # not checking certificate for a self-signed cert, default parameters server = kiwibes.KiwibesServer("python-client-token") try: server.get_all_jobs() assert True == False except kiwibes.KiwibesServerError as e: assert e.error == server.ERROR_HTTPS_CERTS_FAIL try: server.start_job("sleep_10") assert True == False except kiwibes.KiwibesServerError as e: assert e.error == server.ERROR_HTTPS_CERTS_FAIL # invalid authentication token server = kiwibes.KiwibesServer("invalid-security-token", verify_cert=False) assert server.ERROR_AUTHENTICATION_FAIL == server.start_job("sleep_10") assert None == server.get_job_details("sleep_10") # server un-reachable server = kiwibes.KiwibesServer("python-client-token", host="somewhere", port=12345, verify_cert=False) try: server.start_job("sleep_10") assert True == False except kiwibes.KiwibesServerError as e: assert e.error == server.ERROR_SERVER_NOT_FOUND try: server.get_job_details("sleep_10") assert True == False except kiwibes.KiwibesServerError as e: assert e.error == server.ERROR_SERVER_NOT_FOUND
def test_ping_server(): """ Use the ping() call to verify that the client can communicate with the server. """ # pinging a server that cannot be reached server = kiwibes.KiwibesServer("python-client-token", host="somewhere", port=12345, verify_cert=False) assert None == server.ping() # pinging a server, using an invalid authentication token server = kiwibes.KiwibesServer("blavlalbal", verify_cert=False) assert None == server.ping() # pinging a server with a self-signed certificate but explicitly checking it server = kiwibes.KiwibesServer("python-client-token") assert None == server.ping() # pinging a server with a correctly initialized client server = kiwibes.KiwibesServer("python-client-token", verify_cert=False) assert "pong" == server.ping()
def test_edit_job_parameters(): """ Verify it is possible to edit the job parameters """ server = kiwibes.KiwibesServer("python-client-token",verify_cert=False) # cannot modify the details of a non-existing job assert server.ERROR_JOB_NAME_UNKNOWN == server.edit_job_schedule("asdasd","") assert server.ERROR_JOB_NAME_UNKNOWN == server.edit_job_program("asdasd",[]) assert server.ERROR_JOB_NAME_UNKNOWN == server.edit_job_max_runtime("asdasd",0) # can modify the details of a job server.ERROR_NO_ERROR == server.edit_job_schedule("sleep_10","* * * * 5 1") server.ERROR_NO_ERROR == server.edit_job_max_runtime("sleep_10",20) server.ERROR_NO_ERROR == server.edit_job_program("sleep_10",["/bin/sleep","20"]) details = server.get_job_details("sleep_10") assert "* * * * 5 1" == details["schedule"] assert ["/bin/sleep","20"] == details["program"] assert 20 == details["max-runtime"] assert "sleep_10" in server.get_scheduled_jobs()
def test_start_and_stop_jobs(): """ Verify that jobs can be started and stop via the client """ server = kiwibes.KiwibesServer("python-client-token",verify_cert=False) # attempt to start or stop a job that does not exist assert server.ERROR_JOB_NAME_UNKNOWN == server.start_job("jobby") assert server.ERROR_JOB_NAME_UNKNOWN == server.stop_job("jobby") # cannot stop a job that is not running assert server.ERROR_JOB_IS_NOT_RUNNING == server.stop_job("sleep_10") # can start a job that is already running, it will be queue assert server.ERROR_NO_ERROR == server.start_job("sleep_10") assert server.ERROR_NO_ERROR == server.start_job("sleep_10") assert server.ERROR_NO_ERROR == server.start_job("sleep_10") assert server.ERROR_NO_ERROR == server.start_job("sleep_10") details = server.get_job_details("sleep_10") assert "running" == details["status"] assert 3 == details["pending-start"] # clear the wait queue assert server.ERROR_NO_ERROR == server.clear_job_queue("sleep_10") details = server.get_job_details("sleep_10") assert "running" == details["status"] assert 0 == details["pending-start"] # stop the job assert server.ERROR_NO_ERROR == server.stop_job("sleep_10") time.sleep(1.0) details = server.get_job_details("sleep_10") assert "stopped" == details["status"]