Skip to content

[multi-asic] Fixed systemd-sonic-generator for multi-asic#7633

Merged
theasianpianist merged 3 commits intosonic-net:masterfrom
anamehra:anamehra/master/systemd-sonic-gen
May 28, 2021
Merged

[multi-asic] Fixed systemd-sonic-generator for multi-asic#7633
theasianpianist merged 3 commits intosonic-net:masterfrom
anamehra:anamehra/master/systemd-sonic-gen

Conversation

@anamehra
Copy link
Copy Markdown
Contributor

@anamehra anamehra commented May 17, 2021

Signed-off-by: Anand Mehra [email protected]

Why I did it

  1. systemd-sonic-generator limits multi-asic unit file instances to 10 (single digit instance number 0 - 10). This limitation needs to be removed to handle more than 10 asics.
  2. MAX_NUM_TARGETS and MAX_NUM_INSTALL_LINES limits to 15 which is not sufficient for systems with more than 15 asics.
  3. Inside get_unit_files(), strcmp produce incorrect results due to non null terminated string being compared.

How I did it

1. In function insert_instance_number instance_string was malloced for 2 char
   size which was limiting the instance number value in instance_name to 1 digit.
   Fixed insert_instance_number to use asprintf to generate instancd_name for
   any number of instances. Added _GNU_SOURCE to CFLAGS for asprintf.

2. Fixed get_unit_files() to use calloc instead of malloc. Uninitialized memory
   was causing incorrect string mismatch error while comparing unit file name
   string.

3. Increased MAX_NUM_TARGETS and MAX_NUM_INSTALL_LINES values to 48 to handle more
   asic instances.

4. Added build UT support for systemd-sonic-generator:
    a. Refactor systemd-sonic-generator.c to be used with UT infra.
    b. Added UT infra to run build UT for systemd-sonic-generator
    c. Added functional level and program level UT class and test cases.

How to verify it

On a single asic system:

  1. Verify Unit file symlinks at following path for single instance system:
    /run/systemd/generator/multi-user.target.wants/
    /run/systemd/generator/sonic.target.wants/
    /run/systemd/generator/swss.service.wants/

On a multi asic system:

  1. Verify Unit file symlinks at following path for multi instance system:
    /run/systemd/generator/multi-user.target.wants/
    /run/systemd/generator/sonic.target.wants/
    /run/systemd/generator/[email protected]/ where n is instance num 0 - (num_asic-1)

Build UT logs:
systemd-sonic-generator_1.0.0_amd64.deb.log

Single asic system logs:
Single_asic.logs.txt

Multi asic system logs:
multi-asic.logs.txt

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012

Description for the changelog

A picture of a cute animal (not mandatory but encouraged)

    1. In function insert_instance_number instance_string was malloced for 2 char
       size which was limiting the instance number value in instance_name to 1 digit.
       Fixed insert_instance_number to use asprintf to generate instancd_name for
       any number of instances. Added _GNU_SOURCE to CFLAGS for asprintf.

    2. Fixed get_unit_files() to use calloc instead of malloc. Uninitialized memory
       was causing incorrect string mismatch error while comparing unit file name
       string.

    3. Increased MAX_NUM_TARGETS and MAX_NUM_INSTALL_LINES values to 48 to handle more
       asic instances.

    4. Added build UT support for systemd-sonic-generator:
        a. Refactor systemd-sonic-generator.c to be used with UT infra.
        b. Added UT infra to run build UT for systemd-sonic-generator
        c. Added functional level and program level UT class and test cases.

Signed-off-by: Anand Mehra <[email protected]>
@anamehra anamehra requested a review from lguohan as a code owner May 17, 2021 23:33
@ghost
Copy link
Copy Markdown

ghost commented May 17, 2021

CLA assistant check
All CLA requirements met.

Copy link
Copy Markdown
Contributor

@jleveque jleveque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comments.

And thank you for adding the unit tests!

@lguohan
Copy link
Copy Markdown
Collaborator

lguohan commented May 18, 2021

@theasianpianist to check

    1. Explicitly setting global pointers to NULL in definitions.
    2. Added a space before ": public" in class definitions to align style
       with SONiC C++ files.

Signed-off-by: Anand Mehra <[email protected]>
@anamehra
Copy link
Copy Markdown
Contributor Author

Hi @lguohan , The build errors reported after new commit does not look like related. Were these observed earlier? May we rerun the builds? Thanks

@theasianpianist
Copy link
Copy Markdown
Contributor

/Azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@abdosi
Copy link
Copy Markdown
Contributor

abdosi commented May 25, 2021

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@anamehra
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Commenter does not have sufficient privileges for PR 7633 in repo Azure/sonic-buildimage

@anshuv-mfst
Copy link
Copy Markdown

Hi @theasianpianist - could you please initiate azp run.

@theasianpianist
Copy link
Copy Markdown
Contributor

/Azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@anamehra
Copy link
Copy Markdown
Contributor Author

Thanks @theasianpianist for re-executing pipeline.
@anshuv-mfst As all build/test pass, could this be merged or do we need more approvals?

@anshuv-mfst
Copy link
Copy Markdown

@theasianpianist - thanks, could you please review and approve, kindly help with merge.

@theasianpianist theasianpianist merged commit 4f8dec9 into sonic-net:master May 28, 2021
@lguohan
Copy link
Copy Markdown
Collaborator

lguohan commented Jun 9, 2021

revert this pr, please fix the armhf build.

lguohan added a commit that referenced this pull request Jun 9, 2021
@anamehra
Copy link
Copy Markdown
Contributor Author

Hi @lguohan , @theasianpianist , the build issue with armfh was because the static gtest lib was not being pacakged. I have fixed it by using -lgtest which works for both arm64 and armfh builds.

I was wondering if I should split this PR in two PRs, one for actual systemd-sonic-generator changes to required multi-asic enhancements and the other for UT code enhancement only. Please advise.

@theasianpianist
Copy link
Copy Markdown
Contributor

@anamehra unless @lguohan has a preference, I am fine with either

@anamehra anamehra deleted the anamehra/master/systemd-sonic-gen branch June 23, 2021 18:24
@anamehra
Copy link
Copy Markdown
Contributor Author

@theasianpianist Created #7954 with only change in Makefile for -lgtest

carl-nokia pushed a commit to carl-nokia/sonic-buildimage that referenced this pull request Aug 7, 2021
…7633)

* Fixed systemd-sonic-generator for multi-asic

    1. In function insert_instance_number instance_string was malloced for 2 char
       size which was limiting the instance number value in instance_name to 1 digit.
       Fixed insert_instance_number to use asprintf to generate instancd_name for
       any number of instances. Added _GNU_SOURCE to CFLAGS for asprintf.

    2. Fixed get_unit_files() to use calloc instead of malloc. Uninitialized memory
       was causing incorrect string mismatch error while comparing unit file name
       string.

    3. Increased MAX_NUM_TARGETS and MAX_NUM_INSTALL_LINES values to 48 to handle more
       asic instances.

    4. Added build UT support for systemd-sonic-generator:
        a. Refactor systemd-sonic-generator.c to be used with UT infra.
        b. Added UT infra to run build UT for systemd-sonic-generator
        c. Added functional level and program level UT class and test cases.

* Resolved review comments.

    1. Explicitly setting global pointers to NULL in definitions.
    2. Added a space before ": public" in class definitions to align style
       with SONiC C++ files.

* Merged strtok_r statements in single command.

Signed-off-by: Anand Mehra <[email protected]>
carl-nokia pushed a commit to carl-nokia/sonic-buildimage that referenced this pull request Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants