Skip to content

Logging updates prior to supporting configuration through the API #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2018
Merged

Logging updates prior to supporting configuration through the API #246

merged 1 commit into from
May 3, 2018

Conversation

dianpopa
Copy link
Contributor

@dianpopa dianpopa commented May 1, 2018

Changes

  • changed signature of the set functions inside the logger to receive reference to self (when configuring the logger from an external struct we need to be able to call the set functions separately).
  • added a constant to tell us when user attempts initialization of the logging system
  • updated unit tests to match changes

Testing

Build Time

Prerequisite

## add the necessary musl target to the active toolchain
rustup target add x86_64-unknown-linux-musl

Build tests

cargo fmt —all
cargo build # no warning
cargo build —release # no warning
sudo env "PATH=$PATH" cargo test --all #no warin
sudo env "PATH=$PATH" cargo kcov —all # overall 44.3%

Integration Testing

rm -f /tmp/firecracker.socket && \
target/debug/firecracker --api-sock=/tmp/firecracker.socket
  • in another console start sending curl requests for starting basic firecracker guest
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}\" 
                }
        }"

echo 2
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
echo 3
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\"
         }"


# Add readonly device
echo 4
curl --unix-socket /tmp/firecracker.socket -i \
     -X PUT "http://localhost/drives/read_only_drive" \
     -H "accept: application/json" \
     -H "Content-Type: application/json" \
     -d "{ 
            \"drive_id\": \"read_only_drive\",
            \"path_on_host\": \"${ro_drive_path}\", 
            \"is_root_device\": false, 
            \"permissions\": \"ro\", 
            \"state\": \"Attached\"
         }"

# Create a tap interface
ip tuntap add name vmtap33 mode tap
ifconfig vmtap33 192.168.241.1/24 up
echo 5
curl --unix-socket /tmp/firecracker.socket -i \
     -X PUT "http://localhost/network-interfaces/1" \
     -H "accept: application/json" \
     -H "Content-Type: application/json" \
     -d "{ 
            \"iface_id\": \"1\", 
            \"host_dev_name\": \"vmtap33\", 
            \"guest_mac\": \"06:00:00:00:00:01\", 
            \"state\": \"Attached\" 
        }"

echo 6
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
echo 7
curl --unix-socket /tmp/firecracker.socket -i \
     -X GET "http://localhost/actions/start" \
     -H "accept: application/json"

sudo ip link delete vmtap33
  • in the initial console the guest should start up
# login: ...
# reboot

@dianpopa dianpopa self-assigned this May 1, 2018
@dianpopa dianpopa requested a review from a team May 1, 2018 15:06
@dianpopa dianpopa changed the title Logging updates prior to support configuration through the API Logging updates prior to supporting configuration through the API May 2, 2018
@acatangiu
Copy link
Contributor

typo in commit message: s/confiuring/configuring

@@ -24,6 +26,7 @@ impl fmt::Display for LoggerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let printable = match *self {
LoggerError::NeverInitialized(ref e) => e,
LoggerError::AlreadyInitialized => "Attempt at reinitialization",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This error message is a bit nondescript, maybe change it to something like "Reinitialization of logger is not allowed" or "Logger already initialized" ?

@@ -259,7 +258,10 @@ impl Logger {
"{}",
INIT_RES.as_ref().err().unwrap()
)));
} else if INIT_RES.is_ok() && INIT_RES.as_ref().ok().unwrap() == &INITIALIZED {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • no need for .ok() before .unwrap()
  • while comparing references is fine in Rust because auto DeRef() is being done ( https://www.reddit.com/r/rust/comments/2dmzf6/why_do_equality_tests_of_references_seem_to/ ), it looks a bit weird; I suggest removing the '&' from '&INITIALIZED' if the compiler doesn't complain about it.
  • nit: instead of error on "state == INITIALIZED", it's better practice to error on "state != UNINITIALIZED", that way if for whatever reason a new state is added, this check is still valid and correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I did try it without references. If I call unwrap on INIT_RES it would try to move the content and given that INIT_RES is static the compiler complains about it. It does complain if I remove the &.

assert_eq!(l.show_line_numbers, false);

let l = Logger::new()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to be able to do the configuration of the logger (i.e. call the set functions) progressively. In the first version where the functions would return self I would only be able to do it from one call (Logger::new.set_bla.set_bla2 ...). But in the case of the API I need to be able to parse the config that I receive and call the set functions separately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@dianpopa
Copy link
Contributor Author

dianpopa commented May 3, 2018

@acatangiu The typo is in the pr description. I updated it. The commit message looks ok to me.

@dianpopa dianpopa requested a review from a team May 3, 2018 09:16
alxiord
alxiord previously approved these changes May 3, 2018
acatangiu
acatangiu previously approved these changes May 3, 2018
configuration of the logger from outside the crate.

Signed-off-by: Diana Popa <[email protected]>
@dianpopa dianpopa merged commit 6480b5b into firecracker-microvm:master May 3, 2018
@dianpopa dianpopa deleted the logger_updates branch June 13, 2018 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants