Skip to content

Commit 602d9ec

Browse files
shwstpprCopilotnvazquez
authored
engine-schema: upgrade path for 24.0.0 (#14033)
* engine-schema: upgrade path for 24.0.0 Adds a 4.23.0 to 24.0.0 upgrade path. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix CS version Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix upgrade unit tests for cutover Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix imports Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix template version * continue using 3 part version for sys template * fix * fix more * use security version after cutover Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * improvements and add tests Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix more scripts Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * address remaining comments Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * more changes Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * Update versioning logic in export-templates.sh Refactor versioning logic to handle four-component metadata separately. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix export-templates.sh syntax --------- Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: nvazquez <nicovazquez90@gmail.com>
1 parent 5812290 commit 602d9ec

15 files changed

Lines changed: 680 additions & 85 deletions

File tree

‎engine/schema/pom.xml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@
153153
<artifactId>exec-maven-plugin</artifactId>
154154
<version>${cs.exec-maven-plugin.version}</version>
155155
<executions>
156+
<execution>
157+
<id>test-templateConfig</id>
158+
<phase>test</phase>
159+
<goals>
160+
<goal>exec</goal>
161+
</goals>
162+
<configuration>
163+
<workingDirectory>${basedir}/</workingDirectory>
164+
<executable>bash</executable>
165+
<arguments>
166+
<argument>test_templateConfig.sh</argument>
167+
</arguments>
168+
</configuration>
169+
</execution>
156170
<execution>
157171
<id>systemvm-template-metadata</id>
158172
<phase>package</phase>

‎engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@
9191
import com.cloud.upgrade.dao.Upgrade42020to42030;
9292
import com.cloud.upgrade.dao.Upgrade42030to42040;
9393
import com.cloud.upgrade.dao.Upgrade42040to42100;
94-
import com.cloud.upgrade.dao.Upgrade42100to42200;
95-
import com.cloud.upgrade.dao.Upgrade42200to42210;
9694
import com.cloud.upgrade.dao.Upgrade420to421;
95+
import com.cloud.upgrade.dao.Upgrade42100to42200;
9796
import com.cloud.upgrade.dao.Upgrade421to430;
97+
import com.cloud.upgrade.dao.Upgrade42200to42210;
9898
import com.cloud.upgrade.dao.Upgrade42210to42300;
99+
import com.cloud.upgrade.dao.Upgrade42300to2400;
99100
import com.cloud.upgrade.dao.Upgrade430to440;
100101
import com.cloud.upgrade.dao.Upgrade431to440;
101102
import com.cloud.upgrade.dao.Upgrade432to440;
@@ -248,6 +249,7 @@ public DatabaseUpgradeChecker() {
248249
.next("4.21.0.0", new Upgrade42100to42200())
249250
.next("4.22.0.0", new Upgrade42200to42210())
250251
.next("4.22.1.0", new Upgrade42210to42300())
252+
.next("4.23.0.0", new Upgrade42300to2400())
251253
.build();
252254
}
253255

@@ -513,8 +515,7 @@ protected void doUpgrades(GlobalLock lock) {
513515
String csVersion = parseSystemVmMetadata();
514516
final CloudStackVersion sysVmVersion = CloudStackVersion.parse(csVersion);
515517
final CloudStackVersion currentVersion = CloudStackVersion.parse(currentVersionValue);
516-
SystemVmTemplateRegistration.CS_MAJOR_VERSION = sysVmVersion.getMajorRelease() + "." + sysVmVersion.getMinorRelease();
517-
SystemVmTemplateRegistration.CS_TINY_VERSION = String.valueOf(sysVmVersion.getPatchRelease());
518+
updateSystemVmTemplateVersion(sysVmVersion);
518519

519520
LOGGER.info("DB version = {} Code Version = {}", dbVersion, currentVersion);
520521

@@ -540,6 +541,18 @@ protected void doUpgrades(GlobalLock lock) {
540541
}
541542
}
542543

544+
/**
545+
* Sets the system VM template major/tiny version used to look up the matching system VM template,
546+
* from the version parsed out of the system VM template metadata file. Below the versioning cutover
547+
* (major &lt; 24) the tiny version is the legacy patch release; from the cutover onwards it is the
548+
* security release, since the patch position is dropped in that scheme.
549+
*/
550+
@VisibleForTesting
551+
protected static void updateSystemVmTemplateVersion(CloudStackVersion sysVmVersion) {
552+
SystemVmTemplateRegistration.CS_MAJOR_VERSION = String.format("%d.%d", sysVmVersion.getMajorRelease(), sysVmVersion.getMinorRelease());
553+
SystemVmTemplateRegistration.CS_TINY_VERSION = String.valueOf(sysVmVersion.getTinyRelease());
554+
}
555+
543556
/**
544557
* Hook that is called when an upgrade is required but the management server is clustered.
545558
* Default behavior is to exit the JVM, tests can override to throw instead.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.upgrade.dao;
18+
19+
public class Upgrade42300to2400 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate {
20+
21+
@Override
22+
public String[] getUpgradableVersionRange() {
23+
return new String[]{"4.23.0.0", "24.0.0"};
24+
}
25+
26+
@Override
27+
public String getUpgradedVersion() {
28+
return "24.0.0";
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade cleanup from 4.23.0.0 to 24.0.0
20+
--;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade from 4.23.0.0 to 24.0.0
20+
--;

‎engine/schema/src/test/java/com/cloud/upgrade/DatabaseUpgradeCheckerTest.java‎

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,25 @@
1616
// under the License.
1717
package com.cloud.upgrade;
1818

19-
import java.sql.SQLException;
19+
import static org.junit.Assert.assertArrayEquals;
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertNotNull;
23+
import static org.junit.Assert.assertTrue;
24+
2025
import java.lang.reflect.Field;
2126
import java.sql.Connection;
2227
import java.sql.PreparedStatement;
2328
import java.sql.ResultSet;
29+
import java.sql.SQLException;
2430

2531
import javax.sql.DataSource;
2632

2733
import org.apache.cloudstack.utils.CloudStackVersion;
28-
import org.junit.Test;
29-
import org.junit.Before;
3034
import org.junit.After;
35+
import org.junit.Before;
36+
import org.junit.Test;
3137
import org.junit.runner.RunWith;
32-
3338
import org.mockito.ArgumentMatchers;
3439
import org.mockito.Mock;
3540
import org.mockito.Mockito;
@@ -47,6 +52,7 @@
4752
import com.cloud.upgrade.dao.Upgrade42020to42030;
4853
import com.cloud.upgrade.dao.Upgrade42030to42040;
4954
import com.cloud.upgrade.dao.Upgrade42040to42100;
55+
import com.cloud.upgrade.dao.Upgrade42300to2400;
5056
import com.cloud.upgrade.dao.Upgrade452to453;
5157
import com.cloud.upgrade.dao.Upgrade453to460;
5258
import com.cloud.upgrade.dao.Upgrade460to461;
@@ -55,15 +61,8 @@
5561
import com.cloud.upgrade.dao.Upgrade471to480;
5662
import com.cloud.upgrade.dao.Upgrade480to481;
5763
import com.cloud.upgrade.dao.Upgrade490to4910;
58-
5964
import com.cloud.utils.db.TransactionLegacy;
6065

61-
import static org.junit.Assert.assertTrue;
62-
import static org.junit.Assert.assertFalse;
63-
import static org.junit.Assert.assertNotNull;
64-
import static org.junit.Assert.assertEquals;
65-
import static org.junit.Assert.assertArrayEquals;
66-
6766

6867
@RunWith(MockitoJUnitRunner.class)
6968
public class DatabaseUpgradeCheckerTest {
@@ -81,6 +80,8 @@ public class DatabaseUpgradeCheckerTest {
8180
ResultSet resultSet;
8281

8382
private DataSource backupDataSource;
83+
private String previousCsMajorVersion;
84+
private String previousCsTinyVersion;
8485

8586
@Before
8687
public void setup() throws Exception {
@@ -92,13 +93,19 @@ public void setup() throws Exception {
9293
Mockito.when(dataSource.getConnection()).thenReturn(connection);
9394
Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement);
9495
Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet);
96+
97+
previousCsMajorVersion = SystemVmTemplateRegistration.CS_MAJOR_VERSION;
98+
previousCsTinyVersion = SystemVmTemplateRegistration.CS_TINY_VERSION;
9599
}
96100

97101
@After
98102
public void cleanup() throws Exception {
99103
Field dsField = TransactionLegacy.class.getDeclaredField("s_ds");
100104
dsField.setAccessible(true);
101105
dsField.set(null, backupDataSource);
106+
107+
SystemVmTemplateRegistration.CS_MAJOR_VERSION = previousCsMajorVersion;
108+
SystemVmTemplateRegistration.CS_TINY_VERSION = previousCsTinyVersion;
102109
}
103110

104111
@Test
@@ -214,10 +221,10 @@ public void testFindUpgradePath452to490() {
214221
@Test
215222
public void testCalculateUpgradePathUnknownDbVersion() {
216223

217-
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.99.0.0");
224+
final CloudStackVersion dbVersion = CloudStackVersion.parse("99.0.0");
218225
assertNotNull(dbVersion);
219226

220-
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.99.1.0");
227+
final CloudStackVersion currentVersion = CloudStackVersion.parse("99.1.0");
221228
assertNotNull(currentVersion);
222229

223230
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
@@ -234,7 +241,7 @@ public void testCalculateUpgradePathFromKnownDbVersion() {
234241
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.17.0.0");
235242
assertNotNull(dbVersion);
236243

237-
final CloudStackVersion currentVersion = CloudStackVersion.parse("4.99.1.0");
244+
final CloudStackVersion currentVersion = CloudStackVersion.parse("99.1.0");
238245
assertNotNull(currentVersion);
239246

240247
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
@@ -268,10 +275,7 @@ public void testCalculateUpgradePathFromLatestDbVersion() {
268275
final CloudStackVersion dbVersion = checker.getLatestVersion();
269276
assertNotNull(dbVersion);
270277

271-
final CloudStackVersion currentVersion = CloudStackVersion.parse(dbVersion.getMajorRelease() + "."
272-
+ dbVersion.getMinorRelease() + "."
273-
+ dbVersion.getPatchRelease() + "."
274-
+ (dbVersion.getSecurityRelease() + 1));
278+
final CloudStackVersion currentVersion = getNextSecurityRelease(dbVersion);
275279
assertNotNull(currentVersion);
276280

277281
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
@@ -293,10 +297,7 @@ public void testCalculateUpgradePathFrom41800toNextSecurityRelease() {
293297
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
294298
assertNotNull(upgrades);
295299

296-
final CloudStackVersion nextSecurityRelease = CloudStackVersion.parse(currentVersion.getMajorRelease() + "."
297-
+ currentVersion.getMinorRelease() + "."
298-
+ currentVersion.getPatchRelease() + "."
299-
+ (currentVersion.getSecurityRelease() + 1));
300+
final CloudStackVersion nextSecurityRelease = getNextSecurityRelease(currentVersion);
300301
assertNotNull(nextSecurityRelease);
301302

302303
final DbUpgrade[] upgradesToNext = checker.calculateUpgradePath(dbVersion, nextSecurityRelease);
@@ -306,16 +307,26 @@ public void testCalculateUpgradePathFrom41800toNextSecurityRelease() {
306307
assertTrue(upgradesToNext[upgradesToNext.length - 1] instanceof NoopDbUpgrade);
307308
}
308309

310+
private static CloudStackVersion getNextSecurityRelease(CloudStackVersion version, int increment) {
311+
String nextSecurityReleaseVersionStr = version.getMajorRelease() + "."
312+
+ version.getMinorRelease() + "."
313+
+ (version.usesNewVersioning() ? "" : version.getPatchRelease() + ".")
314+
+ (version.getSecurityRelease() + increment);
315+
316+
return CloudStackVersion.parse(nextSecurityReleaseVersionStr);
317+
}
318+
319+
private static CloudStackVersion getNextSecurityRelease(CloudStackVersion version) {
320+
return getNextSecurityRelease(version, 1);
321+
}
322+
309323
@Test
310324
public void testCalculateUpgradePathFromSecurityReleaseToLatest() {
311325

312326
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.17.2.0"); // a EOL version
313327
assertNotNull(dbVersion);
314328

315-
final CloudStackVersion oldSecurityRelease = CloudStackVersion.parse(dbVersion.getMajorRelease() + "."
316-
+ dbVersion.getMinorRelease() + "."
317-
+ dbVersion.getPatchRelease() + "."
318-
+ (dbVersion.getSecurityRelease() + 100));
329+
final CloudStackVersion oldSecurityRelease = getNextSecurityRelease(dbVersion, 100);
319330
assertNotNull(oldSecurityRelease); // fake security release 4.17.2.100
320331

321332
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
@@ -347,10 +358,7 @@ public void testCalculateUpgradePathFromSecurityReleaseToNextSecurityRelease() {
347358
final CloudStackVersion currentVersion = checker.getLatestVersion();
348359
assertNotNull(currentVersion);
349360

350-
final CloudStackVersion nextSecurityRelease = CloudStackVersion.parse(currentVersion.getMajorRelease() + "."
351-
+ currentVersion.getMinorRelease() + "."
352-
+ currentVersion.getPatchRelease() + "."
353-
+ (currentVersion.getSecurityRelease() + 1));
361+
final CloudStackVersion nextSecurityRelease = getNextSecurityRelease(currentVersion);
354362
assertNotNull(nextSecurityRelease); // fake security release
355363

356364
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
@@ -422,4 +430,48 @@ public void testCalculateUpgradePath42010to42100() {
422430
assertTrue(upgrades[2] instanceof Upgrade42040to42100);
423431
assertEquals(currentVersion.toString(), upgrades[2].getUpgradedVersion());
424432
}
433+
434+
@Test
435+
public void testCalculateUpgradePath42300to2400() {
436+
437+
final CloudStackVersion dbVersion = CloudStackVersion.parse("4.23.0.0");
438+
assertNotNull(dbVersion);
439+
440+
final CloudStackVersion currentVersion = CloudStackVersion.parse("24.0.0");
441+
assertNotNull(currentVersion);
442+
443+
final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker();
444+
final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion);
445+
446+
assertNotNull(upgrades);
447+
assertEquals(1, upgrades.length);
448+
assertTrue(upgrades[0] instanceof Upgrade42300to2400);
449+
450+
assertArrayEquals(new String[]{"4.23.0.0", "24.0.0"}, upgrades[0].getUpgradableVersionRange());
451+
assertEquals(currentVersion.toString(), upgrades[0].getUpgradedVersion());
452+
}
453+
454+
@Test
455+
public void testUpdateSystemVmTemplateVersionBelowCutover() {
456+
DatabaseUpgradeChecker.updateSystemVmTemplateVersion(CloudStackVersion.parse("4.22.1.0"));
457+
458+
assertEquals("4.22", SystemVmTemplateRegistration.CS_MAJOR_VERSION);
459+
assertEquals("1", SystemVmTemplateRegistration.CS_TINY_VERSION);
460+
}
461+
462+
@Test
463+
public void testUpdateSystemVmTemplateVersionAtCutover() {
464+
DatabaseUpgradeChecker.updateSystemVmTemplateVersion(CloudStackVersion.parse("24.0.1"));
465+
466+
assertEquals("24.0", SystemVmTemplateRegistration.CS_MAJOR_VERSION);
467+
assertEquals("1", SystemVmTemplateRegistration.CS_TINY_VERSION);
468+
}
469+
470+
@Test
471+
public void testUpdateSystemVmTemplateVersionAfterCutover() {
472+
DatabaseUpgradeChecker.updateSystemVmTemplateVersion(CloudStackVersion.parse("25.3.2"));
473+
474+
assertEquals("25.3", SystemVmTemplateRegistration.CS_MAJOR_VERSION);
475+
assertEquals("2", SystemVmTemplateRegistration.CS_TINY_VERSION);
476+
}
425477
}

0 commit comments

Comments
 (0)