1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Hector Sanjuan 2012-02-08 10:58:04 +01:00
commit 39e9bc69f7
21 changed files with 713 additions and 149 deletions

View File

@ -9,7 +9,7 @@ distributed data center infrastructures.
Complete documentation can be found at
http://opennebula.org/documentation:rel3.0
http://opennebula.org/documentation:documentation
## INSTALLATION
@ -42,7 +42,7 @@ include a handy script to install them and the requirements. It is located at
`share/install_gems/install_gems` and you should use it to install the
required gems. You have more information at:
http://opennebula.org/documentation:rel3.0:compile
http://opennebula.org/documentation:documentation:compile
### OPTIONAL PACKAGES
@ -122,7 +122,7 @@ where **install_options** can be one or more of:
## CONFIGURATION
Information on how to configure OpenNebula is located at
http://opennebula.org/documentation:rel3.0:cg
http://opennebula.org/documentation:documentation:cg
## CONTACT

View File

@ -817,6 +817,7 @@ ONEDB_MIGRATOR_FILES="src/onedb/2.0_to_2.9.80.rb \
src/onedb/3.0.0_to_3.1.0.rb \
src/onedb/3.1.0_to_3.1.80.rb \
src/onedb/3.1.80_to_3.2.0.rb \
src/onedb/3.2.0_to_3.2.1.rb \
src/onedb/onedb.rb \
src/onedb/onedb_backend.rb"

View File

@ -22,10 +22,16 @@
# --------------------------------------------------------------------------
ONE_LOCATION=ENV['ONE_LOCATION']
ONE_LOCATION=ENV["ONE_LOCATION"]
$: << ONE_LOCATION+'/lib/ruby'
$: << ONE_LOCATION+'/lib/ruby/cli'
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cli"
require 'rubygems'

View File

@ -44,6 +44,7 @@ module EC2CloudAuth
params.delete('Signature')
params.delete('econe_host')
params.delete('econe_port')
params.delete('econe_path')
req_desc = params.sort {|x,y| x[0].downcase <=> y[0].downcase}.to_s
digest_generator = OpenSSL::Digest::Digest.new(digest)
@ -59,6 +60,7 @@ module EC2CloudAuth
server_host = params.delete('econe_host')
server_port = params.delete('econe_port')
server_path = params.delete('econe_path') || '/'
if include_port
server_str = "#{server_host}:#{server_port}"
else
@ -68,7 +70,8 @@ module EC2CloudAuth
canonical_str = AWS.canonical_string(
params,
server_str,
env['REQUEST_METHOD'])
env['REQUEST_METHOD'],
server_path)
# Use the correct signature strength
sha_strength = case params['SignatureMethod']

View File

@ -76,7 +76,8 @@ module EC2QueryClient
:secret_access_key => @access_key_secret,
:server => @uri.host,
:port => @uri.port,
:use_ssl => @uri.scheme == 'https')
:use_ssl => @uri.scheme == 'https',
:path => @uri.path)
end

View File

@ -44,6 +44,7 @@ $: << RUBY_LIB_LOCATION+"/cloud/econe"
require 'rubygems'
require 'sinatra'
require 'yaml'
require 'uri'
require 'EC2QueryServer'
require 'CloudAuth'
@ -89,12 +90,20 @@ end
set :cloud_auth, cloud_auth
econe_host = conf[:ssl_server]
econe_host ||= conf[:server]
econe_port = conf[:port]
if conf[:ssl_server]
uri = URI.parse(conf[:ssl_server])
econe_host = uri.host
econe_port = uri.port
econe_path = uri.path
else
econe_host = conf[:server]
econe_port = conf[:port]
econe_path = '/'
end
set :econe_host, econe_host
set :econe_port, econe_port
set :econe_path, econe_path
##############################################################################
# Actions
@ -104,6 +113,7 @@ before do
begin
params['econe_host'] = settings.econe_host
params['econe_port'] = settings.econe_port
params['econe_path'] = settings.econe_path
username = settings.cloud_auth.auth(request.env, params)
rescue Exception => e
error 500, error_xml("AuthFailure", 0)

