summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-07-20 20:01:46 +0000
committerGerrit Code Review <review@openstack.org>2012-07-20 20:01:46 +0000
commit45205734d31c8b281056a44c236a64af343efb70 (patch)
tree65b8c6cbae7095e62d284926e09dd1493a8ef338
parenta8e16cfd8886e09493f23f72022756209060f8a0 (diff)
parent8b7765276951f4a2a6a80df3bce7c12e64cee44f (diff)
downloadnova-45205734d31c8b281056a44c236a64af343efb70.tar.gz
nova-45205734d31c8b281056a44c236a64af343efb70.tar.xz
nova-45205734d31c8b281056a44c236a64af343efb70.zip
Merge "Fix cloudpipe keypair creation. Add pipelib tests"
-rw-r--r--nova/cloudpipe/pipelib.py7
-rw-r--r--nova/tests/test_pipelib.py75
2 files changed, 79 insertions, 3 deletions
diff --git a/nova/cloudpipe/pipelib.py b/nova/cloudpipe/pipelib.py
index 6926978fc..6a772eb63 100644
--- a/nova/cloudpipe/pipelib.py
+++ b/nova/cloudpipe/pipelib.py
@@ -26,8 +26,6 @@ import os
import string
import zipfile
-# NOTE(vish): cloud is only for the _gen_key functionality
-from nova.api.ec2 import cloud
from nova import compute
from nova.compute import instance_types
from nova import crypto
@@ -146,7 +144,10 @@ class CloudPipe(object):
def setup_key_pair(self, context):
key_name = '%s%s' % (context.project_id, FLAGS.vpn_key_suffix)
try:
- result = cloud._gen_key(context, context.user_id, key_name)
+ keypair_api = compute.api.KeypairAPI()
+ result = keypair_api.create_key_pair(context,
+ context.user_id,
+ key_name)
private_key = result['private_key']
key_dir = os.path.join(FLAGS.keys_path, context.user_id)
if not os.path.exists(key_dir):
diff --git a/nova/tests/test_pipelib.py b/nova/tests/test_pipelib.py
new file mode 100644
index 000000000..26ab82ffd
--- /dev/null
+++ b/nova/tests/test_pipelib.py
@@ -0,0 +1,75 @@
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from nova.cloudpipe import pipelib
+from nova import context
+from nova import crypto
+from nova import db
+from nova import flags
+from nova import test
+from nova import utils
+
+
+FLAGS = flags.FLAGS
+
+
+class PipelibTest(test.TestCase):
+ def setUp(self):
+ super(PipelibTest, self).setUp()
+ self.cloudpipe = pipelib.CloudPipe()
+ self.project = "222"
+ self.user = "111"
+ self.context = context.RequestContext(self.user, self.project)
+
+ def test_get_encoded_zip(self):
+ with utils.tempdir() as tmpdir:
+ self.flags(ca_path=tmpdir)
+ crypto.ensure_ca_filesystem()
+
+ ret = self.cloudpipe.get_encoded_zip(self.project)
+ self.assertTrue(ret)
+
+ def test_launch_vpn_instance(self):
+ self.stubs.Set(self.cloudpipe.compute_api,
+ "create",
+ lambda *a, **kw: (None, "r-fakeres"))
+ with utils.tempdir() as tmpdir:
+ self.flags(ca_path=tmpdir, keys_path=tmpdir)
+ crypto.ensure_ca_filesystem()
+ self.cloudpipe.launch_vpn_instance(self.context)
+
+ def test_setup_security_group(self):
+ group_name = "%s%s" % (self.project, FLAGS.vpn_key_suffix)
+
+ # First attemp, does not exist (thus its created)
+ res1_group = self.cloudpipe.setup_security_group(self.context)
+ self.assertEqual(res1_group, group_name)
+
+ # Second attem, it exists in the DB
+ res2_group = self.cloudpipe.setup_security_group(self.context)
+ self.assertEqual(res1_group, res2_group)
+
+ def test_setup_key_pair(self):
+ key_name = "%s%s" % (self.project, FLAGS.vpn_key_suffix)
+ with utils.tempdir() as tmpdir:
+ self.flags(keys_path=tmpdir)
+
+ # First attemp, key does not exist (thus it is generated)
+ res1_key = self.cloudpipe.setup_key_pair(self.context)
+ self.assertEqual(res1_key, key_name)
+
+ # Second attem, it exists in the DB
+ res2_key = self.cloudpipe.setup_key_pair(self.context)
+ self.assertEqual(res2_key, res1_key)