def test_process_router_throw_config_error(self):
     snip_name = 'CREATE_SUBINTERFACE'
     e_type = 'Fake error'
     e_tag = 'Fake error tag'
     params = {'snippet': snip_name, 'type': e_type, 'tag': e_tag}
     self.routing_helper._internal_network_added.side_effect = (
         cfg_exceptions.CSR1kvConfigException(**params))
     router, ports = prepare_router_data()
     ri = RouterInfo(router['id'], router)
     self.assertRaises(cfg_exceptions.CSR1kvConfigException,
                       self.routing_helper._process_router, ri)
Exemplo n.º 2
0
    def _check_response(rpc_obj, snippet_name):
        """This function checks the rpc response object for status.

        This function takes as input the response rpc_obj and the snippet name
        that was executed. It parses it to see, if the last edit operation was
        a success or not.
            <?xml version="1.0" encoding="UTF-8"?>
            <rpc-reply message-id="urn:uuid:81bf8082-....-b69a-000c29e1b85c"
                       xmlns="urn:ietf:params:netconf:base:1.0">
                <ok />
            </rpc-reply>
        In case of error, CSR1kv sends a response as follows.
        We take the error type and tag.
            <?xml version="1.0" encoding="UTF-8"?>
            <rpc-reply message-id="urn:uuid:81bf8082-....-b69a-000c29e1b85c"
            xmlns="urn:ietf:params:netconf:base:1.0">
                <rpc-error>
                    <error-type>protocol</error-type>
                    <error-tag>operation-failed</error-tag>
                    <error-severity>error</error-severity>
                </rpc-error>
            </rpc-reply>
        :return: True if the config operation completed successfully
        :raises: neutron.plugins.cisco.cfg_agent.cfg_exceptions.
        CSR1kvConfigException
        """
        LOG.debug("RPCReply for %(snippet_name)s is %(rpc_obj)s", {
            'snippet_name': snippet_name,
            'rpc_obj': rpc_obj.xml
        })
        xml_str = rpc_obj.xml
        if "<ok />" in xml_str:
            LOG.debug("RPCReply for %s is OK", snippet_name)
            LOG.info(_("%s successfully executed"), snippet_name)
            return True
        # Not Ok, we throw a ConfigurationException
        e_type = rpc_obj._root[0][0].text
        e_tag = rpc_obj._root[0][1].text
        params = {'snippet': snippet_name, 'type': e_type, 'tag': e_tag}
        raise cfg_exc.CSR1kvConfigException(**params)