deactivate_interfaces throwing error while doing a bf.fork_snapshot
bharmarsameer opened this issue · comments
I am trying to do a failover analysis and when doing deactivate_nodes it works fine however when I am trying to use deactivate_interfaces it is throwing off below error. Here is the code.
Code:
%run startup.py
import pandas as pd
from pybatfish.client.session import Session
from pybatfish.datamodel import *
from pybatfish.datamodel.answer import *
from pybatfish.datamodel.flow import *
bf = Session(host="localhost")
bf.set_network('example_dc')
NETWORK_NAME = "example_network"
BASE_SNAPSHOT_NAME = "base"
SNAPSHOT_PATH = "./snapshot"
bf.set_network(NETWORK_NAME)
bf.init_snapshot(SNAPSHOT_PATH, name=BASE_SNAPSHOT_NAME, overwrite=True)
FAIL_CHI_SNAPSHOT_NAME = "fail_chi"
bf.fork_snapshot(BASE_SNAPSHOT_NAME, FAIL_CHI_SNAPSHOT_NAME, deactivate_nodes=["rtr1"], deactivate_interfaces = ["Ethernet22/1"], overwrite=True)
pop_prefix = "10.8.8.0/20"
tr_answer = bf.q.traceroute(startLocation='/site$/[Loopback0]', headers=HeaderConstraints(dstIps=pop_prefix), maxTraces=1).answer(FAIL_CHI_SNAPSHOT_NAME)
show(tr_answer.frame())
Error:
HTTPError Traceback (most recent call last)
/spare/local/sbharmar/sbharmar/scripts/py3/my_scripts/sb-py3/lib/python3.6/site-packages/pybatfish/client/restv2helper.py in _check_response_status(response)
571 try:
--> 572 response.raise_for_status()
573 except HTTPError as e:
/spare/local/sbharmar/sbharmar/scripts/py3/my_scripts/sb-py3/lib/python3.6/site-packages/requests/models.py in raise_for_status(self)
959 if http_error_msg:
--> 960 raise HTTPError(http_error_msg, response=self)
961
HTTPError: 400 Client Error: Bad Request for url: http://localhost:9996/v2/networks/example_network/snapshots:fork
During handling of the above exception, another exception occurred:
HTTPError Traceback (most recent call last)
in
13 bf.init_snapshot(SNAPSHOT_PATH, name=BASE_SNAPSHOT_NAME, overwrite=True)
14 FAIL_CHI_SNAPSHOT_NAME = "fail_chi"
---> 15 bf.fork_snapshot(BASE_SNAPSHOT_NAME, FAIL_CHI_SNAPSHOT_NAME, deactivate_nodes=["7260cx3-r1-1.chi"], deactivate_interfaces=["Ethernet22/1"],overwrite=True)
16 pop_prefix = "10.34.176.0/20"
17 tr_answer = bf.q.traceroute(startLocation='/ny4$/[Loopback0]', headers=HeaderConstraints(dstIps=pop_prefix), maxTraces=1).answer(FAIL_CHI_SNAPSHOT_NAME)
/spare/local/sbharmar/sbharmar/scripts/py3/my_scripts/sb-py3/lib/python3.6/site-packages/pybatfish/client/session.py in fork_snapshot(self, base_name, name, overwrite, deactivate_interfaces, deactivate_nodes, restore_interfaces, restore_nodes, add_files, extra_args)
589 restore_nodes=restore_nodes,
590 add_files=add_files,
--> 591 extra_args=extra_args,
592 )
593 assert isinstance(ss_name, str) # Guaranteed since background=False
/spare/local/sbharmar/sbharmar/scripts/py3/my_scripts/sb-py3/lib/python3.6/site-packages/pybatfish/client/session.py in _fork_snapshot(self, base_name, name, overwrite, background, deactivate_interfaces, deactivate_nodes, restore_interfaces, restore_nodes, add_files, extra_args)
649 "zipFile": encoded_file,
650 }
--> 651 restv2helper.fork_snapshot(self, json_data)
652
653 return self._parse_snapshot(name, background, extra_args)
/spare/local/sbharmar/sbharmar/scripts/py3/my_scripts/sb-py3/lib/python3.6/site-packages/pybatfish/client/restv2helper.py in fork_snapshot(session, obj)
171 CoordConstsV2.RSC_FORK,
172 )
--> 173 return _post(session, url_tail, obj)
174
175
/spare/local/sbharmar/sbharmar/scripts/py3/my_scripts/sb-py3/lib/python3.6/site-packages/pybatfish/client/restv2helper.py in _post(session, url_tail, obj, params)
665 verify=session.verify_ssl_certs,
666 )
--> 667 _check_response_status(response)
668 return None
669
/spare/local/sbharmar/sbharmar/scripts/py3/my_scripts/sb-py3/lib/python3.6/site-packages/pybatfish/client/restv2helper.py in _check_response_status(response)
572 response.raise_for_status()
573 except HTTPError as e:
--> 574 raise HTTPError("{}. {}".format(e, response.text), response=response)
575
576
HTTPError: 400 Client Error: Bad Request for url: http://localhost:9996/v2/networks/example_network/snapshots:fork. Cannot construct instance of org.batfish.datamodel.collections.NodeInterfacePair
(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('Ethernet22/1')
at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 78] (through reference chain: org.batfish.coordinator.resources.ForkSnapshotBean["deactivateInterfaces"]->java.util.ArrayList[0])
Hi @bharmarsameer - thanks for the report!
I think you are misinterpreting the arguments to fork_snapshot
. See the docs here: https://pybatfish.readthedocs.io/en/latest/batfish_commands.html?highlight=fork_snapshot#pybatfish.client.session.Session.fork_snapshot
tl;dr: deactivate_nodes
means "fail the entire node". deactivate_interfaces
means "fail this specific interface, defined as a node + interface pair". For more info, see the docs above.
I'm guessing you meant deactivate_interfaces=[Interface(hostname="7260cx3-r1-1.chi", interface="Ethernet22/1")]
Awesome. Thank you for the input.