Esempio n. 1
0
 def test_restore_decrypted_xtrabackup_command(self):
     restoreBase.RestoreRunner.is_zipped = True
     restoreBase.RestoreRunner.is_encrypted = False
     RunnerClass = utils.import_class(RESTORE_XTRA_CLS)
     restr = RunnerClass(None, restore_location="/var/lib/mysql")
     self.assertEqual(restr.restore_cmd, UNZIP + PIPE + XTRA_RESTORE)
     self.assertEqual(restr.prepare_cmd, PREPARE)
Esempio n. 2
0
 def test_backup_decrypted_mysqldump_command(self):
     backupBase.BackupRunner.is_zipped = True
     backupBase.BackupRunner.is_encrypted = False
     RunnerClass = utils.import_class(BACKUP_SQLDUMP_CLS)
     bkup = RunnerClass(12345, user="******", password="******")
     self.assertEqual(bkup.command, SQLDUMP_BACKUP + PIPE + ZIP)
     self.assertEqual(bkup.manifest, "12345.gz")
Esempio n. 3
0
 def test_restore_decrypted_mysqldump_command(self):
     restoreBase.RestoreRunner.is_zipped = True
     restoreBase.RestoreRunner.is_encrypted = False
     RunnerClass = utils.import_class(RESTORE_SQLDUMP_CLS)
     restr = RunnerClass(None, restore_location="/var/lib/mysql",
                         user="******", password="******")
     self.assertEqual(restr.restore_cmd, UNZIP + PIPE + SQLDUMP_RESTORE)
     self.assertIsNone(restr.prepare_cmd)
Esempio n. 4
0
 def test_backup_encrypted_xtrabackup_command(self):
     backupBase.BackupRunner.is_zipped = True
     backupBase.BackupRunner.is_encrypted = True
     backupBase.BackupRunner.encrypt_key = CRYPTO_KEY
     RunnerClass = utils.import_class(BACKUP_XTRA_CLS)
     bkup = RunnerClass(12345, user="******", password="******")
     self.assertEqual(bkup.command,
                      XTRA_BACKUP + PIPE + ZIP + PIPE + ENCRYPT)
     self.assertEqual(bkup.manifest, "12345.xbstream.gz.enc")
Esempio n. 5
0
    def get_strategy(cls, name, ns=None):
        """
        Load a strategy from namespace
        """
        ns = ns or cls.__strategy_ns__
        if ns is None:
            raise RuntimeError("No namespace provided or __strategy_ns__ unset")

        LOG.debug("Looking for strategy %s in %s", name, ns)

        return utils.import_class(ns + "." + name)
Esempio n. 6
0
    def get_strategy(cls, name, ns=None):
        """
        Load a strategy from namespace
        """
        ns = ns or cls.__strategy_ns__
        if ns is None:
            raise RuntimeError(
                'No namespace provided or __strategy_ns__ unset')

        LOG.debug('Looking for strategy %s in %s', name, ns)

        return utils.import_class(ns + "." + name)
Esempio n. 7
0
 def __init__(self, host, binary, topic, manager, report_interval=None,
              periodic_interval=None, *args, **kwargs):
     self.host = host
     self.binary = binary
     self.topic = topic
     self.manager_class_name = manager
     manager_class = utils.import_class(self.manager_class_name)
     self.manager = manager_class(host=self.host, *args, **kwargs)
     self.report_interval = report_interval
     self.periodic_interval = periodic_interval
     super(Service, self).__init__(*args, **kwargs)
     self.saved_args, self.saved_kwargs = args, kwargs
     self.timers = []
Esempio n. 8
0
 def __init__(self, host, binary, topic, manager, report_interval=None,
              periodic_interval=None, *args, **kwargs):
     if not host:
         host = socket.gethostname()
     self.host = host
     self.binary = binary
     self.topic = topic
     self.manager_class_name = manager
     manager_class = utils.import_class(self.manager_class_name)
     self.manager = manager_class(host=self.host, *args, **kwargs)
     self.report_interval = report_interval
     self.periodic_interval = periodic_interval
     super(Service, self).__init__(*args, **kwargs)
     self.saved_args, self.saved_kwargs = args, kwargs
     self.timers = []
