Skip to content

Commit

Permalink
Improvement of new product fix (#4390)
Browse files Browse the repository at this point in the history
* added a function that creates a database before addproduct() function connects to it

* renamed function to follow convention of naming

* retrigger checks

* removed unnecessary test case

* test commit

* changed try catch block

* working implementation

* commit to check if test cases will work

* fixed sqlite error

* fixed tests failing

* changed behaviour of add_test_package_product to work with new fucntionality of add_product

* possible fix of psql_psycopq2

* removed changed to creation of test package product

* probable fix

* final working implementation

* removed automatic prevention of previous jobs, as it was already implemented by other pr

* comments applied

* probable fix multiple server database prohibition problem

* fix of failing test

* log fix

* final implementation

* final final commit

* uncommented a test case
  • Loading branch information
feyruzb authored Nov 29, 2024
1 parent f74a8f4 commit 59a3c6a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
7 changes: 4 additions & 3 deletions web/server/codechecker_server/api/product_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def getProductConfiguration(self, product_id):
return prod

@timeit
def __add_product_support(self, product):
def __create_product_database(self, product):
"""
Creates a database for the given product,
to assist addProduct() function that connects to
Expand Down Expand Up @@ -416,8 +416,9 @@ def addProduct(self, product):
"Database is already in use by another product!")

# Add database before letting product connect to it
if self.__add_product_support(product):
LOG.info("Database support added successfully.")
if self.__create_product_database(product):
LOG.info("Database '%s' created successfully.",
product.connection.database)

# Some values come encoded as Base64, decode these.
displayed_name = convert.from_b64(product.displayedName_b64) \
Expand Down
16 changes: 9 additions & 7 deletions web/server/codechecker_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,18 +915,20 @@ def is_database_used(self, conn):
else f"{conn.engine}+psycopg2",
conn.database, conn.host, conn.port)

# dynamic_list contains the currently connected databases to servers
dynamic_list = [(make_url(a.connection).drivername,
make_url(a.connection).database,
make_url(a.connection).host,
make_url(a.connection).port)
for a in self.cfg_sess_private.query(ORMProduct).all()]
# create a tuple of database that is already connected for comparison
def to_tuple(product):
url = make_url(product.connection)
return url.drivername, url.database, url.host, url.port
# creates a list of currently connected databases
current_connected_databases = list(map(
to_tuple,
self.cfg_sess_private.query(ORMProduct).all()))

self.cfg_sess_private.commit()
self.cfg_sess_private.close()

# True if found, False otherwise
return to_add in dynamic_list
return to_add in current_connected_databases

@property
def num_products(self):
Expand Down
10 changes: 5 additions & 5 deletions web/tests/functional/products/test_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""


# from copy import deepcopy
from copy import deepcopy
import os
import unittest

Expand Down Expand Up @@ -93,10 +93,10 @@ def test_add_invalid_product(self):

# Test setting up product with valid endpoint but no database
# connection.
# with self.assertRaises(RequestFailed):
# cfg = deepcopy(product_cfg)
# cfg.endpoint = "valid"
# self._root_client.addProduct(cfg)
with self.assertRaises(RequestFailed):
cfg = deepcopy(product_cfg)
cfg.endpoint = "valid"
self._root_client.addProduct(cfg)

# Test some invalid strings based on pattern.
dbc = DatabaseConnection(
Expand Down

0 comments on commit 59a3c6a

Please sign in to comment.