Ejemplo n.º 1
0
    def testRequest(self):
        sk = session.SessionKey(device_name='xr1.foo',
                                connect_method='sshv2',
                                user='******',
                                privilege_level='ro')

        sess = self.mock.CreateMock(session.Session)
        sess.request('command',
                     command='show run',
                     connect_method='sshv2',
                     device_name='xr1.foo',
                     mode='shell',
                     privilege_level='ro',
                     user='******').AndReturn('# show run output.')

        self.mock.ReplayAll()
        self.controller.sessions = {sk: sess}
        resp = self.controller.request('command',
                                       command='show run',
                                       mode='shell',
                                       device_name='xr1.foo',
                                       connect_method='sshv2',
                                       user='******',
                                       privilege_level='ro')
        self.assertEqual(resp, '# show run output.')
        self.mock.VerifyAll()
Ejemplo n.º 2
0
 def testSessionKey(self):
     sk = session.SessionKey(device_name='xr1.foo',
                             connect_method='sshv2',
                             user='******',
                             privilege_level='ro')
     self.assertEqual(sk.device_name, 'xr1.foo')
     self.assertEqual(sk.connect_method, 'sshv2')
     self.assertEqual(sk.user, 'anonymous')
     self.assertEqual(sk.privilege_level, 'ro')
     return sk
Ejemplo n.º 3
0
 def testRequestNoDeviceName(self):
     sk = session.SessionKey(device_name=None,
                             connect_method=None,
                             user=None,
                             privilege_level=None)
     sess = self.mock.CreateMock(session.Session)
     self.mock.ReplayAll()
     self.controller.sessions = {sk: sess}
     self.assertRaises(errors.NoSessionCreatedError,
                       self.controller.request,
                       'command',
                       command='show run')
     self.mock.VerifyAll()
Ejemplo n.º 4
0
 def testRequestNoSessionCreated(self):
     sk = session.SessionKey(device_name='xr1.foo',
                             connect_method=None,
                             user=None,
                             privilege_level=None)
     sess = self.mock.CreateMock(session.Session)
     self.mock.ReplayAll()
     self.controller.sessions = {sk: sess}
     # Invalid name (so address lookup fails and no session created).
     self.assertRaises(errors.NoSessionCreatedError,
                       self.controller.request,
                       'command',
                       command='show run',
                       device_name='___')
     self.mock.VerifyAll()
Ejemplo n.º 5
0
 def testCreateSession(self):
     sk = session.SessionKey(device_name='xr1.foo',
                             connect_method='sshv2',
                             user='******',
                             privilege_level='ro')
     dev1 = device_manager.DeviceInfo(device_name='xr1.foo',
                                      device_type='juniper',
                                      addresses=('10.0.0.1', ))
     self.dm = self.mock.CreateMock(device_manager.DeviceManager)
     self.controller.device_manager = self.dm
     self.dm.device_info('xr1.foo').AndReturn(dev1)
     self.dm.device_info('xr1.foo').AndReturn(dev1)
     self.mock.ReplayAll()
     sess = self.controller.create_session(sk)
     self.assertEqual(sess.device.name, 'xr1.foo')
     self.assertEqual(sess.device.addresses, [ipaddr.IPAddress('10.0.0.1')])
     self.assertEqual(sess.connected, False)
     get_sess = self.controller.get_session(device_name='xr1.foo',
                                            connect_method='sshv2',
                                            user='******',
                                            privilege_level='ro')
     self.assertEqual(sess, get_sess)
     self.mock.VerifyAll()