Esempio n. 9
0
 def create_guest_driver(self, service_impl):
     guest_drivers = [service_impl, 'reddwarf.guestagent.pkg.PkgAgent']
     classes = []
     for guest_driver in guest_drivers:
         LOG.info(guest_driver)
         driver = utils.import_class(guest_driver)
         classes.append(driver)
     try:
         cls = type("GuestDriver", tuple(set(classes)), {})
         self.driver = cls()
     except TypeError as te:
         msg = "An issue occurred instantiating the GuestDriver as the " \
               "following classes: " + str(classes) + \
               " Exception=" + str(te)
         raise TypeError(msg)
Esempio n. 10
0
 def create_guest_driver(self, service_impl):
     guest_drivers = [service_impl,
                      'reddwarf.guestagent.pkg.PkgAgent']
     classes = []
     for guest_driver in guest_drivers:
         LOG.info(guest_driver)
         driver = utils.import_class(guest_driver)
         classes.append(driver)
     try:
         cls = type("GuestDriver", tuple(set(classes)), {})
         self.driver = cls()
     except TypeError as te:
         msg = "An issue occurred instantiating the GuestDriver as the " \
               "following classes: " + str(classes) + \
               " Exception=" + str(te)
         raise TypeError(msg)
Esempio n. 11
0
#    under the License.
#

import logging
from reddwarf.backup.models import DBBackup, BackupState
from reddwarf.common import cfg
from reddwarf.common import utils
from reddwarf.guestagent.dbaas import ADMIN_USER_NAME
from reddwarf.guestagent.dbaas import get_auth_password
from reddwarf.guestagent.backup.runner import BackupError
from reddwarf.common.remote import create_swift_client

LOG = logging.getLogger(__name__)
CONF = cfg.CONF

RUNNER = utils.import_class(CONF.backup_runner)
BACKUP_CONTAINER = CONF.backup_swift_container


class BackupAgent(object):

    def execute_backup(self, context, backup_id, runner=RUNNER):
        LOG.debug("Searching for backup instance %s", backup_id)
        backup = DBBackup.find_by(id=backup_id)
        LOG.info("Setting task state to %s for instance %s",
                 BackupState.NEW, backup.instance_id)
        backup.state(BackupState.NEW)
        backup.save()

        LOG.info("Running backup %s", backup_id)
        user = ADMIN_USER_NAME
Esempio n. 12
0
def create_dbaas_client(user):
    """Creates a rich client for the RedDwarf API using the test config."""
    auth_strategy = None

    kwargs = {
        'service_type': 'database',
        'insecure': test_config.values['reddwarf_client_insecure'],
    }

    def set_optional(kwargs_name, test_conf_name):
        value = test_config.values.get(test_conf_name, None)
        if value is not None:
            kwargs[kwargs_name] = value
    force_url = 'override_reddwarf_api_url' in test_config.values

    service_url = test_config.get('override_reddwarf_api_url', None)
    if user.requirements.is_admin:
        service_url = test_config.get('override_admin_reddwarf_api_url',
                                      service_url)
    if service_url:
        kwargs['service_url'] = service_url

    auth_strategy = None
    if user.requirements.is_admin:
        auth_strategy = test_config.get('admin_auth_strategy',
                                        test_config.auth_strategy)
    else:
        auth_strategy = test_config.auth_strategy
    set_optional('region_name', 'reddwarf_client_region_name')
    if test_config.values.get('override_reddwarf_api_url_append_tenant',
                              False):
        kwargs['service_url'] += "/" + user.tenant

    if auth_strategy == 'fake':
        from reddwarfclient import auth

        class FakeAuth(auth.Authenticator):

            def authenticate(self):
                class FakeCatalog(object):
                    def __init__(self, auth):
                        self.auth = auth

                    def get_public_url(self):
                        return "%s/%s" % (test_config.dbaas_url,
                                          self.auth.tenant)

                    def get_token(self):
                        return self.auth.tenant

                return FakeCatalog(self)

        auth_strategy = FakeAuth

    if auth_strategy:
        kwargs['auth_strategy'] = auth_strategy

    if not user.requirements.is_admin:
        auth_url = test_config.reddwarf_auth_url
    else:
        auth_url = test_config.values.get('reddwarf_admin_auth_url',
                                          test_config.reddwarf_auth_url)

    if test_config.values.get('reddwarf_client_cls'):
        cls_name = test_config.reddwarf_client_cls
        kwargs['client_cls'] = import_class(cls_name)

    dbaas = Dbaas(user.auth_user, user.auth_key, tenant=user.tenant,
                  auth_url=auth_url, **kwargs)
    dbaas.authenticate()
    with Check() as check:
        check.is_not_none(dbaas.client.auth_token, "Auth token not set!")
        if not force_url and user.requirements.is_admin:
            expected_prefix = test_config.dbaas_url
            actual = dbaas.client.service_url
            msg = "Dbaas management url was expected to start with %s, but " \
                  "was %s." % (expected_prefix, actual)
            check.true(actual.startswith(expected_prefix), msg)
    return TestClient(dbaas)
