Exemple #1
0
    def test_add_datasource_synchronizer_error(self, register_ds):
        register_ds.side_effect = Exception('Error in registering service')

        req = self._get_datasource_request()
        self.assertRaises(congressException.DatasourceCreationError,
                          self.ds_manager.add_datasource, req)
        ds = datasource_db.get_datasource_by_name(req['name'])
        self.assertIsNone(ds)
    def test_add_datasource_synchronizer_error(self, register_ds):
        register_ds.side_effect = Exception('Error in registering service')

        req = self._get_datasource_request()
        self.assertRaises(congressException.DatasourceCreationError,
                          self.dseNode.add_datasource, req)
        ds = datasource_db.get_datasource_by_name(req['name'])
        self.assertIsNone(ds)
 def test_get_datasource_by_name(self):
     id_ = uuidutils.generate_uuid()
     datasources.add_datasource(
         id_=id_, name="hiya", driver="foo", config="{user: foo}", description="hello", enabled=True
     )
     source = datasources.get_datasource_by_name("hiya")
     self.assertEqual(id_, source.id)
     self.assertEqual("hiya", source.name)
     self.assertEqual("foo", source.driver)
     self.assertEqual("hello", source.description)
     self.assertEqual('"{user: foo}"', source.config)
     self.assertTrue(source.enabled)
    def sync_one_policy_nonlocking(self,
                                   name,
                                   datasource=True,
                                   db_session=None):
        """Synchronize single policy with DB.

        :param name: policy name to be synchronized
        :param datasource: True, to sync a datasource policy

        """
        LOG.info("sync %s policy with DB", name)

        if datasource:
            policy_object = datasources.get_datasource_by_name(
                name, session=db_session)
            if policy_object is not None:
                if name not in self.engine.policy_names():
                    self._register_datasource_with_pe(name)
                return

        policy_object = db_policy_rules.get_policy_by_name(name,
                                                           session=db_session)
        if policy_object is None:
            if name in self.engine.policy_names():
                self.engine.delete_policy(name)
                LOG.info("policy %s deleted by synchronizer", name)
            return

        p = policy_object.to_dict()
        if name not in self.engine.policy_names():
            self.engine.create_policy(p['name'],
                                      id_=p['id'],
                                      abbr=p['abbreviation'],
                                      kind=p['kind'],
                                      desc=p['description'],
                                      owner=p['owner_id'])
            LOG.debug("policy %s added by synchronizer", name)

        elif p['id'] != self.engine.policy_object(name).id:
            # if same name but not identical attributes
            # replace by new policy obj according to DB
            self.engine.delete_policy(name)
            self.engine.create_policy(p['name'],
                                      id_=p['id'],
                                      abbr=p['abbreviation'],
                                      kind=p['kind'],
                                      desc=p['description'],
                                      owner=p['owner_id'])
            LOG.debug("synchronizer, policy replaced %s", name)
Exemple #5
0
 def test_get_datasource_by_name(self):
     id_ = uuidutils.generate_uuid()
     datasources.add_datasource(id_=id_,
                                name="hiya",
                                driver="foo",
                                config={'user': '******'},
                                description="hello",
                                enabled=True)
     source = datasources.get_datasource_by_name('hiya')
     self.assertEqual(id_, source.id)
     self.assertEqual("hiya", source.name)
     self.assertEqual("foo", source.driver)
     self.assertEqual("hello", source.description)
     self.assertEqual({'user': '******'}, json.loads(source.config))
     self.assertTrue(source.enabled)
Exemple #6
0
 def test_get_datasource_by_name(self):
     id_ = uuidutils.generate_uuid()
     datasources.add_datasource(id_=id_,
                                name="hiya",
                                driver="foo",
                                config='{user: foo}',
                                description="hello",
                                enabled=True)
     source = datasources.get_datasource_by_name('hiya')
     self.assertEqual(id_, source.id)
     self.assertEqual("hiya", source.name)
     self.assertEqual("foo", source.driver)
     self.assertEqual("hello", source.description)
     self.assertEqual('"{user: foo}"', source.config)
     self.assertEqual(True, source.enabled)
 def test_get_datasource_by_name(self):
     id_ = uuidutils.generate_uuid()
     datasources.add_datasource(
         id_=id_,
         name="hiya",
         driver="foo",
         config={'user': '******'},
         description="hello",
         enabled=True)
     source = datasources.get_datasource_by_name('hiya')
     self.assertEqual(id_, source.id)
     self.assertEqual("hiya", source.name)
     self.assertEqual("foo", source.driver)
     self.assertEqual("hello", source.description)
     self.assertEqual({'user': '******'}, json.loads(source.config))
     self.assertTrue(source.enabled)
    def sync_datasource(self, ds_name):
        if not cfg.CONF.datasources:
            LOG.info("sync not supported on non-datasource node")
            return
        datasource = datasources.get_datasource_by_name(ds_name)
        service_obj = self.node.service_object(ds_name)

        if datasource and not service_obj:
            # register service with data node
            service = self.node.create_datasource_service(datasource)
            self.node.register_service(service)
            LOG.debug("service %s registered by synchronizer", ds_name)
            return
        if service_obj and datasource is None:
            # unregister, datasource not present in DB
            self.node.unregister_service(ds_name)
            LOG.debug("service %s unregistered by synchronizer", ds_name)
            return
    def sync_datasource(self, ds_name):
        if not cfg.CONF.datasources:
            LOG.info("sync not supported on non-datasource node")
            return
        datasource = datasources.get_datasource_by_name(ds_name)
        service_obj = self.node.service_object(ds_name)

        if datasource and not service_obj:
            # register service with data node
            service = self.node.create_datasource_service(datasource)
            self.node.register_service(service)
            LOG.debug("service %s registered by synchronizer", ds_name)
            return
        if service_obj and datasource is None:
            # unregister, datasource not present in DB
            self.node.unregister_service(ds_name)
            LOG.debug("service %s unregistered by synchronizer", ds_name)
            return
    def sync_one_policy_nonlocking(
            self, name, datasource=True, db_session=None):
        """Synchronize single policy with DB.

        :param: name: policy name to be synchronized
        :param: datasource: True, to sync a datasource policy

        """
        LOG.info("sync %s policy with DB", name)

        if datasource:
            policy_object = datasources.get_datasource_by_name(
                name, session=db_session)
            if policy_object is not None:
                if name not in self.engine.policy_names():
                    self._register_datasource_with_pe(name)
                return

        policy_object = db_policy_rules.get_policy_by_name(
            name, session=db_session)
        if policy_object is None:
            if name in self.engine.policy_names():
                self.engine.delete_policy(name)
                LOG.info("policy %s deleted by synchronizer", name)
            return

        p = policy_object.to_dict()
        if name not in self.engine.policy_names():
            self.engine.create_policy(
                p['name'], id_=p['id'], abbr=p['abbreviation'],
                kind=p['kind'], desc=p['description'],
                owner=p['owner_id'])
            LOG.debug("policy %s added by synchronizer", name)

        elif p['id'] != self.engine.policy_object(name).id:
            # if same name but not identical attributes
            # replace by new policy obj according to DB
            self.engine.delete_policy(name)
            self.engine.create_policy(
                p['name'], id_=p['id'], abbr=p['abbreviation'],
                kind=p['kind'], desc=p['description'],
                owner=p['owner_id'])
            LOG.debug("synchronizer, policy replaced %s", name)