Bug #2293

Sunstone template update not working

Added by OpenNebula Systems Support Team almost 8 years ago. Updated over 7 years ago.

Status:ClosedStart date:09/02/2013
Priority:NormalDue date:
Assignee:Tino Vázquez% Done:

100%

Category:Sunstone
Target version:Release 4.4
Resolution:fixed Pull request:
Affected Versions:OpenNebula 4.2

Description

Syntax error when trying to change the CPU, for example


Related issues

Related to Bug #2390: Template fails over Sunstone but succeeds via CLI Closed 10/17/2013
Related to Bug #2255: Sunstone template editing in wizzard mode destroys RAW se... Closed 08/01/2013

Associated revisions

Revision 436ef22b
Added by Tino Vázquez almost 8 years ago

Bug #2293: In VM template update, replace \" with ' on client, and replace back in Sunstone server.

Revision 0126e3f0
Added by Tino Vázquez almost 8 years ago

Bug #2293: In VM template update, replace \" with ' on client, and replace back in Sunstone server.
(cherry picked from commit 436ef22ba7352b43211a6b3c5a377910c1a3e044)

History

#1 Updated by Tino Vázquez almost 8 years ago

  • Status changed from New to Pending
  • Resolution set to worksforme

This VM template context section breaks it:

CONTEXT=[
DNS_SEARCH="$NETWORK[DNS_SEARCH, NETWORK=\"hola\"]",
DOMAIN="$NETWORK[DOMAIN, NETWORK=\"hola\"]",
FILES_DS="$FILE[IMAGE=\"init.sh\"] $FILE[IMAGE=\"opennebula-context.rpm\"]",
NAME="$NAME",
NETWORK="YES",
NTP="$NTP",
RELAYHOST="$RELAYHOST" ]

#2 Updated by Tino Vázquez almost 8 years ago

  • Status changed from Pending to Closed
  • Assignee set to Tino Vázquez
  • % Done changed from 0 to 100
  • Resolution changed from worksforme to fixed

Problem
-------

AJAX calls substitutes \" for ", so a valid template (A="B=\"C\"") turns to garbage (A="B="C"")

Solution
-------

Make a preventive substitution

Browser to Sunstone Server: \" for '
Sunstone Server to OpenNebula: ' for \"

#3 Updated by Rolandas Naujikas over 7 years ago

In opennebula 4.2.0 from github branch one-4.2 there is a problem.
Every time I save changes to template additional backslash is added to ".
In TemplateJSON.rb I changed:
--- TemplateJSON.rb.orig 2013-11-06 11:08:34.000000000 0200
+
+ TemplateJSON.rb 2013-11-06 13:42:33.000000000 +0200
@ -68,7 +68,7 @

  1. Substitue single quotes (not supported by ONE core)
  2. with \" (supported)
    - template.gsub!(/'/,"\\\"")
    + template.gsub!(/'/,"\"")
File.open("/tmp/opa","w"){|f| f.write template}
After it works much better. There also some debuging code left in one-4.2 branch.
Tested with Firefox 25.0, Safari 7.0 and Chrome 30 - all on OS X.

Regards

#4 Updated by Rolandas Naujikas over 7 years ago

Corrected formating.

Rolandas Naujikas wrote:

In opennebula 4.2.0 from github branch one-4.2 there is a problem.
Every time I save changes to template additional backslash is added to ".
In TemplateJSON.rb I changed:

--- TemplateJSON.rb.orig        2013-11-06 11:08:34.000000000 +0200
+++ TemplateJSON.rb     2013-11-06 13:42:33.000000000 +0200
@@ -68,7 +68,7 @@

             # Substitue single quotes (not supported by ONE core) 
             # with \" (supported)
-            template.gsub!(/'/,"\\\"")
+            template.gsub!(/'/,"\"")

             File.open("/tmp/opa","w"){|f| f.write template}

After it works much better. There also some debuging code left in one-4.2 branch.
Tested with Firefox 25.0, Safari 7.0 and Chrome 30 - all on OS X.

Regards

#5 Updated by Rolandas Naujikas over 7 years ago

But it breaks editing with wizard :-(

#6 Updated by Rolandas Naujikas over 7 years ago

After some testing I found that problem is in templates-tab.js (not in TemplateJSON.rb).

--- templates-tab.js.orig       2013-11-06 11:08:34.000000000 +0200
+++ templates-tab.js    2013-11-06 14:46:07.000000000 +0200
@@ -4137,9 +4137,6 @@
         //wrap it in the "vm" object
         template = {"vmtemplate": {"template_raw": template}};
         var vm_json = JSON.stringify(template);
-
-        vm_json=vm_json.replace(/\\\"/g,"'");
-
         Sunstone.runAction("Template.update",template_to_update_id,vm_json);

         $create_template_dialog.trigger("reveal:close")


vm_json.replace is not needed inside manual_template_update_button case,
probably because it is already in raw format.
Tested both wizard and manual and now it works.

#7 Updated by Daniel Molina over 7 years ago

Hi Rolandas,

I have pushed a commit that should fix these issues, you can find it this issue http://dev.opennebula.org/issues/2255. The commit is already in the master and one-4.4 branches

Also available in: Atom PDF