Skip to content

server: fix resource count updated unmanage vm#8169

Merged
vishesh92 merged 1 commit intoapache:4.19from
shapeblue:fix-unmanagevm-resourcecount
Jun 26, 2024
Merged

server: fix resource count updated unmanage vm#8169
vishesh92 merged 1 commit intoapache:4.19from
shapeblue:fix-unmanagevm-resourcecount

Conversation

@shwstppr
Copy link
Contributor

@shwstppr shwstppr commented Nov 1, 2023

Description

This PR ensures that the resource counts are not decremented twice for a running VM while unmanaging.
Currently, the code does the same operation for a non-stopped VM twice. This could lead to resource count discrepancy for an account or domain.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Before fix:

  • Create an account
  • Deploy a VM for that account
  • Observe the account limits and count
  • Unmanage the VM
  • Again observe the account limits and count. There will be some negative values for VM, CPU and memory as the resource counts have been decremented twice
(localcloud) 🐱 > list virtualmachines account=ACSuser
{
  "count": 1,
  "virtualmachine": [
    {
      "account": "ACSUser",
      "affinitygroup": [],
      "cpunumber": 1,
      "cpuspeed": 500,
      "created": "2024-06-12T12:48:59+0000",
      "details": {
        "cpuOvercommitRatio": "2.0",
        "dataDiskController": "osdefault",
        "memoryOvercommitRatio": "1.0",
        "rootDiskController": "ide"
      },
      "displayname": "uservm",
      "displayvm": true,
      "domain": "ROOT",
      "domainid": "8ce79cd7-1d86-11ef-a886-1e0095000407",
      "guestosid": "8cf5785f-1d86-11ef-a886-1e0095000407",
      "haenable": false,
      "hasannotations": false,
      "hostcontrolstate": "Enabled",
      "hostid": "13b19f23-b01f-49b3-98bb-f708cc668b47",
      "hostname": "10.0.35.149",
      "hypervisor": "VMware",
      "id": "bab406c5-f235-4cd2-b365-10338d613f7a",
      "instancename": "i-4-10-VM",
      "isdynamicallyscalable": false,
      "lastupdated": "2024-06-12T12:49:18+0000",
      "memory": 512,
      "name": "uservm",
      "nic": [
        {
          "broadcasturi": "vlan://2047",
          "deviceid": "0",
          "extradhcpoption": [],
          "id": "30a97242-158e-41ae-ac4b-eefbc73d09a8",
          "isdefault": true,
          "isolationuri": "vlan://2047",
          "macaddress": "02:01:00:ce:00:01",
          "networkid": "fb6d8567-74d6-43cc-a4bb-539c165c5a63",
          "networkname": "usernet",
          "secondaryip": [],
          "traffictype": "Guest",
          "type": "L2"
        }
      ],
      "osdisplayname": "CentOS 5.3 (64-bit)",
      "ostypeid": "8cf5785f-1d86-11ef-a886-1e0095000407",
      "passwordenabled": false,
      "pooltype": "NetworkFilesystem",
      "receivedbytes": 0,
      "rootdeviceid": 0,
      "rootdevicetype": "ROOT",
      "securitygroup": [],
      "sentbytes": 0,
      "serviceofferingid": "7d856b41-9a5e-40c4-b96d-72217a82fa5f",
      "serviceofferingname": "Small Instance",
      "state": "Running",
      "tags": [],
      "templatedisplaytext": "CentOS 5.3(64-bit) no GUI (vSphere)",
      "templateformat": "OVA",
      "templateid": "8cf00de6-1d86-11ef-a886-1e0095000407",
      "templatename": "CentOS 5.3(64-bit) no GUI (vSphere)",
      "templatetype": "BUILTIN",
      "userid": "cd6f78c9-ed6f-44ae-8733-570148c28540",
      "username": "user",
      "zoneid": "40e1cd6a-9353-4325-bd43-d0ffa691f10e",
      "zonename": "pr8601-t10311-vmware-67u3"
    }
  ]
}
(localcloud) 🐱 > list accounts id=39223f34-f465-438f-8d43-04ff0670514d 
{
  "account": [
    {
      "accounttype": 0,
      "cpuavailable": "39",
      "cpulimit": "40",
      "cputotal": 1,
      "created": "2024-05-29T06:48:57+0000",
      "domain": "ROOT",
      "domainid": "8ce79cd7-1d86-11ef-a886-1e0095000407",
      "domainpath": "ROOT",
      "groups": [],
      "id": "39223f34-f465-438f-8d43-04ff0670514d",
      "ipavailable": "16",
      "iplimit": "20",
      "iptotal": 0,
      "isdefault": false,
      "memoryavailable": "40448",
      "memorylimit": "40960",
      "memorytotal": 512,
      "name": "ACSUser",
      "networkavailable": "19",
      "networklimit": "20",
      "networktotal": 1,
      "primarystorageavailable": "198",
      "primarystoragelimit": "200",
      "primarystoragetotal": 2,
      "projectavailable": "Unlimited",
      "projectlimit": "Unlimited",
      "projecttotal": 0,
      "roleid": "a51b7f95-1d86-11ef-a886-1e0095000407",
      "rolename": "User",
      "roletype": "User",
      "secondarystorageavailable": "400.0",
      "secondarystoragelimit": "400",
      "secondarystoragetotal": 0,
      "snapshotavailable": "20",
      "snapshotlimit": "20",
      "snapshottotal": 0,
      "state": "enabled",
      "templateavailable": "20",
      "templatelimit": "20",
      "templatetotal": 0,
      "user": [
        {
          "account": "ACSUser",
          "accountid": "39223f34-f465-438f-8d43-04ff0670514d",
          "accounttype": 0,
          "created": "2024-05-29T06:49:01+0000",
          "domain": "ROOT",
          "domainid": "8ce79cd7-1d86-11ef-a886-1e0095000407",
          "email": "sblab@shapeblue.com",
          "firstname": "ACloudStack",
          "id": "cd6f78c9-ed6f-44ae-8733-570148c28540",
          "is2faenabled": false,
          "is2famandated": false,
          "iscallerchilddomain": false,
          "isdefault": false,
          "lastname": "User",
          "roleid": "a51b7f95-1d86-11ef-a886-1e0095000407",
          "rolename": "User",
          "roletype": "User",
          "state": "enabled",
          "timezone": "Etc/UTC",
          "username": "user",
          "usersource": "native"
        }
      ],
      "vmavailable": "19",
      "vmlimit": "20",
      "vmrunning": 1,
      "vmstopped": 0,
      "vmtotal": 1,
      "volumeavailable": "19",
      "volumelimit": "20",
      "volumetotal": 1,
      "vpcavailable": "20",
      "vpclimit": "20",
      "vpctotal": 0
    }
  ],
  "count": 1
}
(localcloud) 🐱 > unmanage virtualmachine id=bab406c5-f235-4cd2-b365-10338d613f7a 
{
  "unmanagevirtualmachineresponse": {
    "details": "VM unmanaged successfully",
    "success": true
  }
}
(localcloud) 🐱 > list accounts id=39223f34-f465-438f-8d43-04ff0670514d 
{
  "account": [
    {
      "accounttype": 0,
      "cpuavailable": "41",
      "cpulimit": "40",
      "cputotal": -1,
      "created": "2024-05-29T06:48:57+0000",
      "domain": "ROOT",
      "domainid": "8ce79cd7-1d86-11ef-a886-1e0095000407",
      "domainpath": "ROOT",
      "groups": [],
      "id": "39223f34-f465-438f-8d43-04ff0670514d",
      "ipavailable": "16",
      "iplimit": "20",
      "iptotal": 0,
      "isdefault": false,
      "memoryavailable": "41472",
      "memorylimit": "40960",
      "memorytotal": -512,
      "name": "ACSUser",
      "networkavailable": "19",
      "networklimit": "20",
      "networktotal": 1,
      "primarystorageavailable": "200",
      "primarystoragelimit": "200",
      "primarystoragetotal": 0,
      "projectavailable": "Unlimited",
      "projectlimit": "Unlimited",
      "projecttotal": 0,
      "roleid": "a51b7f95-1d86-11ef-a886-1e0095000407",
      "rolename": "User",
      "roletype": "User",
      "secondarystorageavailable": "400.0",
      "secondarystoragelimit": "400",
      "secondarystoragetotal": 0,
      "snapshotavailable": "20",
      "snapshotlimit": "20",
      "snapshottotal": 0,
      "state": "enabled",
      "templateavailable": "20",
      "templatelimit": "20",
      "templatetotal": 0,
      "user": [
        {
          "account": "ACSUser",
          "accountid": "39223f34-f465-438f-8d43-04ff0670514d",
          "accounttype": 0,
          "created": "2024-05-29T06:49:01+0000",
          "domain": "ROOT",
          "domainid": "8ce79cd7-1d86-11ef-a886-1e0095000407",
          "email": "sblab@shapeblue.com",
          "firstname": "ACloudStack",
          "id": "cd6f78c9-ed6f-44ae-8733-570148c28540",
          "is2faenabled": false,
          "is2famandated": false,
          "iscallerchilddomain": false,
          "isdefault": false,
          "lastname": "User",
          "roleid": "a51b7f95-1d86-11ef-a886-1e0095000407",
          "rolename": "User",
          "roletype": "User",
          "state": "enabled",
          "timezone": "Etc/UTC",
          "username": "user",
          "usersource": "native"
        }
      ],
      "vmavailable": "21",
      "vmlimit": "20",
      "vmrunning": 0,
      "vmstopped": 0,
      "vmtotal": -1,
      "volumeavailable": "20",
      "volumelimit": "20",
      "volumetotal": 0,
      "vpcavailable": "20",
      "vpclimit": "20",
      "vpctotal": 0
    }
  ],
  "count": 1
}

