Ejemplo n.º 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.')
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 5
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)
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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')