1
1
import os
2
- import hubblestack .extmods .modules .pulsar as pulsar
3
- from salt .exceptions import CommandExecutionError
4
-
5
2
import shutil
3
+ import logging
6
4
import six
7
- import pyinotify
5
+
6
+ from salt .exceptions import CommandExecutionError
7
+ import hubblestack .extmods .modules .pulsar as pulsar
8
+
9
+ log = logging .getLogger (__name__ )
8
10
9
11
if os .environ .get ('DEBUG_SHOW_PULSAR_LOGS' ):
10
12
import logging
@@ -145,26 +147,26 @@ class TestPulsar2():
145
147
atdir = os .path .abspath (tdir )
146
148
atfile = os .path .abspath (tfile )
147
149
148
- def reset (self , ** kw ):
150
+ def reset (self , ** kwargs ):
149
151
def config_get (value , default ):
150
152
return default
151
153
152
- if 'paths' not in kw :
153
- kw ['paths' ] = []
154
+ if 'paths' not in kwargs :
155
+ kwargs ['paths' ] = []
154
156
155
157
__salt__ = {}
156
158
__salt__ ['config.get' ] = config_get
157
159
pulsar .__salt__ = __salt__
158
- pulsar .__opts__ = {'pulsar' : kw }
160
+ pulsar .__opts__ = {'pulsar' : kwargs }
159
161
pulsar .__context__ = c = {}
160
162
self .nuke_tdir ()
161
163
162
164
pulsar ._get_notifier () # sets up the dequeue
163
165
164
166
self .events = []
165
167
self .N = c ['pulsar.notifier' ]
166
- self .wm = self .N ._watch_manager
167
- self .wm .update_config ()
168
+ self .watch_manager = self .N ._watch_manager
169
+ self .watch_manager .update_config ()
168
170
169
171
def process (self ):
170
172
self .events .extend ([ "{change}(path)" .format (** x ) for x in pulsar .process () ])
@@ -181,28 +183,28 @@ def mk_tdir_and_write_tfile(self, fname=None, to_write='supz\n'):
181
183
with open (self .tfile , 'w' ) as fh :
182
184
fh .write (to_write )
183
185
184
- def mk_subdir_files (self , * f , ** kw ):
185
- if len (f ) == 1 and isinstance (f [0 ], (list ,tuple )):
186
- f = f [0 ]
187
- for _f in f :
188
- _f = _f if _f .startswith (self .tdir + '/' ) else os .path .join (self .tdir , _f )
189
- s = _f .split ('/' )
190
- if s :
191
- fn = s .pop ()
192
- b = ''
193
- for i in s :
194
- b = os .path .join (b ,i )
186
+ def mk_subdir_files (self , * files , ** kwargs ):
187
+ if len (files ) == 1 and isinstance (files [0 ], (list ,tuple )):
188
+ files = files [0 ]
189
+ for file in files :
190
+ file = file if file .startswith (self .tdir + '/' ) else os .path .join (self .tdir , file )
191
+ split_file = file .split ('/' )
192
+ if split_file :
193
+ output_fname = split_file .pop ()
194
+ dir_to_make = ''
195
+ for i in split_file :
196
+ dir_to_make = os .path .join (dir_to_make ,i )
195
197
if not os .path .isdir (i ):
196
- os .mkdir (b )
197
- k = ('{}_out' , 'out_{}' , '{}_to_write' , 'to_write' )
198
- for _k in k :
199
- to_write = kw .get (_k .format (fn ))
198
+ os .mkdir (dir_to_make )
199
+ forms = ('{}_out' , 'out_{}' , '{}_to_write' , 'to_write' )
200
+ for form in forms :
201
+ to_write = kwargs .get (form .format (output_fname ))
200
202
if to_write is not None :
201
203
break
202
204
if to_write is None :
203
205
to_write = 'supz\n '
204
- fn = os .path .join (b , fn )
205
- with open (fn , 'a' ) as fh :
206
+ output_fname = os .path .join (dir_to_make , output_fname )
207
+ with open (output_fname , 'a' ) as fh :
206
208
fh .write (to_write if to_write is not None else 'supz\n ' )
207
209
208
210
def more_fname (self , number , base = None ):
@@ -234,33 +236,33 @@ def sla(x,e):
234
236
235
237
def test_add_watch (self , modality = 'add-watch' ):
236
238
o = {}
237
- kw = { self .atdir : o }
239
+ kwargs = { self .atdir : o }
238
240
239
241
if modality in ('watch_new_files' , 'watch_files' ):
240
242
o [modality ] = True
241
243
242
- self .reset (** kw )
244
+ self .reset (** kwargs )
243
245
244
246
# NOTE: without new_files and/or without watch_files parent_db should
245
247
# remain empty, and we shouldn't get a watch on tfile
246
248
247
249
os .mkdir (self .tdir )
248
250
249
251
if modality == 'add-watch' :
250
- self .wm .add_watch (self .tdir , pulsar .DEFAULT_MASK )
252
+ self .watch_manager .add_watch (self .tdir , pulsar .DEFAULT_MASK )
251
253
252
254
elif modality in ('watch' , 'watch_new_files' , 'watch_files' ):
253
- self .wm .watch (self .tdir )
255
+ self .watch_manager .watch (self .tdir )
254
256
255
257
else :
256
258
raise Exception ("unknown modality" )
257
259
258
260
self .process ()
259
261
assert len (self .events ) == 0
260
- assert self .wm .watch_db .get (self .tdir ) is None
261
- assert self .wm .watch_db .get (self .atdir ) > 0
262
- assert len (self .wm .watch_db ) == 1
263
- assert not isinstance (self .wm .parent_db .get (self .atdir ), set )
262
+ assert self .watch_manager .watch_db .get (self .tdir ) is None
263
+ assert self .watch_manager .watch_db .get (self .atdir ) > 0
264
+ assert len (self .watch_manager .watch_db ) == 1
265
+ assert not isinstance (self .watch_manager .parent_db .get (self .atdir ), set )
264
266
265
267
self .mk_tdir_and_write_tfile () # write supz to tfile
266
268
@@ -270,11 +272,11 @@ def test_add_watch(self, modality='add-watch'):
270
272
assert self .events [1 ].startswith ('IN_MODIFY' )
271
273
272
274
if modality in ('watch_files' , 'watch_new_files' ):
273
- assert len (self .wm .watch_db ) == 2
274
- assert isinstance (self .wm .parent_db .get (self .atdir ), set )
275
+ assert len (self .watch_manager .watch_db ) == 2
276
+ assert isinstance (self .watch_manager .parent_db .get (self .atdir ), set )
275
277
else :
276
- assert len (self .wm .watch_db ) == 1
277
- assert not isinstance (self .wm .parent_db .get (self .atdir ), set )
278
+ assert len (self .watch_manager .watch_db ) == 1
279
+ assert not isinstance (self .watch_manager .parent_db .get (self .atdir ), set )
278
280
279
281
self .nuke_tdir ()
280
282
@@ -290,15 +292,15 @@ def test_recurse_without_watch_files(self):
290
292
291
293
self .reset (** c1 )
292
294
self .mk_subdir_files ('blah1' ,'a/b/c/blah2' )
293
- self .wm .watch (self .tdir )
294
- self .wm .prune ()
295
- s1 = set (self .wm .watch_db )
295
+ self .watch_manager .watch (self .tdir )
296
+ self .watch_manager .prune ()
297
+ s1 = set (self .watch_manager .watch_db )
296
298
297
299
self .reset (** c2 )
298
300
self .mk_subdir_files ('blah1' ,'a/b/c/blah2' )
299
- self .wm .watch (self .tdir )
300
- self .wm .prune ()
301
- s2 = set (self .wm .watch_db )
301
+ self .watch_manager .watch (self .tdir )
302
+ self .watch_manager .prune ()
303
+ s2 = set (self .watch_manager .watch_db )
302
304
303
305
s0a = set ([self .atdir ])
304
306
s0b = [self .atdir ]
@@ -325,18 +327,18 @@ def config_make_files_watch_process_reconfig(self, config, reconfig=None, mk_fil
325
327
"""
326
328
self .reset (** config )
327
329
self .mk_tdir_and_write_tfile ()
328
- self .wm .watch (self .tdir )
329
- s0 = set (self .wm .watch_db )
330
+ self .watch_manager .watch (self .tdir )
331
+ s0 = set (self .watch_manager .watch_db )
330
332
if mk_files > 0 :
331
333
self .mk_more_files (count = mk_files )
332
334
self .process ()
333
- s1 = set (self .wm .watch_db )
335
+ s1 = set (self .watch_manager .watch_db )
334
336
if reconfig is None :
335
- del self .wm .cm .nc_config [ self .atdir ]
337
+ del self .watch_manager .cm .nc_config [ self .atdir ]
336
338
else :
337
- self .wm .cm .nc_config [ self .atdir ] = reconfig
339
+ self .watch_manager .cm .nc_config [ self .atdir ] = reconfig
338
340
self .process ()
339
- s2 = set (self .wm .watch_db )
341
+ s2 = set (self .watch_manager .watch_db )
340
342
return s0 ,s1 ,s2
341
343
342
344
def test_pruning_watch_files_false (self ):
0 commit comments