[systemd-generator]: Fix dependency update for multi-asic platform (#4820)

* [systemd-generator]: Fix the code to make sure that dependencies
of host services are generated correctly for multi-asic platforms.
Add code to make sure that systemd timer files are also modified
to add the correct service dependency for multi-asic platforms.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>

* [systemd-generator]: Minor fix, remove debug code and
remove unused variable.
This commit is contained in:
SuvarnaMeenakshi 2020-06-29 09:39:23 -07:00 committed by GitHub
parent ce391645f2
commit ab2177b4a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -519,10 +519,10 @@ sudo LANG=C cp $SCRIPTS_DIR/sonic-netns-exec $FILESYSTEM_ROOT/usr/bin/sonic-netn
# Copy systemd timer configuration # Copy systemd timer configuration
# It implements delayed start of services # It implements delayed start of services
sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM sudo cp $BUILD_TEMPLATES/snmp.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable snmp.timer echo "snmp.timer" | sudo tee -a $GENERATED_SERVICE_FILE
{% if enable_system_telemetry == 'y' %} {% if enable_system_telemetry == 'y' %}
sudo cp $BUILD_TEMPLATES/telemetry.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM sudo cp $BUILD_TEMPLATES/telemetry.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable telemetry.timer echo "telemetry.timer" | sudo tee -a $GENERATED_SERVICE_FILE
{% endif %} {% endif %}
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y python-dev sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get purge -y python-dev

View File

@ -147,12 +147,16 @@ static void replace_multi_inst_dep(char *src) {
char *line_copy; char *line_copy;
char *service_name; char *service_name;
char *type; char *type;
char *save_ptr1 = NULL;
char *save_ptr2 = NULL;
ssize_t nread; ssize_t nread;
bool section_done = false; bool section_done = false;
char tmp_file_path[PATH_MAX]; char tmp_file_path[PATH_MAX];
/* assumes that the service files has 3 sections, /* Assumes that the service files has 3 sections,
* in the order: Unit, Service and Install. * in the order: Unit, Service and Install.
* Assumes that the timer file has 3 sectiosn,
* in the order: Unit, Timer and Install.
* Read service dependency from Unit and Install * Read service dependency from Unit and Install
* sections, replace if dependent on multi instance * sections, replace if dependent on multi instance
* service. * service.
@ -162,7 +166,8 @@ static void replace_multi_inst_dep(char *src) {
fp_tmp = fopen(tmp_file_path, "w"); fp_tmp = fopen(tmp_file_path, "w");
while ((nread = getline(&line, &len, fp_src)) != -1 ) { while ((nread = getline(&line, &len, fp_src)) != -1 ) {
if (strstr(line, "[Service]") != NULL) { if ((strstr(line, "[Service]") != NULL) ||
(strstr(line, "[Timer]") != NULL)) {
section_done = true; section_done = true;
fputs(line,fp_tmp); fputs(line,fp_tmp);
} else if (strstr(line, "[Install]") != NULL) { } else if (strstr(line, "[Install]") != NULL) {
@ -174,16 +179,16 @@ static void replace_multi_inst_dep(char *src) {
fputs(line,fp_tmp); fputs(line,fp_tmp);
} else { } else {
line_copy = strdup(line); line_copy = strdup(line);
token = strtok(line_copy, "="); token = strtok_r(line_copy, "=", &save_ptr1);
while ((word = strtok(NULL, " "))){ while ((word = strtok_r(NULL, " ", &save_ptr1))) {
if((strchr(word, '.') == NULL) || if((strchr(word, '.') == NULL) ||
(strchr(word, '@') != NULL)) { (strchr(word, '@') != NULL)) {
snprintf(buf, MAX_BUF_SIZE,"%s=%s\n",token, word); snprintf(buf, MAX_BUF_SIZE,"%s=%s\n",token, word);
fputs(buf,fp_tmp); fputs(buf,fp_tmp);
} else { } else {
service_name = strdup(word); service_name = strdup(word);
service_name = strtok(service_name, "."); service_name = strtok_r(service_name, ".", &save_ptr2);
type = strtok(NULL, " "); type = strtok_r(NULL, " ", &save_ptr2);
if (is_multi_instance_service(word)) { if (is_multi_instance_service(word)) {
for(i = 0; i < num_asics; i++) { for(i = 0; i < num_asics; i++) {
snprintf(buf, MAX_BUF_SIZE, "%s=%s@%d.%s\n", snprintf(buf, MAX_BUF_SIZE, "%s=%s@%d.%s\n",