Skip to content
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

Storewolf: adds feature to create inventory file symlink #3035

Merged
merged 1 commit into from
Apr 27, 2023

Conversation

jpmcb
Copy link
Contributor

@jpmcb jpmcb commented Apr 19, 2023

Issue number:

Closes #2967

Description of changes:

Feature for storewolf to create a symlink at a given path and destination:

/usr/bin/storewolf \
    --data-store-base-path /var/lib/bottlerocket/datastore \
    --inventory-file-symlink-path /var/lib/bottlerocket/inventory/application.json

will then create the a symlink to the default file location /usr/share/bottlerocket/application-inventory.json. Users may also specify the source location of the inventory file via the optional --inventory-file-path flag.

Testing done:

Built bottlerocket, launched instance and see symlink created correctly:

bash-5.1# ls -la /var/lib/bottlerocket/inventory/
total 8
drwxr-xr-x. 2 root root 4096 Apr 19 16:37 .
drwxr-xr-x. 5 root root 4096 Apr 19 16:37 ..
lrwxrwxrwx. 1 root root   50 Apr 19 16:37 application.json -> /usr/share/bottlerocket/application-inventory.json

Contents looks good:

bash-5.1# cat /var/lib/bottlerocket/inventory/application.json | head
{
  "Content": [
    {
      "Name": "acpid",
      "Publisher": "Bottlerocket",
      "Version": "1.14.0",
      "Release": "1ecaea34-dirty",
      "InstalledTime": "2023-04-19T16:35:20Z",
      "ApplicationType": "Unspecified",
      "Architecture": "x86_64",

And bootlogs look good:

bash-5.1# journalctl | grep "storewolf"
Apr 19 16:37:54 localhost storewolf[1537]: 16:37:54 [INFO] Storewolf started
Apr 19 16:37:54 localhost storewolf[1537]: 16:37:54 [INFO] Deleting pending transactions
Apr 19 16:37:54 localhost storewolf[1537]: 16:37:54 [INFO] Populating datastore at: /var/lib/bottlerocket/datastore
Apr 19 16:37:54 localhost storewolf[1537]: 16:37:54 [INFO] Creating datastore at: /var/lib/bottlerocket/datastore/current/live
Apr 19 16:37:54 localhost storewolf[1537]: 16:37:54 [INFO] Datastore populated
Apr 19 16:37:54 localhost storewolf[1537]: 16:37:54 [INFO] Creating inventory file symlink at: /var/lib/bottlerocket/inventory/application.json
Apr 19 16:37:54 localhost storewolf[1537]: 16:37:54 [INFO] Inventory symlink created

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@jpmcb
Copy link
Contributor Author

jpmcb commented Apr 19, 2023

Needs a rebase and cargo fmt now that #2848 has merged - incoming!

packages/os/storewolf.service Outdated Show resolved Hide resolved
sources/api/storewolf/src/main.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

Provided @bcressey / @webern 's feedback is addressed, this looks good.

One non-blocking nit. :)

sources/api/storewolf/src/main.rs Outdated Show resolved Hide resolved
@jpmcb
Copy link
Contributor Author

jpmcb commented Apr 24, 2023

Force pushed to address Ben's comments on deleting the symlink (if it's there) before attempting to create it.

@jpmcb
Copy link
Contributor Author

jpmcb commented Apr 24, 2023

Force pushed to address Zac's comment: now use two different AsRef params - tests still look good:

bash-5.1# ls -la /var/lib/bottlerocket/inventory/application.json
lrwxrwxrwx. 1 root root 50 Apr 24 15:51 /var/lib/bottlerocket/inventory/application.json -> /usr/share/bottlerocket/application-inventory.json
bash-5.1# journalctl | grep storewolf
Apr 24 15:51:26 localhost storewolf[1581]: 15:51:26 [INFO] Storewolf started
Apr 24 15:51:26 localhost storewolf[1581]: 15:51:26 [INFO] Deleting pending transactions
Apr 24 15:51:26 localhost storewolf[1581]: 15:51:26 [INFO] Populating datastore at: /var/lib/bottlerocket/datastore
Apr 24 15:51:26 localhost storewolf[1581]: 15:51:26 [INFO] Creating datastore at: /var/lib/bottlerocket/datastore/current/live
Apr 24 15:51:26 localhost storewolf[1581]: 15:51:26 [INFO] Datastore populated
Apr 24 15:51:26 localhost storewolf[1581]: 15:51:26 [INFO] Creating inventory file symlink at: /var/lib/bottlerocket/inventory/application.json
Apr 24 15:51:26 localhost storewolf[1581]: 15:51:26 [INFO] Inventory symlink created

@jpmcb jpmcb force-pushed the storewolf-symlink branch 2 times, most recently from f3c66d4 to 29469e5 Compare April 24, 2023 22:18
@jpmcb
Copy link
Contributor Author

jpmcb commented Apr 24, 2023

Force pushed to add migration and rebase on develop

@jpmcb
Copy link
Contributor Author

jpmcb commented Apr 24, 2023

Force pushed for cargo make check shenanigans.

@jpmcb
Copy link
Contributor Author

jpmcb commented Apr 26, 2023

Rebased to fix merge conflict in Release.toml

Comment on lines 25 to 45
/// On downgrade, the inventory directory (and its content) needs to be
/// deleted (see above). Also note, the "remove_dir_all" function will not
/// **not** follow symbolic links and it will simply remove the symbolic
/// link itself (which is exactly what we want).
fn backward(&mut self, input: MigrationData) -> Result<MigrationData> {
println!(
"Deleting inventory Bottlerocket directory: '{}'",
INVENTORY_SYMLINK_PATH
);
if let Err(e) = fs::remove_dir_all(INVENTORY_SYMLINK_PATH) {
if e.kind() != io::ErrorKind::NotFound {
return Err(e).context(error::RemoveFileSnafu {
path: INVENTORY_SYMLINK_PATH,
});
} else {
println!("NotFound: '{}'", INVENTORY_SYMLINK_PATH)
}
}
Ok(input)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A migration for this seems like overkill. I'm not opposed to including it but I don't see any real upside.

Signed-off-by: John McBride <jpmmcb@amazon.com>
@jpmcb
Copy link
Contributor Author

jpmcb commented Apr 26, 2023

Force pushed to remove migration per @bcressey! Will merge once tests pass again!

@jpmcb jpmcb merged commit 075b067 into bottlerocket-os:develop Apr 27, 2023
37 checks passed
@jpmcb jpmcb deleted the storewolf-symlink branch April 27, 2023 16:22
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.

Bottlerocket inventory file symlink on host
4 participants