intel / ccloudvm

Configurable Cloud VM is a small command line tool for automatically creating development and demo environments for complex projects. The tool sets up these development environments inside a virtual machine which it automatically creates on the user’s host computer. This avoids polluting the user’s host machine with components from the chosen development environment and provides a clean, predictable and repeatable environment in which this development environment can run.
Apache License 2.0
32 stars 19 forks source link

Enable option to send msg to host without task #52

Closed ganeshmaharaj closed 6 years ago

ganeshmaharaj commented 6 years ago

Signed-off-by: Ganesh Maharaj Mahalingam ganesh.mahalingam@intel.com

ganeshmaharaj commented 6 years ago

I found that cloud-init supports final-message which can be used here, but that was never printed out to the host. If that can be fixed, then we will not need this. Though i can imagine this won't be bad to have as an option.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.2%) to 68.643% when pulling 885df06ca8d1da5eb1bd19e514b3a837b35b360d on ganeshmaharaj:messagehost into d16f82c0cbcd8a18a581c670f5157cb883410baf on intel:master.

ganeshmaharaj commented 6 years ago

After i rebased the patch to the latest master and made changes to add the line-ending for MESSAGE, i am no longer able to schedule VMs and they are all crashing with this error.

[   12.993576] cloud-init[1056]: 2018-03-03 00:10:09,623 - util.py[WARNING]: Failed to shellify ['curl -X PUT -d "Booting VM" 10.0.2.2:36221', 'curl -X PUT -d "OK" 10.0.2.2:36221', 'curl -X PUT -d "Adding angry-galahad to /etc/hosts" 10.0.2.2:36221', 'echo "127.0.0.1 angry-galahad" >> /etc/hosts', 'if [ $? -eq 0 ] ; then ret="OK" ; else ret="FAIL" ; fi ; curl -X PUT -d $ret 10.0.2.2:36221', {'curl -X PUT -d "MESSAGE': 'All Done!" 10.0.2.2:36221'}, 'curl -X PUT -d "FINISHED" 10.0.2.2:36221'] into file /var/lib/cloud/instances/08a58d69-722e-4f18-a54d-46341eaa4df8/scripts/runcmd

specifically {'curl -X PUT -d "MESSAGE': 'All Done!" 10.0.2.2:36221'}, is causing the failure. Will try to debug this and see what is happening.

ganeshmaharaj commented 6 years ago

Right. The code I had pushed up was wrong since it was based on the old code prior to systemd changes. But fixing them also got me the shellify error. I thought the message tag up from would be good. I can try dumping it.

On Mon, Mar 5, 2018, 2:12 AM Mark Ryan notifications@github.com wrote:

@markdryan commented on this pull request.

In ccvm/vm.go https://github.com/intel/ccloudvm/pull/52#discussion_r172139170:

@@ -190,6 +190,9 @@ func startHTTPServer(ctx context.Context, resultCh chan interface{}, downloadCh _ = listener.Close() return }

  • if strings.HasPrefix(line, "MESSAGE:") {

You also need to skip the first few characters of the string that contain the text "MESSAGE:"

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/intel/ccloudvm/pull/52#discussion_r172139170, or mute the thread https://github.com/notifications/unsubscribe-auth/AFSZughyffirkt7QgEW8v4mZuNl4ZJn4ks5tbQ9-gaJpZM4SF-9X .

markdryan commented 6 years ago

@ganeshmaharaj Looking at the string you posted

{'curl -X PUT -d "MESSAGE': 'All Done!" 10.0.2.2:36221'},

There seem to be single quotes inside the string itself. Perhaps that's the issue.

ganeshmaharaj commented 6 years ago

Yup. That's what I had assumed. But as to where it's coming from is still a mystery to me. Will fix the coffee and push it up soon and see if that might give us some idea.

On Mon, Mar 5, 2018, 7:13 AM Mark Ryan notifications@github.com wrote:

@ganeshmaharaj https://github.com/ganeshmaharaj Looking at the string you posted

{'curl -X PUT -d "MESSAGE': 'All Done!" 10.0.2.2:36221'},

There seem to be single quotes inside the string itself. Perhaps that's the issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/intel/ccloudvm/pull/52#issuecomment-370450430, or mute the thread https://github.com/notifications/unsubscribe-auth/AFSZujWa9BoKhp1eVBMDSMNol1moO3mOks5tbVYAgaJpZM4SF-9X .

markdryan commented 6 years ago

What does your cloud-init file look like?

markdryan commented 6 years ago

@ganeshmaharaj I tested the new commit out this morning. It's working fine (well mostly see below) but the first commit is missing a message body.

I did find another issue with both the message and begintask functions. If you include a ' in the message the workload cannot be parsed. For example,

Will result in the following unhelpful error (which I'll enter a separate bug about)

Error: Error applying template to user-data: Error parsing workload: Unable to unmarshal userdata: yaml: line 34: did not find expected '-' indicator

The interesting thing is

does work, so we just need to modify our message and beginTask functions to escape quotes, .e.g.,

func messageFN(ws *workspace, message string) string {
    const msgStr = `'curl -X PUT -d "%s%s" 10.0.2.2:%d'`
    message = strings.Replace(message, "'", "''", -1)
    return fmt.Sprintf(msgStr, msgprefix, message, ws.HTTPServerPort)
}