Beispiel #1
0
 def test_create_with_extended_args(self):
     ctx = context.TroveContext(user="******",
                                request_id="test_req_id",
                                limit="500",
                                marker="x")
     self.assertThat(ctx.limit, Equals("500"))
     self.assertThat(ctx.marker, Equals("x"))
 def setUp(self):
     super(TestBackupController, self).setUp()
     self.uuid = "d6338c9c-3cc8-4313-b98f-13cc0684cf15"
     self.invalid_uuid = "ead-edsa-e23-sdf-23"
     self.controller = BackupController()
     self.context = context.TroveContext(project_id=str(uuid.uuid4()))
     util.init_db()
Beispiel #3
0
 def test_create(self):
     ctx = context.TroveContext(user='******',
                                request_id='test_req_id')
     self.assertThat(ctx.user, Equals('test_user_id'))
     self.assertThat(ctx.request_id, Equals('test_req_id'))
     self.assertThat(ctx.limit, Is(None))
     self.assertThat(ctx.marker, Is(None))
Beispiel #4
0
 def process_request(self, request):
     service_catalog = None
     catalog_header = request.headers.get('X-Service-Catalog', None)
     if catalog_header:
         try:
             service_catalog = jsonutils.loads(catalog_header)
         except ValueError:
             raise webob.exc.HTTPInternalServerError(
                 _('Invalid service catalog json.'))
     tenant_id = request.headers.get('X-Tenant-Id', None)
     auth_token = request.headers["X-Auth-Token"]
     user_id = request.headers.get('X-User-ID', None)
     roles = request.headers.get('X-Role', '').split(',')
     is_admin = False
     for role in roles:
         if role.lower() in self.admin_roles:
             is_admin = True
             break
     limits = self._extract_limits(request.params)
     context = rd_context.TroveContext(auth_token=auth_token,
                                       tenant=tenant_id,
                                       user=user_id,
                                       is_admin=is_admin,
                                       limit=limits.get('limit'),
                                       marker=limits.get('marker'),
                                       service_catalog=service_catalog,
                                       roles=roles)
     request.environ[CONTEXT_KEY] = context
Beispiel #5
0
    def setUp(self, *args):
        super(GuestAgentOracleReplicationTest, self).setUp()
        self.context = context.TroveContext()
        self.patch_datastore_manager('oracle')

        # Mock out the Oracle driver cx_Oracle before importing
        # the guestagent functionality
        mock_cx_oracle = mock.MagicMock()
        mock_cx_oracle.SYSDBA = 0
        mock_cx_oracle.PRELIM_AUTH = 1
        self.oracle_patch = mock.patch.dict('sys.modules',
                                            {'cx_Oracle': mock_cx_oracle})
        self.addCleanup(self.oracle_patch.stop)
        self.oracle_patch.start()
        import trove.guestagent.datastore.oracle.service as service_module
        self.service_module = service_module
        self.dbname = 'testdb'
        with mock.patch.object(self.service_module,
                               'OracleVMConfig') as mock_conf:
            mock_conf().db_name = self.dbname
            self.service = self.service_module.OracleVMApp(
                self.service_module.OracleVMAppStatus())

        from trove.guestagent.strategies.replication import oracle_sync
        self.replication_module = oracle_sync
        self.replication = self.replication_module.OracleSyncReplication()

        self.cursor = mock.MagicMock()
 def setUp(self, *args):
     super(ApiTest, self).setUp()
     self.context = context.TroveContext()
     self.guest = VerticaGuestAgentAPI(self.context, 0)
     self.guest._call = _mock_call
     self.api = VerticaGuestAgentAPI(self.context, "instance-id-x23d2d")
     self._mock_rpc_client()
Beispiel #7
0
    def report_root(self, user):
        """Use conductor to update the root-enable status."""
        LOG.debug("Casting report_root message to conductor.")
        ctxt = context.TroveContext(user=CONF.nova_proxy_admin_user,
                                    auth_token=CONF.nova_proxy_admin_pass)

        conductor_api.API(ctxt).report_root(CONF.guest_id, user)
        LOG.debug("Successfully cast report_root.")
Beispiel #8
0
 def setUp(self):
     super(VerticaTaskManagerAPITest, self).setUp()
     self.context = context.TroveContext()
     self.api = task_api(self.context)
     self.call_context = trove_testtools.TroveTestContext(self)
     self.api.client.prepare = Mock(return_value=self.call_context)
     self.call_context.cast = Mock()
     self.rpc_api_version = '1.0'
