Skip to content
Newer
Older
100755 92 lines (74 sloc) 3.01 KB
07ccf29 @labisso Cleaned up EC2 keypair situation
labisso authored May 25, 2011
1 import uuid
2 import base64
3 import os
4 from boto.ec2.connection import EC2Connection
5 import unittest
6 import pycb
7 import pynimbusauthz
8 from pynimbusauthz.db import *
9 from pynimbusauthz.user import *
10 import pycb.test_common
11
12 def get_nimbus_home():
13 """Determines home directory of Nimbus install we are using.
14
15 First looks for a NIMBUS_HOME enviroment variable, else assumes that
16 the home directory is the parent directory of the directory with this
17 script.
18 """
19 nimbus_home = os.getenv("NIMBUS_HOME")
20 if not nimbus_home:
21 script_dir = os.path.dirname(__file__)
22 nimbus_home = os.path.dirname(script_dir)
23 if not os.path.exists(nimbus_home):
24 raise CLIError('ENIMBUSHOME', "NIMBUS_HOME must refer to a valid path")
25 return nimbus_home
26
27 PUBKEY1 = """
28 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6DrU6ncayShbPTMrWC8PmvnkTlifNyDSr5qwJsxK
29 hWyO3lDJmEHtpYc0WfKSJTv4LzbGjjeU1SH0mox5UsdaPUu0UCZ8z7O7R9MGpbIkGIEkcv1qdhkO
30 fGq03u1asoY3GUMkzQY2HfM40YQ93AQJQ96uDhALPAyEV3ZzEtI8z53++cP0pV6qVI5Wze68DmBu
31 KReG5I6xCWjcxYfx7e/PXXtkOl1WYZIj8eeiS9UkHN4QhdVCMHSALfz8k4D/N8iiYHm9EBKJp8tA
32 byPLiPAtZAOodlwlsMINwFY+Qcx1z4US/p8t5J6A+1EMZ9npWyxorFk2AfKDi1KIOeuUC72tfw==
33 """.replace('\n','')
34
35
36 class TestEC2Misc(unittest.TestCase):
37
38 def setUp(self):
39 host = 'localhost'
40 ec2port = 8444
572868b @buzztroll allowing the port to be overridden by an environment variable
buzztroll authored Nov 18, 2011
41 try:
42 ec2port = int(os.environ['NIMBUS_TEST_EC2_PORT'])
43 except:
44 pass
45
07ccf29 @labisso Cleaned up EC2 keypair situation
labisso authored May 25, 2011
46 self.db = DB(pycb.config.authzdb)
47 self.friendly = os.environ['NIMBUS_TEST_USER']
48 self.can_user = User.get_user_by_friendly(self.db, self.friendly)
49 s3a = self.can_user.get_alias_by_friendly(self.friendly, pynimbusauthz.alias_type_s3)
50
51 self.s3id = s3a.get_name()
52 self.s3pw = s3a.get_data()
53
54 self.ec2conn = EC2Connection(self.s3id, self.s3pw, host=host, port=ec2port)
55 self.ec2conn.host = host
56
57 def test_import_keypair(self):
58 keyname = str(uuid.uuid4())
59
60 # this is different in trunk boto, key is already encoded. til then..
61
62 keymaterial = base64.b64encode(PUBKEY1)
63 self.ec2conn.import_key_pair(keyname, keymaterial)
64 pair = self.ec2conn.get_key_pair(keyname)
65 self.assertTrue(pair)
66 self.assertEqual(pair.name, keyname)
67
68 self.ec2conn.delete_key_pair(keyname)
69 pair = self.ec2conn.get_key_pair(keyname)
70 self.assertFalse(pair)
71
72 def test_create_keypair(self):
73 keyname = str(uuid.uuid4())
74 pair = self.ec2conn.create_key_pair(keyname)
75 self.assertTrue(pair)
76 self.assertTrue(pair.material)
77 pair = self.ec2conn.get_key_pair(keyname)
78 self.assertTrue(pair)
79 self.assertEqual(pair.name, keyname)
80
81 self.ec2conn.delete_key_pair(keyname)
82 pair = self.ec2conn.get_key_pair(keyname)
83 self.assertFalse(pair)
84
15d7f9a @oldpatricka Add integration tests for Availability Zones
oldpatricka authored Sep 23, 2011
85 def test_availability_zones(self):
86 """Test wheter AZs are described correctly
87 """
88
89 got_zones = self.ec2conn.get_all_zones()
90 print dir(got_zones[0])
91 self.assertEqual("default", got_zones[0].name)
Something went wrong with that request. Please try again.