Skip to content

Commit

Permalink
Merge branch 'main' into ci-housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
sajith committed May 28, 2024
2 parents 7059c64 + d8a2c3b commit ad2fb55
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies = [
"pika >= 1.2.0",
"dataset",
"pymongo > 3.0",
"sdx-pce @ git+https://github.com/atlanticwave-sdx/pce@2.0.6.rc0",
"sdx-pce @ git+https://github.com/atlanticwave-sdx/pce@2.0.6.rc1",
]

[project.optional-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions sdx_controller/controllers/connection_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def delete_connection(connection_id):
#
# https://github.com/atlanticwave-sdx/pce/issues/180
current_app.te_manager.unreserve_vlan(connection_id)
deleted = db_instance.mark_deleted("connections", f"{connection_id}")
if not deleted:
return "Did not find connection", 404
except Exception as e:
logger.info(f"Delete failed (connection id: {connection_id}): {e}")
return "Failed, reason: {e}", 500
Expand Down
2 changes: 1 addition & 1 deletion sdx_controller/test/test_connection_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_delete_connection_no_setup(self):
f"{BASE_PATH}/connection/{connection_id}",
method="DELETE",
)
self.assert200(response, f"Response body is : {response.data.decode('utf-8')}")
self.assert404(response, f"Response body is : {response.data.decode('utf-8')}")

def __add_the_three_topologies(self):
"""
Expand Down
19 changes: 15 additions & 4 deletions sdx_controller/utils/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,31 @@ def add_key_value_pair_to_db(self, collection, key, value):
key = str(key)
obj = self.read_from_db(collection, key)
if obj is None:
# self.logger.debug(f"Adding key value pair {key}:{value} to DB.")
return self.sdxdb[collection].insert_one({key: value})

query = {"_id": obj["_id"]}
# self.logger.debug(f"Updating DB entry {key}:{value}.")
result = self.sdxdb[collection].replace_one(query, {key: value})
return result

def read_from_db(self, collection, key):
key = str(key)
return self.sdxdb[collection].find_one({key: {"$exists": 1}})
return self.sdxdb[collection].find_one(
{key: {"$exists": 1}, "deleted": {"$ne": True}}
)

def get_all_entries_in_collection(self, collection):
db_collection = self.sdxdb[collection]
# MongoDB has an ObjectId for each item, so need to exclude the ObjectIds
all_entries = db_collection.find({}, {"_id": 0})
all_entries = db_collection.find({"deleted": {"$ne": True}}, {"_id": 0})
return all_entries

def mark_deleted(self, collection, key):
db_collection = self.sdxdb[collection]
key = str(key)
item_to_delete = self.read_from_db(collection, key)
if item_to_delete is None:
return False
filter = {"_id": item_to_delete["_id"]}
update = {"$set": {"deleted": True}}
db_collection.update_one(filter, update)
return True
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ setenv =
SDX_VERSION = 1.0.0
SDX_NAME = sdx-controller-test
MQ_HOST = localhost
MQ_PORT = 5672
SUB_QUEUE = sdx-controller-test-queue
DB_NAME = sdx-controller-test-db
DB_CONFIG_TABLE_NAME = sdx-controller-test-table
Expand Down

0 comments on commit ad2fb55

Please sign in to comment.