Esempio n. 1
0
    def setUp(self):
        super(TpoolDbapiWrapperTestCase, self).setUp()
        self.db_api = concurrency.TpoolDbapiWrapper(
            conf=self.conf, backend_mapping=FAKE_BACKEND_MAPPING)

        # NOTE(akurilin): We are not  going to add `eventlet` to `oslo_db` in
        # requirements (`requirements.txt` and `test-requirements.txt`) due to
        # the following reasons:
        #  - supporting of eventlet's thread pooling is totally optional;
        #  - we don't need to test `tpool.Proxy` functionality itself,
        #    because it's a tool from the third party library;
        #  - `eventlet` would prevent us from running unit tests on Python 3.x
        #    versions, because it doesn't support them yet.
        #
        # As we don't test `tpool.Proxy`, we can safely mock it in tests.

        self.proxy = mock.MagicMock()
        self.eventlet = mock.MagicMock()
        self.eventlet.tpool.Proxy.return_value = self.proxy
        sys.modules['eventlet'] = self.eventlet
        self.addCleanup(sys.modules.pop, 'eventlet', None)
Esempio n. 2
0
    cfg.StrOpt('snapshot_name_template',
               default='snapshot-%s',
               help='Template string to be used to generate snapshot names'),
    cfg.StrOpt('backup_name_template',
               default='backup-%s',
               help='Template string to be used to generate backup names'),
]

CONF = cfg.CONF
CONF.register_opts(db_opts)
db_options.set_defaults(CONF)
CONF.set_default('sqlite_db', 'cinder.sqlite', group='database')

_BACKEND_MAPPING = {'sqlalchemy': 'cinder.db.sqlalchemy.api'}

IMPL = db_concurrency.TpoolDbapiWrapper(CONF, _BACKEND_MAPPING)

# The maximum value a signed INT type may have
MAX_INT = 0x7FFFFFFF

###################


def dispose_engine():
    """Force the engine to establish new connections."""

    # FIXME(jdg): When using sqlite if we do the dispose
    # we seem to lose our DB here.  Adding this check
    # means we don't do the dispose, but we keep our sqlite DB
    # This likely isn't the best way to handle this
Esempio n. 3
0
#    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.
"""
Defines interface for DB access.
"""

from oslo_config import cfg
from oslo_db import concurrency as db_concurrency

CONF = cfg.CONF

_BACKEND_MAPPING = {'sqlalchemy': 'terracotta.db.sqlalchemy.api'}

IMPL = db_concurrency.TpoolDbapiWrapper(CONF, backend_mapping=_BACKEND_MAPPING)


def select_cpu_mhz_for_vm(uuid, limit):
    """Select n last values of CPU MHz for a VM UUID.

    :param uuid: The UUID of a VM.
    :param limit: The number of last values to select.
    :return: The list of n last CPU Mhz values.
    """
    return IMPL.select_cpu_mhz_for_vm(uuid, limit)


def select_last_cpu_mhz_for_vms():
    """Select the last value of CPU MHz for all the VMs.