Esempio n. 13
0
def create_dbaas_client(user):
    """Creates a rich client for the RedDwarf API using the test config."""
    auth_strategy = None

    kwargs = {
        'service_type': 'database',
        'insecure': test_config.values['reddwarf_client_insecure'],
    }

    def set_optional(kwargs_name, test_conf_name):
        value = test_config.values.get(test_conf_name, None)
        if value is not None:
            kwargs[kwargs_name] = value

    force_url = 'override_reddwarf_api_url' in test_config.values

    service_url = test_config.get('override_reddwarf_api_url', None)
    if user.requirements.is_admin:
        service_url = test_config.get('override_admin_reddwarf_api_url',
                                      service_url)
    if service_url:
        kwargs['service_url'] = service_url

    auth_strategy = None
    if user.requirements.is_admin:
        auth_strategy = test_config.get('admin_auth_strategy',
                                        test_config.auth_strategy)
    else:
        auth_strategy = test_config.auth_strategy
    set_optional('region_name', 'reddwarf_client_region_name')
    if test_config.values.get('override_reddwarf_api_url_append_tenant',
                              False):
        kwargs['service_url'] += "/" + user.tenant

    if auth_strategy == 'fake':
        from reddwarfclient import auth

        class FakeAuth(auth.Authenticator):
            def authenticate(self):
                class FakeCatalog(object):
                    def __init__(self, auth):
                        self.auth = auth

                    def get_public_url(self):
                        return "%s/%s" % (test_config.dbaas_url,
                                          self.auth.tenant)

                    def get_token(self):
                        return self.auth.tenant

                return FakeCatalog(self)

        auth_strategy = FakeAuth

    if auth_strategy:
        kwargs['auth_strategy'] = auth_strategy

    if not user.requirements.is_admin:
        auth_url = test_config.reddwarf_auth_url
    else:
        auth_url = test_config.values.get('reddwarf_admin_auth_url',
                                          test_config.reddwarf_auth_url)

    if test_config.values.get('reddwarf_client_cls'):
        cls_name = test_config.reddwarf_client_cls
        kwargs['client_cls'] = import_class(cls_name)

    dbaas = Dbaas(user.auth_user,
                  user.auth_key,
                  tenant=user.tenant,
                  auth_url=auth_url,
                  **kwargs)
    dbaas.authenticate()
    with Check() as check:
        check.is_not_none(dbaas.client.auth_token, "Auth token not set!")
        if not force_url and user.requirements.is_admin:
            expected_prefix = test_config.dbaas_url
            actual = dbaas.client.service_url
            msg = "Dbaas management url was expected to start with %s, but " \
                  "was %s." % (expected_prefix, actual)
            check.true(actual.startswith(expected_prefix), msg)
    return TestClient(dbaas)