How did you try to break this feature and the system with this change?

@codecov
Copy link

codecov bot commented Nov 1, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 15.21%. Comparing base (1577218) to head (f4776cc).
Report is 74 commits behind head on 4.19.

Additional details and impacted files
@@             Coverage Diff              @@
##               4.19    #8169      +/-   ##
============================================
+ Coverage     14.96%   15.21%   +0.24%     
- Complexity    11002    11534     +532     
============================================
  Files          5373     5389      +16     
  Lines        469315   491097   +21782     
  Branches      59847    70632   +10785     
============================================
+ Hits          70233    74697    +4464     
- Misses       391309   408170   +16861     
- Partials       7773     8230     +457     
Flag Coverage Δ
uitests 4.34% <ø> (+0.04%) ⬆️
unittests 15.91% <ø> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DaanHoogland
Copy link
Contributor

@shwstppr @vishesh92 , in view of other work on this topic, should we keep this open?

Do not decrement resource count for a running VM twice while unmanaging.

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@github-actions
Copy link

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@shwstppr shwstppr changed the base branch from 4.18 to 4.19 June 12, 2024 07:46
@shwstppr shwstppr closed this Jun 12, 2024
@shwstppr shwstppr reopened this Jun 12, 2024
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_STOP, vm.getAccountId(), vm.getDataCenterId(),
vm.getId(), vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(),
vm.getHypervisorType().toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), cpu, ram);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same method is called later at line 8502

@shwstppr
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@shwstppr a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@shwstppr shwstppr marked this pull request as ready for review June 12, 2024 07:50
Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 9886

@shwstppr
Copy link
Contributor Author

Added steps to reproduce in the PR description. cc @DaanHoogland

@yadvr yadvr added this to the 4.19.1.0 milestone Jun 25, 2024
@yadvr yadvr closed this Jun 25, 2024
@yadvr yadvr reopened this Jun 25, 2024
@yadvr
Copy link
Member

yadvr commented Jun 25, 2024

@blueorangutan package

@blueorangutan
Copy link

@rohityadavcloud a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 10115

Copy link
Member

@vishesh92 vishesh92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm. Tested.
Before patch. resource count got decremented by 2. After patch, it got decremented by 1.

@vishesh92 vishesh92 merged commit 7a8066d into apache:4.19 Jun 26, 2024
@vishesh92 vishesh92 deleted the fix-unmanagevm-resourcecount branch June 26, 2024 09:04
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Jul 2, 2024
Do not decrement resource count for a running VM twice while unmanaging a VM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Abhishek's Bugfix List
Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants