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

agent: implement status command #399

Open
glimchb opened this issue Jun 18, 2024 · 2 comments · May be fixed by #453
Open

agent: implement status command #399

glimchb opened this issue Jun 18, 2024 · 2 comments · May be fixed by #453
Labels
good first issue Good for newcomers

Comments

@glimchb
Copy link
Member

glimchb commented Jun 18, 2024

this is empty https://github.com/opiproject/sztp/blob/main/sztp-agent/pkg/secureagent/status.go

status command should show where in the onboarding stage the device is right now...
for example: waiting on DHCP response...
or downloading file...
or pending reboot...
or provisioning was already completed...
or something else...

See this example:
https://cloudinit.readthedocs.io/en/latest/howto/status.html

and code https://github.com/canonical/cloud-init/blob/a01b8d31f8364a3d86f016a2940df1b38598889d/doc/status.txt#L4

maybe do do this, we need to create a file on the filesystem, like in example above, in /var/lib/sztp/result.json and in /run/sztp/result.json

@glimchb glimchb added the question Further information is requested label Jun 18, 2024
@glimchb glimchb added good first issue Good for newcomers and removed question Further information is requested labels Jul 1, 2024
@bhoopesh369
Copy link
Contributor

bhoopesh369 commented Sep 19, 2024

In this should we recreate the /var/lib/sztp/result.json file
or just append to it, by opening in write mode
because there are potential complications with managing partial writes or file corruption. (basically to maintain atomicity)

I think initially writing to a temp file and then replace it with original works?

func SaveResultFile(result *Result, path string) error {
    tempPath := path + ".tmp"
    file, err := os.Create(tempPath)
    if err != nil {
        return err
    }
    defer file.Close()

    encoder := json.NewEncoder(file)
    if err := encoder.Encode(result); err != nil {
        return err
    }

    // Atomic move of temp file to replace the original.
    return os.Rename(tempPath, path)
}

@bhoopesh369 bhoopesh369 linked a pull request Sep 19, 2024 that will close this issue
@glimchb
Copy link
Member Author

glimchb commented Oct 3, 2024

  1. add /var/lib/sztp/result.json as argument to daemon command. this json can be default value
  2. add /var/lib/sztp/result.json as argument to status command. this json can be default value
  3. every time we doReportProgress you should also save the local state here inside this json
  4. sometimes you save local state without sending a report to bootstrap server since report progress is API call to bootstrap see https://www.rfc-editor.org/rfc/pdfrfc/rfc8572.txt.pdf

@glimchb glimchb linked a pull request Oct 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants