def testConstructorAcceptsId(self): """Test an ID parameter is accepted in those passed to constructor""" id = '23' o = nxsession.nxsession('id=%s' % id) self.assertEquals(id, o.params['id'])
def testConstructorPopulatesReplacesId(self): """Test a full_id parameter provided in vars is overriden""" test_full_id = 'hostname-1-ID' o = nxsession.nxsession('full_id=%s' % test_full_id) self.failUnless('full_id' in o.params) self.assertNotEqual(o.params['full_id'], test_full_id)
def testSetInvalidState(self): o = nxsession.nxsession('') state = 'invalud_state_name' o.set_state(state) self.assertNotEquals(o.params['state'], state)
def testSetStateAllStates(self): o = nxsession.nxsession('') for state in nxsession.state_names: o.set_state(state) self.assertEquals(o.params['state'], state)
def testConstructorAcceptsUser(self): """Test a user paramater specified in vars is not replaced""" username = '******' o = nxsession.nxsession('user=%s' % username) self.failUnless('user' in o.params) self.assertEquals(username, o.params['user'])
def _session_read_loop(self): sess = None while True: line = self.input.readline() if not line: return line = line.rstrip() nxlog.log(nxlog.LOG_DEBUG, 'Got from nxnode %r\n' % line) # FIXME(diamond): change number to something sensible if line.startswith('NX> 8888 sessioncreate'): if sess: nxlog.log( nxlog.LOG_ERR, 'Nxnode tried to create a session when one ' 'already exists: %s\n' % line) else: args = line.split(' ', 3)[-1].replace(' ', '\n') sess = nxsession.nxsession(args) elif line.startswith('NX> 8888 agentpid:'): if not sess: nxlog.log( nxlog.LOG_ERR, 'Nxagent-helper tried to change session ' 'when none exists: %s\n' % line) else: agent_pid = line.rstrip().split(' ')[3] sess.params['agent_pid'] = agent_pid sess.save() nxlog.log( nxlog.LOG_DEBUG, "Agent pid set to '%s'\n" % sess.params['agent_pid']) elif line.startswith('NX> 1009 Session status:'): if not sess: nxlog.log( nxlog.LOG_ERR, 'Nxagent-helper tried to change session ' 'when none exists: %s\n' % line) else: state_name = line.rstrip().split(' ')[4] sess.set_state(state_name) sess.save() nxlog.log( nxlog.LOG_DEBUG, "Session state updated to '%s'\n" % sess.params['state']) elif line.startswith('NX> 500 Error:'): if sess: sess.set_state('terminated') sess.save() nxlog.log( nxlog.LOG_DEBUG, "Session state updated to '%s', exiting\n" % sess.params['state']) break
def testConstructorCookieIsUniqId(self): old_id = nxsession.gen_uniq_id() time.sleep(1) # Make sure the id from the generator is now different self.assertNotEqual(old_id, nxsession.gen_uniq_id()) o = nxsession.nxsession('') self.failUnless('cookie' in o.params) self.assertNotEqual(old_id, o.params['cookie'])
def testConstructorAcceptsCookie(self): """Test a cookie paramete is read from vars""" cookie = nxsession.gen_uniq_id() time.sleep(1) # Make sure the id from the generator is now different self.assertNotEqual(cookie, nxsession.gen_uniq_id()) o = nxsession.nxsession('cookie=%s' % cookie) self.failUnless('cookie' in o.params) self.assertEqual(cookie, o.params['cookie'])
def _session_read_loop(self): sess = None while True: line = self.input.readline() if not line: return line = line.rstrip() nxlog.log(nxlog.LOG_DEBUG, 'Got from nxnode %r\n' % line) # FIXME(diamond): change number to something sensible if line.startswith('NX> 8888 sessioncreate'): if sess: nxlog.log(nxlog.LOG_ERR, 'Nxnode tried to create a session when one ' 'already exists: %s\n' % line) else: args = line.split(' ', 3)[-1].replace(' ', '\n') sess = nxsession.nxsession(args) elif line.startswith('NX> 8888 agentpid:'): if not sess: nxlog.log(nxlog.LOG_ERR, 'Nxagent-helper tried to change session ' 'when none exists: %s\n' % line) else: agent_pid = line.rstrip().split(' ')[3] sess.params['agent_pid'] = agent_pid sess.save() nxlog.log(nxlog.LOG_DEBUG, "Agent pid set to '%s'\n" % sess.params['agent_pid']) elif line.startswith('NX> 1009 Session status:'): if not sess: nxlog.log(nxlog.LOG_ERR, 'Nxagent-helper tried to change session ' 'when none exists: %s\n' % line) else: state_name = line.rstrip().split(' ')[4] sess.set_state(state_name) sess.save() nxlog.log(nxlog.LOG_DEBUG, "Session state updated to '%s'\n" % sess.params['state']) elif line.startswith('NX> 500 Error:'): if sess: sess.set_state('terminated') sess.save() nxlog.log(nxlog.LOG_DEBUG, "Session state updated to '%s', exiting\n" % sess.params['state']) break
def testConstructorUnknownParams(self): """Test calling the nxsession constructor with param not in defaults""" nxsession.nxsession('foo=bar')
def testConstructorPopulatesFullId(self): """Test a full_id parameter is set up by the constructor""" o = nxsession.nxsession('') self.failUnless('full_id' in o.params)
def testConstructor(self): """Test calling the nxsession constructor""" nxsession.nxsession('')
def testSetState(self): """Test setting state on a session""" o = nxsession.nxsession('') o.set_state(nxsession.state_names[0])
def testConstructorPopulatesCookie(self): """Test a cookie parameter is set up""" o = nxsession.nxsession('') self.failUnless('cookie' in o.params)
def testConstructorSetUser(self): """Test a user parameter is set by constructor""" o = nxsession.nxsession('') self.failUnless('user' in o.params)
def testConstructorGoodParam(self): """Test calling the nxsession constructor with param which is ok""" key = nxsession.default_params.keys()[0] nxsession.nxsession('%s=bar' % key)
def testConstructorSetsUpId(self): """Test a default ID parameter is set up by the constructor""" o = nxsession.nxsession('') self.failUnless('id' in o.params)