Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new cli to add a interface ip as secondary address #3016

Conversation

shbalaku-microsoft
Copy link
Contributor

What I did

Added a new CLI command to add secondary subnet value.

How I did it

In the config class, added a snippet of code where the code to validate the secondary field and set the appropriate flag.

How to verify it

Added a test to validate the added flag

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

@@ -4551,6 +4552,11 @@ def add(ctx, interface_name, ip_addr, gw):
config_db.set_entry(table_name, interface_name, {"NULL": "NULL"})
config_db.set_entry(table_name, (interface_name, str(ip_address)), {"NULL": "NULL"})

if secondary:
# We update the secondary flag only in case of VLAN Interface.
if table_name == "VLAN_INTERFACE":
Copy link
Contributor

Choose a reason for hiding this comment

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

For other interface types, do we need to throw an error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a validation to make sure not all IPs are marked as secondary?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a validation to make sure no more than one primary IP for a given VLAN interface?

Choose a reason for hiding this comment

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

Do we need a validation to make sure not all IPs are marked as secondary?

Ack, this is a good check.

Do we need a validation to make sure no more than one primary IP for a given VLAN interface?

This we cannot do for two reasons: a) impact to potential existing devices with more than one interface b) interchanging primary with secondary would need more than one primary intermittently.

Choose a reason for hiding this comment

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

This has been addressed. Only vlans with atleast one primary can be added with secondaries.

result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["add"], ["Vlan100", "10.11.20.1/24", "--secondary"], obj=obj)
assert result.exit_code == 0
assert ('Vlan100', '10.11.20.1/24') in db.cfgdb.get_table('VLAN_INTERFACE')
assert db.cfgdb.get_table('VLAN_INTERFACE')[('Vlan100', '10.11.20.1/24')]['secondary'] == "true"

Choose a reason for hiding this comment

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

nit: add a test where 'secondary' is false for non-secondary cli call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the test case for this scenario.

@shbalaku-microsoft
Copy link
Contributor Author

@venkatmahalingam can you review the PR?

@zhangyanzhao
Copy link
Collaborator

prsunny
prsunny previously approved these changes Feb 6, 2024
@prsunny
Copy link
Contributor

prsunny commented Feb 6, 2024

@venkatmahalingam , can you signoff?

@irene-pan1202
Copy link

@shbalaku-microsoft
The design of the secondary IP seems to have an issue that hasn't been considered?

  1. If a VLAN interface has only an IPv6 address, it is also considered as the primary IP, and an IPv4 secondary IP can still be successfully configured.
  2. Deleting the primary IP seems to not check if the secondary IP exists?

@zhangyanzhao
Copy link
Collaborator

@qiluo-msft can we merge this PR? Thanks.

@qiluo-msft
Copy link
Contributor

Please merge latest master branch. The semgrep checker is added after this PR raised, so it will always block.

@prsunny
Copy link
Contributor

prsunny commented Apr 29, 2024

@shbalaku-microsoft , can you please rebase the code?

@zhangyanzhao
Copy link
Collaborator

@shbalaku-microsoft kind reminder to rebase the code, so that we can merge this feature before 202405 fork date on 5/30

@qiluo-msft qiluo-msft merged commit e054b45 into sonic-net:master May 15, 2024
7 checks passed
arfeigin pushed a commit to arfeigin/sonic-utilities that referenced this pull request Jun 16, 2024
#### What I did

Added a new CLI command to add secondary subnet value. 

#### How I did it

In the config class, added a snippet of code where the code to validate the secondary field and set the appropriate flag.

#### How to verify it

Added a test to validate the added flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants