Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit eba9482

Browse files
authored
Linux logging fix for AUMV1 (#890)
* Update nxAvailableUpdates.py * Update nxAvailableUpdates.py * Update nxAvailableUpdates.py * Update nxAvailableUpdates.py * Update nxAvailableUpdates.py * Update nxAvailableUpdates.py * Update nxAvailableUpdates.py * Update nxAvailableUpdates.py * Update nxAvailableUpdates.py * Update nxAvailableUpdates.py * Added files * Changed file name * Corrected out to rmout * Completed * adding backup * Added os.path.join * Refactored * Necessary changes * Changes * done * Correcting conf * done * Delete filter_patch_management.rb * Revert "Delete filter_patch_management.rb" This reverts commit 099cc79.
1 parent ef1fa08 commit eba9482

File tree

6 files changed

+168
-109
lines changed

6 files changed

+168
-109
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ providers:
272272
ifeq ($(BUILD_OMS),BUILD_OMS)
273273
nx:
274274
rm -rf output/staging; \
275-
VERSION="1.4"; \
275+
VERSION="1.5"; \
276276
PROVIDERS="nxService nxPackage nxUser nxGroup nxAvailableUpdates"; \
277277
STAGINGDIR="output/staging/$@/DSCResources"; \
278278
cat Providers/Modules/$@.psd1 | sed "s@<MODULE_VERSION>@$${VERSION}@" > intermediate/Modules/$@.psd1; \
@@ -294,7 +294,7 @@ nx:
294294
else
295295
nx:
296296
rm -rf output/staging; \
297-
VERSION="1.4"; \
297+
VERSION="1.5"; \
298298
PROVIDERS="nxFile nxScript nxUser nxGroup nxService nxPackage nxEnvironment nxSshAuthorizedKeys nxArchive nxFileLine"; \
299299
STAGINGDIR="output/staging/$@/DSCResources"; \
300300
cat Providers/Modules/$@.psd1 | sed "s@<MODULE_VERSION>@$${VERSION}@" > intermediate/Modules/$@.psd1; \

Providers/Modules/Plugins/PatchManagement/plugin/filter_patch_management.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ def filter(tag, time, record)
4545
return linuxUpdates.transform_and_wrap(xml_string, @hostname, time)
4646
end # filter
4747
end # class
48-
end # module
48+
end # module

Providers/Scripts/2.4x-2.5x/Scripts/nxAvailableUpdates.py

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import fnmatch
1313
import time
1414
import os
15+
import uuid
1516

1617
protocol = imp.load_source('protocol', '../protocol.py')
1718
nxDSCLog = imp.load_source('nxDSCLog', '../nxDSCLog.py')
@@ -71,9 +72,15 @@ def GetAptUpdates(Name):
7172

7273
updates_list = []
7374
d = {}
75+
g_guid = str(uuid.uuid4())
76+
privileged_path = "/tmp/"
77+
7478
#Collect Security updates
75-
security_sources_list = '/tmp/az-update-security.list'
79+
security_sources_list = os.path.join(privileged_path, 'msft-v1-assess-security-{0}.list'.format(g_guid))
7680
prep_security_sources_list_cmd = 'grep security /etc/apt/sources.list > ' + security_sources_list
81+
82+
#to remove all files, following this pattern
83+
remove_security_sources_list_cmd = 'rm ' + os.path.join(privileged_path, 'msft-v1-assess-security-*.list')
7784
dist_upgrade_simulation_cmd_template = 'LANG=en_US.UTF8 apt-get -s dist-upgrade <SOURCES> '
7885
# Refresh the repo
7986
if helperlib.CONFIG_SYSCONFDIR_DSC == "omsconfig":
@@ -83,38 +90,51 @@ def GetAptUpdates(Name):
8390
code, out = RunGetOutput(cmd, False, False)
8491
#Get Security Patches list
8592
security_patch_list = []
86-
code, out = RunGetOutput(prep_security_sources_list_cmd,False,False)
87-
security_updates_cmd = dist_upgrade_simulation_cmd_template.replace('<SOURCES>', '-oDir::Etc::Sourcelist=' + security_sources_list)
88-
code,out = RunGetOutput(security_updates_cmd,False,False)
89-
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
90-
srch = re.compile(srch_txt, re.M | re.S)
91-
pkg_list = srch.findall(str(out))
92-
for package in pkg_list:
93-
security_patch_list.append(package[0])
94-
cmd = 'LANG=en_US.UTF8 apt-get -s dist-upgrade | grep "^Inst"'
95-
LG().Log('DEBUG', "Retrieving update package list using cmd:" + cmd)
96-
code, out = RunGetOutput(cmd, False, False)
97-
if len(out) < 2:
93+
94+
try:
95+
code, out = RunGetOutput(prep_security_sources_list_cmd,False,False)
96+
if code != 0:
97+
LG().Log('ERROR', "Unexpected error in running cmd {0} : {1}".format(prep_security_sources_list_cmd, out))
98+
raise Exception("Unexpected error in running cmd {0} : {1}".format(prep_security_sources_list_cmd, out))
99+
100+
security_updates_cmd = dist_upgrade_simulation_cmd_template.replace('<SOURCES>', '-oDir::Etc::Sourcelist=' + security_sources_list)
101+
code,out = RunGetOutput(security_updates_cmd,False,False)
102+
103+
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
104+
srch = re.compile(srch_txt, re.M | re.S)
105+
pkg_list = srch.findall(str(out))
106+
for package in pkg_list:
107+
security_patch_list.append(package[0])
108+
cmd = 'LANG=en_US.UTF8 apt-get -s dist-upgrade | grep "^Inst"'
109+
LG().Log('DEBUG', "Retrieving update package list using cmd:" + cmd)
110+
111+
if len(out) < 2:
112+
return updates_list
113+
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
114+
srch = re.compile(srch_txt, re.M | re.S)
115+
pkg_list = srch.findall(out)
116+
for pkg in pkg_list:
117+
d['BuildDate'] = ''
118+
d['Name'] = pkg[0]
119+
if len(Name) and not fnmatch.fnmatch(d['Name'], Name):
120+
continue
121+
d['Architecture'] = pkg[3]
122+
d['Version'] = pkg[1]
123+
if d['Name'] in security_patch_list:
124+
d['Classification'] = "Security Updates"
125+
else:
126+
d['Classification'] = "Others"
127+
d['Repository'] = pkg[2]
128+
updates_list.append(copy.deepcopy(d))
129+
130+
LG().Log('DEBUG', "Number of packages being written to the XML: " + str(len(updates_list)))
98131
return updates_list
99-
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
100-
srch = re.compile(srch_txt, re.M | re.S)
101-
pkg_list = srch.findall(out)
102-
for pkg in pkg_list:
103-
d['BuildDate'] = ''
104-
d['Name'] = pkg[0]
105-
if len(Name) and not fnmatch.fnmatch(d['Name'], Name):
106-
continue
107-
d['Architecture'] = pkg[3]
108-
d['Version'] = pkg[1]
109-
if d['Name'] in security_patch_list:
110-
d['Classification'] = "Security Updates"
132+
finally:
133+
rmcode, rmout = RunGetOutput(remove_security_sources_list_cmd,False,False)
134+
if rmcode != 0:
135+
LG().Log('DEBUG', "Not able to delete {0}. Error: {1}".format(security_sources_list, rmout))
111136
else:
112-
d['Classification'] = "Others"
113-
d['Repository'] = pkg[2]
114-
updates_list.append(copy.deepcopy(d))
115-
LG().Log('DEBUG', "Number of packages being written to the XML: " + str(len(updates_list)))
116-
return updates_list
117-
137+
LG().Log('DEBUG', "{0} folder cleared".format(privileged_path))
118138

119139
def GetYumUpdates(Name):
120140
# Format:
@@ -193,7 +213,6 @@ def GetYumUpdates(Name):
193213

194214
if len(param_list) == 0 and len(param_list2) > 0:
195215
LG().Log('DEBUG', "No valid packages found. Falling back to package_info based on the package name.")
196-
param_list = param_list2
197216

198217
cmd = "LANG=en_US.UTF8 " + yum_info + param_list
199218
LG().Log('DEBUG', "Retrieving individual package information from Yum using cmd: " + cmd)

Providers/Scripts/2.6x-2.7x/Scripts/nxAvailableUpdates.py

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import fnmatch
1313
import time
1414
import os
15+
import uuid
1516

1617
protocol = imp.load_source('protocol', '../protocol.py')
1718
nxDSCLog = imp.load_source('nxDSCLog', '../nxDSCLog.py')
@@ -71,9 +72,15 @@ def GetAptUpdates(Name):
7172

7273
updates_list = []
7374
d = {}
75+
g_guid = str(uuid.uuid4())
76+
privileged_path = "/tmp/"
77+
7478
#Collect Security updates
75-
security_sources_list = '/tmp/az-update-security.list'
79+
security_sources_list = os.path.join(privileged_path, 'msft-v1-assess-security-{0}.list'.format(g_guid))
7680
prep_security_sources_list_cmd = 'grep security /etc/apt/sources.list > ' + security_sources_list
81+
82+
#to remove all files, following this pattern
83+
remove_security_sources_list_cmd = 'rm ' + os.path.join(privileged_path, 'msft-v1-assess-security-*.list')
7784
dist_upgrade_simulation_cmd_template = 'LANG=en_US.UTF8 apt-get -s dist-upgrade <SOURCES> '
7885
# Refresh the repo
7986
if helperlib.CONFIG_SYSCONFDIR_DSC == "omsconfig":
@@ -83,38 +90,51 @@ def GetAptUpdates(Name):
8390
code, out = RunGetOutput(cmd, False, False)
8491
#Get Security Patches list
8592
security_patch_list = []
86-
code, out = RunGetOutput(prep_security_sources_list_cmd,False,False)
87-
security_updates_cmd = dist_upgrade_simulation_cmd_template.replace('<SOURCES>', '-oDir::Etc::Sourcelist=' + security_sources_list)
88-
code,out = RunGetOutput(security_updates_cmd,False,False)
89-
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
90-
srch = re.compile(srch_txt, re.M | re.S)
91-
pkg_list = srch.findall(str(out))
92-
for package in pkg_list:
93-
security_patch_list.append(package[0])
94-
cmd = 'LANG=en_US.UTF8 apt-get -s dist-upgrade | grep "^Inst"'
95-
LG().Log('DEBUG', "Retrieving update package list using cmd:" + cmd)
96-
code, out = RunGetOutput(cmd, False, False)
97-
if len(out) < 2:
93+
try:
94+
code, out = RunGetOutput(prep_security_sources_list_cmd,False,False)
95+
if code != 0:
96+
LG().Log('ERROR', "Unexpected error in running cmd {0} : {1}".format(prep_security_sources_list_cmd, out))
97+
raise Exception("Unexpected error in running cmd {0} : {1}".format(prep_security_sources_list_cmd, out))
98+
99+
security_updates_cmd = dist_upgrade_simulation_cmd_template.replace('<SOURCES>', '-oDir::Etc::Sourcelist=' + security_sources_list)
100+
code,out = RunGetOutput(security_updates_cmd,False,False)
101+
102+
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
103+
srch = re.compile(srch_txt, re.M | re.S)
104+
pkg_list = srch.findall(str(out))
105+
for package in pkg_list:
106+
security_patch_list.append(package[0])
107+
cmd = 'LANG=en_US.UTF8 apt-get -s dist-upgrade | grep "^Inst"'
108+
LG().Log('DEBUG', "Retrieving update package list using cmd:" + cmd)
109+
code, out = RunGetOutput(cmd, False, False)
110+
111+
if len(out) < 2:
112+
return updates_list
113+
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
114+
srch = re.compile(srch_txt, re.M | re.S)
115+
pkg_list = srch.findall(out)
116+
for pkg in pkg_list:
117+
d['BuildDate'] = ''
118+
d['Name'] = pkg[0]
119+
if len(Name) and not fnmatch.fnmatch(d['Name'], Name):
120+
continue
121+
d['Architecture'] = pkg[3]
122+
d['Version'] = pkg[1]
123+
if d['Name'] in security_patch_list:
124+
d['Classification'] = "Security Updates"
125+
else:
126+
d['Classification'] = "Others"
127+
d['Repository'] = pkg[2]
128+
updates_list.append(copy.deepcopy(d))
129+
130+
LG().Log('DEBUG', "Number of packages being written to the XML: " + str(len(updates_list)))
98131
return updates_list
99-
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
100-
srch = re.compile(srch_txt, re.M | re.S)
101-
pkg_list = srch.findall(out)
102-
for pkg in pkg_list:
103-
d['BuildDate'] = ''
104-
d['Name'] = pkg[0]
105-
if len(Name) and not fnmatch.fnmatch(d['Name'], Name):
106-
continue
107-
d['Architecture'] = pkg[3]
108-
d['Version'] = pkg[1]
109-
if d['Name'] in security_patch_list:
110-
d['Classification'] = "Security Updates"
132+
finally:
133+
rmcode, rmout = RunGetOutput(remove_security_sources_list_cmd,False,False)
134+
if rmcode != 0:
135+
LG().Log('DEBUG', "Not able to delete {0}. Error: {1}".format(security_sources_list, rmout))
111136
else:
112-
d['Classification'] = "Others"
113-
d['Repository'] = pkg[2]
114-
updates_list.append(copy.deepcopy(d))
115-
LG().Log('DEBUG', "Number of packages being written to the XML: " + str(len(updates_list)))
116-
return updates_list
117-
137+
LG().Log('DEBUG', "{0} folder cleared".format(privileged_path))
118138

119139
def GetYumUpdates(Name):
120140
# Format:
@@ -193,7 +213,6 @@ def GetYumUpdates(Name):
193213

194214
if len(param_list) == 0 and len(param_list2) > 0:
195215
LG().Log('DEBUG', "No valid packages found. Falling back to package_info based on the package name.")
196-
param_list = param_list2
197216

198217
cmd = "LANG=en_US.UTF8 " + yum_info + param_list
199218
LG().Log('DEBUG', "Retrieving individual package information from Yum using cmd: " + cmd)

Providers/Scripts/3.x/Scripts/nxAvailableUpdates.py

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import fnmatch
1313
import time
1414
import os
15+
import uuid
1516

1617
protocol = imp.load_source('protocol', '../protocol.py')
1718
nxDSCLog = imp.load_source('nxDSCLog', '../nxDSCLog.py')
@@ -69,9 +70,15 @@ def GetAptUpdates(Name):
6970

7071
updates_list = []
7172
d = {}
73+
g_guid = str(uuid.uuid4())
74+
privileged_path = "/tmp/"
75+
7276
#Collect Security updates
73-
security_sources_list = '/tmp/az-update-security.list'
77+
security_sources_list = os.path.join(privileged_path, 'msft-v1-assess-security-{0}.list'.format(g_guid))
7478
prep_security_sources_list_cmd = 'grep security /etc/apt/sources.list > ' + security_sources_list
79+
80+
#to remove all files, following this pattern
81+
remove_security_sources_list_cmd = 'rm ' + os.path.join(privileged_path, 'msft-v1-assess-security-*.list')
7582
dist_upgrade_simulation_cmd_template = 'LANG=en_US.UTF8 apt-get -s dist-upgrade <SOURCES> '
7683
# Refresh the repo
7784
if helperlib.CONFIG_SYSCONFDIR_DSC == "omsconfig":
@@ -81,38 +88,53 @@ def GetAptUpdates(Name):
8188
code, out = RunGetOutput(cmd, False, False)
8289
#Get Security Patches list
8390
security_patch_list = []
84-
code, out = RunGetOutput(prep_security_sources_list_cmd,False,False)
85-
security_updates_cmd = dist_upgrade_simulation_cmd_template.replace('<SOURCES>', '-oDir::Etc::Sourcelist=' + security_sources_list)
86-
code,out = RunGetOutput(security_updates_cmd,False,False)
87-
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
88-
srch = re.compile(srch_txt, re.M | re.S)
89-
pkg_list = srch.findall(str(out))
90-
for package in pkg_list:
91-
security_patch_list.append(package[0])
92-
cmd = 'LANG=en_US.UTF8 apt-get -s dist-upgrade | grep "^Inst"'
93-
LG().Log('DEBUG', "Retrieving update package list using cmd:" + cmd)
94-
code, out = RunGetOutput(cmd, False, False)
95-
if len(out) < 2:
91+
92+
try:
93+
code, out = RunGetOutput(prep_security_sources_list_cmd,False,False)
94+
if code != 0:
95+
LG().Log('ERROR', "Unexpected error in running cmd {0} : {1}".format(prep_security_sources_list_cmd, out))
96+
raise Exception("Unexpected error in running cmd {0} : {1}".format(prep_security_sources_list_cmd, out))
97+
98+
security_updates_cmd = dist_upgrade_simulation_cmd_template.replace('<SOURCES>', '-oDir::Etc::Sourcelist=' + security_sources_list)
99+
code,out = RunGetOutput(security_updates_cmd,False,False)
100+
101+
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
102+
srch = re.compile(srch_txt, re.M | re.S)
103+
pkg_list = srch.findall(str(out))
104+
for package in pkg_list:
105+
security_patch_list.append(package[0])
106+
107+
cmd = 'LANG=en_US.UTF8 apt-get -s dist-upgrade | grep "^Inst"'
108+
LG().Log('DEBUG', "Retrieving update package list using cmd:" + cmd)
109+
code, out = RunGetOutput(cmd, False, False)
110+
if len(out) < 2:
111+
return updates_list
112+
113+
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
114+
srch = re.compile(srch_txt, re.M | re.S)
115+
pkg_list = srch.findall(out)
116+
for pkg in pkg_list:
117+
d['BuildDate'] = ''
118+
d['Name'] = pkg[0]
119+
if len(Name) and not fnmatch.fnmatch(d['Name'], Name):
120+
continue
121+
d['Architecture'] = pkg[3]
122+
d['Version'] = pkg[1]
123+
if d['Name'] in security_patch_list:
124+
d['Classification'] = "Security Updates"
125+
else:
126+
d['Classification'] = "Others"
127+
d['Repository'] = pkg[2]
128+
updates_list.append(copy.deepcopy(d))
129+
130+
LG().Log('DEBUG', "Number of packages being written to the XML: " + str(len(updates_list)))
96131
return updates_list
97-
srch_txt = r'Inst[ ](.*?)[ ].*?[(](.*?)[ ](.*?)[ ]\[(.*?)\]'
98-
srch = re.compile(srch_txt, re.M | re.S)
99-
pkg_list = srch.findall(out)
100-
for pkg in pkg_list:
101-
d['BuildDate'] = ''
102-
d['Name'] = pkg[0]
103-
if len(Name) and not fnmatch.fnmatch(d['Name'], Name):
104-
continue
105-
d['Architecture'] = pkg[3]
106-
d['Version'] = pkg[1]
107-
if d['Name'] in security_patch_list:
108-
d['Classification'] = "Security Updates"
132+
finally:
133+
rmcode, rmout = RunGetOutput(remove_security_sources_list_cmd,False,False)
134+
if rmcode != 0:
135+
LG().Log('DEBUG', "Not able to delete {0}. Error: {1}".format(security_sources_list, rmout))
109136
else:
110-
d['Classification'] = "Others"
111-
d['Repository'] = pkg[2]
112-
updates_list.append(copy.deepcopy(d))
113-
LG().Log('DEBUG', "Number of packages being written to the XML: " + str(len(updates_list)))
114-
return updates_list
115-
137+
LG().Log('DEBUG', "{0} folder cleared".format(privileged_path))
116138

117139
def GetYumUpdates(Name):
118140
# Format:
@@ -191,7 +213,6 @@ def GetYumUpdates(Name):
191213

192214
if len(param_list) == 0 and len(param_list2) > 0:
193215
LG().Log('DEBUG', "No valid packages found. Falling back to package_info based on the package name.")
194-
param_list = param_list2
195216

196217
cmd = "LANG=en_US.UTF8 " + yum_info + param_list
197218
LG().Log('DEBUG', "Retrieving individual package information from Yum using cmd: " + cmd)
@@ -467,4 +488,4 @@ def GetPackageManager():
467488
if ret == 'apt-get':
468489
ret = 'apt'
469490
break
470-
return ret
491+
return ret

0 commit comments

Comments
 (0)