コード例 #1
0
    def report_state(self):
        """Update the state of this service in the datastore."""
        ctxt = context.get_admin_context()
        zone = CONF.storage_availability_zone
        state_catalog = {}
        try:
            try:
                service_ref = db.service_get(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug(
                    _('The service database object disappeared, '
                      'Recreating it.'))
                self._create_service_ref(ctxt)
                service_ref = db.service_get(ctxt, self.service_id)

            state_catalog['report_count'] = service_ref['report_count'] + 1
            if zone != service_ref['availability_zone']:
                state_catalog['availability_zone'] = zone

            db.service_update(ctxt, self.service_id, state_catalog)

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_('Recovered model server connection!'))

        # TODO(vish): this should probably only catch connection errors
        except Exception:  # pylint: disable=W0702
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_('model server went away'))
コード例 #2
0
ファイル: service.py プロジェクト: estephany/cinder
    def report_state(self):
        """Update the state of this service in the datastore."""
        ctxt = context.get_admin_context()
        zone = CONF.storage_availability_zone
        state_catalog = {}
        try:
            try:
                service_ref = db.service_get(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug(_('The service database object disappeared, '
                            'Recreating it.'))
                self._create_service_ref(ctxt)
                service_ref = db.service_get(ctxt, self.service_id)

            state_catalog['report_count'] = service_ref['report_count'] + 1
            if zone != service_ref['availability_zone']:
                state_catalog['availability_zone'] = zone

            db.service_update(ctxt,
                              self.service_id, state_catalog)

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_('Recovered model server connection!'))

        # TODO(vish): this should probably only catch connection errors
        except Exception:  # pylint: disable=W0702
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_('model server went away'))
コード例 #3
0
ファイル: service.py プロジェクト: souvik-ray/cinder
    def report_state(self):
        """Update the state of this service in the datastore."""
        if not self.manager.is_working():
            # NOTE(dulek): If manager reports a problem we're not sending
            # heartbeats - to indicate that service is actually down.
            LOG.error(
                _LE('Manager for service %(binary)s %(host)s is '
                    'reporting problems, not sending heartbeat. '
                    'Service will appear "down".'), {
                        'binary': self.binary,
                        'host': self.host
                    })
            return

        ctxt = context.get_admin_context()
        zone = CONF.storage_availability_zone
        state_catalog = {}
        try:
            try:
                service_ref = db.service_get(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug('The service database object disappeared, '
                          'recreating it.')
                self._create_service_ref(ctxt)
                service_ref = db.service_get(ctxt, self.service_id)

            state_catalog['report_count'] = service_ref['report_count'] + 1
            if zone != service_ref['availability_zone']:
                state_catalog['availability_zone'] = zone

            db.service_update(ctxt, self.service_id, state_catalog)

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_LE('Recovered model server connection!'))

        except db_exc.DBConnectionError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('model server went away'))

        # NOTE(jsbryant) Other DB errors can happen in HA configurations.
        # such errors shouldn't kill this thread, so we handle them here.
        except db_exc.DBError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('DBError encountered: '))

        except Exception:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('Exception encountered: '))
コード例 #4
0
ファイル: service.py プロジェクト: rahul4-jain/cinder
    def report_state(self):
        """Update the state of this service in the datastore."""
        if not self.manager.is_working():
            # NOTE(dulek): If manager reports a problem we're not sending
            # heartbeats - to indicate that service is actually down.
            LOG.error(_LE('Manager for service %(binary)s %(host)s is '
                          'reporting problems, not sending heartbeat. '
                          'Service will appear "down".'),
                      {'binary': self.binary,
                       'host': self.host})
            return

        ctxt = context.get_admin_context()
        zone = CONF.storage_availability_zone
        state_catalog = {}
        try:
            try:
                service_ref = db.service_get(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug('The service database object disappeared, '
                          'recreating it.')
                self._create_service_ref(ctxt)
                service_ref = db.service_get(ctxt, self.service_id)

            state_catalog['report_count'] = service_ref['report_count'] + 1
            if zone != service_ref['availability_zone']:
                state_catalog['availability_zone'] = zone

            db.service_update(ctxt,
                              self.service_id, state_catalog)

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_LE('Recovered model server connection!'))

        except db_exc.DBConnectionError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('model server went away'))

        # NOTE(jsbryant) Other DB errors can happen in HA configurations.
        # such errors shouldn't kill this thread, so we handle them here.
        except db_exc.DBError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('DBError encountered: '))

        except Exception:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('Exception encountered: '))
