RosiKyu commented on PR #11605:
URL: https://github.com/apache/cloudstack/pull/11605#issuecomment-3799222975

   ### LGTM
   
   The install path now properly uses the template's actual `account_id` 
instead of hardcoded `1`.
   
   ###  Test Execution Summary
   
   
   | Test Case | Description | Status |
   |-----------|-------------|--------|
   | TC1 | Baseline - System account template (account_id=1) | **PASS** |
   | TC2 | Core fix - Admin-registered template (account_id=2) | **PASS** |
   
   ---
   
   
   ### TC1: Baseline - System account template (account_id=1)
   
   **Objective:** Verify adding a new zone works correctly with the default 
system-owned template (account_id=1). This establishes baseline functionality 
and confirms the PR doesn't break existing behavior.
   
   **Test Steps:**
   1. Verify current state - single zone with SystemVM template owned by system 
account (account_id=1)
   2. Prepare secondary storage for Zone 2 with pre-copied template files
   3. Add Zone 2 via UI wizard with KVM host, primary and secondary storage
   4. Verify DB stores correct template path for Zone 2's secondary storage
   5. Enable Zone 2 and verify System VMs deploy successfully
   
   **Expected Result:**
   - Template path stored as `template/tmpl/1/3/` (using account_id=1)
   - System VMs (CPVM, SSVM) deploy and reach Running state in Zone 2
   
   **Actual Result:**
   - Template path correctly stored as `template/tmpl/1/3/`
   - System VMs v-3-VM (CPVM) and s-4-VM (SSVM) deployed successfully and 
reached Running state
   
   **Test Evidence:**
   
   1. Pre-test DB state (Zone 1 only):
   ```
   mysql> SELECT t.id, t.name, t.account_id, tsr.store_id, tsr.install_path 
FROM cloud.vm_template t JOIN cloud.template_store_ref tsr ON t.id = 
tsr.template_id WHERE t.type = 'SYSTEM';
   
+----+-------------------------+------------+----------+--------------------------------------------------------------+
   | id | name                    | account_id | store_id | install_path        
                                         |
   
+----+-------------------------+------------+----------+--------------------------------------------------------------+
   |  3 | SystemVM Template (KVM) |          1 |        1 | 
template/tmpl/1/3/d1496fd3-8b91-4687-944a-1e2c25e7163b.qcow2 |
   
+----+-------------------------+------------+----------+--------------------------------------------------------------+
   ```
   
   2. Secondary storage preparation:
   ```
   [root@sl-nestednfs acs]# mkdir -p 
/acs/secondary/ref-trl-10714-k-Mol9-rositsa-kyuchukova/zone2-sec1/template/tmpl/1/3
   [root@sl-nestednfs acs]# cp -r 
/acs/secondary/ref-trl-10714-k-Mol9-rositsa-kyuchukova/ref-trl-10714-k-Mol9-rositsa-kyuchukova-sec1/template/tmpl/1/3/*
 
/acs/secondary/ref-trl-10714-k-Mol9-rositsa-kyuchukova/zone2-sec1/template/tmpl/1/3/
   [root@sl-nestednfs acs]# ls -la 
/acs/secondary/ref-trl-10714-k-Mol9-rositsa-kyuchukova/zone2-sec1/template/tmpl/1/3/
   total 519736
   drwxr-xr-x. 2 root root        83 Jan 26 11:11 .
   drwxr-xr-x. 3 root root        23 Jan 26 11:10 ..
   -rw-r--r--. 1 root root 532205568 Jan 26 11:11 
d1496fd3-8b91-4687-944a-1e2c25e7163b.qcow2
   -rw-r--r--. 1 root root       295 Jan 26 11:11 template.properties
   ```
   
   3. Post Zone 2 creation - DB verification (store_id=2 is Zone 2's secondary 
storage):
   ```
   mysql> SELECT t.id, t.name, t.account_id, tsr.store_id, tsr.install_path 
FROM cloud.vm_template t JOIN cloud.template_store_ref tsr ON t.id = 
tsr.template_id WHERE t.type = 'SYSTEM';
   
+----+-------------------------------+------------+----------+--------------------------------------------------------------+
   | id | name                          | account_id | store_id | install_path  
                                               |
   
+----+-------------------------------+------------+----------+--------------------------------------------------------------+
   |  1 | SystemVM Template (XenServer) |          1 |        2 | 
template/tmpl/1/1/                                           |
   |  3 | SystemVM Template (KVM)       |          1 |        1 | 
template/tmpl/1/3/d1496fd3-8b91-4687-944a-1e2c25e7163b.qcow2 |
   |  3 | SystemVM Template (KVM)       |          1 |        2 | 
template/tmpl/1/3/                                           |
   |  8 | SystemVM Template (vSphere)   |          1 |        2 | 
template/tmpl/1/8/                                           |
   |  9 | SystemVM Template (HyperV)    |          1 |        2 | 
template/tmpl/1/9/                                           |
   | 10 | SystemVM Template (LXC)       |          1 |        2 | 
template/tmpl/1/10/                                          |
   | 12 | SystemVM Template (Ovm3)      |          1 |        2 | 
template/tmpl/1/12/                                          |
   
+----+-------------------------------+------------+----------+--------------------------------------------------------------+
   ```
   
   4. System VMs deployed successfully in Zone 2:
   ```
   (localcloud) 🐱 > list systemvms
   ...
       {
         "name": "v-3-VM",
         "state": "Running",
         "systemvmtype": "consoleproxy",
         "zonename": "Zone2"
       },
       {
         "name": "s-4-VM",
         "state": "Running",
         "systemvmtype": "secondarystoragevm",
         "zonename": "Zone2"
       }
   ```
   
   **Status: PASSED**
   
   ### TC2: Core fix - Admin-registered template (account_id=2)
   
   **Objective:** Verify that when a SystemVM template is registered by a 