Beispiel #9
0
 def setUp(self):
     super(ApiTest, self).setUp()
     self.context = context.TroveContext()
     self.guest = api.API(self.context, 0)
     self.guest._cast = _mock_call_pwd_change
     self.guest._call = _mock_call
     self.FAKE_ID = 'instance-id-x23d2d'
     self.api = api.API(self.context, self.FAKE_ID)
Beispiel #10
0
 def setUp(self, *args):
     super(ApiTest, self).setUp()
     self.context = context.TroveContext()
     self.guest = api.API(self.context, 0)
     self.guest._cast = _mock_call_pwd_change
     self.guest._call = _mock_call
     self.api = api.API(self.context, "instance-id-x23d2d")
     self._mock_rpc_client()
 def setUp(self, *args):
     super(ApiTest, self).setUp()
     cluster_guest_api = (GaleraCommonGuestAgentStrategy()
                          .guest_client_class)
     self.context = context.TroveContext()
     self.guest = cluster_guest_api(self.context, 0)
     self.guest._call = _mock_call
     self.api = cluster_guest_api(self.context, "instance-id-x23d2d")
     self._mock_rpc_client()
Beispiel #12
0
    def setUp(self, mock_get_encryption_key, *args):
        super(ApiTest, self).setUp()
        self.context = context.TroveContext()
        self.guest = VerticaGuestAgentAPI(self.context, 0)

        self.guest._call = _mock_call
        self.api = VerticaGuestAgentAPI(self.context, "instance-id-x23d2d")
        self._mock_rpc_client()
        mock_get_encryption_key.assert_called()
Beispiel #13
0
 def test_create_with_extended_args(self):
     expected_service_catalog = {'key': 'value'}
     ctx = context.TroveContext(user="******",
                                request_id="test_req_id",
                                limit="500",
                                marker="x",
                                service_catalog=expected_service_catalog)
     self.assertThat(ctx.limit, Equals("500"))
     self.assertThat(ctx.marker, Equals("x"))
     self.assertThat(ctx.service_catalog, Equals(expected_service_catalog))
    def setUp(self, _):
        super(GuestAgentMongoDBClusterManagerTest, self).setUp()
        self.context = context.TroveContext()
        self.manager = manager.Manager()
        self.manager.app.configuration_manager = mock.MagicMock()
        self.manager.app.status = mock.MagicMock()
        self.conf_mgr = self.manager.app.configuration_manager

        self.pymongo_patch = mock.patch.object(pymongo, 'MongoClient')
        self.addCleanup(self.pymongo_patch.stop)
        self.pymongo_patch.start()
Beispiel #15
0
    def set_status(self, status):
        """Use conductor to update the DB app status."""
        LOG.debug("Casting set_status message to conductor.")
        ctxt = context.TroveContext(user=CONF.nova_proxy_admin_user,
                                    auth_token=CONF.nova_proxy_admin_pass)

        heartbeat = {
            'service_status': status.description,
        }
        conductor_api.API(ctxt).heartbeat(CONF.guest_id, heartbeat)
        LOG.debug("Successfully cast set_status.")
        self.status = status
Beispiel #16
0
    def set_status(self, status):
        """Use conductor to update the DB app status."""
        LOG.debug("Casting set_status message to conductor.")
        context = trove_context.TroveContext()

        heartbeat = {
            'service_status': status.description,
        }
        conductor_api.API(context).heartbeat(CONF.guest_id,
                                             heartbeat,
                                             sent=timeutils.float_utcnow())
        LOG.debug("Successfully cast set_status.")
        self.status = status
Beispiel #17
0
 def test_to_dict_with_notification(self):
     ctx = context.TroveContext(user='******',
                                tenant='the_tenant',
                                request_id='test_req_id')
     ctx.notification = DBaaSInstanceCreate(ctx, request=Mock())
     ctx_dict = ctx.to_dict()
     self.assertThat(ctx_dict.get('user'), Equals('test_user_id'))
     self.assertThat(ctx_dict.get('request_id'), Equals('test_req_id'))
     self.assertTrue('trove_notification' in ctx_dict)
     n_dict = ctx_dict['trove_notification']
     self.assertThat(
         n_dict.get('notification_classname'),
         Equals('trove.common.notification.'
                'DBaaSInstanceCreate'))