コード例 #5
0
ファイル: test_db_api.py プロジェクト: AsherBond/cinder
    def test_service_destroy(self):
        service1 = self._create_service({})
        service2 = self._create_service({"host": "fake_host2"})

        db.service_destroy(self.ctxt, service1["id"])
        self.assertRaises(exception.ServiceNotFound, db.service_get, self.ctxt, service1["id"])
        self._assertEqualObjects(db.service_get(self.ctxt, service2["id"]), service2)
コード例 #6
0
ファイル: test_db_api.py プロジェクト: medlefsen/cinder
    def test_service_destroy(self):
        service1 = self._create_service({})
        service2 = self._create_service({'host': 'fake_host2'})

        db.service_destroy(self.ctxt, service1['id'])
        self.assertRaises(exception.ServiceNotFound, db.service_get, self.ctxt,
                          service1['id'])
        self._assertEqualObjects(db.service_get(self.ctxt, service2['id']),
                                 service2)
コード例 #7
0
ファイル: test_db_api.py プロジェクト: niuzhenguo/cinder
    def test_service_destroy(self):
        service1 = self._create_service({})
        service2 = self._create_service({'host': 'fake_host2'})

        db.service_destroy(self.ctxt, service1['id'])
        self.assertRaises(exception.ServiceNotFound,
                          db.service_get, self.ctxt, service1['id'])
        self._assertEqualObjects(db.service_get(self.ctxt, service2['id']),
                                 service2)
コード例 #8
0
ファイル: test_service.py プロジェクト: keiichishima/cinder
 def test_service_disabled_on_create_based_on_flag(self):
     self.flags(enable_new_services=False)
     host = "foo"
     binary = "cinder-fake"
     app = service.Service.create(host=host, binary=binary)
     app.start()
     app.stop()
     ref = db.service_get(context.get_admin_context(), app.service_id)
     db.service_destroy(context.get_admin_context(), app.service_id)
     self.assertTrue(ref["disabled"])
コード例 #9
0
ファイル: test_service.py プロジェクト: dims/cinder
 def test_service_enabled_on_create_based_on_flag(self):
     self.flags(enable_new_services=True)
     host = 'foo'
     binary = 'cinder-fake'
     app = service.Service.create(host=host, binary=binary)
     app.start()
     app.stop()
     ref = db.service_get(context.get_admin_context(), app.service_id)
     db.service_destroy(context.get_admin_context(), app.service_id)
     self.assertFalse(ref['disabled'])
コード例 #10
0
 def test_service_disabled_on_create_based_on_flag(self):
     self.flags(enable_new_services=False)
     host = 'foo'
     binary = 'cinder-fake'
     app = service.Service.create(host=host, binary=binary)
     app.start()
     app.stop()
     ref = db.service_get(context.get_admin_context(), app.service_id)
     db.service_destroy(context.get_admin_context(), app.service_id)
     self.assert_(ref['disabled'])
コード例 #11
0
ファイル: utils.py プロジェクト: ebalduf/cinder-backports
def create_service(ctxt, values=None):
    values = values or {}
    v = default_service_values()
    v.update(values)
    service = db.service_create(ctxt, v)
    # We need to read the contents from the DB if we have set updated_at
    # or created_at fields
    if 'updated_at' in values or 'created_at' in values:
        service = db.service_get(ctxt, service.id)
    return service
コード例 #12
0
ファイル: utils.py プロジェクト: homolkad/deb-cinder
def create_service(ctxt, values=None):
    values = values or {}
    v = default_service_values()
    v.update(values)
    service = db.service_create(ctxt, v)
    # We need to read the contents from the DB if we have set updated_at
    # or created_at fields
    if 'updated_at' in values or 'created_at' in values:
        service = db.service_get(ctxt, service.id)
    return service
コード例 #13
0
    def report_state(self):
        """Update the state of this service in the datastore."""
        ctxt = context.get_admin_context()
        zone = CONF.storage_availability_zone
        state_catalog = {}
        try:
            try:
                service_ref = db.service_get(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug('The service database object disappeared, '
                          'recreating it.')
                self._create_service_ref(ctxt)
                service_ref = db.service_get(ctxt, self.service_id)

            state_catalog['report_count'] = service_ref['report_count'] + 1
            if zone != service_ref['availability_zone']:
                state_catalog['availability_zone'] = zone

            db.service_update(ctxt, self.service_id, state_catalog)

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_LE('Recovered model server connection!'))

        except db_exc.DBConnectionError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('model server went away'))

        # NOTE(jsbryant) Other DB errors can happen in HA configurations.
        # such errors shouldn't kill this thread, so we handle them here.
        except db_exc.DBError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('DBError encountered: '))

        except Exception:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('Exception encountered: '))
