diff --git a/web/server/codechecker_server/api/product_server.py b/web/server/codechecker_server/api/product_server.py index bcf9b841f1..e9ce9ff4f2 100644 --- a/web/server/codechecker_server/api/product_server.py +++ b/web/server/codechecker_server/api/product_server.py @@ -395,13 +395,13 @@ def addProduct(self, product): codechecker_api_shared.ttypes.ErrorCode.GENERAL, msg) - # db_in_use = self.__server.get_if_database_in_use(product.connection) - # if db_in_use: - # LOG.error("Database '%s' is already in use by another product!", - # product.connection.database) - # raise codechecker_api_shared.ttypes.RequestFailed( - # codechecker_api_shared.ttypes.ErrorCode.DATABASE, - # "Database is already in use by another product!") + db_in_use = self.__server.get_if_database_in_use(product.connection) + if db_in_use: + LOG.error("Database '%s' is already in use by another product!", + product.connection.database) + raise codechecker_api_shared.ttypes.RequestFailed( + codechecker_api_shared.ttypes.ErrorCode.DATABASE, + "Database is already in use by another product!") if self.add_product_support(product): LOG.info("Database support added successfully.") diff --git a/web/server/codechecker_server/server.py b/web/server/codechecker_server/server.py index 7554a51ef6..f7c8f30341 100644 --- a/web/server/codechecker_server/server.py +++ b/web/server/codechecker_server/server.py @@ -262,11 +262,10 @@ def __check_prod_db(self, product_endpoint): """ product = self.server.get_product(product_endpoint) - LOG.info("####Request's product: %s", product_endpoint) if not product: raise ValueError( f"The product with the given endpoint '{product_endpoint}' " - "does not exist! BITCH") + "does not exist!") if product.db_status == DBStatus.OK: # No reconnect needed. @@ -951,7 +950,7 @@ def num_products(self): """ return len(self.__products) - def get_product(self, endpoint): # marker + def get_product(self, endpoint): """ Get the product connection object for the given endpoint, or None. """ @@ -966,17 +965,10 @@ def get_product(self, endpoint): # marker # database. try: cfg_sess = self.config_session() - holder = cfg_sess.query(ORMProduct) \ + product = cfg_sess.query(ORMProduct) \ .filter(ORMProduct.endpoint == endpoint) \ - .limit(1) - LOG.info('#########################') - LOG.info('holder: %s', holder) - LOG.info('######LOW###################') - product = holder.one_or_none() - LOG.info(product) - LOG.info('######MIDDLE###################') - LOG.info(product) - LOG.info('#########################') + .limit(1).one_or_none() + if not product: return None diff --git a/web/tests/functional/products/test_config_db_share.py b/web/tests/functional/products/test_config_db_share.py index 44b2e52c8c..7ce1f710d0 100644 --- a/web/tests/functional/products/test_config_db_share.py +++ b/web/tests/functional/products/test_config_db_share.py @@ -170,11 +170,10 @@ def create_test_product(product_name, product_endpoint): product_cfg = create_test_product('producttest_second 2', 'producttest_second_2') - self.assertTrue(self._pr_client_2.addProduct(product_cfg), - "Cannot create product on secondary server.") - # with self.assertRaises(RequestFailed): - # self._pr_client_2.addProduct(product_cfg) + with self.assertRaises(RequestFailed): + self._pr_client_2.addProduct(product_cfg) + # Product name full string match. products = self._pr_client_2.getProducts('producttest_second', None) self.assertEqual(len(products), 1) @@ -185,10 +184,10 @@ def create_test_product(product_name, product_endpoint): # Product name substring match. products = self._pr_client_2.getProducts('producttest_second*', None) - self.assertEqual(len(products), 2) + self.assertEqual(len(products), 1) products = self._pr_client_2.getProducts(None, 'producttest_second*') - self.assertEqual(len(products), 2) + self.assertEqual(len(products), 1) # Use the same CodeChecker config that was used on the main server, # but store into the secondary one. @@ -214,8 +213,8 @@ def create_test_product(product_name, product_endpoint): "connected through the main server.") # Remove the product through the main server. - p_id = self._root_client.getProducts('producttest_second', None)[0].id # PROBLEM HERE - p_id2 = self._pr_client_2.getProducts('producttest_second', None)[0].id # PROBLEM HERE + p_id = self._root_client.getProducts('producttest_second', None)[0].id + p_id2 = self._pr_client_2.getProducts('producttest_second', None)[0].id self.assertIsNotNone(p_id) self.assertEqual(p_id, p_id2, "The products have different ID across the two "