Specifically, make sure we can parse bash-style
config files (NAME=VALUE, export NAME=VALUE).  Also make
sure that we output a lot more debugging information.

Signed-off-by: Chris Lalancette <[email protected]>
---
 src/classad_plugin/classad_plugin.rb             |   37 +++++++++++++--
 src/classad_plugin/deltacloud_classad_plugin.cpp |   56 ++++++++++++++++++++--
 2 files changed, 85 insertions(+), 8 deletions(-)

diff --git a/src/classad_plugin/classad_plugin.rb 
b/src/classad_plugin/classad_plugin.rb
index 5ac4b09..2aabfb9 100644
--- a/src/classad_plugin/classad_plugin.rb
+++ b/src/classad_plugin/classad_plugin.rb
@@ -8,13 +8,40 @@ require 'instance'
 require 'cloud_account'
 require 'pool'
 require 'quota'
-require 'parseconfig'
+
+class BashParser
+  def initialize(filename)
+    @config = {}
+
+    f = File.open(filename, 'r')
+    while (line = f.gets)
+      strip = line.strip.gsub(/#.*/, '').gsub(/^export /, '')
+      if strip.length == 0
+        next
+      end
+
+      x = strip.split('=')
+      if x.length != 2
+        next
+      end
+
+      @config[x[0]] = x[1]
+    end
+
+    f.close
+  end
+
+  def get_value(name)
+    @config[name]
+  end
+end
 
 def classad_plugin(logf, conf_path, instance_key, account_id)
   rails_env = "development"
+
   begin
-    config = ParseConfig.new('/etc/sysconfig/deltacloud-rails')
-    env = config.get_value("RAILS_ENV")
+    config = BashParser.new('/etc/sysconfig/deltacloud-rails')
+    env = config.get_value('RAILS_ENV')
     if not env.nil?
       rails_env = env
     end
@@ -23,7 +50,7 @@ def classad_plugin(logf, conf_path, instance_key, account_id)
     # hope for the best
   end
 
-  logf.puts "loading db config from #{conf_path}"
+  logf.puts "loading db config from #{conf_path}, using environment 
#{rails_env}"
   conf = YAML::load(File.open(conf_path))
   ActiveRecord::Base.establish_connection(conf[rails_env])
 
@@ -43,7 +70,9 @@ def classad_plugin(logf, conf_path, instance_key, account_id)
 
   logf.puts "checking quota.."
   ret = Quota.can_start_instance?(instance, cloud_account)
+  logf.puts "After checking quota, ret is #{ret}"
 
+  logf.puts "Disconnecting from the database"
   ActiveRecord::Base.connection.disconnect!
 
   return ret
diff --git a/src/classad_plugin/deltacloud_classad_plugin.cpp 
b/src/classad_plugin/deltacloud_classad_plugin.cpp
index dc3fb10..74d6023 100644
--- a/src/classad_plugin/deltacloud_classad_plugin.cpp
+++ b/src/classad_plugin/deltacloud_classad_plugin.cpp
@@ -12,7 +12,53 @@ using namespace std;
 using namespace classad;
 #endif
 
-void print_value(FILE *fp, Value val, const char *name)
+#define print_value(fp, val) _print_value(fp, val, #val)
+#define print_type(fp, val) _print_type(fp, val, #val)
+
+static void _print_type(FILE *fp, Value val, const char *name)
+{
+  fprintf(fp, "%s type is: ", name);
+
+  switch(val.GetType()) {
+  case Value::NULL_VALUE:
+    fprintf(fp, "NULL");
+    break;
+  case Value::ERROR_VALUE:
+    fprintf(fp, "Error");
+    break;
+  case Value::UNDEFINED_VALUE:
+    fprintf(fp, "Undefined");
+    break;
+  case Value::BOOLEAN_VALUE:
+    fprintf(fp, "Boolean");
+    break;
+  case Value::INTEGER_VALUE:
+    fprintf(fp, "Integer");
+    break;
+  case Value::REAL_VALUE:
+    fprintf(fp, "Real");
+    break;
+  case Value::LIST_VALUE:
+    fprintf(fp, "List");
+    break;
+  case Value::CLASSAD_VALUE:
+    fprintf(fp, "Classad");
+    break;
+  case Value::RELATIVE_TIME_VALUE:
+    fprintf(fp, "RelativeTime");
+    break;
+  case Value::ABSOLUTE_TIME_VALUE:
+    fprintf(fp, "AbsoluteTime");
+    break;
+  case Value::STRING_VALUE:
+    fprintf(fp, "String");
+    break;
+  }
+
+  fprintf(fp, "\n");
+}
+
+static void _print_value(FILE *fp, Value val, const char *name)
 {
     /* AFAICT the only way to get at the string in a 'Value' object is to use
      * the C++ stream operator <<,  so we set up a stringstream and write
@@ -56,7 +102,7 @@ deltacloud_quota_check(const char *name, const ArgumentList 
&arglist,
 
     if (arglist.size() != 2) {
       result.SetErrorValue();
-      fprintf(fp, "Expected 2 arguments, saw %d\n", arglist.size());
+      fprintf(fp, "Expected 2 arguments, saw %z\n", arglist.size());
       goto do_ret;
     }
 
@@ -71,19 +117,21 @@ deltacloud_quota_check(const char *name, const 
ArgumentList &arglist,
       goto do_ret;
     }
 
+    print_type(fp, instance_key);
+    print_value(fp, instance_key);
     if (instance_key.GetType() != Value::STRING_VALUE) {
       result.SetErrorValue();
       fprintf(fp, "Instance type was not a string\n");
       goto do_ret;
     }
-    //print_value(fp, instance_key, "instance_key");
 
+    print_type(fp, account_id);
+    print_value(fp, account_id);
     if (account_id.GetType() != Value::STRING_VALUE) {
       result.SetErrorValue();
       fprintf(fp, "Account ID type was not a string\n");
       goto do_ret;
     }
-    //print_value(fp, account_id, "account_id");
 
     ruby_init();
     ruby_init_loadpath();
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to