Skip to content

[DB] Add force recreate parameter to cloudstack-setup-databases script #11239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nvazquez
Copy link
Contributor

@nvazquez nvazquez commented Jul 17, 2025

Description

This PR adds a new parameter --force-recreate to the cloudstack-setup-databases script, to prevent the recreation of existing databases and prevent accidental data loss.
Fixes: #11202

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
  • test (unit or integration test code)

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?

  • Tested without passing the --force-recreate parameter having already defined cloud and cloud_usage databases:
# cloudstack-setup-databases cloud:[email protected] --deploy-as=root:XXX -i 10.0.34.102
Mysql user name:cloud                                                           [ OK ]
Mysql user password:******                                                      [ OK ]
Mysql server ip:10.0.34.102                                                     [ OK ]
Mysql server port:3306                                                          [ OK ]
Mysql root user name:root                                                       [ OK ]
Mysql root user password:******                                                 [ OK ]
Using specified cluster management server node IP 10.0.34.102                   [ OK ]
Checking Cloud database files ...                                               [ OK ]
Checking local machine hostname ...                                             [ OK ]
Checking SELinux setup ...                                                      [ OK ]
Preparing /etc/cloudstack/management/db.properties                              [ OK ]


We apologize for below error:
***************************************************************
Aborting script as the databases (cloud, cloud_usage) already exist.
Please use the --force-recreation parameter if you want to recreate the schemas.
***************************************************************
Please run:

    cloudstack-setup-databases -h

for full help
  • Tested passing the --force-recreate parameter having already defined cloud and cloud_usage databases:
# cloudstack-setup-databases cloud:[email protected] --deploy-as=root:XXX -i 10.0.34.102 --force-recreate
Mysql user name:cloud                                                           [ OK ]
Mysql user password:******                                                      [ OK ]
Mysql server ip:10.0.34.102                                                     [ OK ]
Mysql server port:3306                                                          [ OK ]
Mysql root user name:root                                                       [ OK ]
Mysql root user password:******                                                 [ OK ]
Using specified cluster management server node IP 10.0.34.102                   [ OK ]
Checking Cloud database files ...                                               [ OK ]
Checking local machine hostname ...                                             [ OK ]
Checking SELinux setup ...                                                      [ OK ]
Preparing /etc/cloudstack/management/db.properties                              [ OK ]
Applying /usr/share/cloudstack-management/setup/create-database.sql             [ OK ]
Applying /usr/share/cloudstack-management/setup/create-schema.sql               [ OK ]
Applying /usr/share/cloudstack-management/setup/create-database-premium.sql     [ OK ]
Applying /usr/share/cloudstack-management/setup/create-schema-premium.sql       [ OK ]
Applying /usr/share/cloudstack-management/setup/server-setup.sql                [ OK ]
Applying /usr/share/cloudstack-management/setup/templates.sql                   [ OK ]
Processing encryption ...                                                       [ OK ]
Finalizing setup ...                                                            [ OK ]

CloudStack has successfully initialized database, you can check your database configuration in /etc/cloudstack/management/db.properties
  • Dropped cloud database manually
  • Invoked the script with and without the parameter:
# cloudstack-setup-databases cloud:[email protected] --deploy-as=root:XXX -i 10.0.34.102
Mysql user name:cloud                                                           [ OK ]
Mysql user password:******                                                      [ OK ]
Mysql server ip:10.0.34.102                                                     [ OK ]
Mysql server port:3306                                                          [ OK ]
Mysql root user name:root                                                       [ OK ]
Mysql root user password:******                                                 [ OK ]
Using specified cluster management server node IP 10.0.34.102                   [ OK ]
Checking Cloud database files ...                                               [ OK ]
Checking local machine hostname ...                                             [ OK ]
Checking SELinux setup ...                                                      [ OK ]
Preparing /etc/cloudstack/management/db.properties                              [ OK ]


We apologize for below error:
***************************************************************
Aborting script as the databases (cloud, cloud_usage) already exist.
Please use the --force-recreation parameter if you want to recreate the schemas.
***************************************************************
Please run:

    cloudstack-setup-databases -h

for full help
# cloudstack-setup-databases cloud:[email protected] --deploy-as=root:XXX -i 10.0.34.102 --force-recreate
Mysql user name:cloud                                                           [ OK ]
Mysql user password:******                                                      [ OK ]
Mysql server ip:10.0.34.102                                                     [ OK ]
Mysql server port:3306                                                          [ OK ]
Mysql root user name:root                                                       [ OK ]
Mysql root user password:******                                                 [ OK ]
Using specified cluster management server node IP 10.0.34.102                   [ OK ]
Checking Cloud database files ...                                               [ OK ]
Checking local machine hostname ...                                             [ OK ]
Checking SELinux setup ...                                                      [ OK ]
Preparing /etc/cloudstack/management/db.properties                              [ OK ]
Applying /usr/share/cloudstack-management/setup/create-database.sql             [ OK ]
Applying /usr/share/cloudstack-management/setup/create-schema.sql               [ OK ]
Applying /usr/share/cloudstack-management/setup/create-database-premium.sql     [ OK ]
Applying /usr/share/cloudstack-management/setup/create-schema-premium.sql       [ OK ]
Applying /usr/share/cloudstack-management/setup/server-setup.sql                [ OK ]
Applying /usr/share/cloudstack-management/setup/templates.sql                   [ OK ]
Processing encryption ...                                                       [ OK ]
Finalizing setup ...                                                            [ OK ]

CloudStack has successfully initialized database, you can check your database configuration in /etc/cloudstack/management/db.properties

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

@nvazquez
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@nvazquez 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.

Copy link

codecov bot commented Jul 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 16.57%. Comparing base (b57994e) to head (5d5a70b).
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #11239      +/-   ##
============================================
- Coverage     16.57%   16.57%   -0.01%     
+ Complexity    14059    14058       -1     
============================================
  Files          5772     5772              
  Lines        512938   512938              
  Branches      62304    62304              
============================================
- Hits          85026    85025       -1     
- Misses       418431   418432       +1     
  Partials       9481     9481              
Flag Coverage Δ
uitests 3.89% <ø> (ø)
unittests 17.47% <ø> (-0.01%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@blueorangutan
Copy link

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

@nvazquez
Copy link
Contributor Author

@blueorangutan test

@blueorangutan
Copy link

@nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

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

[SF] Trillian test result (tid-13816)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 57004 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr11239-t13816-kvm-ol8.zip
Smoke tests completed. 142 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@DaanHoogland
Copy link
Contributor

@adietrich-ussignal , can you review and test this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

when creating a DB the script should refuse to create if the schemas already exist.
4 participants