From 21bca2078048cebd607d0c4adc482c649d5ecfe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 10 Oct 2011 06:14:46 -0700 Subject: [PATCH 1/9] Bug #848: Add error message and stop oned execution if bootstrap fails --- include/AclManager.h | 3 ++- include/Group.h | 5 +++-- include/GroupPool.h | 5 +++-- include/Host.h | 5 +++-- include/HostPool.h | 5 +++-- include/Image.h | 5 +++-- include/ImagePool.h | 5 +++-- include/Nebula.h | 4 +++- include/User.h | 5 +++-- include/UserPool.h | 5 +++-- include/VMTemplate.h | 5 +++-- include/VMTemplatePool.h | 5 +++-- include/VirtualMachine.h | 11 +++++++--- include/VirtualMachinePool.h | 5 +++-- include/VirtualNetwork.h | 11 +++++++--- include/VirtualNetworkPool.h | 5 +++-- src/acl/AclManager.cc | 4 ++-- src/nebula/Nebula.cc | 41 ++++++++++++++++++++++++------------ 18 files changed, 87 insertions(+), 47 deletions(-) diff --git a/include/AclManager.h b/include/AclManager.h index e096d7de69..cc6d5eaa4c 100644 --- a/include/AclManager.h +++ b/include/AclManager.h @@ -99,8 +99,9 @@ public: /** * Bootstraps the database table(s) associated to the ACL Manager + * @return 0 on success */ - static void bootstrap(SqlDB * _db); + static int bootstrap(SqlDB * _db); /** * Dumps the rule set in XML format. diff --git a/include/Group.h b/include/Group.h index ff21f8e06a..51086f12c6 100644 --- a/include/Group.h +++ b/include/Group.h @@ -103,12 +103,13 @@ private: /** * Bootstraps the database table(s) associated to the Group + * @return 0 on success */ - static void bootstrap(SqlDB * db) + static int bootstrap(SqlDB * db) { ostringstream oss(Group::db_bootstrap); - db->exec(oss); + return db->exec(oss); }; /** diff --git a/include/GroupPool.h b/include/GroupPool.h index 0addc889ab..934dd61ff6 100644 --- a/include/GroupPool.h +++ b/include/GroupPool.h @@ -119,10 +119,11 @@ public: /** * Bootstraps the database table(s) associated to the Group pool + * @return 0 on success */ - static void bootstrap(SqlDB * _db) + static int bootstrap(SqlDB * _db) { - Group::bootstrap(_db); + return Group::bootstrap(_db); }; /** diff --git a/include/Host.h b/include/Host.h index 52643d3452..f112532aa0 100644 --- a/include/Host.h +++ b/include/Host.h @@ -362,12 +362,13 @@ private: /** * Bootstraps the database table(s) associated to the Host + * @return 0 on success */ - static void bootstrap(SqlDB * db) + static int bootstrap(SqlDB * db) { ostringstream oss_host(Host::db_bootstrap); - db->exec(oss_host); + return db->exec(oss_host); }; /** diff --git a/include/HostPool.h b/include/HostPool.h index 27eff36afe..89a516218e 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -82,10 +82,11 @@ public: /** * Bootstraps the database table(s) associated to the Host pool + * @return 0 on success */ - static void bootstrap(SqlDB *_db) + static int bootstrap(SqlDB *_db) { - Host::bootstrap(_db); + return Host::bootstrap(_db); }; /** diff --git a/include/Image.h b/include/Image.h index 5f5defe5ea..d3328dadc1 100644 --- a/include/Image.h +++ b/include/Image.h @@ -338,12 +338,13 @@ private: /** * Bootstraps the database table(s) associated to the Image + * @return 0 on success */ - static void bootstrap(SqlDB * db) + static int bootstrap(SqlDB * db) { ostringstream oss_image(Image::db_bootstrap); - db->exec(oss_image); + return db->exec(oss_image); }; /** diff --git a/include/ImagePool.h b/include/ImagePool.h index 78052d7349..7eab479ddf 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -104,10 +104,11 @@ public: /** * Bootstraps the database table(s) associated to the Image pool + * @return 0 on success */ - static void bootstrap(SqlDB *_db) + static int bootstrap(SqlDB *_db) { - Image::bootstrap(_db); + return Image::bootstrap(_db); }; /** diff --git a/include/Nebula.h b/include/Nebula.h index 4c746ada43..1048358887 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -445,8 +445,10 @@ private: /** * Bootstraps the database control tables + * + * @return 0 on success */ - void bootstrap(); + int bootstrap(); /** * Callback function for the check_db_version method. Stores the read diff --git a/include/User.h b/include/User.h index c78ed283f6..72fb6228fd 100644 --- a/include/User.h +++ b/include/User.h @@ -174,12 +174,13 @@ private: /** * Bootstraps the database table(s) associated to the User + * @return 0 on success */ - static void bootstrap(SqlDB * db) + static int bootstrap(SqlDB * db) { ostringstream oss_user(User::db_bootstrap); - db->exec(oss_user); + return db->exec(oss_user); }; /** diff --git a/include/UserPool.h b/include/UserPool.h index d077f3906c..1258463556 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -92,10 +92,11 @@ public: /** * Bootstraps the database table(s) associated to the User pool + * @return 0 on success */ - static void bootstrap(SqlDB * _db) + static int bootstrap(SqlDB * _db) { - User::bootstrap(_db); + return User::bootstrap(_db); }; /** diff --git a/include/VMTemplate.h b/include/VMTemplate.h index 819eb29c01..130cbcc851 100644 --- a/include/VMTemplate.h +++ b/include/VMTemplate.h @@ -108,12 +108,13 @@ private: /** * Bootstraps the database table(s) associated to the VMTemplate + * @return 0 on success */ - static void bootstrap(SqlDB * db) + static int bootstrap(SqlDB * db) { ostringstream oss(VMTemplate::db_bootstrap); - db->exec(oss); + return db->exec(oss); }; /** diff --git a/include/VMTemplatePool.h b/include/VMTemplatePool.h index 0b66952bfd..4b5be1472d 100644 --- a/include/VMTemplatePool.h +++ b/include/VMTemplatePool.h @@ -104,10 +104,11 @@ public: /** * Bootstraps the database table(s) associated to the pool + * @return 0 on success */ - static void bootstrap(SqlDB *_db) + static int bootstrap(SqlDB *_db) { - VMTemplate::bootstrap(_db); + return VMTemplate::bootstrap(_db); }; private: diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 8e8c8b6d0a..568c48ceee 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -784,14 +784,19 @@ private: /** * Bootstraps the database table(s) associated to the VirtualMachine + * @return 0 on success */ - static void bootstrap(SqlDB * db) + static int bootstrap(SqlDB * db) { + int rc; + ostringstream oss_vm(VirtualMachine::db_bootstrap); ostringstream oss_hist(History::db_bootstrap); - db->exec(oss_vm); - db->exec(oss_hist); + rc = db->exec(oss_vm); + rc += db->exec(oss_hist); + + return rc; }; /** diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index 44edfc2ca2..1a8035ad9d 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -122,10 +122,11 @@ public: /** * Bootstraps the database table(s) associated to the VirtualMachine pool + * @return 0 on success */ - static void bootstrap(SqlDB * _db) + static int bootstrap(SqlDB * _db) { - VirtualMachine::bootstrap(_db); + return VirtualMachine::bootstrap(_db); }; /** diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index dc78655908..be02e86954 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -236,14 +236,19 @@ private: /** * Bootstraps the database table(s) associated to the Virtual Network + * @return 0 on success */ - static void bootstrap(SqlDB * db) + static int bootstrap(SqlDB * db) { + int rc; + ostringstream oss_vnet(VirtualNetwork::db_bootstrap); ostringstream oss_lease(Leases::db_bootstrap); - db->exec(oss_vnet); - db->exec(oss_lease); + rc = db->exec(oss_vnet); + rc += db->exec(oss_lease); + + return rc; }; /** diff --git a/include/VirtualNetworkPool.h b/include/VirtualNetworkPool.h index e77438acd0..6dc2ef2c1e 100644 --- a/include/VirtualNetworkPool.h +++ b/include/VirtualNetworkPool.h @@ -108,10 +108,11 @@ public: /** * Bootstraps the database table(s) associated to the VirtualNetwork pool + * @return 0 on success */ - static void bootstrap(SqlDB * _db) + static int bootstrap(SqlDB * _db) { - VirtualNetwork::bootstrap(_db); + return VirtualNetwork::bootstrap(_db); }; /** diff --git a/src/acl/AclManager.cc b/src/acl/AclManager.cc index d6a9338a8f..a183eb9f19 100644 --- a/src/acl/AclManager.cc +++ b/src/acl/AclManager.cc @@ -474,11 +474,11 @@ int AclManager::del_rule(int oid, string& error_str) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void AclManager::bootstrap(SqlDB * _db) +int AclManager::bootstrap(SqlDB * _db) { ostringstream oss(db_bootstrap); - _db->exec(oss); + return _db->exec(oss); } /* -------------------------------------------------------------------------- */ diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 5f9aa2f6ad..87c7d7d578 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -236,17 +236,29 @@ void Nebula::start() if( rc == -2 ) { + rc = 0; + NebulaLog::log("ONE",Log::INFO,"Bootstraping OpenNebula database."); - bootstrap(); - VirtualMachinePool::bootstrap(db); - HostPool::bootstrap(db); - VirtualNetworkPool::bootstrap(db); - GroupPool::bootstrap(db); - UserPool::bootstrap(db); - ImagePool::bootstrap(db); - VMTemplatePool::bootstrap(db); - AclManager::bootstrap(db); + rc += VirtualMachinePool::bootstrap(db); + rc += HostPool::bootstrap(db); + rc += VirtualNetworkPool::bootstrap(db); + rc += GroupPool::bootstrap(db); + rc += UserPool::bootstrap(db); + rc += ImagePool::bootstrap(db); + rc += VMTemplatePool::bootstrap(db); + rc += AclManager::bootstrap(db); + + // Create the versioning table only if bootstrap went well + if ( rc == 0 ) + { + rc += bootstrap(); + } + + if ( rc != 0 ) + { + throw runtime_error("Error bootstrapping database."); + } } } catch (exception&) @@ -627,27 +639,30 @@ void Nebula::start() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void Nebula::bootstrap() +int Nebula::bootstrap() { + int rc; ostringstream oss; oss << "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, " "last_oid BIGINT UNSIGNED)"; - db->exec(oss); + rc = db->exec(oss); oss.str(""); oss << "CREATE TABLE db_versioning (oid INTEGER PRIMARY KEY, " "version VARCHAR(256), timestamp INTEGER, comment VARCHAR(256))"; - db->exec(oss); + rc += db->exec(oss); oss.str(""); oss << "INSERT INTO db_versioning (oid, version, timestamp, comment) " << "VALUES (0, '" << db_version() << "', " << time(0) << ", '" << version() << " daemon bootstrap')"; - db->exec(oss); + rc += db->exec(oss); + + return rc; } /* -------------------------------------------------------------------------- */ From 771a4ac8d994f4ad296f37efcd631161884f145b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 10 Oct 2011 17:48:06 +0200 Subject: [PATCH 2/9] Bug #848: Set name columns to 128 chars. The name length is checked for new objects --- src/group/Group.cc | 2 +- src/group/GroupPool.cc | 9 +++++++++ src/host/Host.cc | 2 +- src/host/HostPool.cc | 9 +++++++++ src/image/Image.cc | 4 ++-- src/image/ImagePool.cc | 9 +++++++++ src/nebula/Nebula.cc | 2 +- src/um/User.cc | 2 +- src/um/UserPool.cc | 6 ++++++ src/vm/VirtualMachine.cc | 12 ++++++++++-- src/vm_template/VMTemplate.cc | 7 ++++++- src/vnm/VirtualNetworkPool.cc | 9 +++++++++ 12 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/group/Group.cc b/src/group/Group.cc index a944e67d14..a6d8dbc54a 100644 --- a/src/group/Group.cc +++ b/src/group/Group.cc @@ -27,7 +27,7 @@ const char * Group::table = "group_pool"; const char * Group::db_names = "oid, name, body"; const char * Group::db_bootstrap = "CREATE TABLE IF NOT EXISTS group_pool (" - "oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, " + "oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, " "UNIQUE(name))"; /* ************************************************************************ */ diff --git a/src/group/GroupPool.cc b/src/group/GroupPool.cc index c3cd4e6e9c..23213fb8a1 100644 --- a/src/group/GroupPool.cc +++ b/src/group/GroupPool.cc @@ -91,6 +91,11 @@ int GroupPool::allocate(string name, int * oid, string& error_str) goto error_name; } + if ( name.length() > 128 ) + { + goto error_name_length; + } + // Check for duplicates group = get(name, false); @@ -111,6 +116,10 @@ error_name: oss << "NAME cannot be empty."; goto error_common; +error_name_length: + oss << "NAME is too long; max length is 128 chars."; + goto error_common; + error_duplicated: oss << "NAME is already taken by GROUP " << group->get_oid() << "."; diff --git a/src/host/Host.cc b/src/host/Host.cc index 32e98ad3fc..52361a96ed 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -61,7 +61,7 @@ const char * Host::table = "host_pool"; const char * Host::db_names = "oid, name, body, state, last_mon_time"; const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool (" - "oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, " + "oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, state INTEGER, " "last_mon_time INTEGER, UNIQUE(name))"; /* ------------------------------------------------------------------------ */ diff --git a/src/host/HostPool.cc b/src/host/HostPool.cc index ec6edb511f..d33529cbad 100644 --- a/src/host/HostPool.cc +++ b/src/host/HostPool.cc @@ -150,6 +150,11 @@ int HostPool::allocate ( goto error_name; } + if ( hostname.length() > 128 ) + { + goto error_name_length; + } + if ( im_mad_name.empty() ) { goto error_im; @@ -187,6 +192,10 @@ error_name: oss << "NAME cannot be empty."; goto error_common; +error_name_length: + oss << "NAME is too long; max length is 128 chars."; + goto error_common; + error_im: oss << "IM_MAD_NAME cannot be empty."; goto error_common; diff --git a/src/image/Image.cc b/src/image/Image.cc index ace9db96ba..647860d6f9 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -74,7 +74,7 @@ const char * Image::table = "image_pool"; const char * Image::db_names = "oid, name, body, uid, gid, public"; const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool (" - "oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, " + "oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, " "gid INTEGER, public INTEGER, UNIQUE(name,uid) )"; /* ------------------------------------------------------------------------ */ @@ -235,7 +235,7 @@ error_size_format: goto error_common; error_path_and_source: - error_str = "Template malformed, PATH and SOURCE are mutuallly exclusive."; + error_str = "Template malformed, PATH and SOURCE are mutually exclusive."; goto error_common; error_common: diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index f64a0bb386..87ff03086a 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -78,6 +78,11 @@ int ImagePool::allocate ( goto error_name; } + if ( name.length() > 128 ) + { + goto error_name_length; + } + // Check for duplicates img_aux = get(name,uid,false); @@ -111,6 +116,10 @@ error_name: goto error_common; +error_name_length: + oss << "NAME is too long; max length is 128 chars."; + goto error_common; + error_duplicated: oss << "NAME is already taken by IMAGE " << img_aux->get_oid() << "."; diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 87c7d7d578..da0900f41b 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -238,7 +238,7 @@ void Nebula::start() { rc = 0; - NebulaLog::log("ONE",Log::INFO,"Bootstraping OpenNebula database."); + NebulaLog::log("ONE",Log::INFO,"Bootstrapping OpenNebula database."); rc += VirtualMachinePool::bootstrap(db); rc += HostPool::bootstrap(db); diff --git a/src/um/User.cc b/src/um/User.cc index 71b2d4cd28..30cde85f0b 100644 --- a/src/um/User.cc +++ b/src/um/User.cc @@ -38,7 +38,7 @@ const char * User::table = "user_pool"; const char * User::db_names = "oid,name,body"; const char * User::db_bootstrap = "CREATE TABLE IF NOT EXISTS user_pool (" - "oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, UNIQUE(name))"; + "oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, UNIQUE(name))"; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index f2ba70a7a7..2403e86e00 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -146,6 +146,12 @@ int UserPool::allocate ( goto error_name; } + if ( uname.length() > 128 ) + { + error_str = "max length is 128 chars"; + goto error_name; + } + user = get(uname,false); if ( user !=0 ) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index b7dbc1b66a..bcb71e7ca5 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -96,7 +96,7 @@ const char * VirtualMachine::db_names = "oid, name, body, uid, gid, last_poll, state, lcm_state"; const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS " - "vm_pool (oid INTEGER PRIMARY KEY, name TEXT, body TEXT, uid INTEGER, " + "vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, " "gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER)"; /* -------------------------------------------------------------------------- */ @@ -209,6 +209,10 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) replace_template_attribute("NAME", name); } + else if ( name.length() > 128 ) + { + goto error_name_length; + } this->name = name; @@ -284,7 +288,11 @@ error_rollback: error_leases_rollback: release_network_leases(); - goto error_common; // just to avoid compilation warnings + goto error_common; + +error_name_length: + oss << "NAME is too long; max length is 128 chars."; + goto error_common; error_common: NebulaLog::log("ONE",Log::ERROR, error_str); diff --git a/src/vm_template/VMTemplate.cc b/src/vm_template/VMTemplate.cc index 8df3b1da1f..b231ac1d44 100644 --- a/src/vm_template/VMTemplate.cc +++ b/src/vm_template/VMTemplate.cc @@ -63,7 +63,7 @@ const char * VMTemplate::db_names = "oid, name, body, uid, gid, public"; const char * VMTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS template_pool (oid INTEGER PRIMARY KEY, " - "name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER)"; + "name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, public INTEGER)"; /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ @@ -92,6 +92,11 @@ int VMTemplate::insert(SqlDB *db, string& error_str) oss << "template-" << oid; name = oss.str(); } + else if ( name.length() > 128 ) + { + error_str = "NAME is too long; max length is 128 chars."; + return -1; + } // ------------ PUBLIC -------------------- diff --git a/src/vnm/VirtualNetworkPool.cc b/src/vnm/VirtualNetworkPool.cc index aecb58dec5..44a50d9fd2 100644 --- a/src/vnm/VirtualNetworkPool.cc +++ b/src/vnm/VirtualNetworkPool.cc @@ -93,6 +93,11 @@ int VirtualNetworkPool::allocate ( goto error_name; } + if ( name.length() > 128 ) + { + goto error_name_length; + } + // Check for duplicates vn_aux = get(name,uid,false); @@ -112,6 +117,10 @@ error_name: goto error_common; +error_name_length: + oss << "NAME is too long; max length is 128 chars."; + goto error_common; + error_duplicated: oss << "NAME is already taken by NET " << vn_aux->get_oid() << "."; From ee28c22f53bcf1339fd2a0adc207f1ffc98eb777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 10 Oct 2011 18:56:19 +0200 Subject: [PATCH 3/9] Bug #848: Fix tests --- src/test/Nebula.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/Nebula.cc b/src/test/Nebula.cc index c0794b1ce2..3f698567f3 100644 --- a/src/test/Nebula.cc +++ b/src/test/Nebula.cc @@ -529,11 +529,11 @@ void Nebula::start() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void Nebula::bootstrap() +int Nebula::bootstrap() { ostringstream oss; oss << "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, " "last_oid BIGINT UNSIGNED)"; - db->exec(oss); + return db->exec(oss); } From ba8399c9f5cf0b7390417d5812230e54160ee560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 14 Oct 2011 15:13:56 +0200 Subject: [PATCH 4/9] Bug #848: Add 3.1.0 migrator, it will truncate existing names with more than 128 chars. --- install.sh | 1 + src/onedb/3.0_to_3.1.0.rb | 71 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/onedb/3.0_to_3.1.0.rb diff --git a/install.sh b/install.sh index 9157e15055..88b3e4ca66 100755 --- a/install.sh +++ b/install.sh @@ -654,6 +654,7 @@ ONEDB_MIGRATOR_FILES="src/onedb/2.0_to_2.9.80.rb \ src/onedb/2.9.80_to_2.9.85.rb \ src/onedb/2.9.85_to_2.9.90.rb \ src/onedb/2.9.90_to_3.0.rb \ + src/onedb/3.0_to_3.1.0.rb \ src/onedb/onedb.rb \ src/onedb/onedb_backend.rb" diff --git a/src/onedb/3.0_to_3.1.0.rb b/src/onedb/3.0_to_3.1.0.rb new file mode 100644 index 0000000000..821d8f6b8f --- /dev/null +++ b/src/onedb/3.0_to_3.1.0.rb @@ -0,0 +1,71 @@ +# -------------------------------------------------------------------------- * +# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # +# Licensed under the Apache License, Version 2.0 (the "License"); you may * +# not use this file except in compliance with the License. You may obtain * +# a copy of the License at * +# * +# http://www.apache.org/licenses/LICENSE-2.0 * +# * +# Unless required by applicable law or agreed to in writing, software * +# distributed under the License is distributed on an "AS IS" BASIS, * +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * +# See the License for the specific language governing permissions and * +# limitations under the License. * +# -------------------------------------------------------------------------- * + +require "rexml/document" +include REXML + +module Migrator + def db_version + "3.1.0" + end + + def one_version + "OpenNebula 3.1.0" + end + + def up + [ [:group_pool, "group"], + [:host_pool, "host"], + [:image_pool, "image"], + [:network_pool, "network"], + [:template_pool,"template"], + [:user_pool, "user"], + [:vm_pool, "vm"] + ].each { |pair| + # Check that all objects have names shorter that 128 + check_names(pair[0], pair[1]) + + # Change the name column to 128 chars. In SQLite, ALTER COLUMN is + # not supported, but since the char limit is ignored, + # VARCHAR(128) and VARCHAR(256) are the same type + if ( self.class == BackEndMySQL ) + @db.run "ALTER TABLE #{pair[0]} CHANGE name name VARCHAR(128);" + end + } + + return true + end + + def check_names(table, elem) + @db.fetch("SELECT * FROM #{table}") do |row| + if ( row[:name].length > 128 ) + # Element name is bigger than 128 chars + new_name = "#{elem}-#{row[:oid]}-#{row[:name][0..99]}" + + doc = Document.new(row[:body]) + + doc.root.each_element("NAME") { |e| + e.text = new_name + + @db[table].filter(:oid => row[:oid]).update( + :name => new_name, + :body => doc.root.to_s) + } + + puts " > #{elem} ##{row[:oid]} had a name bigger than 128 chars and has been renamed to #{new_name[0..10]}..." + end + end + end +end From 057e20531c99054811eda4d2d6f0e91a4b79b60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 14 Oct 2011 15:37:10 +0200 Subject: [PATCH 5/9] Bug #848: Fix tests --- src/onedb/test/test_sqlite.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/onedb/test/test_sqlite.sh b/src/onedb/test/test_sqlite.sh index 08255d13a0..f435fbe1a4 100755 --- a/src/onedb/test/test_sqlite.sh +++ b/src/onedb/test/test_sqlite.sh @@ -80,7 +80,10 @@ sort results/one.db.3.0.tmpschema > results/one.db.3.0.schema rm results/one.db.upgraded.tmpschema rm results/one.db.3.0.tmpschema - +# Small cheat: the 3.0 schema had some columns with type VARCHAR(256), now it +# has changed to VARCHAR(128); but sqlite ignores the char limit +sed -i "s/name VARCHAR(256)/name VARCHAR(128)/" results/one.db.upgraded.schema +sed -i "s/name TEXT/name VARCHAR(128)/" results/one.db.upgraded.schema # Perform a diff FILE=results/schema.diff From 9ed5b738a4a28051e39be8427b5c393b03c56359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 14 Oct 2011 16:49:13 +0200 Subject: [PATCH 6/9] Bug #848: Take into account bug #871, avoid table lock --- src/onedb/3.0_to_3.1.0.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/onedb/3.0_to_3.1.0.rb b/src/onedb/3.0_to_3.1.0.rb index 821d8f6b8f..b2700da390 100644 --- a/src/onedb/3.0_to_3.1.0.rb +++ b/src/onedb/3.0_to_3.1.0.rb @@ -49,6 +49,8 @@ module Migrator end def check_names(table, elem) + @db.run "CREATE TABLE migrator_tmp (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT);" + @db.fetch("SELECT * FROM #{table}") do |row| if ( row[:name].length > 128 ) # Element name is bigger than 128 chars @@ -58,14 +60,23 @@ module Migrator doc.root.each_element("NAME") { |e| e.text = new_name - - @db[table].filter(:oid => row[:oid]).update( - :name => new_name, - :body => doc.root.to_s) } + @db[:migrator_tmp].insert( + :oid => row[:oid], + :name => new_name, + :body => doc.root.to_s) + puts " > #{elem} ##{row[:oid]} had a name bigger than 128 chars and has been renamed to #{new_name[0..10]}..." end end + + @db.fetch("SELECT * FROM migrator_tmp") do |row| + @db[table].filter(:oid => row[:oid]).update( + :name => row[:name], + :body => row[:body]) + end + + @db.run "DROP TABLE migrator_tmp" end end From a61cd0bb0ae697ccdf9e8eddbd036c9196898c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 14 Oct 2011 16:51:29 +0200 Subject: [PATCH 7/9] Bug #871: Avoid locked tables in onedb upgrade. Thanks to jan horacek --- src/onedb/2.9.80_to_2.9.85.rb | 16 +++++++++++++--- src/onedb/2.9.90_to_3.0.rb | 8 +++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/onedb/2.9.80_to_2.9.85.rb b/src/onedb/2.9.80_to_2.9.85.rb index 5ff04ee1e8..83ff29e797 100644 --- a/src/onedb/2.9.80_to_2.9.85.rb +++ b/src/onedb/2.9.80_to_2.9.85.rb @@ -32,7 +32,10 @@ module Migrator # Image pool table: # CREATE TABLE image_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER, UNIQUE(name,uid) ); - @db.fetch("SELECT * FROM image_pool") do |row| + @db.run "ALTER TABLE image_pool RENAME TO old_image_pool;" + @db.run "CREATE TABLE image_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER, UNIQUE(name,uid) );" + + @db.fetch("SELECT * FROM old_image_pool") do |row| doc = Document.new(row[:body]) source = nil @@ -48,10 +51,17 @@ module Migrator size_elem = doc.root.add_element("SIZE") size_elem.text = size - @db[:image_pool].filter(:oid => row[:oid]).update( - :body => doc.root.to_s) + @db[:image_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => doc.root.to_s, + :uid => row[:uid], + :gid => row[:gid], + :public => row[:public]) end + @db.run "DROP TABLE old_image_pool;" + return true end end diff --git a/src/onedb/2.9.90_to_3.0.rb b/src/onedb/2.9.90_to_3.0.rb index 8692af3bfe..880685a74c 100644 --- a/src/onedb/2.9.90_to_3.0.rb +++ b/src/onedb/2.9.90_to_3.0.rb @@ -29,7 +29,11 @@ module Migrator # The tm_nfs driver has been renamed to tm_shared # CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, last_mon_time INTEGER, UNIQUE(name)); - @db.fetch("SELECT * FROM host_pool") do |row| + @db.run "ALTER TABLE host_pool RENAME TO old_host_pool;" + @db.run "CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, last_mon_time INTEGER, UNIQUE(name));" + @db.run "INSERT INTO host_pool SELECT * FROM old_host_pool;" + + @db.fetch("SELECT * FROM old_host_pool") do |row| doc = Document.new(row[:body]) source = nil @@ -43,6 +47,8 @@ module Migrator } end + @db.run "DROP TABLE old_host_pool;" + return true end end From 66134fa087f0a8072f6c0f6d8f00cc741c46f890 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 14 Oct 2011 17:28:41 +0200 Subject: [PATCH 8/9] typo in install_gems (nokogiri) (cherry picked from commit 19029f7f761af3a8b494275f1984e29df560d36d) --- share/install_gems/install_gems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/install_gems/install_gems b/share/install_gems/install_gems index f9dc603092..d0c44fc7db 100755 --- a/share/install_gems/install_gems +++ b/share/install_gems/install_gems @@ -14,7 +14,7 @@ if defined?(RUBY_VERSION) && RUBY_VERSION>="1.8.7" OPTIONAL=%w{nokogiri} else SQLITE='sqlite3-ruby --version 1.2.0' - OPTIONAL=%w{nokogir xmlparser} + OPTIONAL=%w{nokogiri xmlparser} end GROUPS={ From cd4c5d5dcbb4825864ccba9e7aeb3fc18e78fa5c Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 15 Oct 2011 00:06:51 +0200 Subject: [PATCH 9/9] bug #866: Removed unneeded check after starting the server --- src/ozones/Server/bin/ozones-server | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/ozones/Server/bin/ozones-server b/src/ozones/Server/bin/ozones-server index 4da44f11e0..6d87ee81c1 100755 --- a/src/ozones/Server/bin/ozones-server +++ b/src/ozones/Server/bin/ozones-server @@ -80,14 +80,6 @@ start() exit 1 fi - sleep 1 - ps $LASTPID &> /dev/null - - if [ $? -ne 0 ]; then - echo "Error executing $OZONES_SERVER, please check the log $OZONES_LOG" - exit 1 - fi - echo "ozones-server listening on $HOST:$PORT" }