Example #1
0
    def test_get_broker_metadata_by_broker_id(self):
        """Tests get broker_metadata by broker_id from BrokerMetadata objects

         API.
         """
        new_broker = objects.Broker(**func_utils.get_test_broker_dict())
        new_broker.create_broker(self.context)
        broker_metadata_1 = self.create_object_broker_metadata(
            broker_id=new_broker.id)
        broker_metadata_2 = self.create_object_broker_metadata(
            broker_id=new_broker.id,
            id='a2dcf598-ef5d-11e4-90ec-1681e6b88ec1',
            key='SEC_GROUP',
            value='test')

        metadata_list = (
            objects.BrokerMetadata.get_broker_metadata_by_broker_id(
                self.context, new_broker.id))
        # check for the list length
        self.assertEqual(2, len(metadata_list), "Invalid number of "
                         "broker_metadata returned")
        for metadata in metadata_list:
            if metadata.id == broker_metadata_1.id:
                self.validate_broker_metadata_values(broker_metadata_1,
                                                     metadata)
            else:
                self.validate_broker_metadata_values(broker_metadata_2,
                                                     metadata)
    def test_create_broker(self):
        """Tests create broker from Broker objects API."""
        test_broker_dict = func_utils.get_test_broker_dict()
        new_broker = objects.Broker(**test_broker_dict)
        self.validate_broker_values(new_broker, test_broker_dict)
        retrieved_broker = new_broker.create_broker(self.context)

        self.validate_broker_values(new_broker, retrieved_broker)
Example #3
0
    def test_delete_broker_metadata(self):
        """Tests delete broker_metadata from BrokerMetadata objects API."""
        new_broker = objects.Broker(**func_utils.get_test_broker_dict())
        new_broker.create_broker(self.context)
        new_broker_metadata = self.create_object_broker_metadata(
            broker_id=new_broker.id)
        new_broker_metadata.delete_broker_metadata(self.context)
        metadata_returned = self.dbapi.get_broker_metadata_by_broker_id(
            self.context, new_broker_metadata.broker_id)

        self.assertListEqual([], metadata_returned)
Example #4
0
    def test_get_image_id_by_nonexistent_broker_name(self):
        """Tests get broker image_id by nonexistent broker_name from

        BrokerMetadata objects API.
        """
        new_broker = objects.Broker(**func_utils.get_test_broker_dict())
        new_broker.create_broker(self.context)
        self.create_object_broker_metadata(broker_id=new_broker.id)
        invalid_broker_name = "kafka"
        self.assertRaises(exception.NotFound,
                          objects.BrokerMetadata.get_image_id_by_broker_name,
                          self.context, invalid_broker_name)
 def create_object_broker(self, **kw):
     """Create a broker object."""
     test_broker_dict = func_utils.get_test_broker_dict(**kw)
     new_broker = objects.Broker(**test_broker_dict)
     self.validate_broker_values(test_broker_dict, new_broker)
     new_broker.create_broker(self.context)
     # retrieve created broker
     broker_query = sqlalchemy_api.model_query(
         self.context, models.Broker).filter_by(id=test_broker_dict['id'])
     db_broker = broker_query.one()
     broker_obj = objects.Broker._from_db_object(objects.Broker(),
                                                 db_broker)
     return broker_obj
Example #6
0
    def test_get_broker_metadata_by_invalid_broker_id(self):
        """Tests get broker_metadata from BrokerMetadata objects API with

        invalid broker id.
        """
        new_broker = objects.Broker(**func_utils.get_test_broker_dict())
        new_broker.create_broker(self.context)
        self.create_object_broker_metadata(broker_id=new_broker.id)
        invalid_broker_id = '17efe8ae-e93c-11e4-b02c-1681e6b88ec1'
        metadata = objects.BrokerMetadata.get_broker_metadata_by_broker_id(
            self.context, invalid_broker_id)

        self.assertListEqual([], metadata)
Example #7
0
    def test_create_broker_metadata(self):
        """Tests create broker_metadata from BrokerMetadata objects API."""
        new_broker = objects.Broker(**func_utils.get_test_broker_dict())
        new_broker.create_broker(self.context)
        test_metadata_dict = func_utils.get_test_broker_metadata_dict()
        new_broker_metadata = objects.BrokerMetadata(**test_metadata_dict)
        self.validate_broker_metadata_values(new_broker_metadata,
                                             test_metadata_dict)
        new_broker_metadata.create_broker_metadata(self.context)
        returned_broker_metadata = self.dbapi.get_broker_metadata_by_broker_id(
            self.context, new_broker.id)

        self.validate_broker_metadata_values(new_broker_metadata,
                                             returned_broker_metadata[0])
    def test_broker_db_to_object_to_db(self):
        """Tests Broker db object conversion to Broker object and back

        to db object.
        """
        broker_dict = func_utils.get_test_broker_dict()
        db_broker_object = models.Broker()
        db_broker_object.update(broker_dict)
        object_broker = objects.Broker._from_db_object(objects.Broker(),
                                                       db_broker_object)
        self.validate_broker_values(db_broker_object, object_broker)

        broker_changes = object_broker.obj_get_changes()
        db_broker_object_2 = models.Broker()
        db_broker_object_2.update(broker_changes)
        self.validate_broker_values(db_broker_object, db_broker_object_2)
Example #9
0
    def test_get_image_id_by_broker_name(self):
        """Tests get broker image_id by broker_name from BrokerMetadata objects

        API.
        """

        new_broker = objects.Broker(**func_utils.get_test_broker_dict())
        new_broker.create_broker(self.context)
        test_metadata_dict = func_utils.get_test_broker_metadata_dict()
        new_broker_metadata = objects.BrokerMetadata(**test_metadata_dict)
        self.validate_broker_metadata_values(new_broker_metadata,
                                             test_metadata_dict)
        new_broker_metadata.create_broker_metadata(self.context)

        image_id = objects.BrokerMetadata.get_image_id_by_broker_name(
            self.context, new_broker.name)

        self.assertEqual(image_id, new_broker_metadata.value)
 def test_broker_object_generation(self):
     """Test Broker Object generation from a broker dictionary object."""
     broker_dict = func_utils.get_test_broker_dict()
     broker_object = objects.Broker(**broker_dict)
     self.validate_broker_values(broker_dict, broker_object)