OpenNebula / one

The open source Cloud & Edge Computing Platform bringing real freedom to your Enterprise Cloud 🚀
http://opennebula.io
Apache License 2.0
1.23k stars 478 forks source link

Instantiate request restarts oned service #6580

Closed dcarracedo closed 4 months ago

dcarracedo commented 4 months ago

Description ONE service is restarted when instantiate a template and send empty schedule actions using XML API

To Reproduce

  1. Create a vm template with the following content:
CONTEXT=[
  NETWORK="YES",
  SSH_PUBLIC_KEY="$USER[SSH_PUBLIC_KEY]" ]
CPU="1"
DISK=[
  FORMAT="qcow2",
  FS="ext2",
  SIZE="128",
  TYPE="fs" ]
DISK=[
  IMAGE="image01",
  IMAGE_UNAME="oneadmin" ]
GRAPHICS=[
  LISTEN="0.0.0.0",
  TYPE="VNC" ]
HYPERVISOR="dummy"
MEMORY="128"
NIC=[
  NETWORK="vnet5",
  NETWORK_UID="0",
  NETWORK_UNAME="oneadmin" ]
NIC=[
  NETWORK="vnet4",
  NETWORK_UID="0",
  NETWORK_UNAME="oneadmin" ]
SCHED_ACTION=[
  ACTION="hold",
  TIME="1714730400" ]
  1. Instantiate the template using the instantiate operation though the XML API:
    
    curl --location 'http://172.20.0.8:2633/RPC2' \
    --header 'accept: text/xml' \
    --header 'accept-charset: UTF8' \
    --header 'connection: Keep-Alive' \
    --header 'Content-Type: text/xml' \
    --header 'User-Agent: NodeJS XML-RPC Client' \
    --data '<?xml version="1.0"?><methodCall><methodName>one.template.instantiate</methodName><params><param><value><string>serveradmin:oneadmin:cFN/HHkIP9ZNdw/QwA13btcze3aXDA/JIWuxU8OuRN8=</string></value></param><param><value><int>6</int></value></param><param><value><string/></value></param><param><value><boolean>0</boolean></value></param><param><value><string><![CDATA[<ROOT><CPU>1</CPU><HYPERVISOR>dummy</HYPERVISOR><MEMORY>128</MEMORY><CONTEXT><NETWORK>YES</NETWORK><SSH_PUBLIC_KEY>$USER[SSH_PUBLIC_KEY]</SSH_PUBLIC_KEY></CONTEXT><GRAPHICS><LISTEN>0.0.0.0</LISTEN><TYPE>VNC</TYPE></GRAPHICS><SCHED_REQUIREMENTS>(HYPERVISOR=dummy)</SCHED_REQUIREMENTS><OS><BOOT></BOOT></OS><NIC>![CDATA[]]</NIC><DISK>![CDATA[]]</DISK><SCHED_ACTION>![CDATA[]]</SCHED_ACTION></ROOT>]]></string></value></param><param><value><boolean>0</boolean></value></param></params></methodCall>'

<?xml version="1.0" encoding="UTF-8"?>

1 dummy 128 YES $USER[SSH_PUBLIC_KEY] 0.0.0.0 VNC (HYPERVISOR=dummy) ![CDATA[]] ![CDATA[]] ![CDATA[]]

3. As result of this request, the oned service is restarted. After the restart, the vm is instantiated without schedule actions, so the behavior is right, except for the restart of the service.

**Expected behavior**
That the service is not restarted when the request is sent to the API and the virtual machine is instantiated without disks, nics and schedule actions.

**Details**
 - Affected Component: Core
 - Hypervisor: N/A
 - Version: 6.8

**Additional context**
NIC and DISK attributes:
![CDATA[]] ![CDATA[]]

work fine, the problem is only with:
`<SCHED_ACTION>![CDATA[]]</SCHED_ACTION>`

After solve this problem on the core, we need to uncomment the code in Fireedge Sunstone to send the attribute with CDATA value (src/client/utils/parser/vmTemplateFilter.js):

![image](https://github.com/OpenNebula/one/assets/134921994/e2917e56-48d3-4d0d-9f2a-69556888830b)

<!--////////////////////////////////////////////-->
<!-- THIS SECTION IS FOR THE DEVELOPMENT TEAM   -->
<!-- BOTH FOR BUGS AND ENHANCEMENT REQUESTS     -->
<!-- PROGRESS WILL BE REFLECTED HERE            -->
<!--////////////////////////////////////////////-->

## Progress Status
- [ ] Code committed
- [ ] Fireedge Sunstone Code committed
- [ ] Testing - QA
- [ ] Documentation (Release notes - resolved issues, compatibility, known issues)
paczerny commented 4 months ago

It was crashing because the the SCHED_ACTION is expected to be a Vector of values, but vmTemplateFilter.js assigns a single value ![CDATA[]]. This may cause troubles also for other Vector attributes like PCI, OS, ... Fixed casting in the Template::Remove method should solve all similar cases, silently ignoring malformed attribute value.