mirror of https://github.com/apache/cloudstack.git
bug 12361: more fixes to DB upgrade for network_offerings table
Added unittest for testing network offerings db upgrade
This commit is contained in:
parent
6717218d1d
commit
9219d4c41d
|
|
@ -72,6 +72,8 @@ public class Upgrade2214to30 implements DbUpgrade {
|
|||
dropKeysIfExist(conn);
|
||||
//physical network setup
|
||||
setupPhysicalNetworks(conn);
|
||||
//network offering
|
||||
createNetworkOfferingServices(conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -170,7 +172,7 @@ public class Upgrade2214to30 implements DbUpgrade {
|
|||
values += ",'" + domainId + "'";
|
||||
values += ",'" + broadcastDomainRange + "'";
|
||||
values += ",'Enabled'";
|
||||
values += ",'" + zoneName + "-pNtwk";
|
||||
values += ",'" + zoneName + "-pNtwk'";
|
||||
values += ")";
|
||||
|
||||
s_logger.debug("Adding PhysicalNetwork "+physicalNetworkId+" for Zone id "+ zoneId);
|
||||
|
|
@ -180,7 +182,6 @@ public class Upgrade2214to30 implements DbUpgrade {
|
|||
pstmtUpdate.executeUpdate();
|
||||
pstmtUpdate.close();
|
||||
|
||||
|
||||
//add traffic types
|
||||
s_logger.debug("Adding PhysicalNetwork traffic types");
|
||||
String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` (physical_network_id, traffic_type, xen_network_label, uuid) VALUES ( ?, ?, ?, ?)";
|
||||
|
|
@ -321,7 +322,6 @@ public class Upgrade2214to30 implements DbUpgrade {
|
|||
encryptHostDetails(conn);
|
||||
encryptVNCPassword(conn);
|
||||
encryptUserCredentials(conn);
|
||||
createNetworkOfferingServices(conn);
|
||||
}
|
||||
|
||||
private void encryptConfigValues(Connection conn) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import java.sql.Connection;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
@ -32,6 +34,7 @@ import org.junit.Before;
|
|||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.DbTestUtils;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class Test2214To30DBUpgrade extends TestCase {
|
||||
private static final Logger s_logger = Logger.getLogger(Test2214To30DBUpgrade.class);
|
||||
|
|
@ -47,38 +50,92 @@ public class Test2214To30DBUpgrade extends TestCase {
|
|||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void test2213to30Upgrade() throws SQLException {
|
||||
public void test2213to30Upgrade() throws SQLException{
|
||||
s_logger.debug("Finding sample data from 2.2.14");
|
||||
DbTestUtils.executeScript("PreviousDatabaseSchema/2.2.14/advance_zone_2.2.14.sql", false, true);
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement pstmt;
|
||||
|
||||
DatabaseUpgradeChecker checker = ComponentLocator.inject(DatabaseUpgradeChecker.class);
|
||||
|
||||
checker.upgrade("2.2.14", "3.0.0");
|
||||
|
||||
conn = Transaction.getStandaloneConnection();
|
||||
Connection conn = Transaction.getStandaloneConnection();
|
||||
|
||||
try {
|
||||
pstmt = conn.prepareStatement("SELECT version FROM version ORDER BY id DESC LIMIT 1");
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
assert rs.next() : "No version selected";
|
||||
assert rs.getString(1).equals("3.0.0") : "VERSION stored is not 3.0.0: " + rs.getString(1);
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
pstmt = conn.prepareStatement("SELECT COUNT(*) FROM physical_network");
|
||||
rs = pstmt.executeQuery();
|
||||
assert rs.next() : "No physical networks setup.";
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
checkPhysicalNetworks(conn);
|
||||
|
||||
checkNetworkOfferings(conn);
|
||||
} finally {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void checkPhysicalNetworks(Connection conn) throws SQLException {
|
||||
PreparedStatement pstmt;
|
||||
|
||||
pstmt = conn.prepareStatement("SELECT version FROM version ORDER BY id DESC LIMIT 1");
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
assert rs.next() : "No version selected";
|
||||
assert rs.getString(1).equals("3.0.0") : "VERSION stored is not 3.0.0: " + rs.getString(1);
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
pstmt = conn.prepareStatement("SELECT COUNT(*) FROM physical_network");
|
||||
rs = pstmt.executeQuery();
|
||||
assert rs.next() : "No physical networks setup.";
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void checkNetworkOfferings(Connection conn) throws SQLException {
|
||||
//1) verify that all fields are present
|
||||
List<String> fields = new ArrayList<String>();
|
||||
fields.add("id");
|
||||
fields.add("name");
|
||||
fields.add("unique_name");
|
||||
fields.add("display_text");
|
||||
fields.add("nw_rate");
|
||||
fields.add("mc_rate");
|
||||
fields.add("traffic_type");
|
||||
fields.add("specify_vlan");
|
||||
fields.add("system_only");
|
||||
fields.add("service_offering_id");
|
||||
fields.add("tags");
|
||||
fields.add("default");
|
||||
fields.add("availability");
|
||||
fields.add("state");
|
||||
fields.add("removed");
|
||||
fields.add("created");
|
||||
fields.add("guest_type");
|
||||
fields.add("dedicated_lb_service");
|
||||
fields.add("shared_source_nat_service");
|
||||
fields.add("specify_ip_ranges");
|
||||
fields.add("sort_key");
|
||||
fields.add("uuid");
|
||||
fields.add("redundant_router_service");
|
||||
fields.add("conserve_mode");
|
||||
fields.add("elastic_ip_service");
|
||||
fields.add("elastic_lb_service");
|
||||
|
||||
PreparedStatement pstmt;
|
||||
for (String field : fields) {
|
||||
pstmt = conn.prepareStatement("SHOW COLUMNS FROM network_offerings LIKE ?");
|
||||
pstmt.setString(1, field);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (!rs.next()) {
|
||||
throw new CloudRuntimeException("Field " + field + " is missing in upgraded network_offerings table");
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
}
|
||||
|
||||
//2) compare default network offerings
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -287,19 +287,18 @@ UPDATE configuration SET description = '[''random'', ''firstfit'', ''userdispers
|
|||
--;
|
||||
-- Usage db upgrade from 2.2.14 to 3.0;
|
||||
--;
|
||||
|
||||
update `cloud_usage`.`usage_network` set agg_bytes_received = net_bytes_received + current_bytes_received, agg_bytes_sent = net_bytes_sent + current_bytes_sent;
|
||||
ALTER TABLE `cloud_usage`.`user_statistics` ADD COLUMN `agg_bytes_received` bigint unsigned NOT NULL default '0';
|
||||
ALTER TABLE `cloud_usage`.`user_statistics` ADD COLUMN `agg_bytes_sent` bigint unsigned NOT NULL default '0';
|
||||
|
||||
ALTER TABLE `cloud_usage`.`usage_network` ADD COLUMN `agg_bytes_received` bigint unsigned NOT NULL default '0';
|
||||
ALTER TABLE `cloud_usage`.`usage_network` ADD COLUMN `agg_bytes_sent` bigint unsigned NOT NULL default '0';
|
||||
|
||||
update `cloud_usage`.`usage_network` set agg_bytes_received = net_bytes_received + current_bytes_received, agg_bytes_sent = net_bytes_sent + current_bytes_sent;
|
||||
|
||||
ALTER TABLE `cloud_usage`.`usage_network` DROP COLUMN `net_bytes_received`;
|
||||
ALTER TABLE `cloud_usage`.`usage_network` DROP COLUMN `net_bytes_sent`;
|
||||
ALTER TABLE `cloud_usage`.`usage_network` DROP COLUMN `current_bytes_received`;
|
||||
ALTER TABLE `cloud_usage`.`usage_network` DROP COLUMN `current_bytes_sent`;
|
||||
ALTER TABLE `cloud_usage`.`usage_vpn_user` ADD INDEX `i_usage_vpn_user__account_id`(`account_id`);
|
||||
ALTER TABLE `cloud_usage`.`usage_vpn_user` ADD INDEX `i_usage_vpn_user__created`(`created`);
|
||||
ALTER TABLE `cloud_usage`.`usage_vpn_user` ADD INDEX `i_usage_vpn_user__deleted`(`deleted`);
|
||||
|
||||
CREATE TABLE `cloud_usage`.`usage_vpn_user` (
|
||||
`zone_id` bigint unsigned NOT NULL,
|
||||
|
|
@ -311,13 +310,12 @@ CREATE TABLE `cloud_usage`.`usage_vpn_user` (
|
|||
`deleted` DATETIME NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
DELETE FROM configuration WHERE name='host.capacity.checker.wait';
|
||||
DELETE FROM configuration WHERE name='host.capacity.checker.interval';
|
||||
INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'management-server', 'disable.extraction' , 'false', 'Flag for disabling extraction of template, isos and volumes');
|
||||
INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.check.interval' , '30', 'Interval (in seconds) to report redundant router status.');
|
||||
ALTER TABLE `cloud_usage`.`usage_vpn_user` ADD INDEX `i_usage_vpn_user__account_id`(`account_id`);
|
||||
ALTER TABLE `cloud_usage`.`usage_vpn_user` ADD INDEX `i_usage_vpn_user__created`(`created`);
|
||||
ALTER TABLE `cloud_usage`.`usage_vpn_user` ADD INDEX `i_usage_vpn_user__deleted`(`deleted`);
|
||||
|
||||
ALTER TABLE `cloud`.`security_ingress_rule` RENAME TO `security_group_rule`;
|
||||
|
||||
ALTER TABLE `cloud`.`security_group_rule` ADD COLUMN `type` varchar(10) default 'ingress' AFTER security_group_id;
|
||||
|
|
@ -561,8 +559,15 @@ UPDATE `cloud`.`network_offerings` SET `guest_type`='Shared' where `guest_type`=
|
|||
UPDATE `cloud`.`network_offerings` SET `guest_type`='Isolated' where `guest_type`='Virtual';
|
||||
UPDATE `cloud`.`network_offerings` SET `availability`='Optional' where `availability`='Required' and `guest_type`='Shared';
|
||||
|
||||
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `elastic_ip_service` int(1) unsigned NOT NULL DEFAULT '0' COMMENT 'true if the network offering provides elastic ip service';
|
||||
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `elastic_lb_service` int(1) unsigned NOT NULL DEFAULT '0' COMMENT 'true if the network offering provides elastic lb service';
|
||||
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `specify_ip_ranges` int(1) unsigned NOT NULL DEFAULT '0' COMMENT 'true if the network offering provides an ability to define ip ranges';
|
||||
|
||||
insert into network_offerings (`name`, `unique_name`, `display_text`, `traffic_type`, `system_only`, `specify_vlan`, `default`, `availability`, `state`, `guest_type`, `created`, `userdata_service`, `dns_service`, `dhcp_service`) values ('DefaultIsolatedNetworkOffering', 'DefaultIsolatedNetworkOffering', 'Offering for Isolated networks with no Source Nat service', 'Guest', 0, 1, 1, 'Optional', 'Enabled', 'Isolated', now(), 1, 1, 1);
|
||||
|
||||
insert into `cloud`.`network_offerings` (`name`, `unique_name`, `display_text`, `traffic_type`, `system_only`, `specify_vlan`, `default`, `availability`, `state`, `guest_type`, `created`, `userdata_service`, `dns_service`, `dhcp_service`) values ('DefaultIsolatedNetworkOffering', 'DefaultIsolatedNetworkOffering', 'Offering for Isolated networks with no Source Nat service', 'Guest', 0, 1, 1, 'Optional', 'Enabled', 'Isolated', now(), 1, 1, 1);
|
||||
|
||||
|
||||
UPDATE `cloud`.`network_offerings` set specify_ip_ranges=1 where name in ('System-Public-Network', 'System-Storage-Network', 'DefaultSharedNetworkOfferingWithSGService', 'DefaultSharedNetworkOffering', 'DefaultIsolatedNetworkOffering');
|
||||
|
||||
|
||||
CREATE TABLE `ntwk_offering_service_map` (
|
||||
|
|
|
|||
Loading…
Reference in New Issue