コード例 #14
0
ファイル: test_db_api.py プロジェクト: niuzhenguo/cinder
 def test_service_update(self):
     service = self._create_service({})
     new_values = {
         'host': 'fake_host1',
         'binary': 'fake_binary1',
         'topic': 'fake_topic1',
         'report_count': 4,
         'disabled': True
     }
     db.service_update(self.ctxt, service['id'], new_values)
     updated_service = db.service_get(self.ctxt, service['id'])
     for key, value in new_values.iteritems():
         self.assertEqual(value, updated_service[key])
コード例 #15
0
ファイル: test_db_api.py プロジェクト: AsherBond/cinder
 def test_service_update(self):
     service = self._create_service({})
     new_values = {
         "host": "fake_host1",
         "binary": "fake_binary1",
         "topic": "fake_topic1",
         "report_count": 4,
         "disabled": True,
     }
     db.service_update(self.ctxt, service["id"], new_values)
     updated_service = db.service_get(self.ctxt, service["id"])
     for key, value in new_values.iteritems():
         self.assertEqual(value, updated_service[key])
コード例 #16
0
ファイル: test_db_api.py プロジェクト: medlefsen/cinder
 def test_service_update(self):
     service = self._create_service({})
     new_values = {
         'host': 'fake_host1',
         'binary': 'fake_binary1',
         'topic': 'fake_topic1',
         'report_count': 4,
         'disabled': True
     }
     db.service_update(self.ctxt, service['id'], new_values)
     updated_service = db.service_get(self.ctxt, service['id'])
     for key, value in new_values.iteritems():
         self.assertEqual(value, updated_service[key])
コード例 #17
0
ファイル: service.py プロジェクト: samsong8610/cinder
    def report_state(self):
        """Update the state of this service in the datastore."""
        if not self.manager.is_working():
            # NOTE(dulek): If manager reports a problem we're not sending
            # heartbeats - to indicate that service is actually down.
            LOG.error(_LE('Manager for service %s is reporting problems, skip '
                          'sending heartbeat. Service will appear "down".'),
                      self.binary)
            return

        ctxt = context.get_admin_context()
        zone = CONF.storage_availability_zone
        state_catalog = {}
        try:
            try:
                service_ref = db.service_get(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug('The service database object disappeared, '
                          'recreating it.')
                self._create_service_ref(ctxt)
                service_ref = db.service_get(ctxt, self.service_id)

            state_catalog['report_count'] = service_ref['report_count'] + 1
            if zone != service_ref['availability_zone']:
                state_catalog['availability_zone'] = zone

            db.service_update(ctxt,
                              self.service_id, state_catalog)

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_LE('Recovered model server connection!'))

        except db_exc.DBConnectionError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('model server went away'))
コード例 #18
0
ファイル: service.py プロジェクト: aishi1979/studyKilo
    def report_state(self):
        """Update the state of this service in the datastore."""
        ctxt = context.get_admin_context()
        zone = CONF.storage_availability_zone
        state_catalog = {}
        try:
            try:
                service_ref = db.service_get(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug('The service database object disappeared, '
                          'recreating it.')
                self._create_service_ref(ctxt)
                service_ref = db.service_get(ctxt, self.service_id)

            state_catalog['report_count'] = service_ref['report_count'] + 1
            if zone != service_ref['availability_zone']:
                state_catalog['availability_zone'] = zone

            db.service_update(ctxt,
                              self.service_id, state_catalog)

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_LE('Recovered model server connection!'))

        except db_exc.DBConnectionError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('model server went away'))

        # NOTE(jsbryant) Other DB errors can happen in HA configurations.
        # such errors shouldn't kill this thread, so we handle them here.
        except db_exc.DBError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('DBError encountered: '))