Beispiel #18
0
    def set_status(self, status, force=False):
        """Use conductor to update the DB app status."""

        if force or self.is_installed:
            LOG.debug("Casting set_status message to conductor "
                      "(status is '%s')." % status.description)
            context = trove_context.TroveContext()

            heartbeat = {'service_status': status.description}
            conductor_api.API(context).heartbeat(
                CONF.guest_id, heartbeat, sent=timeutils.float_utcnow())
            LOG.debug("Successfully cast set_status.")
            self.status = status
        else:
            LOG.debug("Prepare has not completed yet, skipping heartbeat.")
Beispiel #19
0
    def setUp(self, _):
        super(GuestAgentMongoDBManagerTest, self).setUp()
        self.context = context.TroveContext()
        self.manager = manager.Manager()

        self.execute_with_timeout_patch = mock.patch.object(
            utils, 'execute_with_timeout')
        self.addCleanup(self.execute_with_timeout_patch.stop)
        self.execute_with_timeout_patch.start()

        self.pymongo_patch = mock.patch.object(pymongo, 'MongoClient')
        self.addCleanup(self.pymongo_patch.stop)
        self.pymongo_patch.start()

        self.mount_point = '/var/lib/mongodb'
Beispiel #20
0
    def setUp(self):
        super(GuestAgentManagerTest, self).setUp()
        self.context = context.TroveContext()

        # Mock out the Oracle driver cx_Oracle before importing
        # the guestagent functionality
        self.oracle_patch = mock.patch.dict('sys.modules',
                                            {'cx_Oracle': mock.Mock()})
        self.addCleanup(self.oracle_patch.stop)
        self.oracle_patch.start()
        import trove.guestagent.datastore.oracle_ra.manager as manager
        import trove.guestagent.datastore.oracle_ra.service as dbaas
        self.manager = manager.Manager()
        self.dbaas = dbaas

        self.LocalOracleClient = self.dbaas.LocalOracleClient
        self.dbaas.LocalOracleClient = mock.MagicMock()
Beispiel #21
0
 def process_request(self, request):
     tenant_id = request.headers.get('X-Tenant-Id', None)
     auth_token = request.headers["X-Auth-Token"]
     user = request.headers.get('X-User', None)
     roles = request.headers.get('X-Role', '').split(',')
     is_admin = False
     for role in roles:
         if role.lower() in self.admin_roles:
             is_admin = True
             break
     limits = self._extract_limits(request.params)
     context = rd_context.TroveContext(auth_token=auth_token,
                                       tenant=tenant_id,
                                       user=user,
                                       is_admin=is_admin,
                                       limit=limits.get('limit'),
                                       marker=limits.get('marker'))
     request.environ[CONTEXT_KEY] = context
Beispiel #22
0
    def setUp(self):
        super(GuestAgentOracleManagerTest, self).setUp()
        self.context = context.TroveContext()

        # Mock out the Oracle driver cx_Oracle before importing
        # the guestagent functionality
        self.oracle_patch = mock.patch.dict('sys.modules',
                                            {'cx_Oracle': mock.Mock()})
        self.addCleanup(self.oracle_patch.stop)
        self.oracle_patch.start()
        self.patch_datastore_manager('oracle')
        import trove.guestagent.datastore.oracle.manager as manager_module
        self.manager_module = manager_module
        self.manager = self.manager_module.Manager()
        self.manager._oracle_app = mock.MagicMock()

        self.mount_point = '/u01/app/oracle/oradata'
        self.test_instance_name = 'ora1'
        self.patch_conf_property('guest_name', self.test_instance_name)
Beispiel #23
0
    def setUp(self):
        super(GuestAgentOracleRestoreTest, self).setUp()
        self.context = context.TroveContext()
        self.patch_datastore_manager('oracle')

        # Mock out the Oracle driver cx_Oracle before importing
        # the guestagent functionality
        self.oracle_patch = mock.patch.dict('sys.modules',
                                            {'cx_Oracle': mock.Mock()})
        self.addCleanup(self.oracle_patch.stop)
        self.oracle_patch.start()
        import trove.guestagent.datastore.oracle.service as service_module
        self.service_module = service_module
        import trove.guestagent.strategies.restore.oracle_impl as restore_module
        self.restore_module = restore_module

        self.backup_id = 'testbackup'
        self.dbname = 'testdb'
        self.admin = 'os_admin'
        self.password = '******'
