~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/tests/test_pipelib.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 OpenStack LLC.
 
2
# All Rights Reserved.
 
3
#
 
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
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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
 
14
#    under the License.
 
15
 
 
16
from nova.cloudpipe import pipelib
 
17
from nova import context
 
18
from nova import crypto
 
19
from nova import flags
 
20
from nova import test
 
21
from nova import utils
 
22
 
 
23
 
 
24
FLAGS = flags.FLAGS
 
25
 
 
26
 
 
27
class PipelibTest(test.TestCase):
 
28
    def setUp(self):
 
29
        super(PipelibTest, self).setUp()
 
30
        self.cloudpipe = pipelib.CloudPipe()
 
31
        self.project = "222"
 
32
        self.user = "111"
 
33
        self.context = context.RequestContext(self.user, self.project)
 
34
 
 
35
    def test_get_encoded_zip(self):
 
36
        with utils.tempdir() as tmpdir:
 
37
            self.flags(ca_path=tmpdir)
 
38
            crypto.ensure_ca_filesystem()
 
39
 
 
40
            ret = self.cloudpipe.get_encoded_zip(self.project)
 
41
            self.assertTrue(ret)
 
42
 
 
43
    def test_launch_vpn_instance(self):
 
44
        self.stubs.Set(self.cloudpipe.compute_api,
 
45
                       "create",
 
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)
 
51
 
 
52
    def test_setup_security_group(self):
 
53
        group_name = "%s%s" % (self.project, FLAGS.vpn_key_suffix)
 
54
 
 
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)
 
58
 
 
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)
 
62
 
 
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)
 
67
 
 
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)
 
71
 
 
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)