Permalink
Browse files

created a new test for ec2 interface. fixed some naming issues in ima…

…ge location
  • Loading branch information...
1 parent 4266eb1 commit 852ec344f89f317cfc74650e4c8bbbd371c48b83 BuzzTroll committed Jul 14, 2010
@@ -275,7 +275,16 @@ public String getImageLocation(Caller caller)
for (ObjectWrapper ow : objList)
{
FileListing fl = new FileListing();
- fl.setName(ow.getName());
+ String name = ow.getName();
+ String [] parts = name.split("/", 3);
+ if(parts.length != 3)
+ {
+ // if a bad name jsut skip this file... they may have uploaded baddness
+ logger.error("The filename " + name + " is not in the proper format");
+ continue;
+ }
+ name = parts[2];
+ fl.setName(name);
fl.setSize(ow.getSize());
long tm = ow.getTime();
View
@@ -20,4 +20,4 @@ export DJANGO_SETTINGS_MODULE
source $NIMBUS_HOME/ve/bin/activate
cd $NIMBUS_HOME/libexec
-nosetests ../tests/ec2_test.py
+nosetests ../tests/ec2_repo_test.py ../tests/ec2_submit_tests.py
@@ -86,3 +86,4 @@ def test_ec2_list_upload(self):
print i
+
View
@@ -0,0 +1,100 @@
+import string
+import random
+import os
+import sys
+import nose.tools
+import boto
+from boto.ec2.connection import EC2Connection
+import boto.ec2
+import sys
+from ConfigParser import SafeConfigParser
+import time
+import unittest
+import tempfile
+import filecmp
+import pycb
+import pynimbusauthz
+from pynimbusauthz.db import *
+from pynimbusauthz.user import *
+import pycb.test_common
+from boto.s3.connection import OrdinaryCallingFormat
+from boto.s3.connection import S3Connection
+import random
+from nimbusweb.setup.groupauthz import *
+
+def get_nimbus_home():
+ """Determines home directory of Nimbus install we are using.
+
+ First looks for a NIMBUS_HOME enviroment variable, else assumes that
+ the home directory is the parent directory of the directory with this
+ script.
+ """
+ nimbus_home = os.getenv("NIMBUS_HOME")
+ if not nimbus_home:
+ script_dir = os.path.dirname(__file__)
+ nimbus_home = os.path.dirname(script_dir)
+ if not os.path.exists(nimbus_home):
+ raise CLIError('ENIMBUSHOME', "NIMBUS_HOME must refer to a valid path")
+ return nimbus_home
+
+
+class TestEC2Submit(unittest.TestCase):
+
+ def cb_random_bucketname(self, len):
+ chars = string.letters + string.digits
+ newpasswd = ""
+ for i in range(len):
+ newpasswd = newpasswd + random.choice(chars)
+ return newpasswd
+
+ def setUp(self):
+ host = 'localhost'
+ cumport = 8888
+ ec2port = 8444
+ self.db = DB(pycb.config.authzdb)
+ self.friendly = self.cb_random_bucketname(21)
+ self.can_user = User(self.db, friendly=self.friendly, create=True)
+ self.subject = self.cb_random_bucketname(21)
+ self.s3id = self.cb_random_bucketname(21)
+ self.s3pw = self.cb_random_bucketname(42)
+ self.s3user = self.can_user.create_alias(self.s3id, pynimbusauthz.alias_type_s3, self.friendly, self.s3pw)
+ self.dnuser = self.can_user.create_alias(self.subject, pynimbusauthz.alias_type_x509, self.friendly)
+
+ self.ec2conn = EC2Connection(self.s3id, self.s3pw, host=host, port=ec2port, debug=2)
+ self.ec2conn.host = host
+
+ cf = OrdinaryCallingFormat()
+ self.s3conn = S3Connection(self.s3id, self.s3pw, host=host, port=cumport, is_secure=False, calling_format=cf)
+ self.db.commit()
+
+ nh = get_nimbus_home()
+ groupauthz_dir = os.path.join(nh, "services/etc/nimbus/workspace-service/group-authz/")
+ add_member(groupauthz_dir, self.subject, 4)
+
+
+ def tearDown(self):
+ if self.s3conn != None:
+ pass
+ if self.ec2conn != None:
+ pass
+ if self.s3user != None:
+ self.s3user.remove()
+ if self.dnuser != None:
+ self.dnuser.remove()
+ if self.can_user != None:
+ self.can_user.destroy_brutally()
+ if self.db != None:
+ self.db.close()
+
+
+ def test_ec2_list_empty(self):
+
+ bucket = self.s3conn.get_bucket("Repo")
+ k = boto.s3.key.Key(bucket)
+ image_name = self.cb_random_bucketname(10)
+ k.key = "VMS/" + self.can_user.get_id() + "/" + image_name
+ k.set_contents_from_filename("/etc/group")
+ image = self.ec2conn.get_image(image_name)
+ res = image.run()
+ dir(res)
+ res.stop_all()

0 comments on commit 852ec34

Please sign in to comment.