def testConnect(self): dev = self.mock.CreateMock(device.Device) dev.connect(credential=self.credential, connect_method='foo').AndReturn(None) self.mock.ReplayAll() s = session.Session(device=dev) s.credential = self.credential s.connect() self.assertTrue(s.connected) self.mock.VerifyAll()
def testCommandRequestInShellMode(self): dev = self.mock.CreateMock(device.Device) dev.connect(credential=self.credential, connect_method='foo').AndReturn(None) dev.command('show version', mode='shell').AndReturn('# Shell mode') self.mock.ReplayAll() s = session.Session(device=dev) s.credential = self.credential result = s.request('command', 'show version', mode='shell') self.assertEqual(base64.b64decode(result), '# Shell mode') self.mock.VerifyAll()
def testGetSession(self): sk = self.testSessionKey() dev = self.mock.CreateMock(device.Device) self.mock.ReplayAll() expected_session = session.Session(device=dev) self.controller.sessions = {sk: expected_session} sess = self.controller.get_session(device_name='xr1.foo', connect_method='sshv2', user='******', privilege_level='ro') self.assertEqual(sess, expected_session) self.mock.VerifyAll()
def testExpireSession(self): dev = self.mock.CreateMock(device.Device) dev.name = 'xr1.foo' dev.vendor = 'junos' dev.connect(credential=self.credential, connect_method='foo').AndReturn(None) dev.disconnect().AndReturn(None) self.mock.ReplayAll() sess = session.Session(device=dev) sess.credential = self.credential sess.connect() self.controller.expire_session(None, sess) # No value assertions, just confirm all the device calls are made. self.mock.VerifyAll()
def testRunMaintenanceWithDisconnectableSession(self): dev = self.mock.CreateMock(device.Device) dev.MAX_IDLE_TIME = 300.0 dev.name = 'xr1.foo' dev.disconnect().AndReturn(None) self.mock.ReplayAll() # Send the stop event so that only one run of maintenance will occur. self.controller._stopped.send() sess = session.Session(device=dev) sess._connected = True sess.time_last_request = 1.0 self.controller.sessions = {self.testSessionKey(): sess} self.assertTrue(sess.connected) self.controller.run_maintenance() self.assertFalse(sess.connected) self.mock.VerifyAll()
def setUp(self): self.device = device.Device(name='test1.popname', addresses='10.0.0.1') self.credential = credential.Credential(regexp='.*', connect_method='foo') self.session = session.Session(device=self.device) self.session.credential = self.credential
def setUp(self): self.session = session.Session()