Exemplo n.º 1
0
  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'])
Exemplo n.º 2
0
    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'])
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
  def testSetInvalidState(self):

    o = nxsession.nxsession('')

    state = 'invalud_state_name'

    o.set_state(state)

    self.assertNotEquals(o.params['state'], state)
Exemplo n.º 5
0
  def testSetStateAllStates(self):

    o = nxsession.nxsession('')

    for state in nxsession.state_names:

      o.set_state(state)

      self.assertEquals(o.params['state'], state)
Exemplo n.º 6
0
  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'])
Exemplo n.º 7
0
    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'])
Exemplo n.º 8
0
    def testSetStateAllStates(self):

        o = nxsession.nxsession('')

        for state in nxsession.state_names:

            o.set_state(state)

            self.assertEquals(o.params['state'], state)
Exemplo n.º 9
0
  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)
Exemplo n.º 10
0
    def testSetInvalidState(self):

        o = nxsession.nxsession('')

        state = 'invalud_state_name'

        o.set_state(state)

        self.assertNotEquals(o.params['state'], state)
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
    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'])
Exemplo n.º 13
0
  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'])
Exemplo n.º 14
0
    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'])
Exemplo n.º 15
0
  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'])
Exemplo n.º 16
0
 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
Exemplo n.º 17
0
    def testConstructorUnknownParams(self):
        """Test calling the nxsession constructor with param not in defaults"""

        nxsession.nxsession('foo=bar')
Exemplo n.º 18
0
  def testConstructorPopulatesFullId(self):
    """Test a full_id parameter is set up by the constructor"""

    o = nxsession.nxsession('')

    self.failUnless('full_id' in o.params)
Exemplo n.º 19
0
    def testConstructor(self):
        """Test calling the nxsession constructor"""

        nxsession.nxsession('')
Exemplo n.º 20
0
    def testSetState(self):
        """Test setting state on a session"""

        o = nxsession.nxsession('')

        o.set_state(nxsession.state_names[0])
Exemplo n.º 21
0
  def testConstructorPopulatesCookie(self):
    """Test a cookie parameter is set up"""

    o = nxsession.nxsession('')

    self.failUnless('cookie' in o.params)
Exemplo n.º 22
0
    def testConstructorSetUser(self):
        """Test a user parameter is set by constructor"""

        o = nxsession.nxsession('')

        self.failUnless('user' in o.params)
Exemplo n.º 23
0
  def testConstructorSetUser(self):
    """Test a user parameter is set by constructor"""

    o = nxsession.nxsession('')

    self.failUnless('user' in o.params)
Exemplo n.º 24
0
  def testConstructor(self):
    """Test calling the nxsession constructor"""

    nxsession.nxsession('')
Exemplo n.º 25
0
  def testSetState(self):
    """Test setting state on a session"""

    o = nxsession.nxsession('')

    o.set_state(nxsession.state_names[0])
Exemplo n.º 26
0
    def testConstructorPopulatesCookie(self):
        """Test a cookie parameter is set up"""

        o = nxsession.nxsession('')

        self.failUnless('cookie' in o.params)
Exemplo n.º 27
0
  def testConstructorUnknownParams(self):
    """Test calling the nxsession constructor with param not in defaults"""

    nxsession.nxsession('foo=bar')
Exemplo n.º 28
0
    def testConstructorPopulatesFullId(self):
        """Test a full_id parameter is set up by the constructor"""

        o = nxsession.nxsession('')

        self.failUnless('full_id' in o.params)
Exemplo n.º 29
0
  def testConstructorGoodParam(self):
    """Test calling the nxsession constructor with param which is ok"""

    key = nxsession.default_params.keys()[0]

    nxsession.nxsession('%s=bar' % key)
Exemplo n.º 30
0
    def testConstructorGoodParam(self):
        """Test calling the nxsession constructor with param which is ok"""

        key = nxsession.default_params.keys()[0]

        nxsession.nxsession('%s=bar' % key)
Exemplo n.º 31
0
    def testConstructorSetsUpId(self):
        """Test a default ID parameter is set up by the constructor"""

        o = nxsession.nxsession('')

        self.failUnless('id' in o.params)
Exemplo n.º 32
0
  def testConstructorSetsUpId(self):
    """Test a default ID parameter is set up by the constructor"""

    o = nxsession.nxsession('')

    self.failUnless('id' in o.params)