def test_commands(protocol): c = arcomm.connect(HOST, creds=ARCOMM_CREDS, protocol=protocol) r = c.execute("show version") cmd = arcomm.Command({'cmd': 'show version', 'prompt': r'password', 'answer': 'nonya'}) r = c.execute(cmd)
def arcomm(self, line, cell=None, local_ns={}): args = magic_arguments.parse_argstring(self.arcomm, line) commands = [] responses = [] if args.command: commands = [args.command] elif cell: commands = [cmd for cmd in cell.splitlines()] for endpoint in args.endpoints: if endpoint in self._connections: conn = self._connections[endpoint] else: conn = arcomm.connect(endpoint, askpass=args.askpass) self._connections[conn.hostname] = conn if commands: response = conn.send(commands, encoding=args.encoding) print(response) sys.stdout.flush() responses.append(response) return responses
def test_clone(protocol): sess = arcomm.connect(HOST, creds=ARCOMM_CREDS, protocol=protocol) with pytest.raises(arcomm.exceptions.AuthenticationFailed): sess.clone(creds=('leet', 'hacker')) sess.clone()
def dut(self): # hostname field is required, others have defaults hostname = self._config.dut.hostname user = self._config.dut.get('username', 'admin') password = self._config.dut.get('password', '') authorize = self._config.dut.get('authorize', '') protocol = self._config.dut.get('protocol', 'eapi') conn = arcomm.connect(hostname, (user, password), protocol=protocol) conn.authorize() return conn
def test_oldway_funcs(): username = ARCOMM_CREDS.username password = ARCOMM_CREDS.password creds = arcomm.get_credentials(username, password) commands = ['show clock'] conn = arcomm.connect(HOST, creds) assert conn arcomm.authorize(conn) assert arcomm.authorized(conn) assert arcomm.clone(conn) assert arcomm.configure(conn, []) assert arcomm.execute_pool([HOST], creds, commands) assert arcomm.execute_bg(HOST, creds, commands) assert arcomm.execute_once(HOST, creds, commands) arcomm.execute_until(conn, commands, condition=r'\:[0-5]0', timeout=11, sleep=.1) arcomm.close(conn)
def test_bad_auth(protocol): with pytest.raises(arcomm.AuthenticationFailed): arcomm.connect(HOST, creds=arcomm.BasicCreds('baduser', 'badpass'), protocol=protocol)
def test_execute_sess(): conn = arcomm.connect(HOST, creds=ARCOMM_CREDS) arcomm.execute(conn, 'show version')
def test_send_timeout(protocol): conn = arcomm.connect(HOST, creds=ARCOMM_CREDS, protocol=protocol) with pytest.raises(arcomm.exceptions.ExecuteFailed): response = conn.execute(["bash timeout 15 sleep 10"], timeout=1) response.raise_for_error()
def test_connect_timeout(protocol): creds = arcomm.creds("admin", password="") with pytest.raises(arcomm.exceptions.ConnectFailed): conn = arcomm.connect("1.2.3.4", timeout=1, creds=creds, protocol=protocol)
def test_execute_bad_auth(protocol): with pytest.raises(arcomm.AuthenticationFailed): arcomm.connect(HOST, creds=arcomm.BasicCreds('jerk', 'store'), protocol=protocol)
def test_execute(hostaddr, creds): conn = arcomm.connect(hostaddr, creds=creds) response = conn.execute(["show version"]) for item in response: print(type(item))