Add new provision/deprovison command option

Add "--apply" command option for sm-provision and sm-deprovision
commands to apply the change to SM immediately.

If SM runtime configuration has not already been created, the new option
will not do extra. SM will load the up-to-date configuration from static
db when it creates runtime configuration.

The new commands:
sm-provision service-group-member
sm-deprovision service-group-member

will provision/deprovision both service and service group member.
The commands below are now deprecated, although they are still supported
for backward compatibility.

sm-provision service
sm-deprovision service

Story: 2005486
Task: 30622

Depends-on: https://review.opendev.org/#/c/655766

Change-Id: I6dda4129ab1d121a7e5861d20a4df791c0c535a8
Signed-off-by: Bin Qian <bin.qian@windriver.com>
This commit is contained in:
Bin Qian 2019-04-25 15:16:00 -04:00
parent 7d35e10e2c
commit 778d4e2dcf
3 changed files with 77 additions and 11 deletions

View File

@ -1,4 +1,4 @@
SRC_DIR=sm-tools SRC_DIR=sm-tools
TAR_NAME=sm-tools TAR_NAME=sm-tools
VERSION=1.0 VERSION=1.0
TIS_PATCH_VER=1 TIS_PATCH_VER=2

View File

@ -18,6 +18,9 @@ SM_API_MSG_REVISION = "1"
SM_API_MSG_TYPE_RESTART_SERVICE = "RESTART_SERVICE" SM_API_MSG_TYPE_RESTART_SERVICE = "RESTART_SERVICE"
SM_API_MSG_SKIP_DEP_CHECK = "skip-dep" SM_API_MSG_SKIP_DEP_CHECK = "skip-dep"
SM_API_MSG_TYPE_PROVISION_SERVICE = "PROVISION_SERVICE"
SM_API_MSG_TYPE_DEPROVISION_SERVICE = "DEPROVISION_SERVICE"
SM_API_MSG_TYPE_RELOAD_DATA = "RELOAD_DATA" SM_API_MSG_TYPE_RELOAD_DATA = "RELOAD_DATA"
SM_API_MSG_TYPE_SDI_SET_STATE = "SERVICE_DOMAIN_INTERFACE_SET_STATE" SM_API_MSG_TYPE_SDI_SET_STATE = "SERVICE_DOMAIN_INTERFACE_SET_STATE"
@ -65,3 +68,31 @@ def restart_service_safe(service_name):
service_name, SM_API_MSG_SKIP_DEP_CHECK)) service_name, SM_API_MSG_SKIP_DEP_CHECK))
_send_msg_to_sm(sm_api_msg) _send_msg_to_sm(sm_api_msg)
def provision_service(service_name, service_group_name):
"""
:param service_name:
:param service_group_name:
:return:
"""
sm_api_msg = ("%s,%s,%i,%s,%s,%s,%s"
% (SM_API_MSG_VERSION, SM_API_MSG_REVISION, 1,
SM_API_MSG_TYPE_PROVISION_SERVICE, "sm-action",
service_name, service_group_name))
_send_msg_to_sm(sm_api_msg)
def deprovision_service(service_name, service_group_name):
"""
:param service_name:
:param service_group_name:
:return:
"""
sm_api_msg = ("%s,%s,%i,%s,%s,%s,%s"
% (SM_API_MSG_VERSION, SM_API_MSG_REVISION, 1,
SM_API_MSG_TYPE_DEPROVISION_SERVICE, "sm-action",
service_name, service_group_name))
_send_msg_to_sm(sm_api_msg)

View File

@ -1,5 +1,5 @@
# #
# Copyright (c) 2015 Wind River Systems, Inc. # Copyright (c) 2015-2019 Wind River Systems, Inc.
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
@ -7,8 +7,23 @@ import os
import sys import sys
import argparse import argparse
import sqlite3 import sqlite3
from sm_api_msg_utils import provision_service
from sm_api_msg_utils import deprovision_service
database_name = "/var/lib/sm/sm.db" database_name = "/var/lib/sm/sm.db"
runtime_db_name = "/var/run/sm/sm.db"
def update_db(db, sqls):
database = sqlite3.connect(db)
cursor = database.cursor()
for sql in sqls:
cursor.execute(sql)
database.commit()
database.close()
def main(): def main():
@ -64,6 +79,10 @@ def main():
sg_member_parser.add_argument('service_group_member', sg_member_parser.add_argument('service_group_member',
help='service group member name') help='service group member name')
sg_member_parser.add_argument("--apply",
help="Apply the new configuration "
"immediately\n",
action="store_true")
# Service # Service
service_parser = subparsers.add_parser('service', service_parser = subparsers.add_parser('service',
help='Provision Service') help='Provision Service')
@ -125,20 +144,36 @@ def main():
database.close() database.close()
elif args.which == 'service_group_member': elif args.which == 'service_group_member':
database = sqlite3.connect(database_name) sql_update_sgm = "UPDATE SERVICE_GROUP_MEMBERS SET " \
"PROVISIONED = '%s' WHERE NAME = '%s' and " \
cursor = database.cursor() "SERVICE_NAME = '%s';" \
cursor.execute("UPDATE SERVICE_GROUP_MEMBERS SET "
"PROVISIONED = '%s' WHERE NAME = '%s' and "
"SERVICE_NAME = '%s';"
% (provision_str, args.service_group, % (provision_str, args.service_group,
args.service_group_member)) args.service_group_member)
sql_update_svc = "UPDATE SERVICES SET " \
"PROVISIONED = '%s' WHERE NAME = '%s';" \
% (provision_str, args.service_group_member)
database.commit() sqls = [sql_update_sgm, sql_update_svc]
database.close() update_db(database_name, sqls)
if args.apply and os.path.isfile(runtime_db_name):
# update runtime configuration
update_db(runtime_db_name, sqls)
# tell SM to apply changes
if "yes" == provision_str:
provision_service(args.service_group_member,
args.service_group)
elif "no" == provision_str:
deprovision_service(args.service_group_member,
args.service_group)
elif args.which == 'service': elif args.which == 'service':
print('%s service <service_name>\nhas been deprecated and '
'it is supported for backward compatibility.\n'
'Please use %s service-group-member <service_group> '
'<service_group_member>' % (file_name, file_name))
database = sqlite3.connect(database_name) database = sqlite3.connect(database_name)
cursor = database.cursor() cursor = database.cursor()