@@ -72,15 +72,38 @@ def test_4_existing_kinesis(self):
72
72
#self.invoke_lambda()
73
73
self .assert_subscription_filter ("SumoLGLBDFilter" )
74
74
75
- def create_stack_parameters (self , destination , existing , pattern = 'test' ):
75
+ def test_5_matching_existing_loggroup_with_pattern_and_tag (self ):
76
+ self .create_log_group_with_tag ()
77
+ self .create_stack (self .stack_name , self .template_data ,
78
+ self .create_stack_parameters ("Kinesis" ,"true" , loggroup_tag = 'username=akhil' ))
79
+ print ("Testing Stack Creation" )
80
+ self .assertTrue (self .stack_exists (self .stack_name ))
81
+ #self.invoke_lambda()
82
+ self .assert_subscription_filter ("SumoLGLBDFilter" )
83
+
84
+ def test_6_matching_existing_loggroup_by_tag_only (self ):
85
+ self .create_log_group_with_tag ()
86
+ self .create_stack (self .stack_name , self .template_data ,
87
+ self .create_stack_parameters ("Kinesis" ,"true" , loggroup_pattern = '^$' ,
88
+ loggroup_tag = 'username=akhil' ))
89
+ print ("Testing Stack Creation" )
90
+ self .assertTrue (self .stack_exists (self .stack_name ))
91
+ #self.invoke_lambda()
92
+ self .assert_subscription_filter ("SumoLGLBDFilter" )
93
+
94
+ def create_stack_parameters (self , destination , existing , loggroup_pattern = 'test' , loggroup_tag = '' ):
76
95
return [
77
96
{
78
97
'ParameterKey' : 'DestinationType' ,
79
98
'ParameterValue' : destination
80
99
},
81
100
{
82
101
'ParameterKey' : 'LogGroupPattern' ,
83
- 'ParameterValue' : pattern
102
+ 'ParameterValue' : loggroup_pattern
103
+ },
104
+ {
105
+ 'ParameterKey' : 'LogGroupTags' ,
106
+ 'ParameterValue' : loggroup_tag
84
107
},
85
108
{
86
109
'ParameterKey' : 'UseExistingLogs' ,
@@ -137,6 +160,16 @@ def create_log_group(self):
137
160
response = self .log_group_client .create_log_group (logGroupName = self .log_group_name )
138
161
print ("creating log group" , response )
139
162
163
+ def create_log_group_with_tag (self ):
164
+ tags = {
165
+ 'team' : 'apps' ,
166
+ 'username' : 'akhil'
167
+ }
168
+ self .log_group_name = 'mytag-%s' % (datetime .datetime .now ().strftime ("%d-%m-%y-%H-%M-%S" ))
169
+ print ("Loggroup Name" , self .log_group_name )
170
+ response = self .log_group_client .create_log_group (logGroupName = self .log_group_name , tags = tags )
171
+ print ("creating log group" , response )
172
+
140
173
def assert_subscription_filter (self , filter_name ):
141
174
sleep (60 )
142
175
response = self .log_group_client .describe_subscription_filters (
@@ -205,7 +238,8 @@ def create_sam_package_and_upload():
205
238
206
239
def _run (command , input = None , check = False , ** kwargs ):
207
240
if sys .version_info >= (3 , 5 ):
208
- return subprocess .run (command , capture_output = True )
241
+ result = subprocess .run (command , capture_output = True )
242
+ return result .returncode , result .stdout , result .stderr
209
243
if input is not None :
210
244
if 'stdin' in kwargs :
211
245
raise ValueError ('stdin and input arguments may not both be used.' )
@@ -226,11 +260,11 @@ def _run(command, input=None, check=False, **kwargs):
226
260
227
261
228
262
def run_command (cmdargs ):
229
- resp = _run (cmdargs )
230
- if len ( resp . stderr . decode ()) > 0 :
263
+ retcode , stdout , stderr = _run (cmdargs )
264
+ if retcode != 0 :
231
265
# traceback.print_exc()
232
- raise Exception ("Error in run command %s cmd: %s" % (resp , cmdargs ))
233
- return resp . stdout
266
+ raise Exception ("Error in run command %s cmd: %s" % (stderr , cmdargs ))
267
+ return retcode , stdout , stderr
234
268
235
269
236
270
if __name__ == '__main__' :
0 commit comments