non-system account (account_id=2), adding a new zone correctly stores the 
template path as `template/tmpl/2/<id>/` instead of the buggy 
`template/tmpl/1/<id>/`.
   
   **Test Steps:**
   1. Register new SystemVM template as admin account (account_id=2)
   2. Mark the template as SYSTEM type in database
   3. Wait for template download and verify path uses account_id=2
   4. Delete existing Zone2 to prepare fresh test
   5. Prepare secondary storage with template at correct path `tmpl/2/202/`
   6. Add new zone (Zone3) with secondary storage
   7. Verify DB stores correct path for new zone's secondary storage
   8. Enable zone and verify System VMs deploy successfully
   
   **Expected Result:**
   - Template path stored as `template/tmpl/2/202/` (using actual account_id=2, 
not hardcoded 1)
   - System VMs deploy successfully using the admin-registered template
   
   **Actual Result:**
   - Template path correctly stored as `template/tmpl/2/202/` for new zone
   - System VMs v-5-VM (CPVM) and s-6-VM (SSVM) deployed successfully and 
reached Running state
   
   **Test Evidence:**
   
   1. Register template as admin:
   ```
   (localcloud) 🐱 > register template name="SystemVM-KVM-Admin" 
displaytext="SystemVM Template KVM registered by Admin" 
url="https://download.cloudstack.org/systemvm/4.20/systemvmtemplate-4.20.2-x86_64-kvm.qcow2.bz2";
 hypervisor=KVM format=QCOW2 ostypeid=f3d49be1-bc90-4306-8736-4705c4a1fb17 
zoneid=-1 isrouting=true requireshvm=false ispublic=false isfeatured=false 
passwordenabled=false isdynamicallyscalable=false
   {
     "count": 2,
     "template": [
       {
         "account": "admin",
         "id": "3ca00f85-d16e-488e-ad28-99313be5155e",
         "name": "SystemVM-KVM-Admin",
         ...
       }
     ]
   }
   ```
   
   2. Verify template account_id and mark as SYSTEM:
   ```
   mysql> SELECT id, name, account_id, type FROM cloud.vm_template WHERE uuid = 
'3ca00f85-d16e-488e-ad28-99313be5155e';
   +-----+--------------------+------------+---------+
   | id  | name               | account_id | type    |
   +-----+--------------------+------------+---------+
   | 202 | SystemVM-KVM-Admin |          2 | ROUTING |
   +-----+--------------------+------------+---------+
   
   mysql> UPDATE cloud.vm_template SET type = 'SYSTEM' WHERE uuid = 
'3ca00f85-d16e-488e-ad28-99313be5155e';
   Query OK, 1 row affected (0.00 sec)
   ```
   
   3. Verify template path after download (Zone1):
   ```
   mysql> SELECT t.id, t.name, t.account_id, tsr.store_id, tsr.install_path 
FROM cloud.vm_template t JOIN cloud.template_store_ref tsr ON t.id = 
tsr.template_id WHERE t.id = 202;
   
+-----+--------------------+------------+----------+----------------------------------------------------------------+
   | id  | name               | account_id | store_id | install_path            
                                       |
   
+-----+--------------------+------------+----------+----------------------------------------------------------------+
   | 202 | SystemVM-KVM-Admin |          2 |        1 | 
template/tmpl/2/202/d0f97ab3-6b28-3f62-884c-8ef3c14bae56.qcow2 |
   
+-----+--------------------+------------+----------+----------------------------------------------------------------+
   ```
   
   4. Verify template on NFS storage:
   ```
   [root@sl-nestednfs acs]# tree 
/acs/secondary/ref-trl-10714-k-Mol9-rositsa-kyuchukova/ref-trl-10714-k-Mol9-rositsa-kyuchukova-sec1/template/tmpl/2/202/
   
/acs/secondary/ref-trl-10714-k-Mol9-rositsa-kyuchukova/ref-trl-10714-k-Mol9-rositsa-kyuchukova-sec1/template/tmpl/2/202/
   ├── d0f97ab3-6b28-3f62-884c-8ef3c14bae56.qcow2
   └── template.properties
   ```
   
   5. Pre-zone creation DB state (only Zone1):
   ```
   mysql> SELECT t.id, t.name, t.account_id, tsr.store_id, tsr.install_path 
FROM cloud.vm_template t JOIN cloud.template_store_ref tsr ON t.id = 
tsr.template_id WHERE t.id = 202;
   
+-----+--------------------+------------+----------+----------------------------------------------------------------+
   | id  | name               | account_id | store_id | install_path            
                                       |
   
+-----+--------------------+------------+----------+----------------------------------------------------------------+
   | 202 | SystemVM-KVM-Admin |          2 |        1 | 
template/tmpl/2/202/d0f97ab3-6b28-3f62-884c-8ef3c14bae56.qcow2 |
   
+-----+--------------------+------------+----------+----------------------------------------------------------------+
   ```
   
   6. **Post Zone3 creation DB verification (PR fix validation):**
   ```
   mysql> SELECT t.id, t.name, t.account_id, tsr.store_id, tsr.install_path 
FROM cloud.vm_template t JOIN cloud.template_store_ref tsr ON t.id = 
tsr.template_id WHERE t.id = 202;
   
+-----+--------------------+------------+----------+----------------------------------------------------------------+
   | id  | name               | account_id | store_id | install_path            
                                       |
   
+-----+--------------------+------------+----------+----------------------------------------------------------------+
   | 202 | SystemVM-KVM-Admin |          2 |        1 | 
template/tmpl/2/202/d0f97ab3-6b28-3f62-884c-8ef3c14bae56.qcow2 |
   | 202 | SystemVM-KVM-Admin |          2 |        3 | template/tmpl/2/202/    
                                       |
   
+-----+--------------------+------------+----------+----------------------------------------------------------------+
   ```
   **Key observation:** store_id=3 (Zone3's secondary storage) correctly shows 
path `template/tmpl/2/202/` using account_id=2. Without the PR fix, this would 
have been `template/tmpl/1/202/` causing SVM deployment failure.
   
   7. System VMs deployed successfully:
   ```
   (localcloud) 🐱 > list systemvms zoneid=907657f2-0951-4746-9097-dc1afb80bb5f 
filter=name,state,id
   {
     "count": 2,
     "systemvm": [
       {
         "id": "71cbf08d-baee-466a-9590-e585e63cb887",
         "name": "v-5-VM",
         "state": "Running"
       },
       {
         "id": "bb4f643a-a431-4d30-87cf-b27fe5a7d731",
         "name": "s-6-VM",
         "state": "Running"
       }
     ]
   }
   ```
   
   8. SVMs using admin-registered template:
   ```
   "templateid": "3ca00f85-d16e-488e-ad28-99313be5155e",
   "templatename": "SystemVM-KVM-Admin",
   ```
   
   **Status: PASSED**
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to