Reset asyncauth singleton in tests

This commit is contained in:
Thomas Jackson 2015-03-25 09:01:14 -07:00
parent 952d7244b5
commit c6245c869e
3 changed files with 11 additions and 5 deletions

View File

@ -792,6 +792,13 @@ class AsyncAuth(SAuth):
# This class is only a singleton per minion/master pair
instances = {}
@classmethod
def clear_singletons(cls):
'''
Method to forcibly clear all singletons. This should only be used for testing
'''
AsyncAuth.instances = {}
def __new__(cls, opts):
'''
Only create one instance of SAuth per __key()

View File

@ -151,10 +151,7 @@ class AsyncTCPReqChannel(salt.transport.client.ReqChannel):
# communication, we do not subscribe to return events, we just
# upload the results to the master
if data:
try:
data = self.auth.crypticle.loads(data)
except Exception as e:
raise e
raise tornado.gen.Return(data)
if not self.auth.authenticated:
yield self.auth.authenticate()
@ -198,7 +195,8 @@ class AsyncTCPPubChannel(salt.transport.mixins.auth.AESPubClientMixin, salt.tran
def connect(self):
try:
self.auth = salt.crypt.AsyncAuth(self.opts)
creds = yield self.auth.authenticate()
if not self.auth.authenticated:
yield self.auth.authenticate()
self.message_client = SaltMessageClient(self.opts['master_ip'],
int(self.auth.creds['publish_port']),
io_loop=self.io_loop)
@ -355,7 +353,6 @@ class SaltMessageServer(tornado.tcpserver.TCPServer):
self.clients.remove(item)
# TODO: singleton? Something to not re-create the tcp connection so much
# TODO: cleanup send/recv queue stuff
class SaltMessageClient(object):
'''
Low-level message sending client

View File

@ -11,6 +11,7 @@ import threading
import tornado.ioloop
from tornado.testing import AsyncTestCase
import salt.crypt
import salt.config
import salt.utils
import salt.transport.server
@ -114,6 +115,7 @@ class BaseTCPPubCase(AsyncTestCase):
'''
@classmethod
def setUpClass(cls):
salt.crypt.AsyncAuth.clear_singletons() # clear the singletons
cls.master_opts = salt.config.master_config(get_config_file_path('master'))
cls.master_opts.update({
'transport': 'tcp',