Skip to content
This repository
Browse code

adding boto tests for ec2 rest listing

  • Loading branch information...
commit c9ee360f8fec12f1c4810c8a2ede477fddeb2de0 1 parent 8ae0325
BuzzTroll authored

Showing 2 changed files with 93 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 2 cumulus/src/pycb/__init__.py
  2. +91 0 tests/ec2_test.py
4 cumulus/src/pycb/__init__.py
@@ -157,8 +157,8 @@ def load_settings(self):
157 157 posix_dir = s.get("security", "security_dir")
158 158 self.auth = cbPosixSec(posix_dir)
159 159 elif sec == "authz":
160   - authzdb = s.get("security", "authzdb")
161   - self.auth = cbAuthzSec(authzdb)
  160 + self.authzdb = s.get("security", "authzdb")
  161 + self.auth = cbAuthzSec(self.authzdb)
162 162 else:
163 163 self.auth_error = self.auth_error + "no type %s" % (sec)
164 164 except:
91 tests/ec2_test.py
... ... @@ -0,0 +1,91 @@
  1 +import string
  2 +import random
  3 +import os
  4 +import sys
  5 +import nose.tools
  6 +import boto
  7 +from boto.ec2.connection import EC2Connection
  8 +import boto.ec2
  9 +import sys
  10 +from ConfigParser import SafeConfigParser
  11 +import time
  12 +import unittest
  13 +import tempfile
  14 +import filecmp
  15 +import pycb
  16 +import pynimbusauthz
  17 +from pynimbusauthz.db import *
  18 +from pynimbusauthz.user import *
  19 +import pycb.test_common
  20 +from boto.s3.connection import OrdinaryCallingFormat
  21 +from boto.s3.connection import S3Connection
  22 +import random
  23 +
  24 +
  25 +class TestEC2List(unittest.TestCase):
  26 +
  27 + def cb_random_bucketname(self, len):
  28 + chars = string.letters + string.digits
  29 + newpasswd = ""
  30 + for i in range(len):
  31 + newpasswd = newpasswd + random.choice(chars)
  32 + return newpasswd
  33 +
  34 +
  35 + def setUp(self):
  36 + host = 'localhost'
  37 + cumport = 8888
  38 + ec2port = 8444
  39 + self.db = DB(pycb.config.authzdb)
  40 + self.friendly = self.cb_random_bucketname(21)
  41 + self.can_user = User(self.db, friendly=self.friendly, create=True)
  42 + self.subject = self.cb_random_bucketname(21)
  43 + self.s3id = self.cb_random_bucketname(21)
  44 + self.s3pw = self.cb_random_bucketname(42)
  45 + self.s3user = self.can_user.create_alias(self.s3id, pynimbusauthz.alias_type_s3, self.friendly, self.s3pw)
  46 + self.dnuser = self.can_user.create_alias(self.subject, pynimbusauthz.alias_type_x509, self.friendly)
  47 +
  48 + self.ec2conn = EC2Connection(self.s3id, self.s3pw, host=host, port=ec2port, debug=2)
  49 + self.ec2conn.host = host
  50 +
  51 + cf = OrdinaryCallingFormat()
  52 + self.s3conn = S3Connection(self.s3id, self.s3pw, host=host, port=cumport, is_secure=False, calling_format=cf)
  53 + self.db.commit()
  54 +
  55 + def tearDown(self):
  56 + if self.s3conn != None:
  57 + pass
  58 + if self.ec2conn != None:
  59 + pass
  60 + if self.s3user != None:
  61 + self.s3user.remove()
  62 + if self.dnuser != None:
  63 + self.dnuser.remove()
  64 + if self.can_user != None:
  65 + self.can_user.destroy_brutally()
  66 + if self.db != None:
  67 + self.db.close()
  68 +
  69 +
  70 + def test_ec2_list_empty(self):
  71 +
  72 + images = self.ec2conn.get_all_images()
  73 + self.assertEqual(len(images), 0, "should be no images listed %d" % len(images))
  74 +
  75 + def test_ec2_list_upload(self):
  76 + # obviously this will not work if the default name changes
  77 + bucket = self.s3conn.get_bucket("Repo")
  78 + k = boto.s3.key.Key(bucket)
  79 + k.key = self.cb_random_bucketname(25)
  80 + k.set_contents_from_filename("/etc/group")
  81 +
  82 + images = self.ec2conn.get_all_images()
  83 + self.assertEqual(len(images), 1, "should be 1 image %d" % len(images))
  84 +
  85 + for i in images:
  86 + print i
  87 +
  88 + self.fail("poop")
  89 +
  90 +
  91 +

0 comments on commit c9ee360

Please sign in to comment.
Something went wrong with that request. Please try again.