Пример #1
0
    def _read_file(self, fname):
        from ncclient.xml_ import NCElement

        fpath = os.path.join(os.path.dirname(__file__),
                             'rpc-reply', fname)
        with open(fpath) as fp:
            foo = fp.read()

            if fname == 'get-rpc-error.xml':
                # Raise ncclient exception for error
                raise RPCError(etree.XML(foo))
            elif fname == 'get-permission-denied.xml':
                # Raise ncclient exception for error
                raise RPCError(etree.XML(foo))
            elif (fname == 'get-index-error.xml' or
                    fname == 'get-system-core-dumps.xml' or
                    fname == 'load-configuration-error.xml' or
                    fname == 'show-configuration-interfaces.xml' or
                  fname == 'show-interfaces-terse-asdf.xml'):
                rpc_reply = NCElement(foo, self.dev._conn._device_handler
                                      .transform_reply())
            elif (fname == 'show-configuration.xml' or
                  fname == 'show-system-alarms.xml'):
                rpc_reply = NCElement(foo, self.dev._conn._device_handler
                                      .transform_reply())._NCElement__doc
            elif fname == 'show-interface-terse.json':
                rpc_reply = json.loads(foo)
            elif fname == 'get-route-information.json':
                rpc_reply = NCElement(foo, self.dev._conn._device_handler
                                      .transform_reply())
            else:
                rpc_reply = NCElement(foo, self.dev._conn._device_handler
                                      .transform_reply())._NCElement__doc[0]
        return rpc_reply
Пример #2
0
    def _read_file(self, fname):
        fpath = os.path.join(os.path.dirname(__file__), 'rpc-reply', fname)
        foo = open(fpath).read()

        # specific to multi rpc error
        if fname == 'commit-configuration.xml':
            raw = etree.XML(foo)
            obj = RPCReply(raw)
            obj.parse()
            if ncclient.__version__ > (0, 4, 5):
                raise RPCError(etree.XML(foo), errs=obj._errors)
            else:
                raise RPCError(etree.XML(foo))
Пример #3
0
 def test_repr_multi_warning(self):
     rsp = etree.XML(multi_warning_xml)
     from ncclient.operations import RPCError
     warn_msg = '''
     <rpc-error xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/16.1I0/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     <error-severity>warning</error-severity>
     <error-message>
     statement not found
     </error-message>
     </rpc-error>'''
     errs = RPCError(etree.XML(warn_msg))
     errs.errors = [errs, errs]
     obj = RpcError(rsp=rsp, errs=errs)
     self.assertEqual(obj.rpc_error['severity'], 'warning')
Пример #4
0
 def test_repr_multi_warning(self):
     rsp = etree.XML(multi_warning_xml)
     from ncclient.operations import RPCError
     warn_msg = '''
     <rpc-error xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/16.1I0/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
     <error-severity>warning</error-severity>
     <error-message>
     statement not found
     </error-message>
     </rpc-error>'''
     errs = RPCError(etree.XML(warn_msg))
     errs.errors = [errs, errs]
     obj = RpcError(rsp=rsp, errs=errs)
     self.assertEqual(obj.rpc_error['severity'], 'warning')
Пример #5
0
    def _read_file(self, fname):
        fpath = os.path.join(os.path.dirname(__file__), "rpc-reply", fname)
        foo = open(fpath).read()

        # specific to multi rpc error
        if fname == "commit-configuration.xml":
            raw = etree.XML(foo)
            obj = RPCReply(raw)
            obj.parse()
            raise RPCError(etree.XML(foo), errs=obj._errors)
Пример #6
0
    def _read_file(self, fname):
        from ncclient.xml_ import NCElement

        fpath = os.path.join(os.path.dirname(__file__), 'rpc-reply', fname)
        foo = open(fpath).read()

        if fname == 'get-rpc-error.xml':
            # Raise ncclient exception for error
            raise RPCError(etree.XML(foo))
        elif (fname == 'get-index-error.xml'
              or fname == 'get-system-core-dumps.xml'
              or fname == 'load-configuration-error.xml'):
            rpc_reply = NCElement(
                foo, self.dev._conn._device_handler.transform_reply())
        elif (fname == 'show-configuration.xml'
              or fname == 'show-system-alarms.xml'):
            rpc_reply = NCElement(
                foo, self.dev._conn._device_handler.transform_reply()
            )._NCElement__doc
        else:
            rpc_reply = NCElement(
                foo, self.dev._conn._device_handler.transform_reply()
            )._NCElement__doc[0]
        return rpc_reply
Пример #7
0
def test_do_rpc_with_rpc_error(test_client):
    test_client._session = mock.MagicMock()
    test_client._session.dispatch.side_effect = RPCError(mock.MagicMock())
    with pytest.raises(RPCError):
        test_client._do_rpc("<rpc>xml</rpc>")
Пример #8
0
def test_do_edit_config_rpc_error(test_client):
    test_client._session = mock.MagicMock()
    test_client._session.edit_config.side_effect = RPCError(mock.MagicMock())
    with pytest.raises(RPCError):
        test_client._do_edit_config("running", "")
Пример #9
0
def test_do_edit_config_rpc_error_and_ignore_delete_error(test_client):
    test_client._session = mock.MagicMock()
    test_client._session.edit_config.side_effect = RPCError(mock.MagicMock())
    with pytest.raises(RPCError):
        test_client._do_edit_config("running", 'operation="delete"', ignore_delete_error=True)
Пример #10
0
def test_do_unlock_rpc_error(test_client):
    test_client._session = mock.MagicMock()
    test_client._session.unlock.side_effect = RPCError(mock.MagicMock())
    with pytest.raises(RPCError):
        test_client._do_unlock("running")
Пример #11
0
def test_do_get_rpc_error(test_client):
    test_client._session = mock.MagicMock()
    test_client._session.get.side_effect = RPCError(mock.MagicMock())
    with pytest.raises(RPCError):
        test_client._do_get("<get>xml</get>")