/usr/share/pyshared/glance/tests/functional/test_rbd.py is in python-glance 2012.1.3+stable~20120821-120fcf-0ubuntu1.5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | # vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 Josh Durgin
# 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.
"""
Tests a Glance API server which uses an RBD backend by default
This test has requires a Ceph cluster, optionally with
authentication. It looks in a file specified in the
GLANCE_TEST_RBD_CONF environment variable for RBD store settings.
For more details, see doc/source/configuring.rst.
For Ceph installation instructions, see:
http://ceph.newdream.net/docs/latest/ops/install/
or, if you want to compile a development version:
http://ceph.newdream.net/wiki/Simple_test_setup
Note this test creates and deletes the pool specified in the
configuration file, so it should not exist prior to running the test.
If a connection cannot be established, or the rados library is not
found, or creating the pool fails, all the test cases are skipped.
"""
import ConfigParser
import os
from glance.tests.functional import test_api
from glance.store.rbd import DEFAULT_POOL, DEFAULT_CONFFILE, DEFAULT_USER
class TestRBD(test_api.TestApi):
"""Functional tests for the RBD backend"""
CONFIG_FILE_PATH = os.environ.get('GLANCE_TEST_RBD_CONF')
def __init__(self, *args, **kwargs):
super(TestRBD, self).__init__(*args, **kwargs)
self.disabled = True
if not self.CONFIG_FILE_PATH:
self.disabled_message = "GLANCE_TEST_RBD_CONF environ not set."
return
# use the default configuration if none is specified
self.rbd_store_ceph_conf = DEFAULT_CONFFILE
self.rbd_store_user = DEFAULT_USER
self.rbd_store_pool = DEFAULT_POOL
if os.path.exists(TestRBD.CONFIG_FILE_PATH):
cp = ConfigParser.RawConfigParser()
try:
cp.read(TestRBD.CONFIG_FILE_PATH)
defaults = cp.defaults()
for key, value in defaults.items():
self.__dict__[key] = value
except ConfigParser.ParsingError, e:
self.disabled_message = ("Failed to read test_rbd config "
"file. Got error: %s" % e)
return
try:
import rados
except ImportError:
self.disabled_message = "rados python library not found"
return
cluster = rados.Rados(conffile=self.rbd_store_ceph_conf,
rados_id=self.rbd_store_user)
try:
cluster.connect()
except rados.Error, e:
self.disabled_message = ("Failed to connect to RADOS: %s" % e)
return
cluster.shutdown()
self.default_store = 'rbd'
self.disabled = False
def setUp(self):
if self.disabled:
return
import rados
try:
self.create_pool()
except rados.Error, e:
self.disabled_message = ("Failed to create pool: %s" % e)
self.disabled = True
return
super(TestRBD, self).setUp()
def tearDown(self):
if not self.disabled:
self.delete_pool()
super(TestRBD, self).tearDown()
def create_pool(self):
from rados import Rados
with Rados(conffile=self.rbd_store_ceph_conf,
rados_id=self.rbd_store_user) as cluster:
cluster.create_pool(self.rbd_store_pool)
def delete_pool(self):
from rados import Rados
with Rados(conffile=self.rbd_store_ceph_conf,
rados_id=self.rbd_store_user) as cluster:
cluster.delete_pool(self.rbd_store_pool)
|