How to use the pyeapi.eapilib.CommandError function in pyeapi

To help you get started, we’ve selected a few pyeapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arista-eosplus / pyeapi / test / system / test_client.py View on Github external
def test_execute_with_autocomplete(self):
        # There are some versions of EOS before 4.17.x that have the
        # autocomplete feature available. If system tests are run on one of
        # those version of EOS this system test will fail.
        for dut in self.duts:
            version = self._dut_eos_version(dut)
            version = version.split('.')
            if int(version[0]) >= 4 and int(version[1]) >= 17:
                result = dut.connection.execute(['sh ver'], encoding='json',
                                                autoComplete=True)
                self.assertIn('version', result['result'][0])
            else:
                # Verify exception thrown for EOS version that does not
                # support autoComplete parameter with EAPI
                with self.assertRaises(pyeapi.eapilib.CommandError):
                    dut.connection.execute(['sh ver'], encoding='json',
                                           autoComplete=True)
github arista-eosplus / pyeapi / test / unit / test_eapilib.py View on Github external
def test_create_command_error(self):
        result = pyeapi.eapilib.CommandError(9999, 'test')
        self.assertIsInstance(result, pyeapi.eapilib.EapiError)
github internap / fake-switches / tests / arista / test_arista_show_interfaces.py View on Github external
def test_show_interfaces_unknown(self, t, api):
        t.write("show interfaces Et3")
        t.readln("% Invalid input")
        t.read("my_arista>")

        with self.assertRaises(CommandError) as expect:
            api.enable("show interfaces Et3", strict=True)

        assert_that(str(expect.exception), is_(
            "Error [1002]: CLI command 2 of 2 'show interfaces Et3' failed: invalid command "
            "[Invalid input]"
github internap / fake-switches / tests / arista / test_arista_rest_api.py View on Github external
def test_execute_show_vlan_unknown_vlan(self):
        with self.assertRaises(CommandError) as expect:
            self.connection.execute("show vlan 999")

        assert_that(str(expect.exception), is_(
            "Error [1000]: CLI command 1 of 1 'show vlan 999' failed: could not run command "
            "[VLAN 999 not found in current VLAN database]"
        ))

        assert_that(expect.exception.output, is_([
            {
                'vlans': {},
                'sourceDetail': '',
                'errors': ['VLAN 999 not found in current VLAN database']
            }
github networktocode / pyntc / test / unit / test_devices / device_mocks / eos / __init__.py View on Github external
def enable(commands, encoding='json'):
    responses = []
    executed_commands = []
    for command in commands:
        command = command.replace(' ', '_')
        path = os.path.join(CURRNENT_DIR, 'enable' + '_' + encoding, command)

        executed_commands.append(command)
        if not os.path.isfile(path):
            raise EOSCommandError(1002, '%s failed' % command, commands=executed_commands)

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

        responses.append(response)

    response_string = ','.join(responses)
    response_string = '[' + response_string + ']'

    return json.loads(response_string)
github internap / fake-switches / tests / arista / test_arista_rest_api.py View on Github external
def test_execute_show_vlan_invalid_input(self):
        with self.assertRaises(CommandError) as expect:
            self.connection.execute("show vlan shizzle")

        assert_that(str(expect.exception), is_(
            "Error [1002]: CLI command 1 of 1 'show vlan shizzle' failed: invalid command "
            "[Invalid input]"
github ktbyers / pynet / pyth_ans_ecourse / class7 / eapi_vlan.py View on Github external
def check_vlan_exists(eapi_conn, vlan_id):
    '''
    Check if the given VLAN exists

    Return either vlan_name or False
    '''
    vlan_id = str(vlan_id)
    cmd = 'show vlan id {}'.format(vlan_id)
    try:
        response = eapi_conn.enable(cmd)
        check_vlan = pyeapi_result(response)['vlans']
        return check_vlan[vlan_id]['name']
    except (pyeapi.eapilib.CommandError, KeyError):
        pass

    return False