i_host capabilities column cleaning
This change adds a new activate script to cleaning old information from capabilities column from i_host table. To allow the usage of Kubernetes Power Manager StarlingX app, the information of minimum and maximum allowed frequency, and cstates available were stored in capabilities column for each node (i_host table). Due to a new approach, information is stored in specific columns for each parameter. To avoid residual information in the capabilities column, during the information migration process, the script removes such parameters from the column. Test Plan: PASS: capabilities column cleaned (target information was removed) PASS: script successfully skipped in other action steps Story: 2011069 Task: 49822 Change-Id: Ifc955ecdb0c2a5b47c0dadbda083811fd2456b05 Signed-off-by: Eduardo Juliano Alberti <eduardo.alberti@windriver.com>
This commit is contained in:
parent
7964871f9b
commit
f5c6e2130c
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/python
|
||||
# Copyright (c) 2024 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# This script is responsible for cleaning the capabilities column of i_host
|
||||
# sysinv table, removing information used on old audit report of cstates
|
||||
# min and max frequency.
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
from psycopg2.extras import RealDictCursor
|
||||
import psycopg2
|
||||
|
||||
from controllerconfig.common import log
|
||||
from sysinv.common import constants
|
||||
|
||||
LOG = log.get_logger(__name__)
|
||||
|
||||
|
||||
def main():
|
||||
action = None
|
||||
from_release = None
|
||||
to_release = None # noqa
|
||||
arg = 1
|
||||
while arg < len(sys.argv):
|
||||
if arg == 1:
|
||||
from_release = sys.argv[arg]
|
||||
elif arg == 2:
|
||||
to_release = sys.argv[arg] # noqa
|
||||
elif arg == 3:
|
||||
action = sys.argv[arg]
|
||||
elif arg == 4:
|
||||
# optional port parameter for USM upgrade
|
||||
# port = sys.argv[arg]
|
||||
pass
|
||||
else:
|
||||
print(f"Invalid option {sys.argv[arg]}.")
|
||||
return 1
|
||||
arg += 1
|
||||
|
||||
log.configure()
|
||||
|
||||
if from_release == "22.12" and action == "migrate":
|
||||
try:
|
||||
LOG.info("removing min_cpu_mhz_allowed, max_cpu_mhz_allowed, and "
|
||||
"cstates_available information from capabilities column, "
|
||||
f"from the release {from_release} to {to_release} with "
|
||||
f"action: {action}")
|
||||
remove_cstates_and_frequency_info()
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
print(ex)
|
||||
return 1
|
||||
|
||||
|
||||
def remove_cstates_and_frequency_info():
|
||||
"""This function removes the information of cstates, min and max frequency
|
||||
from the capabilities column.
|
||||
"""
|
||||
|
||||
conn = psycopg2.connect("dbname='sysinv' user='postgres'")
|
||||
with conn:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute("select uuid, capabilities from i_host;")
|
||||
row = cur.fetchall()
|
||||
if row is None:
|
||||
LOG.exception("Failed to fetch i_host data")
|
||||
raise
|
||||
|
||||
for record in row:
|
||||
capabilities = json.loads(record['capabilities'])
|
||||
# removing min, max and cstates information
|
||||
capabilities.pop(constants.IHOST_CSTATES_AVAILABLE, None)
|
||||
capabilities.pop(constants.IHOST_MAX_CPU_MHZ_ALLOWED, None)
|
||||
capabilities.pop(constants.IHOST_MIN_CPU_MHZ_ALLOWED, None)
|
||||
|
||||
sqlcom = ("update i_host set "
|
||||
f"capabilities='{json.dumps(capabilities)}' "
|
||||
f"where uuid='{record['uuid']}'")
|
||||
cur.execute(sqlcom)
|
||||
conn.commit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
Loading…
Reference in New Issue