Removing old incompatible versions of roles_operations
Change-Id: I4ea33e5a708c0f6c7b0581b5928146a0b7a9792f
Signed-off-by: Eduardo Sousa <eduardo.sousa@canonical.com>
diff --git a/osm_nbi/auth.py b/osm_nbi/auth.py
index fcebad4..dda1d22 100644
--- a/osm_nbi/auth.py
+++ b/osm_nbi/auth.py
@@ -156,7 +156,7 @@
# Note: it is faster to rewrite the value than to check if it is already there or not
if self.config["authentication"]["backend"] == "internal":
return
-
+
operations = []
with open(self.resources_to_operations_file, "r") as stream:
resources_to_operations_yaml = yaml.load(stream)
diff --git a/osm_nbi/engine.py b/osm_nbi/engine.py
index 5763c38..e7dee84 100644
--- a/osm_nbi/engine.py
+++ b/osm_nbi/engine.py
@@ -56,6 +56,12 @@
# "pm_jobs": PmJobsTopic will be added manually because it needs other parameters
}
+ map_target_version_to_int = {
+ "1.0": 1000,
+ "1.1": 1001
+ # Add new versions here
+ }
+
def __init__(self):
self.db = None
self.fs = None
@@ -321,29 +327,46 @@
return {'project_id': project_id, 'user_id': user_id}
def upgrade_db(self, current_version, target_version):
- if not target_version or current_version == target_version:
- return
- if target_version == '1.0':
- if not current_version:
- # create database version
- serial = urandom(32)
- version_data = {
- "_id": 'version', # Always 'version'
- "version_int": 1000, # version number
- "version": '1.0', # version text
- "date": "2018-10-25", # version date
- "description": "added serial", # changes in this version
- 'status': 'ENABLED', # ENABLED, DISABLED (migration in process), ERROR,
- 'serial': b64encode(serial)
- }
- self.db.create("admin", version_data)
- self.db.set_secret_key(serial)
- return
- # TODO add future migrations here
+ if target_version not in self.map_target_version_to_int.keys():
+ raise EngineException("Wrong database version '{}'. Expected '{}'"
+ ". It cannot be up/down-grade".format(current_version, target_version),
+ http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
- raise EngineException("Wrong database version '{}'. Expected '{}'"
- ". It cannot be up/down-grade".format(current_version, target_version),
- http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
+ if current_version == target_version:
+ return
+
+ target_version_int = self.map_target_version_to_int[target_version]
+
+ if not current_version:
+ # create database version
+ serial = urandom(32)
+ version_data = {
+ "_id": "version", # Always "version"
+ "version_int": 1000, # version number
+ "version": "1.0", # version text
+ "date": "2018-10-25", # version date
+ "description": "added serial", # changes in this version
+ 'status': "ENABLED", # ENABLED, DISABLED (migration in process), ERROR,
+ 'serial': b64encode(serial)
+ }
+ self.db.create("admin", version_data)
+ self.db.set_secret_key(serial)
+ current_version = "1.0"
+
+ if current_version == "1.0" and target_version_int >= self.map_target_version_to_int["1.1"]:
+ self.db.del_list("roles_operations")
+
+ version_data = {
+ "_id": "version",
+ "version_int": 1001,
+ "version": "1.1",
+ "date": "2019-05-24",
+ "description": "set new format for roles_operations"
+ }
+
+ self.db.set_one("admin", {"_id": "version"}, version_data)
+ current_version = "1.1"
+ # TODO add future migrations here
def init_db(self, target_version='1.0'):
"""
diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py
index fc7d11f..0616430 100644
--- a/osm_nbi/nbi.py
+++ b/osm_nbi/nbi.py
@@ -40,7 +40,7 @@
__version__ = "0.1.3"
version_date = "Jan 2019"
-database_version = '1.0'
+database_version = '1.1'
auth_database_version = '1.0'
nbi_server = None # instance of Server class
subscription_thread = None # instance of SubscriptionThread class