type(popen_intance_mock).pid=pid_property_mock# a property mock cannot be attached directly to the mock object, hence use its type object
type(popen_intance_mock).returncode=returncode_property_mock# a property mock cannot be attached directly to the mock object, hence use its type object
popen_mock.assert_called_with("graph_pipeline.sh",body)# assert that the graph pipeline script is ran with the JSON config that was received in the request
popen_intance_mock.pid.assert_called()# assert that the process ID attribute was called and saved
popen_mock.assert_called_once_with(["./graph_pipeline.sh",body])# assert that the graph pipeline script is ran with the JSON config that was received in the request
pid_property_mock.assert_called_once_with()# assert that the process ID attribute was called and saved
returncode_property_mock.assert_called_once_with()# assert that the process return code attribute was called to check if the process has started successfully
# check erroneous behaviour
returncode_property_mock.return_value=-1
request=testing.DummyRequest()
request.body=body.encode(request.charset)
error_raised=False
try:
GraphAPI(request).execute_graph_pipeline()
exceptHTTPInternalServerError:
error_raised=True
asserterror_raised,"Expecting a 500 HTTP error if the process terminated immediately after it was started"
popen_mock.assert_called_with(["./graph_pipeline.sh",body])# assert that the graph pipeline script is ran with the JSON config that was received in the request
pid_property_mock.assert_called_with()# assert that the process ID attribute was called and saved
returncode_property_mock.assert_called_with()# assert that the process return code attribute was called to check if the process has started successfully
else:# a valid returned code was returned, hence the process has terminated one way or another - we do not expect this since the pipeline script must be continuously running
log.warning("Graph pipeline process for SFC {0} with PID {1} has finished executing unexpectedly with return code {2}".format(sfc,process_pid,process_return_code))
raiseHTTPInternalServerError("An unexpected error occurred while trying to start monitoring graph measurements for service function chain {0}".format(sfc))