Skip to content

Commit

Permalink
Merge pull request #90 from netgroup/disable-persistency-by-default
Browse files Browse the repository at this point in the history
Disable persistency on ArangoDB by default
  • Loading branch information
cscarpitta authored Feb 8, 2022
2 parents f1462b8 + bf27375 commit 151d146
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 35 deletions.
9 changes: 8 additions & 1 deletion control_plane/apps/apps/nb_grpc_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
STATUS_GRPC_UNAUTHORIZED,
STATUS_NOT_CONFIGURED,
STATUS_ALREADY_CONFIGURED,
STATUS_NO_SUCH_DEVICE)
STATUS_NO_SUCH_DEVICE,
STATUS_PERSISTENCY_NOT_ENABLED)

# Logger reference
logging.basicConfig(level=logging.NOTSET)
Expand All @@ -70,6 +71,7 @@
STATUS_NOT_CONFIGURED: 'Error: Not configured',
STATUS_ALREADY_CONFIGURED: 'Error: Already configured',
STATUS_NO_SUCH_DEVICE: 'Error: Device not found',
STATUS_PERSISTENCY_NOT_ENABLED: 'Error: Persistency not enabled',
}


Expand Down Expand Up @@ -118,6 +120,11 @@ def raise_exception_on_error(error_code): # TODO exeptions more specific
raise ControllerException('Entity already configured')
if error_code == STATUS_NO_SUCH_DEVICE:
raise ControllerException('No such device')
if error_code == STATUS_PERSISTENCY_NOT_ENABLED:
raise ControllerException('Persistency must be enabled to execute '
'the requested operation. Check '
'ENABLE_PERSISTENCY parameter in '
'your configuration file')
raise ControllerException('Invalid argument')


Expand Down
2 changes: 1 addition & 1 deletion control_plane/controller/controller/config/controller.env
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# export DEBUG=True

# Must persistency be enabled? (optional, default: False)
export ENABLE_PERSISTENCY=True
export ENABLE_PERSISTENCY=False

##############################################################################

Expand Down
25 changes: 17 additions & 8 deletions control_plane/controller/controller/controller_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# General imports
import logging
import os
import requests
import sys
from argparse import ArgumentParser
from pathlib import Path
Expand Down Expand Up @@ -186,12 +187,6 @@ def __main():
args = parse_arguments()
# Path to the .env file containing the parameters for the node manager'
env_file = args.env_file
# Initialize database
init_db('srv6')
init_db('srv6pm')
init_db('topology')
# Initialize collections on database
init_db_collections()
# Create a new configuration object
config = Config()
# Load configuration from .env file
Expand Down Expand Up @@ -221,8 +216,22 @@ def __main():
config.import_dependencies()
# Print configuration
config.print_config()
# Establish a connection to the database
db_client = connect_db()
# Setup persistency
try:
db_client = None
if os.getenv('ENABLE_PERSISTENCY') in ['True', 'true']:
# Initialize database
init_db('srv6')
init_db('srv6pm')
init_db('topology')
# Initialize collections on database
init_db_collections()
# Establish a connection to the database
db_client = connect_db()
except requests.exceptions.ConnectionError:
logging.fatal(
'Cannot establish a connection to ArangoDB. Is ArangoDB running?')
exit(-1)
# Start the northbound gRPC server to expose the controller services
grpc_server.start_server(db_client=db_client)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,14 @@ def __init__(self, db_client=None):
"""
# Establish a connection to the "srv6" database
# We will keep the connection open forever
self.db_conn = arangodb_driver.connect_db(
client=db_client,
db_name='srv6',
username=os.getenv('ARANGO_USER'),
password=os.getenv('ARANGO_PASSWORD')
)
self.db_conn = None
if db_client is not None:
self.db_conn = arangodb_driver.connect_db(
client=db_client,
db_name='srv6',
username=os.getenv('ARANGO_USER'),
password=os.getenv('ARANGO_PASSWORD')
)

def HandleSRv6MicroSIDPolicy(self, request, context):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,14 @@ def __init__(self, db_client=None):
"""
# Establish a connection to the "srv6pm" database
# We will keep the connection open forever
self.db_conn = arangodb_driver.connect_db(
client=db_client,
db_name='srv6pm',
username=os.getenv('ARANGO_USER'),
password=os.getenv('ARANGO_PASSWORD')
)
self.db_conn = None
if db_client is not None:
self.db_conn = arangodb_driver.connect_db(
client=db_client,
db_name='srv6pm',
username=os.getenv('ARANGO_USER'),
password=os.getenv('ARANGO_PASSWORD')
)

def SetConfiguration(self, request, context):
"""
Expand Down
40 changes: 27 additions & 13 deletions control_plane/controller/controller/nb_grpc_server/topo_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,21 @@ def __init__(self, db_client=None):
"""
# Establish a connection to the "topology" database
# We will keep the connection open forever
self.db_conn = arangodb_driver.connect_db(
client=db_client,
db_name='topology',
username=os.getenv('ARANGO_USER'),
password=os.getenv('ARANGO_PASSWORD')
)
# Init database and return nodes and edges collection
self.nodes_collection, self.edges_collection = \
arangodb_utils.initialize_db(
arango_url=os.getenv('ARANGO_URL'),
arango_user=os.getenv('ARANGO_USER'),
arango_password=os.getenv('ARANGO_PASSWORD')
) # TODO reuse the existing db connection
self.db_conn = None
if db_client is not None:
self.db_conn = arangodb_driver.connect_db(
client=db_client,
db_name='topology',
username=os.getenv('ARANGO_USER'),
password=os.getenv('ARANGO_PASSWORD')
)
# Init database and return nodes and edges collection
self.nodes_collection, self.edges_collection = \
arangodb_utils.initialize_db(
arango_url=os.getenv('ARANGO_URL'),
arango_user=os.getenv('ARANGO_USER'),
arango_password=os.getenv('ARANGO_PASSWORD')
) # TODO reuse the existing db connection

def ExtractTopology(self, request, context):
"""
Expand Down Expand Up @@ -319,6 +321,12 @@ def LoadTopology(self, request, context):
"""
# pylint: disable=invalid-name, unused-argument, no-self-use
#
# ENABLE_PERSISTENCY config parameter must be set to execute
# this operation
if os.getenv('ENABLE_PERSISTENCY') not in ['True', 'true']:
return topology_manager_pb2.TopologyManagerReply(
status=nb_commons_pb2.STATUS_PERSISTENCY_NOT_ENABLED)
#
# Extract the parameters from the gRPC request
#
# Extract the nodes from the gRPC request
Expand Down Expand Up @@ -362,6 +370,12 @@ def ExtractAndLoadTopology(self, request, context):
"""
# pylint: disable=invalid-name, unused-argument, no-self-use
#
# ENABLE_PERSISTENCY config parameter must be set to execute
# this operation
if os.getenv('ENABLE_PERSISTENCY') not in ['True', 'true']:
yield topology_manager_pb2.TopologyManagerReply(
status=nb_commons_pb2.STATUS_PERSISTENCY_NOT_ENABLED)
return
# Create the reply message
response = topology_manager_pb2.TopologyManagerReply()
#
Expand Down
1 change: 1 addition & 0 deletions control_plane/nb_protos/nb_commons.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum StatusCode {
STATUS_NOT_CONFIGURED = 10;
STATUS_ALREADY_CONFIGURED = 11;
STATUS_NO_SUCH_DEVICE = 12;
STATUS_PERSISTENCY_NOT_ENABLED = 13;
}

enum FwdEngine {
Expand Down

0 comments on commit 151d146

Please # to comment.