Skip to content

Commit

Permalink
port support added for same Ip-address. Juniper#322
Browse files Browse the repository at this point in the history
  • Loading branch information
rahkumar651991 committed Jan 31, 2020
1 parent 18c1e84 commit 92bcde4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
7 changes: 3 additions & 4 deletions lib/jnpr/jsnapy/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@

class Comparator:

def __init__(self,**kwargs):
def __init__(self, **kwargs):
"""
Comparator object constructor.
:param int port.
"""
self.port = kwargs.get('port', None)
self.logger_check = logging.getLogger(__name__)
self.log_detail = {'hostname': None}

self.port = kwargs.get('port', None)

def is_op(self, op):
"""
Expand Down Expand Up @@ -70,7 +69,7 @@ def generate_snap_file(self, device, prefix, name, reply_format):
This function generates name of snapshot files
"""
if self.port is not None:
device = device + "_" + str(self.port)
device = "{}_{}".format(device, self.port)
if os.path.isfile(prefix):
return prefix
else:
Expand Down
26 changes: 14 additions & 12 deletions lib/jnpr/jsnapy/jsnapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,14 @@ def get_hosts(self):
sys.exit(1)
self.login(output_file)

def generate_rpc_reply(self, dev, output_file, hostname, config_data,**kwargs):
def generate_rpc_reply(self, dev, output_file, hostname, config_data, **kwargs):
"""
Generates rpc-reply based on command/rpc given and stores them in snap_files
:param dev: device handler
:param output_file: filename to store snapshots
:param hostname: hostname of device
:param config_data : data of main config file
"""
port = kwargs.get('port', None)
val = None
test_files = []
for tfile in config_data.get('tests'):
Expand Down Expand Up @@ -488,18 +487,19 @@ def login(self, output_file):
gp = first_entry.get('group', 'all')

dgroup = [i.strip().lower() for i in gp.split(',')]
iter = 0;
for dgp in dev_file:
if dgroup[0].lower() == 'all' or dgp.lower() in dgroup:
for val in dev_file[dgp]:
for counter, val in enumerate(dev_file[dgp]):
# There can be multiple values of device/hostname
# The values can have same hostname but different port
# key for the dictionary modified from hostname to enumerate value to keep distinction
hostname = list(val)[0]
iter+=1
self.log_detail = {'hostname': hostname}
if val.get(hostname) is not None and hostname not in self.host_list:
#host_dict[hostname] = deepcopy(val.get(hostname))
self.host_list.append(hostname)
host_dict[iter] = deepcopy(val.get(hostname))
host_dict[iter]["device"] = hostname
host_dict[counter] = deepcopy(val.get(hostname))
host_dict[counter]["device"] = hostname

# login credentials are given in main config file, can connect to multiple devices
else:
Expand Down Expand Up @@ -542,7 +542,7 @@ def login(self, output_file):
key_value = {'port': port} if port is not None else {}
self.connect(hostname, username, password, output_file, **key_value)

def get_test(self, config_data, hostname, snap_file, post_snap, action,**kwargs):
def get_test(self, config_data, hostname, snap_file, post_snap, action, **kwargs):
"""
Analyse testfile and return object of operator.Operator containing test details
called by connect() function and other functions of Jsnapy module functions
Expand Down Expand Up @@ -1016,9 +1016,8 @@ def get_hosts_list(self, hosts_val, host_dict):
:param hosts_val: has the list of hosts to be parsed
:param host_dict: The dictionary to be created to store the parsed values
"""
iter = -1 #iterator keeps count of number of hosts
for host in hosts_val:
iter += 1

for counter, host in enumerate(hosts_val):
try:
hostname = host['device']
self.log_detail = {'hostname': hostname}
Expand All @@ -1036,7 +1035,10 @@ def get_hosts_list(self, hosts_val, host_dict):
else:
if hostname not in self.host_list:
self.host_list.append(hostname)
host_dict[iter] = deepcopy(host)
# There can be multiple values of device/hostname
# The values can have same hostname but different port
# key for the dictionary modified from hostname to enumerate value to keep distinction
host_dict[counter] = deepcopy(host)

####### generate init folder ######
'''
Expand Down
4 changes: 2 additions & 2 deletions lib/jnpr/jsnapy/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def __init__(self, **kwargs):
:param int port.
"""
self.port = kwargs.get('port', None)
self.logger_snap = logging.getLogger(__name__)
self.log_detail = {'hostname': None}
self.reply = {}
self.command_list = []
self.rpc_list = []
self.test_included = []
self.port = kwargs.get('port', None)

def _write_file(self, rpc_reply, format, output_file):
"""
Expand Down Expand Up @@ -96,7 +96,7 @@ def generate_snap_file(self, output_file, hostname, name, cmd_format):
:return: return output file
"""
if self.port is not None:
hostname = hostname + "_" + str(self.port)
hostname = "{}_{}".format(hostname, self.port)
name = name.split('|')[0].strip()
cmd_rpc = re.sub('/|\*|\.|-|\|', '_', name)
if os.path.isfile(output_file):
Expand Down

0 comments on commit 92bcde4

Please sign in to comment.