From 7883f0b7ffc1868cfa1fff0adb9fce78d58e47ea Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Tue, 1 Oct 2013 16:06:58 +0200 Subject: [PATCH 1/2] Bug #2350: Template cannot be instantiated if CONTEXT, KERNEL or INITRD images are not in READY state. --- src/vm/VirtualMachine.cc | 49 +++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 9619d59a9d..69fabd9fd1 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -457,9 +457,12 @@ int VirtualMachine::set_os_file(VectorAttribute * os, Nebula& nd = Nebula::instance(); ImagePool * ipool = nd.get_ipool(); - Image * img = 0; + Image * img = 0; - Image::ImageType type; + int img_id; + + Image::ImageType type; + Image::ImageState state; DatastorePool * ds_pool = nd.get_dspool(); Datastore * ds; @@ -473,6 +476,10 @@ int VirtualMachine::set_os_file(VectorAttribute * os, string base_name_tm = base_name + "_DS_TM"; string base_name_cluster= base_name + "_DS_CLUSTER_ID"; + string type_str; + + ostringstream oss; + attr = os->vector_value(base_name_ds.c_str()); if ( attr.empty() ) @@ -491,7 +498,9 @@ int VirtualMachine::set_os_file(VectorAttribute * os, return -1; } - img = ipool->get(img_ids.back(), true); + img_id = img_ids.back(); + + img = ipool->get(img_id, true); if ( img == 0 ) { @@ -499,6 +508,8 @@ int VirtualMachine::set_os_file(VectorAttribute * os, return -1; } + state = img->get_state(); + ds_id = img->get_ds_id(); type = img->get_type(); @@ -510,13 +521,24 @@ int VirtualMachine::set_os_file(VectorAttribute * os, img->unlock(); + type_str = Image::type_to_str(type); + if ( type != base_type ) { - ostringstream oss; + oss.str(""); oss << base_name << " needs an image of type " << Image::type_to_str(base_type) << " and not " - << Image::type_to_str(type); + << type_str; + + error_str = oss.str(); + return -1; + } + + if ( state != Image::READY ) { + oss.str(""); + + oss << type_str << " Image '" << img_id << " 'not in READY state."; error_str = oss.str(); return -1; @@ -613,6 +635,7 @@ int VirtualMachine::parse_context(string& error_str) string files_ds_parsed; ostringstream oss_parsed; + ostringstream oss; vector img_ids; @@ -776,6 +799,7 @@ int VirtualMachine::parse_context(string& error_str) Image * img = 0; Image::ImageType type; + Image::ImageState state; for ( it=img_ids.begin() ; it < img_ids.end(); it++ ) { @@ -783,10 +807,13 @@ int VirtualMachine::parse_context(string& error_str) if ( img != 0 ) { + + oss_parsed << img->get_source() << ":'" << img->get_name() << "' "; - type = img->get_type(); + type = img->get_type(); + state = img->get_state(); img->unlock(); @@ -796,6 +823,16 @@ int VirtualMachine::parse_context(string& error_str) " FILE_DS attribute."; return -1; } + + if ( state != Image::READY ) { + oss.str(""); + oss << Image::type_to_str(type) + oss << " Image '" << *it + << "' not in READY state."; + error_str = oss.str(); + return -1; + } + } } } From 1e6e71177bae34b7d6b22bef74043ce625ddee84 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 4 Oct 2013 15:32:05 +0200 Subject: [PATCH 2/2] bug #2350: Move initialization of ostringstream --- src/vm/VirtualMachine.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 69fabd9fd1..33395a6831 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -478,8 +478,6 @@ int VirtualMachine::set_os_file(VectorAttribute * os, string type_str; - ostringstream oss; - attr = os->vector_value(base_name_ds.c_str()); if ( attr.empty() ) @@ -525,7 +523,7 @@ int VirtualMachine::set_os_file(VectorAttribute * os, if ( type != base_type ) { - oss.str(""); + ostringstream oss; oss << base_name << " needs an image of type " << Image::type_to_str(base_type) << " and not " @@ -535,8 +533,9 @@ int VirtualMachine::set_os_file(VectorAttribute * os, return -1; } - if ( state != Image::READY ) { - oss.str(""); + if ( state != Image::READY ) + { + ostringstream oss; oss << type_str << " Image '" << img_id << " 'not in READY state."; @@ -635,7 +634,6 @@ int VirtualMachine::parse_context(string& error_str) string files_ds_parsed; ostringstream oss_parsed; - ostringstream oss; vector img_ids; @@ -807,8 +805,6 @@ int VirtualMachine::parse_context(string& error_str) if ( img != 0 ) { - - oss_parsed << img->get_source() << ":'" << img->get_name() << "' "; @@ -824,12 +820,15 @@ int VirtualMachine::parse_context(string& error_str) return -1; } - if ( state != Image::READY ) { - oss.str(""); + if ( state != Image::READY ) + { + ostringstream oss; + oss << Image::type_to_str(type) - oss << " Image '" << *it - << "' not in READY state."; + << " Image '" << *it << "' not in READY state."; + error_str = oss.str(); + return -1; }