|
| 1 | +/** |
| 2 | + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * This software is licensed under the GNU General Public License v3 or later. |
| 5 | + * |
| 6 | + * It is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or any later version. |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + * |
| 17 | + */ |
| 18 | +package com.cloud.upgrade.dao; |
| 19 | + |
| 20 | + |
| 21 | +import java.sql.Connection; |
| 22 | +import java.sql.PreparedStatement; |
| 23 | +import java.sql.ResultSet; |
| 24 | +import java.sql.SQLException; |
| 25 | + |
| 26 | +import javax.naming.ConfigurationException; |
| 27 | + |
| 28 | +import junit.framework.TestCase; |
| 29 | + |
| 30 | +import org.apache.log4j.Logger; |
| 31 | +import org.junit.After; |
| 32 | +import org.junit.Before; |
| 33 | + |
| 34 | +import com.cloud.upgrade.dao.VersionVO.Step; |
| 35 | +import com.cloud.utils.component.ComponentLocator; |
| 36 | +import com.cloud.utils.db.DbTestUtils; |
| 37 | +import com.cloud.utils.db.Transaction; |
| 38 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 39 | + |
| 40 | +public class BasicZone217To221UpgradeTest extends TestCase { |
| 41 | + private static final Logger s_logger = Logger.getLogger(BasicZone217To221UpgradeTest.class); |
| 42 | + |
| 43 | + @Override |
| 44 | + @Before |
| 45 | + public void setUp() throws Exception { |
| 46 | + VersionVO version = new VersionVO("2.1.7"); |
| 47 | + version.setStep(Step.Cleanup); |
| 48 | + DbTestUtils.executeScript("VersionDaoImplTest/clean-db.sql", false, true); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + @After |
| 53 | + public void tearDown() throws Exception { |
| 54 | + } |
| 55 | + |
| 56 | + public void test217to22Upgrade() { |
| 57 | + s_logger.debug("Finding sample data from 2.1.7"); |
| 58 | + DbTestUtils.executeScript("VersionDaoImplTest/2.1.7/2.1.7_sample_basicZone_noSecurityGroups.sql", false, true); |
| 59 | + |
| 60 | + Connection conn = Transaction.getStandaloneConnection(); |
| 61 | + PreparedStatement pstmt; |
| 62 | + |
| 63 | + VersionDaoImpl dao = ComponentLocator.inject(VersionDaoImpl.class); |
| 64 | + |
| 65 | + String version = dao.getCurrentVersion(); |
| 66 | + |
| 67 | + if (!version.equals("2.1.7")) { |
| 68 | + s_logger.error("Version returned is not 2.1.7 but " + version); |
| 69 | + } else { |
| 70 | + s_logger.debug("Basic zone test version is " + version); |
| 71 | + } |
| 72 | + |
| 73 | + try { |
| 74 | + dao.upgrade("2.1.7", "2.2.1"); |
| 75 | + } catch (ConfigurationException e) { |
| 76 | + s_logger.warn("Exception: ", e); |
| 77 | + assert false : "The test failed. Check logs"; |
| 78 | + } |
| 79 | + |
| 80 | + conn = Transaction.getStandaloneConnection(); |
| 81 | + try { |
| 82 | + |
| 83 | + s_logger.debug("Starting tesing upgrade from 2.1.7 to 2.2.2 for Basic zone..."); |
| 84 | + |
| 85 | + //Version check |
| 86 | + pstmt = conn.prepareStatement("SELECT version FROM version"); |
| 87 | + ResultSet rs = pstmt.executeQuery(); |
| 88 | + |
| 89 | + if (!rs.next()) { |
| 90 | + s_logger.error("ERROR: No version selected"); |
| 91 | + } else if (!rs.getString(1).equals("2.2.1")) { |
| 92 | + s_logger.error("ERROR: VERSION stored is not 2.2.1: " + rs.getString(1)); |
| 93 | + } |
| 94 | + rs.close(); |
| 95 | + pstmt.close(); |
| 96 | + |
| 97 | + //Check that default network offerings are present |
| 98 | + pstmt = conn.prepareStatement("SELECT COUNT(*) FROM network_offerings"); |
| 99 | + rs = pstmt.executeQuery(); |
| 100 | + |
| 101 | + if (!rs.next()) { |
| 102 | + s_logger.error("ERROR: Unable to get the count of network offerings."); |
| 103 | + } else if (rs.getInt(1) != 7) { |
| 104 | + s_logger.error("ERROR: Didn't find 7 network offerings but found " + rs.getInt(1)); |
| 105 | + } else { |
| 106 | + s_logger.debug("Network offerings test passed"); |
| 107 | + } |
| 108 | + |
| 109 | + rs.close(); |
| 110 | + pstmt.close(); |
| 111 | + |
| 112 | + |
| 113 | + //Zone network type check |
| 114 | + pstmt = conn.prepareStatement("SELECT DISTINCT networktype FROM data_center"); |
| 115 | + rs = pstmt.executeQuery(); |
| 116 | + |
| 117 | + if (!rs.next()) { |
| 118 | + s_logger.error("No zone exists after upgrade"); |
| 119 | + } else if (!rs.getString(1).equals("Basic")) { |
| 120 | + s_logger.error("ERROR: Zone type is not Basic"); |
| 121 | + } else if (rs.next()) { |
| 122 | + s_logger.error("ERROR: Why do we have more than 1 zone with different types??"); |
| 123 | + System.exit(2); |
| 124 | + } else { |
| 125 | + s_logger.debug("Test passed. Zone was updated properly with type Basic"); |
| 126 | + } |
| 127 | + rs.close(); |
| 128 | + pstmt.close(); |
| 129 | + |
| 130 | + //Check that vnet/cidr were set to NULL for basic zone |
| 131 | + pstmt = conn.prepareStatement("SELECT vnet, guest_network_cidr FROM data_center"); |
| 132 | + rs = pstmt.executeQuery(); |
| 133 | + |
| 134 | + if (!rs.next()) { |
| 135 | + s_logger.error("ERROR: vnet field is missing for the zone"); |
| 136 | + } else if (rs.getString(1) != null || rs.getString(2) != null) { |
| 137 | + s_logger.error("ERROR: vnet/guestCidr should be NULL for basic zone; instead it's " + rs.getString(1)); |
| 138 | + } else { |
| 139 | + s_logger.debug("Test passed. Vnet and cidr are set to NULL for the basic zone"); |
| 140 | + } |
| 141 | + |
| 142 | + rs.close(); |
| 143 | + pstmt.close(); |
| 144 | + |
| 145 | + //Verify that default Direct guest network got created, and it's Shared and Default |
| 146 | + pstmt = conn.prepareStatement("SELECT traffic_type, guest_type, shared, is_default, id FROM networks WHERE name LIKE '%BasicZoneDirectNetwork%'"); |
| 147 | + rs = pstmt.executeQuery(); |
| 148 | + |
| 149 | + if (!rs.next()) { |
| 150 | + s_logger.error("Direct network is missing for the Basic zone"); |
| 151 | + } else if (!rs.getString(1).equalsIgnoreCase("Guest") || !rs.getString(2).equalsIgnoreCase("Direct") || !rs.getBoolean(3) || !rs.getBoolean(4)) { |
| 152 | + s_logger.error("Direct network for basic zone has incorrect setting"); |
| 153 | + } else { |
| 154 | + s_logger.debug("Test passed. Default Direct Basic zone network parameters were set correctly"); |
| 155 | + } |
| 156 | + |
| 157 | + long defaultDirectNetworkId = rs.getInt(5); |
| 158 | + rs.close(); |
| 159 | + pstmt.close(); |
| 160 | + |
| 161 | + //Verify that all vlans in the zone belong to default Direct network |
| 162 | + pstmt = conn.prepareStatement("SELECT network_id FROM vlan"); |
| 163 | + rs = pstmt.executeQuery(); |
| 164 | + |
| 165 | + while (rs.next()) { |
| 166 | + if (rs.getInt(1) != defaultDirectNetworkId) { |
| 167 | + s_logger.error("ERROR: network_id is set incorrectly for public untagged vlans in Basic zone"); |
| 168 | + System.exit(2); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + s_logger.debug("Test passed for vlan table in Basic zone"); |
| 173 | + |
| 174 | + rs.close(); |
| 175 | + pstmt.close(); |
| 176 | + |
| 177 | + //Verify user_ip_address table |
| 178 | + pstmt = conn.prepareStatement("SELECT source_network_id FROM user_ip_address"); |
| 179 | + rs = pstmt.executeQuery(); |
| 180 | + |
| 181 | + while (rs.next()) { |
| 182 | + if (rs.getInt(1) != defaultDirectNetworkId) { |
| 183 | + s_logger.error("ERROR: network_id is set incorrectly for public Ip addresses (user_ip_address table) in Basic zone"); |
| 184 | + System.exit(2); |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + s_logger.debug("Test passed for user_ip_address table in Basic zone"); |
| 189 | + |
| 190 | + rs.close(); |
| 191 | + pstmt.close(); |
| 192 | + |
| 193 | + //Verify domain_router table |
| 194 | + pstmt = conn.prepareStatement("SELECT network_id FROM domain_router"); |
| 195 | + rs = pstmt.executeQuery(); |
| 196 | + |
| 197 | + while (rs.next()) { |
| 198 | + if (rs.getInt(1) != defaultDirectNetworkId) { |
| 199 | + s_logger.error("ERROR: network_id is set incorrectly for domain routers (domain_router table) in Basic zone"); |
| 200 | + System.exit(2); |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + s_logger.debug("Test passed for domain_router table in Basic zone"); |
| 205 | + |
| 206 | + rs.close(); |
| 207 | + pstmt.close(); |
| 208 | + |
| 209 | + s_logger.debug("Basic zone test is finished"); |
| 210 | + |
| 211 | + } catch (SQLException e) { |
| 212 | + throw new CloudRuntimeException("Problem checking upgrade version", e); |
| 213 | + } finally { |
| 214 | + try { |
| 215 | + conn.close(); |
| 216 | + } catch (SQLException e) { |
| 217 | + } |
| 218 | + } |
| 219 | + } |
| 220 | + |
| 221 | +} |
0 commit comments