Beispiel #24
0
    def set_status(self, status, force=False):
        """Use conductor to update the DB app status."""
        force_heartbeat_status = (
            status == instance.ServiceStatuses.FAILED or
            status == instance.ServiceStatuses.BUILD_PENDING)

        if (not force_heartbeat_status and not force and
                (self.status == instance.ServiceStatuses.NEW or
                 self.status == instance.ServiceStatuses.BUILDING)):
            LOG.debug("Prepare has not run yet, skipping heartbeat.")
            return

        LOG.debug("Casting set_status message to conductor (status is '%s')." %
                  status.description)
        context = trove_context.TroveContext()

        heartbeat = {
            'service_status': status.description,
        }
        conductor_api.API(context).heartbeat(CONF.guest_id,
                                             heartbeat,
                                             sent=timeutils.float_utcnow())
        LOG.debug("Successfully cast set_status.")
        self.status = status
Beispiel #25
0
    def stream_backup_to_storage(self,
                                 backup_info,
                                 runner,
                                 storage,
                                 parent_metadata={},
                                 extra_opts=EXTRA_OPTS):
        backup_id = backup_info['id']
        ctxt = trove_context.TroveContext(
            user=CONF.nova_proxy_admin_user,
            auth_token=CONF.nova_proxy_admin_pass)
        conductor = conductor_api.API(ctxt)

        # Store the size of the filesystem before the backup.
        mount_point = CONFIG_MANAGER.mount_point
        stats = get_filesystem_volume_stats(mount_point)
        backup_state = {
            'backup_id': backup_id,
            'size': stats.get('used', 0.0),
            'state': BackupState.BUILDING,
        }
        conductor.update_backup(CONF.guest_id,
                                sent=timeutils.float_utcnow(),
                                **backup_state)
        LOG.debug("Updated state for %s to %s.", backup_id, backup_state)

        with runner(filename=backup_id,
                    extra_opts=extra_opts,
                    **parent_metadata) as bkup:
            try:
                LOG.debug("Starting backup %s.", backup_id)
                success, note, checksum, location = storage.save(
                    bkup.manifest, bkup)

                backup_state.update({
                    'checksum': checksum,
                    'location': location,
                    'note': note,
                    'success': success,
                    'backup_type': bkup.backup_type,
                })

                LOG.debug(
                    "Backup %(backup_id)s completed status: "
                    "%(success)s.", backup_state)
                LOG.debug(
                    "Backup %(backup_id)s file swift checksum: "
                    "%(checksum)s.", backup_state)
                LOG.debug("Backup %(backup_id)s location: "
                          "%(location)s.", backup_state)

                if not success:
                    raise BackupError(note)

                meta = bkup.metadata()
                meta['datastore'] = backup_info['datastore']
                meta['datastore_version'] = backup_info['datastore_version']
                storage.save_metadata(location, meta)

                backup_state.update({'state': BackupState.COMPLETED})

                return meta

            except Exception:
                LOG.exception(
                    _("Error saving backup: %(backup_id)s.") % backup_state)
                backup_state.update({'state': BackupState.FAILED})
                raise
            finally:
                LOG.info(_("Completed backup %(backup_id)s.") % backup_state)
                conductor.update_backup(CONF.guest_id,
                                        sent=timeutils.float_utcnow(),
                                        **backup_state)
                LOG.debug("Updated state for %s to %s.", backup_id,
                          backup_state)
Beispiel #26
0
 def setUp(self):
     super(CastWithConsumerTest, self).setUp()
     self.context = context.TroveContext()
     self.api = api.API(self.context, 'instance-id-x23d2d')
Beispiel #27
0
 def setUp(self, *args):
     super(ApiTest, self).setUp()
     self.context = context.TroveContext()
     self.api = task_api.API(self.context)
     self._mock_rpc_client()
def _prep_conf(current_time):
    current_time = str(current_time)
    _context = context.TroveContext(tenant='TENANT-' + current_time)
    instance_id = 'INSTANCE-' + current_time
    return _context, instance_id
Beispiel #29
0
 def test_to_dict(self):
     ctx = context.TroveContext(user='******',
                                request_id='test_req_id')
     ctx_dict = ctx.to_dict()
     self.assertThat(ctx_dict.get('user'), Equals('test_user_id'))
     self.assertThat(ctx_dict.get('request_id'), Equals('test_req_id'))
Beispiel #30
0
    def setUp(self):
        trove_testtools.patch_notifier(self)
        self.context = context.TroveContext(project_id=self.random_uuid())

        super(TestBackupController, self).setUp()