Specify log file through API#250
Conversation
| assert!(&desc.into_parsed_request().is_ok()); | ||
| // I will test this when the other unit tests are merged | ||
| //let (sender, receiver) = oneshot::channel(); | ||
| //assert!(&desc.into_parsed_request().eq(&Ok(ParsedRequest::Sync(SyncRequest::PutLogger(desc, sender), receiver)))); |
There was a problem hiding this comment.
In order for this to work, you need to implement the use case for PutLogger in impl PartialEq for SyncRequest.
There was a problem hiding this comment.
Done. Thanks for the hint.
|
|
||
| static INIT: Once = ONCE_INIT; | ||
| static mut INIT_RES: Result<usize> = Ok(UNINITIALIZED); | ||
| //static INIT: Once = ONCE_INIT; |
There was a problem hiding this comment.
If INIT isn't needed any more, please remove it instead of commenting it out.
| INIT_RES = Err(LoggerError::NeverInitialized(format!("{}", e))) | ||
| Err(ref e) => { | ||
| STATE.store(UNINITIALIZED, Ordering::SeqCst); | ||
| return Err(LoggerError::NeverInitialized(format!("{}", e))); |
There was a problem hiding this comment.
Cosmetic concern: the error e is propagated all the way up from libstd::io::File::create and is one of libstd::io::error::ErrorKind, the string representations of which are all lowercase. So the error message (as seen in the tests run) looks like
{
"fault_message": "Cannot initialize logging system! Failed to create log file. entity not found"
}Can you please make the error message something like Failed to create log file. Error: <propagated error> ?
There was a problem hiding this comment.
Solved it; Take a look at error.rs in impl fmt::Display for LoggerError.
| } | ||
| } | ||
| SyncRequest::PutLogger(logger_description, sender) => { | ||
| eprintln!( |
There was a problem hiding this comment.
I mistakenly left it there. I removed it now.
| description: | ||
| Describes the configuration option for the logger intitialization. | ||
| properties: | ||
| source_type: |
There was a problem hiding this comment.
This field is not necessary. Just use the path like all other resources currently do. When we move to FD passing, we will change all API calls from using path to using FDs.
I believe this field will never be used so I suggest removing it.
There was a problem hiding this comment.
Are you confident that we will only support FD passing? Why not keep around both versions?
There was a problem hiding this comment.
I am confident we will not support both versions at the same time 😃
There was a problem hiding this comment.
hehe :) I will do the change.
There was a problem hiding this comment.
done, take a look please
| schema: | ||
| $ref: "#/definitions/Error" | ||
|
|
||
| /logger: |
There was a problem hiding this comment.
Please add these to firecracker-v1.0.yaml as well.
There was a problem hiding this comment.
We discussed about it yesterday. firecracker-v1.0.yaml is very outdated. So we have here two possibilities: either update it to match what we have now in firecracker-beta, or we don't update it at all for now and only use it as a " What the future looks like" yaml. Since we are sort of time bound, I suggest we don't update it for now.
| path, | ||
| str::from_utf8(body.as_ref()).unwrap() | ||
| // when time will come, we could better do | ||
| serde_json::from_slice(&body).unwrap() |
There was a problem hiding this comment.
Uncommenting this debug block breaks compilation with this change.
There was a problem hiding this comment.
I know. I left it there to consider it as an option 'when time will come'. Do we want me to remove it or solve the compilation errors?
There was a problem hiding this comment.
It's more of a nit, you could leave it as is, but I would add '//' to it so that the code still works when uncommenting the whole block.
|
|
||
| type Result<T> = result::Result<T, APILoggerError>; | ||
|
|
||
| pub fn init_logger(api_logger: APILoggerDescription) -> Result<()> { |
There was a problem hiding this comment.
Ideally you could've/should've used the new API<->VMM model that uses common data structs for both api_server and vmm.
This new model is the one proposed in @andreeaflorescu 's PR #248 in the data_model crate.
The code here looks very good and I'm personally fine with merging it, but do have a look at the aforementioned PR and decide for yourself.
There was a problem hiding this comment.
So, if you take a closer look you will see that logger_config does not redefine any type; What #248 wants is to remove the necessity to redefine types inside vmm, which in my case does not happen.
| "{:?}", | ||
| LoggerError::Poisoned(String::from("Never Initialized")) | ||
| ).contains("Poisoned") | ||
| println!( |
There was a problem hiding this comment.
Why do we want to print all of these (all the println!s in this test) during unit tests?
There was a problem hiding this comment.
to increase coverage; this prints are the ones that exercise the Debug trait.
There was a problem hiding this comment.
They exercise, but don't check anything thus giving us false coverage.
Without proper checking we could break something and unittests and coverage will still look good.
I suggest you find a way to actually check the Debug trait output, or otherwise remove this and leave it without coverage.
through an API call. Signed-off-by: Diana Popa <dpopa@amazon.com>
* removed static variable for keeping status * used AtomicSize for safely sharing state between threads * appended relevant error on top of the low level one * removed Poison status error as it stopped us from being able to try reinitialization Signed-off-by: Diana Popa <dpopa@amazon.com>
* call asserts on the last code in the test_init * exercise Display for the LoggerError Signed-off-by: Diana Popa <dpopa@amazon.com>
Signed-off-by: Diana Popa <dpopa@amazon.com>
inside the vmm as an intermediate step in the logger setup triggered by the API. Signed-off-by: Diana Popa <dpopa@amazon.com>
Changes
Testing
Build Time
Prerequisite
## add the necessary musl target to the active toolchain rustup target add x86_64-unknown-linux-muslBuild tests
Coverage report for logger related files
Integration Testing
rm -f /tmp/firecracker.socket && \ target/x86_64-unknown-linux-musl/debug/firecracker --api-sock=/tmp/firecracker.socketHTTP/1.1 400 Bad Request Content-Type: application/json Transfer-Encoding: chunked Date: Fri, 04 May 2018 14:29:05 GMT { "fault_message": "Cannot initialize logging system! Reinitialization of logger not allowed." }curl --unix-socket /tmp/firecracker.socket -i \ -X PUT "http://localhost/boot-source" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ -d "{ \"boot_source_id\": \"alinux_kernel\", \"source_type\": \"LocalImage\", \"local_image\": { \"kernel_image_path\": \"${kernel_path}\" } }" curl --unix-socket /tmp/firecracker.socket -i \ -X PUT "http://localhost/machine-config" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ -d "{ \"vcpu_count\": 4, \"mem_size_mib\": 256}" # Add root block device curl --unix-socket /tmp/firecracker.socket -i \ -X PUT "http://localhost/drives/root" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ -d "{ \"drive_id\": \"root\", \"path_on_host\": \"${rootfs_path}\", \"is_root_device\": true, \"permissions\": \"rw\", \"state\": \"Attached\" }" curl --unix-socket /tmp/firecracker.socket -i \ -X PUT "http://localhost/actions/start" \ -H "accept: application/json" \ -H "Content-Type: application/json" \ -d "{ \"action_id\": \"start\", \"action_type\": \"InstanceStart\" }" # Get the response of starting the instance curl --unix-socket /tmp/firecracker.socket -i \ -X GET "http://localhost/actions/start" \ -H "accept: application/json" sudo ip link delete vmtap33