示例#1
0
 def _cli_error_check(self, command_response):
     error = command_response.get(u'error')
     if error:
         command = command_response.get(u'command')
         if u'data' in error:
             raise CLIError(command, error[u'data'][u'msg'])
         else:
             raise CLIError(command, 'Invalid command.')
示例#2
0
    def test_bad_config(self):
        command = "asdf poknw"
        self.device.native.config.side_effect = CLIError(
            command, "Invalid command.")

        with self.assertRaisesRegex(CommandError, command):
            self.device.config(command)
示例#3
0
    def test_bad_config_list(self):
        commands = ["interface Eth1", "apons"]
        self.device.native.config_list.side_effect = CLIError(
            commands[1], "Invalid command.")

        with self.assertRaisesRegex(CommandListError, commands[1]):
            self.device.config_list(commands)
示例#4
0
    def test_bad_config_list(self):
        commands = ['interface Eth1', 'apons']
        self.device.native.config_list.side_effect = CLIError(
            commands[1], 'Invalid command.')

        with self.assertRaisesRegexp(CommandListError, commands[1]):
            self.device.config_list(commands)
示例#5
0
文件: __init__.py 项目: xuys50/pyntc
def show(command, raw_text=False):
    command = command.replace(" ", "_")
    command = command.replace("/", "_")

    if raw_text:
        path = os.path.join(CURRNENT_DIR, "show_raw", command)
    else:
        path = os.path.join(CURRNENT_DIR, "show", command)

    if not os.path.isfile(path):
        raise CLIError(command, "Invalid command.")

    with open(path, "r") as f:
        response = f.read()

    if raw_text:
        return response
    else:
        return json.loads(response)
示例#6
0
def show(command, raw_text=False):
    command = command.replace(' ', '_')
    command = command.replace('/', '_')

    if raw_text:
        path = os.path.join(CURRNENT_DIR, 'show_raw', command)
    else:
        path = os.path.join(CURRNENT_DIR, 'show', command)

    if not os.path.isfile(path):
        raise CLIError(command, 'Invalid command.')

    with open(path, 'r') as f:
        response = f.read()

    if raw_text:
        return response
    else:
        return json.loads(response)
示例#7
0
    def test_bad_rollback(self):
        self.device.native.rollback.side_effect = CLIError(
            "rollback", "bad rollback command")

        with self.assertRaises(RollbackError):
            self.device.rollback("bad_checkpoint")
示例#8
0
    def test_bad_rollback(self):
        self.device.native.rollback.side_effect = CLIError(
            'rollback', 'bad rollback command')

        with self.assertRaises(RollbackError):
            self.device.rollback('bad_checkpoint')