Skip to content

Commit

Permalink
No more IP validation as it is more likely a URL (sonic-net#1555)
Browse files Browse the repository at this point in the history
Dropped IP validation as server takes URL.
  • Loading branch information
renukamanavalan authored Apr 16, 2021
1 parent d5f5382 commit e296a69
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
21 changes: 1 addition & 20 deletions config/kube.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import click
import socket

from utilities_common.cli import AbbreviationGroup, pass_db

Expand All @@ -21,22 +20,6 @@
KUBE_LABEL_TABLE = "KUBE_LABELS"
KUBE_LABEL_SET_KEY = "SET"

def is_valid_ip4_addr(address):
try:
socket.inet_pton(socket.AF_INET, address)
except socket.error: # not a valid address
return False
return True


def is_valid_ip6_addr(address):
try:
socket.inet_pton(socket.AF_INET6, address)
except socket.error: # not a valid address
return False
return True


def _update_kube_server(db, field, val):
db_data = db.cfgdb.get_entry(KUBE_SERVER_TABLE_NAME, KUBE_SERVER_TABLE_KEY)
def_data = {
Expand Down Expand Up @@ -82,9 +65,7 @@ def server():
@pass_db
def ip(db, vip):
"""Specify a kubernetes cluster VIP"""
if vip and not is_valid_ip4_addr(vip) and not is_valid_ip6_addr(vip):
click.echo('Invalid IP address %s' % vip)
sys.exit(1)

_update_kube_server(db, KUBE_SERVER_IP, vip)


Expand Down
6 changes: 1 addition & 5 deletions tests/kube_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,11 @@ def test_set_server_ip(self, get_cmd_module):
self.__check_res(result, "check server IP", show_server_output_1)


def test_set_server_invalid_ip_port(self, get_cmd_module):
def test_set_server_invalid_port(self, get_cmd_module):
(config, show) = get_cmd_module
db = Db()
runner = CliRunner()

# test invalid IP
result = runner.invoke(config.config.commands["kubernetes"].commands["server"], ["ip", "10101011"], obj=db)
assert result.exit_code == 1

# test invalid port
result = runner.invoke(config.config.commands["kubernetes"].commands["server"], ["port", "10101011"], obj=db)
assert result.exit_code == 1
Expand Down

0 comments on commit e296a69

Please sign in to comment.