This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented ImportKeyPair operation. Left our nonstandard CreateKeyPair behavior, but disabled. Closes #36
- Loading branch information
Showing
9 changed files
with
216 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
if [ "X$NIMBUS_HOME" == "X" ]; then | ||
echo "NIMBUS_HOME must be set to run this test" | ||
exit 1 | ||
fi | ||
|
||
PYTHON_EXE="/usr/bin/env python -Wignore::DeprecationWarning" | ||
|
||
NIMBUS_WEBDIR="$NIMBUS_HOME/web" | ||
|
||
NIMBUS_PYLIB="$NIMBUS_WEBDIR/lib/python" | ||
NIMBUS_PYSRC="$NIMBUS_WEBDIR/src/python" | ||
|
||
source $NIMBUS_HOME/cumulus/env.sh | ||
PYTHONPATH="${PYTHONPATH}:$NIMBUS_PYSRC:$NIMBUS_PYLIB:$PYTHONPATH:$NIMBUS_HOME/sbin:$NIMBUS_HOME/libexec:${PYTHONPATH}" | ||
export PYTHONPATH | ||
|
||
DJANGO_SETTINGS_MODULE="nimbusweb.portal.settings" | ||
export DJANGO_SETTINGS_MODULE | ||
|
||
source $NIMBUS_HOME/ve/bin/activate | ||
exec nosetests ec2_misc_tests.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import uuid | ||
import base64 | ||
import os | ||
from boto.ec2.connection import EC2Connection | ||
import unittest | ||
import pycb | ||
import pynimbusauthz | ||
from pynimbusauthz.db import * | ||
from pynimbusauthz.user import * | ||
import pycb.test_common | ||
|
||
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 | ||
|
||
PUBKEY1 = """ | ||
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6DrU6ncayShbPTMrWC8PmvnkTlifNyDSr5qwJsxK | ||
hWyO3lDJmEHtpYc0WfKSJTv4LzbGjjeU1SH0mox5UsdaPUu0UCZ8z7O7R9MGpbIkGIEkcv1qdhkO | ||
fGq03u1asoY3GUMkzQY2HfM40YQ93AQJQ96uDhALPAyEV3ZzEtI8z53++cP0pV6qVI5Wze68DmBu | ||
KReG5I6xCWjcxYfx7e/PXXtkOl1WYZIj8eeiS9UkHN4QhdVCMHSALfz8k4D/N8iiYHm9EBKJp8tA | ||
byPLiPAtZAOodlwlsMINwFY+Qcx1z4US/p8t5J6A+1EMZ9npWyxorFk2AfKDi1KIOeuUC72tfw== | ||
""".replace('\n','') | ||
|
||
|
||
class TestEC2Misc(unittest.TestCase): | ||
|
||
def setUp(self): | ||
host = 'localhost' | ||
ec2port = 8444 | ||
self.db = DB(pycb.config.authzdb) | ||
self.friendly = os.environ['NIMBUS_TEST_USER'] | ||
self.can_user = User.get_user_by_friendly(self.db, self.friendly) | ||
s3a = self.can_user.get_alias_by_friendly(self.friendly, pynimbusauthz.alias_type_s3) | ||
|
||
self.s3id = s3a.get_name() | ||
self.s3pw = s3a.get_data() | ||
|
||
self.ec2conn = EC2Connection(self.s3id, self.s3pw, host=host, port=ec2port) | ||
self.ec2conn.host = host | ||
|
||
def test_import_keypair(self): | ||
keyname = str(uuid.uuid4()) | ||
|
||
# this is different in trunk boto, key is already encoded. til then.. | ||
|
||
keymaterial = base64.b64encode(PUBKEY1) | ||
self.ec2conn.import_key_pair(keyname, keymaterial) | ||
pair = self.ec2conn.get_key_pair(keyname) | ||
self.assertTrue(pair) | ||
self.assertEqual(pair.name, keyname) | ||
|
||
self.ec2conn.delete_key_pair(keyname) | ||
pair = self.ec2conn.get_key_pair(keyname) | ||
self.assertFalse(pair) | ||
|
||
def test_create_keypair(self): | ||
keyname = str(uuid.uuid4()) | ||
pair = self.ec2conn.create_key_pair(keyname) | ||
self.assertTrue(pair) | ||
self.assertTrue(pair.material) | ||
pair = self.ec2conn.get_key_pair(keyname) | ||
self.assertTrue(pair) | ||
self.assertEqual(pair.name, keyname) | ||
|
||
self.ec2conn.delete_key_pair(keyname) | ||
pair = self.ec2conn.get_key_pair(keyname) | ||
self.assertFalse(pair) | ||
|