View File

@ -67,6 +67,8 @@ class GroupPoolTest : public PoolTest
CPPUNIT_TEST (duplicates);
CPPUNIT_TEST (dump);
CPPUNIT_TEST (name_index);
CPPUNIT_TEST_SUITE_END ();
protected:
@ -222,6 +224,69 @@ public:
CPPUNIT_ASSERT( oss.str() == group_xml_dump );
}
/* ********************************************************************* */
void name_index()
{
Group *group_oid, *group_name;
int oid_0;
int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
group_oid = gpool->get(oid_0, true);
CPPUNIT_ASSERT(group_oid != 0);
name_0 = group_oid->get_name();
uid_0 = group_oid->get_uid();
group_oid->unlock();
// Get by name and check it is the same object
group_name = gpool->get(name_0, true);
CPPUNIT_ASSERT(group_name != 0);
group_name->unlock();
CPPUNIT_ASSERT(group_oid == group_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
gpool->clean();
// Get by oid
group_oid = gpool->get(oid_0, true);
CPPUNIT_ASSERT(group_oid != 0);
group_oid->unlock();
// Get by name and check it is the same object
group_name = gpool->get(name_0, true);
CPPUNIT_ASSERT(group_name != 0);
group_name->unlock();
CPPUNIT_ASSERT(group_oid == group_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
gpool->clean();
// Get by name
group_name = gpool->get(name_0, true);
CPPUNIT_ASSERT(group_name != 0);
group_name->unlock();
// Get by oid and check it is the same object
group_oid = gpool->get(oid_0, true);
CPPUNIT_ASSERT(group_oid != 0);
group_oid->unlock();
CPPUNIT_ASSERT(group_oid == group_name);
}
};
/* ************************************************************************* */

View File

@ -139,6 +139,7 @@ class HostPoolTest : public PoolTest
CPPUNIT_TEST (discover);
CPPUNIT_TEST (duplicates);
CPPUNIT_TEST (update_info);
CPPUNIT_TEST (name_index);
// CPPUNIT_TEST (scale_test);
@ -492,6 +493,70 @@ public:
CPPUNIT_ASSERT( host != 0 );
CPPUNIT_ASSERT( host->to_xml(str) == host0_updated );
}
/* ********************************************************************* */
void name_index()
{
HostPool * hp = static_cast<HostPool *>(pool);
Host *host_oid, *host_name;
int oid_0;
int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
host_oid = hp->get(oid_0, true);
CPPUNIT_ASSERT(host_oid != 0);
name_0 = host_oid->get_name();
uid_0 = host_oid->get_uid();
host_oid->unlock();
// Get by name and check it is the same object
host_name = hp->get(name_0, true);
CPPUNIT_ASSERT(host_name != 0);
host_name->unlock();
CPPUNIT_ASSERT(host_oid == host_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
hp->clean();
// Get by oid
host_oid = hp->get(oid_0, true);
CPPUNIT_ASSERT(host_oid != 0);
host_oid->unlock();
// Get by name and check it is the same object
host_name = hp->get(name_0, true);
CPPUNIT_ASSERT(host_name != 0);
host_name->unlock();
CPPUNIT_ASSERT(host_oid == host_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
hp->clean();
// Get by name
host_name = hp->get(name_0, true);
CPPUNIT_ASSERT(host_name != 0);
host_name->unlock();
// Get by oid and check it is the same object
host_oid = hp->get(oid_0, true);
CPPUNIT_ASSERT(host_oid != 0);
host_oid->unlock();
CPPUNIT_ASSERT(host_oid == host_name);
}
};

View File

@ -87,13 +87,15 @@ public:
class ImagePoolFriend : public ImagePool
{
public:
ImagePoolFriend(SqlDB * db,
const string& _default_type,
const string& _default_dev_prefix):
ImagePoolFriend(SqlDB * db,
const string& _default_type,
const string& _default_dev_prefix,
vector<const Attribute *> _restricted_attrs):
ImagePool( db,
_default_type,
_default_dev_prefix){};
_default_dev_prefix,
_restricted_attrs){};
int allocate(const int& uid, const std::string& stemplate, int* oid)
@ -143,13 +145,15 @@ class ImagePoolTest : public PoolTest
CPPUNIT_TEST ( wrong_templates );
CPPUNIT_TEST ( target_generation );
CPPUNIT_TEST ( bus_source_assignment );
// CPPUNIT_TEST ( public_attribute );
// CPPUNIT_TEST ( persistence );
CPPUNIT_TEST ( persistence );
CPPUNIT_TEST ( imagepool_disk_attribute );
CPPUNIT_TEST ( dump );
CPPUNIT_TEST ( dump_where );
CPPUNIT_TEST ( get_using_name );
CPPUNIT_TEST ( wrong_get_name );
CPPUNIT_TEST ( name_index );
CPPUNIT_TEST ( chown_name_index );
CPPUNIT_TEST_SUITE_END ();
protected:
@ -249,7 +253,8 @@ public:
// Create a new pool, using the same DB. This new pool should read the
// allocated images.
imp = new ImagePool(db,"OS", "hd");
vector<const Attribute *> restricted_attrs;
imp = new ImagePool(db,"OS", "hd", restricted_attrs);
img = imp->get(0, false);
CPPUNIT_ASSERT( img != 0 );
@ -654,100 +659,7 @@ public:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/*
void public_attribute()
{
int oid;
ImagePoolFriend * imp = static_cast<ImagePoolFriend *>(pool);
Image * img;
string templates[] =
{
// false
"NAME = \"name A\"\n"
"PATH = \"/tmp/nothing\"\n",
// true
"NAME = \"name B\"\n"
"PATH = \"/tmp/nothing\"\n"
"PUBLIC = YES",
// false
"NAME = \"name C\"\n"
"PATH = \"/tmp/nothing\"\n"
"PUBLIC = NO",
// false
"NAME = \"name D\"\n"
"PATH = \"/tmp/nothing\"\n"
"PUBLIC = 1",
// true
"NAME = \"name E\"\n"
"PATH = \"/tmp/nothing\"\n"
"PUBLIC = Yes",
// false
"NAME = \"name F\"\n"
"PATH = \"/tmp/nothing\"\n"
"PUBLIC = TRUE",
// true
"NAME = \"name G\"\n"
"PATH = \"/tmp/nothing\"\n"
"PUBLIC = yes",
// false
"NAME = \"name H\"\n"
"PATH = \"/tmp/nothing\"\n"
"PUBLIC = 'YES'",
// true
"NAME = \"name I\"\n"
"PATH = \"/tmp/nothing\"\n"
"PUBLIC = \"YES\"",
"END"
};
bool results[] = { false, true, false, false,
true, false, true, false, true };
int i = 0;
while( templates[i] != "END" )
{
imp->allocate(0, templates[i], &oid);
CPPUNIT_ASSERT( oid >= 0 );
img = imp->get( oid, false );
CPPUNIT_ASSERT( img != 0 );
//cout << endl << i << " : exp. " << results[i] << " got " << img->is_public();
CPPUNIT_ASSERT( img->isPublic() == results[i] );
i++;
}
int success;
// img 0 is not public.
img = imp->get( 0, false );
CPPUNIT_ASSERT( img != 0 );
success = img->publish(false);
CPPUNIT_ASSERT( success == 0 );
CPPUNIT_ASSERT( img->isPublic() == false );
success = img->publish(true);
CPPUNIT_ASSERT( success == 0 );
CPPUNIT_ASSERT( img->isPublic() == true );
}
*/
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/*
void persistence()
{
int oid;
@ -760,44 +672,32 @@ public:
{
"NAME = \"Image 1\"\n"
"PERSISTENT = NO\n"
"PUBLIC = NO\n"
"PATH = /dev/null\n",
"NAME = \"Image 2\"\n"
"PERSISTENT = NO\n"
"PUBLIC = YES\n"
"PATH = /dev/null\n",
"NAME = \"Image 3\"\n"
"PERSISTENT = YES\n"
"PUBLIC = NO\n"
"PATH = /dev/null\n",
"NAME = \"Image 4\"\n"
"PERSISTENT = YES\n"
"PUBLIC = YES\n"
"PATH = /dev/null\n",
"END"
};
bool results[] = { true, true, true, false };
bool persistent[] = { false, false, true };
int i = 0;
while( templates[i] != "END" )
{
imp->allocate(0, templates[i], &oid);
//cout << endl << i << " : exp. " << results[i] << " got " << (oid >= 0);
CPPUNIT_ASSERT( (oid >= 0) == results[i] );
if( oid >= 0 )
{
img = imp->get( oid, false );
CPPUNIT_ASSERT( img != 0 );
CPPUNIT_ASSERT( oid >= 0 );
CPPUNIT_ASSERT( img->isPersistent() == persistent[i] );
}
img = imp->get( oid, false );
CPPUNIT_ASSERT( img != 0 );
CPPUNIT_ASSERT( img->isPersistent() == persistent[i] );
i++;
}
@ -812,12 +712,12 @@ public:
CPPUNIT_ASSERT( img->isPersistent() == true );
// it isn't public, try to unpublish
success = img->publish(false);
success = img->set_permissions(1,1,0, 0,0,0, 0,0,0, error_msg);
CPPUNIT_ASSERT( success == 0 );
CPPUNIT_ASSERT( img->isPublic() == false );
// try to publish, should fail because it is persistent
success = img->publish(true);
success = img->set_permissions(1,1,0, 1,0,0, 0,0,0, error_msg);
CPPUNIT_ASSERT( success == -1 );
CPPUNIT_ASSERT( img->isPublic() == false );
@ -828,16 +728,16 @@ public:
CPPUNIT_ASSERT( img->isPersistent() == false );
// it isn't public, try to unpublish
success = img->publish(false);
success = img->set_permissions(1,1,0, 0,0,0, 0,0,0, error_msg);
CPPUNIT_ASSERT( success == 0 );
CPPUNIT_ASSERT( img->isPublic() == false );
// try to publish, now it should be possible
success = img->publish(true);
success = img->set_permissions(1,1,0, 1,0,0, 0,0,0, error_msg);
CPPUNIT_ASSERT( success == 0 );
CPPUNIT_ASSERT( img->isPublic() == true );
}
*/
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -962,6 +862,132 @@ public:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void name_index()
{
Image *img_oid, *img_name;
int oid_0;
int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
img_oid = ipool->get(oid_0, true);
CPPUNIT_ASSERT(img_oid != 0);
name_0 = img_oid->get_name();
uid_0 = img_oid->get_uid();
img_oid->unlock();
// Get by name and check it is the same object
img_name = ipool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
ipool->clean();
// Get by oid
img_oid = ipool->get(oid_0, true);
CPPUNIT_ASSERT(img_oid != 0);
img_oid->unlock();
// Get by name and check it is the same object
img_name = ipool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
ipool->clean();
// Get by name
img_name = ipool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
// Get by oid and check it is the same object
img_oid = ipool->get(oid_0, true);
CPPUNIT_ASSERT(img_oid != 0);
img_oid->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void chown_name_index()
{
Image *img_oid, *img_name;
int oid;
int old_uid;
int new_uid = 3456;
string name;
oid = allocate(0);
CPPUNIT_ASSERT(oid != -1);
// ---------------------------------
// Get by oid
img_oid = ipool->get(oid, true);
CPPUNIT_ASSERT(img_oid != 0);
name = img_oid->get_name();
old_uid = img_oid->get_uid();
// Change owner and update cache index
img_oid->set_user(new_uid, "new_username");
ipool->update(img_oid);
img_oid->unlock();
ipool->update_cache_index(name, old_uid, name, new_uid);
// Get by name, new_uid and check it is the same object
img_name = ipool->get(name, new_uid, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
// Get by name, old_uid and check it does not exist
img_name = ipool->get(name, old_uid, true);
CPPUNIT_ASSERT(img_name == 0);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
ipool->clean();
// Get by name, old_uid and check it does not exist
img_name = ipool->get(name, old_uid, true);
CPPUNIT_ASSERT(img_name == 0);
// Get by oid
img_oid = ipool->get(oid, true);
CPPUNIT_ASSERT(img_oid != 0);
img_oid->unlock();
// Get by name, new_uid and check it is the same object
img_name = ipool->get(name, new_uid, true);
CPPUNIT_ASSERT(img_name != 0);
img_name->unlock();
CPPUNIT_ASSERT(img_oid == img_name);
}
};
/* ************************************************************************* */

View File

@ -0,0 +1,28 @@
# -------------------------------------------------------------------------- *
# 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. *
# -------------------------------------------------------------------------- *
module Migrator
def db_version
"3.2.1"
end
def one_version
"OpenNebula 3.2.1"
end
def up
return true
end
end

View File

@ -155,8 +155,11 @@ void PoolObjectSQL::set_template_error_message(const string& message)
error_value.insert(make_pair("TIMESTAMP",str));
error_value.insert(make_pair("MESSAGE",message));
//Replace previous error message and insert the new one
attr = new VectorAttribute(error_attribute_name,error_value);
obj_template->erase(error_attribute_name);
obj_template->set(attr);
}
@ -183,6 +186,8 @@ int PoolObjectSQL::replace_template(const string& tmpl_str, string& error)
if (error_msg != 0)
{
oss << ": " << error_msg;
free(error_msg);
}
error = oss.str();

View File

@ -356,7 +356,11 @@ void PoolSQL::update_cache_index(string& old_name,
if ( index != name_pool.end() )
{
name_pool.erase(old_key);
name_pool.insert(make_pair(new_key, index->second));
if ( name_pool.find(new_key) == name_pool.end())
{
name_pool.insert(make_pair(new_key, index->second));
}
}
unlock();

View File

@ -69,6 +69,9 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
PoolObjectSQL * object;
string obj_name;
int old_uid;
// ------------- Check new user and group id's ---------------------
if ( noid > -1 )
@ -138,12 +141,11 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
if ( noid != -1 )
{
string obj_name = object->get_name();
int old_uid = object->get_uid();
obj_name = object->get_name();
old_uid = object->get_uid();
object->set_user(noid,nuname);
pool->update_cache_index(obj_name, old_uid, obj_name, noid);
}
if ( ngid != -1 )
@ -155,6 +157,11 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
object->unlock();
if ( noid != -1 )
{
pool->update_cache_index(obj_name, old_uid, obj_name, noid);
}
success_response(oid, att);
return;

View File

@ -67,6 +67,7 @@ var create_host_tmpl =
<select id="vmm_mad" name="vmm">\
<option value="vmm_kvm">' + tr("KVM") + '</option>\
<option value="vmm_xen">' + tr("XEN") + '</option>\
<option value="vmm_vmware">' + tr("VMware") + '</option>\
<option value="vmm_ec2">' + tr("EC2") + '</option>\
<option value="vmm_dummy">' + tr("Dummy") + '</option>\
</select>\
@ -76,6 +77,7 @@ var create_host_tmpl =
<select id="im_mad" name="im">\
<option value="im_kvm">' + tr("KVM") + '</option>\
<option value="im_xen">' + tr("XEN") + '</option>\
<option value="im_vmware">' + tr("VMware") + '</option>\
<option value="im_ec2">' + tr("EC2") + '</option>\
<option value="im_dummy">' + tr("Dummy") + '</option>\
</select>\
@ -95,6 +97,7 @@ var create_host_tmpl =
<select id="tm_mad" name="tm">\
<option value="tm_shared">' + tr("Shared") + '</option>\
<option value="tm_ssh">' + tr("SSH") + '</option>\
<option value="tm_vmware">' + tr("VMware") + '</option>\
<option value="tm_dummy">' + tr("Dummy") + '</option>\
</select>\
</div>\

View File

@ -822,8 +822,8 @@ function setupCreateVNetDialog() {
var ip_start = $('#ip_start',this).val();
var ip_end = $('#ip_end',this).val();
if (!network_addr.length){
notifyError(tr("Please provide a network address"));
if (!(ip_start.length && ip_end.length) && !network_addr.length){
notifyError(tr("There are missing network parameters"));
return false;
};
@ -832,11 +832,15 @@ function setupCreateVNetDialog() {
"vnet" : {
"type" : "RANGED",
"bridge" : bridge,
"network_mask" : network_mask,
"network_address" : network_addr,
"name" : name }
};
if (network_addr.length)
network_json["vnet"]["network_address"]=network_addr;
if (network_mask.length)
network_json["vnet"]["network_mask"]=network_mask;
if (custom){
if (ip_start.length)
network_json["vnet"]["ip_start"] = ip_start;

View File

@ -22,7 +22,9 @@ VirtualMachinePool* NebulaTest::create_vmpool(SqlDB* db, string hook_location,
string vloc)
{
vector<const Attribute *> hooks;
return new VirtualMachinePool(db, hooks, hook_location, vloc);
vector<const Attribute *> restricted_attrs;
return new VirtualMachinePool(db, hooks, hook_location, vloc, restricted_attrs);
}
HostPool* NebulaTest::create_hpool(SqlDB* db, string hook_location, string vloc)
@ -45,7 +47,9 @@ ImagePool* NebulaTest::create_ipool( SqlDB* db,
string default_image_type,
string default_device_prefix)
{
return new ImagePool(db,default_image_type,default_device_prefix);
vector<const Attribute *> restricted_attrs;
return new ImagePool(db, default_image_type, default_device_prefix, restricted_attrs);
}
VMTemplatePool* NebulaTest::create_tpool(SqlDB* db)

View File

@ -77,6 +77,7 @@ class UserPoolTest : public PoolTest
CPPUNIT_TEST (duplicates);
//CPPUNIT_TEST (dump);
CPPUNIT_TEST (dump_where);
CPPUNIT_TEST (name_index);
CPPUNIT_TEST_SUITE_END ();
@ -374,6 +375,67 @@ public:
CPPUNIT_ASSERT( oss.str() == dump_where_result );
}
void name_index()
{
User *user_oid, *user_name;
int oid_0;
int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
user_oid = upool->get(oid_0, true);
CPPUNIT_ASSERT(user_oid != 0);
name_0 = user_oid->get_name();
uid_0 = user_oid->get_uid();
user_oid->unlock();
// Get by name and check it is the same object
user_name = upool->get(name_0, true);
CPPUNIT_ASSERT(user_name != 0);
user_name->unlock();
CPPUNIT_ASSERT(user_oid == user_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
upool->clean();
// Get by oid
user_oid = upool->get(oid_0, true);
CPPUNIT_ASSERT(user_oid != 0);
user_oid->unlock();
// Get by name and check it is the same object
user_name = upool->get(name_0, true);
CPPUNIT_ASSERT(user_name != 0);
user_name->unlock();
CPPUNIT_ASSERT(user_oid == user_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
upool->clean();
// Get by name
user_name = upool->get(name_0, true);
CPPUNIT_ASSERT(user_name != 0);
user_name->unlock();
// Get by oid and check it is the same object
user_oid = upool->get(oid_0, true);
CPPUNIT_ASSERT(user_oid != 0);
user_oid->unlock();
CPPUNIT_ASSERT(user_oid == user_name);
}
};
/* ************************************************************************* */

View File

@ -74,8 +74,11 @@ const string xml_history_dump =
class VirtualMachinePoolFriend : public VirtualMachinePool
{
public:
VirtualMachinePoolFriend(SqlDB * db, vector<const Attribute *> hook_mads):
VirtualMachinePool(db, hook_mads, "./", "./")
VirtualMachinePoolFriend(
SqlDB * db,
vector<const Attribute *> hook_mads,
vector<const Attribute *> restricted_attrs):
VirtualMachinePool(db, hook_mads, "./", "./", restricted_attrs)
{};
@ -138,7 +141,9 @@ protected:
{
// The VM pool needs a vector containing the vm hooks
vector<const Attribute *> vm_hooks;
return new VirtualMachinePoolFriend(db, vm_hooks);
vector<const Attribute *> restricted_attrs;
return new VirtualMachinePoolFriend(db, vm_hooks, restricted_attrs);
};
int allocate(int index)

View File

@ -110,6 +110,8 @@ class VMTemplatePoolTest : public PoolTest
CPPUNIT_TEST ( duplicates );
CPPUNIT_TEST ( dump );
CPPUNIT_TEST ( dump_where );
CPPUNIT_TEST ( name_index );
CPPUNIT_TEST ( chown_name_index );
CPPUNIT_TEST_SUITE_END ();
@ -447,6 +449,137 @@ public:
CPPUNIT_ASSERT( result == xml_dump_where );
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void name_index()
{
VMTemplatePool *tpool = static_cast<VMTemplatePool*>(pool);
VMTemplate *vnet_oid, *vnet_name;
int oid_0;
int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
vnet_oid = tpool->get(oid_0, true);
CPPUNIT_ASSERT(vnet_oid != 0);
name_0 = vnet_oid->get_name();
uid_0 = vnet_oid->get_uid();
vnet_oid->unlock();
// Get by name and check it is the same object
vnet_name = tpool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
tpool->clean();
// Get by oid
vnet_oid = tpool->get(oid_0, true);
CPPUNIT_ASSERT(vnet_oid != 0);
vnet_oid->unlock();
// Get by name and check it is the same object
vnet_name = tpool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
tpool->clean();
// Get by name
vnet_name = tpool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
// Get by oid and check it is the same object
vnet_oid = tpool->get(oid_0, true);
CPPUNIT_ASSERT(vnet_oid != 0);
vnet_oid->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void chown_name_index()
{
VMTemplatePool *tpool = static_cast<VMTemplatePool*>(pool);
VMTemplate *obj_oid, *obj_name;
int oid;
int old_uid;
int new_uid = 3456;
string name;
oid = allocate(0);
CPPUNIT_ASSERT(oid != -1);
// ---------------------------------
// Get by oid
obj_oid = tpool->get(oid, true);
CPPUNIT_ASSERT(obj_oid != 0);
name = obj_oid->get_name();
old_uid = obj_oid->get_uid();
// Change owner and update cache index
obj_oid->set_user(new_uid, "new_username");
tpool->update(obj_oid);
obj_oid->unlock();
tpool->update_cache_index(name, old_uid, name, new_uid);
// Get by name, new_uid and check it is the same object
obj_name = tpool->get(name, new_uid, true);
CPPUNIT_ASSERT(obj_name != 0);
obj_name->unlock();
CPPUNIT_ASSERT(obj_oid == obj_name);
// Get by name, old_uid and check it does not exist
obj_name = tpool->get(name, old_uid, true);
CPPUNIT_ASSERT(obj_name == 0);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
tpool->clean();
// Get by name, old_uid and check it does not exist
obj_name = tpool->get(name, old_uid, true);
CPPUNIT_ASSERT(obj_name == 0);
// Get by oid
obj_oid = tpool->get(oid, true);
CPPUNIT_ASSERT(obj_oid != 0);
obj_oid->unlock();
// Get by name, new_uid and check it is the same object
obj_name = tpool->get(name, new_uid, true);
CPPUNIT_ASSERT(obj_name != 0);
obj_name->unlock();
CPPUNIT_ASSERT(obj_oid == obj_name);
}
/* ********************************************************************* */
};

View File

@ -14,8 +14,8 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
# Libvirt configuration
:libvirt_uri: "esx://@HOST@/?no_verify=1"
# Libvirt congfiguration
:libvirt_uri: "'esx://@HOST@/?no_verify=1&auto_answer=1'"
# Username and password of the VMware hypervisor
:username: "oneadmin"
@ -23,4 +23,4 @@
# VMotion configuration attributes
:datacenter: "ha-datacenter"
:vcenter:
:vcenter:

View File

@ -180,6 +180,9 @@ class VirtualNetworkPoolTest : public PoolTest
CPPUNIT_TEST (range_definition);
CPPUNIT_TEST (name_index);
CPPUNIT_TEST (chown_name_index);
CPPUNIT_TEST_SUITE_END ();
protected:
@ -1690,6 +1693,135 @@ public:
vnpool->drop(vnet, err);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void name_index()
{
VirtualNetwork *vnet_oid, *vnet_name;
int oid_0;
int uid_0;
string name_0;
oid_0 = allocate(0);
CPPUNIT_ASSERT(oid_0 != -1);
// ---------------------------------
// Get by oid
vnet_oid = vnpool->get(oid_0, true);
CPPUNIT_ASSERT(vnet_oid != 0);
name_0 = vnet_oid->get_name();
uid_0 = vnet_oid->get_uid();
vnet_oid->unlock();
// Get by name and check it is the same object
vnet_name = vnpool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
vnpool->clean();
// Get by oid
vnet_oid = vnpool->get(oid_0, true);
CPPUNIT_ASSERT(vnet_oid != 0);
vnet_oid->unlock();
// Get by name and check it is the same object
vnet_name = vnpool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
vnpool->clean();
// Get by name
vnet_name = vnpool->get(name_0, uid_0, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
// Get by oid and check it is the same object
vnet_oid = vnpool->get(oid_0, true);
CPPUNIT_ASSERT(vnet_oid != 0);
vnet_oid->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void chown_name_index()
{
VirtualNetwork *vnet_oid, *vnet_name;
int oid;
int old_uid;
int new_uid = 3456;
string name;
oid = allocate(0);
CPPUNIT_ASSERT(oid != -1);
// ---------------------------------
// Get by oid
vnet_oid = vnpool->get(oid, true);
CPPUNIT_ASSERT(vnet_oid != 0);
name = vnet_oid->get_name();
old_uid = vnet_oid->get_uid();
// Change owner and update cache index
vnet_oid->set_user(new_uid, "new_username");
vnpool->update(vnet_oid);
vnet_oid->unlock();
vnpool->update_cache_index(name, old_uid, name, new_uid);
// Get by name, new_uid and check it is the same object
vnet_name = vnpool->get(name, new_uid, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
// Get by name, old_uid and check it does not exist
vnet_name = vnpool->get(name, old_uid, true);
CPPUNIT_ASSERT(vnet_name == 0);
// ---------------------------------
// Clean the cache, forcing the pool to read the objects from the DB
vnpool->clean();
// Get by name, old_uid and check it does not exist
vnet_name = vnpool->get(name, old_uid, true);
CPPUNIT_ASSERT(vnet_name == 0);
// Get by oid
vnet_oid = vnpool->get(oid, true);
CPPUNIT_ASSERT(vnet_oid != 0);
vnet_oid->unlock();
// Get by name, new_uid and check it is the same object
vnet_name = vnpool->get(name, new_uid, true);
CPPUNIT_ASSERT(vnet_name != 0);
vnet_name->unlock();
CPPUNIT_ASSERT(vnet_oid == vnet_name);
}
};
/* ************************************************************************* */