def test_create_invalid_image(self): """test create a cluster with invalid image configured.""" # add a new broker image that is not in nova image-list self.CONF.config(default_broker_name='rabbitmq1') broker_values = { 'name': 'rabbitmq1', 'active': '1', } broker = objects.Broker(**broker_values) broker.create_broker(None) broker_list = broker.get_brokers(None) metadata_value = { 'key': 'IMAGE', 'value': 'ea329926-b8bf-11e5-9912-ba0be0483c18', 'broker_id': broker_list[1]['id'] } metadata = objects.BrokerMetadata(**metadata_value) metadata.create_broker_metadata(None) api_cluster = test_utils.create_api_test_cluster() data = self.post_json('/clusters', params=api_cluster, headers=self.auth_headers, expect_errors=True) self.assertEqual(500, data.status_code, 'Invalid status code value received.')
def create_object_broker_metadata(self, broker_id, **kw): """Create broker_metadata object for the given broker.""" test_metadata_dict = func_utils.get_test_broker_metadata_dict( broker_id=broker_id, **kw) 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) return new_broker_metadata
def test_create_broker_metadata_for_nonexistent_broker(self): """Tests create broker_metadata for a nonexistent broker from BrokerMetadata objects API. """ test_metadata_dict = func_utils.get_test_broker_metadata_dict( broker_id=str(uuid.uuid4())) new_broker_metadata = objects.BrokerMetadata(**test_metadata_dict) self.validate_broker_metadata_values(new_broker_metadata, test_metadata_dict) self.assertRaises(exception.NotFound, new_broker_metadata.create_broker_metadata, self.context)
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 add_metadata(self, broker_id, image_id, sec_group): """Add broker metadata - image and sec group for the given broker_id. """ if image_id is not None: metadata_value = { 'key': models.MetadataKey.IMAGE, 'value': image_id, 'broker_id': broker_id } metadata = objects.BrokerMetadata(**metadata_value) metadata.create_broker_metadata(self.context) if sec_group is not None: metadata_value = { 'key': models.MetadataKey.SEC_GROUP, 'value': sec_group, 'broker_id': broker_id } metadata = objects.BrokerMetadata(**metadata_value) metadata.create_broker_metadata(self.context) if image_id is None and sec_group is None: raise exception.Invalid(_("Requires atleast one argument"))
def set_broker(self): # Loading default broker and image to broker and brokerMetadata table broker_values = { 'name': 'rabbitmq', 'active': '1', } broker = objects.Broker(**broker_values) broker.create_broker(None) broker_list = broker.get_brokers(None) broker_id = broker_list[0]['id'] metadata_value = { 'key': 'IMAGE', 'value': 'f7e8c49b-7d1e-472f-a78b-7c46a39c85be', 'broker_id': broker_id } metadata = objects.BrokerMetadata(**metadata_value) metadata.create_broker_metadata(None)
def test_broker_metadata_db_to_object_to_db(self): """Tests BrokerMetadata db object conversion to BrokerMetadata object and back to db object. """ metadata_dict = func_utils.get_test_broker_metadata_dict() db_metadata_object = models.BrokerMetadata() db_metadata_object.update(metadata_dict) object_metadata = objects.BrokerMetadata._from_db_object( objects.BrokerMetadata(), db_metadata_object) self.validate_broker_metadata_values(db_metadata_object, object_metadata) metadata_changes = object_metadata.obj_get_changes() db_metadata_object_2 = models.BrokerMetadata() db_metadata_object_2.update(metadata_changes) self.validate_broker_metadata_values(db_metadata_object, db_metadata_object_2)
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_metadata_object_generation(self): """Test BrokerMetadata Object generation from a metadata dictionary.""" metadata_dict = func_utils.get_test_broker_metadata_dict() metadata_object = objects.BrokerMetadata(**metadata_dict) self.validate_broker_metadata_values(metadata_dict, metadata_object)
def delete_metadata(self, broker_metadata_id): """Delete broker metadata for the given broker_metadata_id.""" broker_metadata_id = {'id': broker_metadata_id} broker_obj = objects.BrokerMetadata(**broker_metadata_id) broker_obj.delete_broker_metadata(self.context)