From 15accc5becd205e7baad03e43b61d43549fbf993 Mon Sep 17 00:00:00 2001 From: Dan Colish Date: Sun, 4 Mar 2012 11:07:35 -0800 Subject: [PATCH 1/3] Fix dynamic reloading of grains --- salt/minion.py | 1 + 1 file changed, 1 insertion(+) diff --git a/salt/minion.py b/salt/minion.py index b74196bcd4..3bd16e3dd1 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -141,6 +141,7 @@ class Minion(object): Return the functions and the returners loaded up from the loader module ''' + self.opts['grains'] = salt.loader.grains(self.opts) functions = salt.loader.minion_mods(self.opts) returners = salt.loader.returners(self.opts) return functions, returners From 17c91adae7bb9c7bf10cd7405fd73e11411be86a Mon Sep 17 00:00:00 2001 From: Dan Colish Date: Sun, 4 Mar 2012 11:25:40 -0800 Subject: [PATCH 2/3] Refactor common code in state.module_refresh --- salt/state.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/salt/state.py b/salt/state.py index 0c41d59d06..24c27eda15 100644 --- a/salt/state.py +++ b/salt/state.py @@ -163,28 +163,23 @@ class State(object): python, pyx, or .so. Always refresh if the function is recuse, since that can lay down anything. ''' + def _refresh(): + self.load_modules() + module_refresh_path = os.path.join( + self.opts['cachedir'], + 'module_refresh') + with open(module_refresh_path, 'w+') as f: + f.write('') + if data['state'] == 'file': if data['fun'] == 'managed': if data['name'].endswith( ('.py', '.pyx', '.pyo', '.pyc', '.so')): - self.load_modules() - open(os.path.join( - self.opts['cachedir'], - 'module_refresh'), - 'w+').write('') + _refresh() elif data['fun'] == 'recurse': - self.load_modules() - open(os.path.join( - self.opts['cachedir'], - 'module_refresh'), - 'w+').write('') + _refresh() elif data['state'] == 'pkg': - self.load_modules() - open(os.path.join( - self.opts['cachedir'], - 'module_refresh'), - 'w+').write('') - + _refresh() def format_verbosity(self, returns): ''' From 0c907dfc7a4a30944a90d478ef8caf728e46d81a Mon Sep 17 00:00:00 2001 From: Dan Colish Date: Sun, 4 Mar 2012 11:35:30 -0800 Subject: [PATCH 3/3] Use a property to recalculate the master_pub uri. This should allow dns updates for the master name to be used when reconnecting --- salt/minion.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/salt/minion.py b/salt/minion.py index 3bd16e3dd1..efe46e8542 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -398,6 +398,11 @@ class Minion(object): open(fn_, 'w+').write(self.serial.dumps(ret)) return ret_val + @property + def master_pub(self): + return 'tcp://{ip}:{port}'.format(ip=self.opts['master_ip'], + port=self.publish_port) + def authenticate(self): ''' Authenticate with the master, this method breaks the functional @@ -432,14 +437,10 @@ class Minion(object): ''' Lock onto the publisher. This is the main event loop for the minion ''' - master_pub = 'tcp://{0}:{1}'.format( - self.opts['master_ip'], - str(self.publish_port) - ) context = zmq.Context() socket = context.socket(zmq.SUB) socket.setsockopt(zmq.SUBSCRIBE, '') - socket.connect(master_pub) + socket.connect(self.master_pub) if self.opts['sub_timeout']: last = time.time() while True: @@ -464,7 +465,7 @@ class Minion(object): socket.close() socket = context.socket(zmq.SUB) socket.setsockopt(zmq.SUBSCRIBE, '') - socket.connect(master_pub) + socket.connect(self.master_pub) last = time.time() time.sleep(0.05) multiprocessing.active_children()