nova/nova/tests/unit/test_pipelib.py
Sean Dague c943cbbc40 ensure DatabaseFixture removes db on cleanup
The DatabaseFixture was previously just ensuring that tests which used
it had a clean database when they started. It did not ensure there was
no working database around when it wasn't being used, so tests which
leaked into the database might pass even if they were listed as a
NoDBTest, because there was an in memory test db from a prior run.

This adds a cleanup path to the fixture which blows away the db at the
end of the test (which itself is tested). There were 46 tests which
failed when we got this isolation correct, and this changes all those
test classes containing those tests to require a db. Many of these
could have narrower fixes, but this returns us to an isolated state.

Change-Id: Id0480035d8e615ae602da9737cd2c94bc7967067
Closes-Bug: #1431519
Closes-Bug: #1431551
2015-03-12 16:55:55 -04:00

75 lines
2.6 KiB
Python

# Copyright 2011 OpenStack Foundation
# 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 oslo_config import cfg
from nova.cloudpipe import pipelib
from nova import context
from nova import crypto
from nova import test
from nova import utils
CONF = cfg.CONF
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, CONF.vpn_key_suffix)
# First attempt, does not exist (thus its created)
res1_group = self.cloudpipe.setup_security_group(self.context)
self.assertEqual(res1_group, group_name)
# Second attempt, 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, CONF.vpn_key_suffix)
with utils.tempdir() as tmpdir:
self.flags(keys_path=tmpdir)
# First attempt, key does not exist (thus it is generated)
res1_key = self.cloudpipe.setup_key_pair(self.context)
self.assertEqual(res1_key, key_name)
# Second attempt, it exists in the DB
res2_key = self.cloudpipe.setup_key_pair(self.context)
self.assertEqual(res2_key, res1_key)