napalm-automation-community / napalm-huawei-vrp

NAPALM Driver for Huawei VRP5/VRP8 Routers and Switches

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This code has a problem with routers that have tow cfcards while saving file in commit object

arashxmohammadi opened this issue · comments

In routers that have 2 cfcards, saving files need to save in slave cards also. So when I want to use the device.commit_config() API, because it trying to save a file into cfcard the router ask an extra question to save the file to slave cfcard:
<BRKSAB_KS0006>save config_20221004_1026.cfg
Warning: Are you sure to save the configuration to cfcard:/config_20221004_1026.cfg? [Y/N]:
By the “y” command that will be sent to the node using “_save_config(self)” function the node goes to the next step, so the situation will be like below:

Warning: cfcard:/config_20221004_1026.cfg exists,overwrite? [Y/N]:y
Now saving the current configuration to the slot 11 .
Info: Save the configuration successfully.
Warning: Are you sure to save the configuration to slave#cfcard:/config_20221004_1026.cfg? [Y/N]:

But in the last line, the node asks to save the file into slave cfcard, but the code doesn’t have an answer for this question. So that it senses an error. In continue we can see the _save_config(self) code:

def _save_config(self, filename=''):
"""Save the current running config to the given file."""
command = 'save {}'.format(filename)
save_log = self.device.send_command(command, max_loops=10, expect_string=r'Y/N')
# Search pattern will not be detected when set a new hostname, so don't use auto_find_prompt=False
save_log += self.device.send_command('y', expect_string=r'<.+>')
search_result = re.search("successfully", save_log, re.M)
if search_result is None:
msg = "Failed to save config. Command output:{}".format(save_log)
raise CommandErrorException(msg)

I have been trying to add change the function code to like below, but it doesn’t work while it seems true:

def _save_config(self, filename=''):
"""Save the current running config to the given file."""
command = 'save {}'.format(filename)
save_log = self.device.send_command(command, max_loops=10, expect_string=r'Y/N')
# Search pattern will not be detected when set a new hostname, so don't use auto_find_prompt=False
save_log += self.device.send_command('y', expect_string=r'Info:')
savecfcard = re.search(“save the configuration to slave#cfcard” , )
if savecfcard == True:
save_log += self.device.send_command('y', expect_string=r'<.+>')
search_result = re.search("successfully", save_log, re.M)
if search_result is None:
msg = "Failed to save config. Command output:{}".format(save_log)
raise CommandErrorException(msg)

Would you help me please to solve this problem?

Hi @arashxmohammadi,

  1. Can you share more information about tis Huawei device? Model, VRP version.
  2. Can you share a full interaction(sessiong logging) with these double confirmation?