コード例 #19
0
ファイル: test_service.py プロジェクト: mahak/cinder
    def test_service_disabled_on_create_based_on_flag(self):
        ctxt = context.get_admin_context()
        self.flags(enable_new_services=False)
        host = 'foo'
        binary = 'cinder-fake'
        cluster = 'cluster'
        app = service.Service.create(host=host, binary=binary, cluster=cluster)
        ref = db.service_get(ctxt, app.service_id)
        db.service_destroy(ctxt, app.service_id)
        self.assertTrue(ref.disabled)

        # Check that the cluster is also enabled
        db_cluster = objects.ClusterList.get_all(ctxt)[0]
        self.assertTrue(db_cluster.disabled)
        db.cluster_destroy(ctxt, db_cluster.id)
コード例 #20
0
    def test_service_disabled_on_create_based_on_flag(self):
        ctxt = context.get_admin_context()
        self.flags(enable_new_services=False)
        host = 'foo'
        binary = 'cinder-fake'
        cluster = 'cluster'
        app = service.Service.create(host=host, binary=binary, cluster=cluster)
        ref = db.service_get(ctxt, app.service_id)
        db.service_destroy(ctxt, app.service_id)
        self.assertTrue(ref.disabled)

        # Check that the cluster is also enabled
        db_cluster = objects.ClusterList.get_all(ctxt)[0]
        self.assertTrue(db_cluster.disabled)
        db.cluster_destroy(ctxt, db_cluster.id)
コード例 #21
0
    def test_disabled_and_frozen_service(self):
        """Test that disabled and frozen services are updated correctly."""
        service_overrides = {'topic': 'cinder-volume',
                             'disabled': True,
                             'frozen': True,
                             'replication_status': 'failed-over',
                             'active_backend_id': 'seconary'}
        service = utils.create_service(self.ctxt, values=service_overrides)
        db.reset_active_backend(self.ctxt, True, 'fake-backend-id',
                                service.host)
        db_service = db.service_get(self.ctxt, service.id)

        self.assertFalse(db_service.disabled)
        self.assertEqual('', db_service.disabled_reason)
        self.assertIsNone(db_service.active_backend_id)
        self.assertEqual('enabled', db_service.replication_status)
コード例 #22
0
ファイル: test_db_api.py プロジェクト: AsherBond/cinder
 def test_service_get(self):
     service1 = self._create_service({})
     real_service1 = db.service_get(self.ctxt, service1["id"])
     self._assertEqualObjects(service1, real_service1)
コード例 #23
0
 def get_by_host_and_topic(cls, context, host, topic, disabled=False):
     db_service = db.service_get(context, disabled=disabled, host=host,
                                 topic=topic)
     return cls._from_db_object(context, cls(context), db_service)
コード例 #24
0
 def get_by_args(cls, context, host, binary_key):
     db_service = db.service_get(context, host=host, binary=binary_key)
     return cls._from_db_object(context, cls(context), db_service)
コード例 #25
0
 def get_by_id(cls, context, id):
     db_service = db.service_get(context, id)
     return cls._from_db_object(context, cls(context), db_service)
コード例 #26
0
ファイル: test_db_api.py プロジェクト: niuzhenguo/cinder
 def test_service_get(self):
     service1 = self._create_service({})
     service2 = self._create_service({'host': 'some_other_fake_host'})
     real_service1 = db.service_get(self.ctxt, service1['id'])
     self._assertEqualObjects(service1, real_service1)
コード例 #27
0
ファイル: service.py プロジェクト: sebrandon1/cinder
 def get_by_args(cls, context, host, binary_key):
     db_service = db.service_get(context, host=host, binary=binary_key)
     return cls._from_db_object(context, cls(context), db_service)
コード例 #28
0
ファイル: service.py プロジェクト: sebrandon1/cinder
 def get_by_host_and_topic(cls, context, host, topic):
     db_service = db.service_get(context, disabled=False, host=host, topic=topic)
     return cls._from_db_object(context, cls(context), db_service)
コード例 #29
0
ファイル: test_db_api.py プロジェクト: medlefsen/cinder
 def test_service_get(self):
     service1 = self._create_service({})
     service2 = self._create_service({'host': 'some_other_fake_host'})
     real_service1 = db.service_get(self.ctxt, service1['id'])
     self._assertEqualObjects(service1, real_service1)
コード例 #30
0
ファイル: test_db_api.py プロジェクト: dtroyer/cinder
 def test_service_get(self):
     service1 = self._create_service({})
     service2 = self._create_service({"host": "some_other_fake_host"})
     real_service1 = db.service_get(self.ctxt, service1["id"])
     self._assertEqualObjects(service1, real_service1)