1
# Copyright 2011 OpenStack LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
16
from nova.cloudpipe import pipelib
17
from nova import context
18
from nova import crypto
19
from nova import flags
21
from nova import utils
27
class PipelibTest(test.TestCase):
29
super(PipelibTest, self).setUp()
30
self.cloudpipe = pipelib.CloudPipe()
33
self.context = context.RequestContext(self.user, self.project)
35
def test_get_encoded_zip(self):
36
with utils.tempdir() as tmpdir:
37
self.flags(ca_path=tmpdir)
38
crypto.ensure_ca_filesystem()
40
ret = self.cloudpipe.get_encoded_zip(self.project)
43
def test_launch_vpn_instance(self):
44
self.stubs.Set(self.cloudpipe.compute_api,
46
lambda *a, **kw: (None, "r-fakeres"))
47
with utils.tempdir() as tmpdir:
48
self.flags(ca_path=tmpdir, keys_path=tmpdir)
49
crypto.ensure_ca_filesystem()
50
self.cloudpipe.launch_vpn_instance(self.context)
52
def test_setup_security_group(self):
53
group_name = "%s%s" % (self.project, FLAGS.vpn_key_suffix)
55
# First attemp, does not exist (thus its created)
56
res1_group = self.cloudpipe.setup_security_group(self.context)
57
self.assertEqual(res1_group, group_name)
59
# Second attem, it exists in the DB
60
res2_group = self.cloudpipe.setup_security_group(self.context)
61
self.assertEqual(res1_group, res2_group)
63
def test_setup_key_pair(self):
64
key_name = "%s%s" % (self.project, FLAGS.vpn_key_suffix)
65
with utils.tempdir() as tmpdir:
66
self.flags(keys_path=tmpdir)
68
# First attemp, key does not exist (thus it is generated)
69
res1_key = self.cloudpipe.setup_key_pair(self.context)
70
self.assertEqual(res1_key, key_name)
72
# Second attem, it exists in the DB
73
res2_key = self.cloudpipe.setup_key_pair(self.context)
74
self.assertEqual(res2_key, res1_key)