Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
package_alerts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
linuxsupport
cronjobs
package_alerts
Commits
4f406746
Commit
4f406746
authored
1 year ago
by
Ben Morrice
Browse files
Options
Downloads
Patches
Plain Diff
Add some pylint suggestions
parent
d394d988
No related branches found
No related tags found
Tags containing commit
1 merge request
!10
Add almalinux support
Pipeline
#6580564
passed
1 year ago
Stage: build
Stage: deploy_test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
package_alerts/package_alerts
+15
-17
15 additions, 17 deletions
package_alerts/package_alerts
with
15 additions
and
17 deletions
package_alerts/package_alerts
+
15
−
17
View file @
4f406746
#!/usr/bin/python3
#!/usr/bin/python3
"""
script to alert us via mm on new
'
interesting
'
packages
"""
import
os
import
os
import
glob
import
glob
...
@@ -9,7 +10,6 @@ import signal
...
@@ -9,7 +10,6 @@ import signal
import
subprocess
import
subprocess
import
sys
import
sys
import
tempfile
import
tempfile
import
time
from
collections
import
ChainMap
from
collections
import
ChainMap
from
datetime
import
datetime
from
datetime
import
datetime
import
dnf
import
dnf
...
@@ -32,7 +32,7 @@ if (
...
@@ -32,7 +32,7 @@ if (
)
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
with
open
(
f
"
/root/
{
interesting_packages_file
}
"
)
as
f
:
with
open
(
f
"
/root/
{
interesting_packages_file
}
"
,
encoding
=
'
utf-8
'
)
as
f
:
interesting_packages
=
yaml
.
safe_load
(
f
)
interesting_packages
=
yaml
.
safe_load
(
f
)
try
:
try
:
interesting_packages
=
interesting_packages
[
"
packages
"
]
interesting_packages
=
interesting_packages
[
"
packages
"
]
...
@@ -44,7 +44,7 @@ with open(f"/root/{interesting_packages_file}") as f:
...
@@ -44,7 +44,7 @@ with open(f"/root/{interesting_packages_file}") as f:
# In case somebody screws up the input format, make sure it's a dict and not a list of dicts
# In case somebody screws up the input format, make sure it's a dict and not a list of dicts
for
package
in
interesting_packages
:
for
package
in
interesting_packages
:
if
typ
e
(
interesting_packages
[
package
]
)
is
list
:
if
isinstanc
e
(
interesting_packages
[
package
]
,
list
)
:
interesting_packages
[
package
]
=
dict
(
ChainMap
(
*
interesting_packages
[
package
]))
interesting_packages
[
package
]
=
dict
(
ChainMap
(
*
interesting_packages
[
package
]))
feeds
=
unformatted_feeds
.
split
(
'
,
'
)
feeds
=
unformatted_feeds
.
split
(
'
,
'
)
...
@@ -52,7 +52,7 @@ feeds = unformatted_feeds.split(',')
...
@@ -52,7 +52,7 @@ feeds = unformatted_feeds.split(',')
logfile_retain_days
=
30
logfile_retain_days
=
30
logfilename
=
f
"
/work/
{
datetime
.
today
().
strftime
(
'
%Y%m%d-%H%M
'
)
}
.log
"
logfilename
=
f
"
/work/
{
datetime
.
today
().
strftime
(
'
%Y%m%d-%H%M
'
)
}
.log
"
# pylint: disable=consider-using-with
# pylint: disable=consider-using-with
logfile
=
open
(
logfilename
,
"
w
"
)
logfile
=
open
(
logfilename
,
"
w
"
,
encoding
=
'
utf-8
'
)
def
generate_temp_file
(
prefix
):
def
generate_temp_file
(
prefix
):
"""
Generate a temp file
"""
"""
Generate a temp file
"""
...
@@ -100,12 +100,11 @@ def get_changelog(token, payload):
...
@@ -100,12 +100,11 @@ def get_changelog(token, payload):
attempts
+=
1
attempts
+=
1
result
=
request_url
(
token
,
url
,
stream
=
True
)
result
=
request_url
(
token
,
url
,
stream
=
True
)
if
result
.
status_code
==
200
:
if
result
.
status_code
==
200
:
# TODO: try and do this with dnf 'add_remote_rpms', although we would need to auth
with
open
(
temp_file
,
"
wb
"
)
as
f
:
with
open
(
temp_file
,
"
wb
"
)
as
f
:
try
:
try
:
for
chunk
in
result
.
iter_content
(
chunk_size
=
1024
):
for
chunk
in
result
.
iter_content
(
chunk_size
=
1024
):
if
chunk
:
if
chunk
:
f
.
write
(
chunk
)
f
.
write
(
chunk
)
rpm_downloaded
=
True
rpm_downloaded
=
True
except
:
except
:
print
(
f
"
Saving changelog appeared to have failed. Retrying
{
attempts
}
/
{
max_attempts
}
"
,
flush
=
True
)
print
(
f
"
Saving changelog appeared to have failed. Retrying
{
attempts
}
/
{
max_attempts
}
"
,
flush
=
True
)
...
@@ -115,7 +114,7 @@ def get_changelog(token, payload):
...
@@ -115,7 +114,7 @@ def get_changelog(token, payload):
else
:
else
:
print
(
f
"
API call failed, Retrying
{
attempts
}
/
{
max_attempts
}
"
,
flush
=
True
)
print
(
f
"
API call failed, Retrying
{
attempts
}
/
{
max_attempts
}
"
,
flush
=
True
)
if
not
rpm_downloaded
:
if
not
rpm_downloaded
:
print
(
f
"
Changelog failed to download, exiting
"
,
flush
=
True
)
print
(
"
Changelog failed to download, exiting
"
,
flush
=
True
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
# TODO: maybe have some better logic instead of the head command
# TODO: maybe have some better logic instead of the head command
changelog
=
do_execute
(
f
"
rpm -qp
{
temp_file
}
--changelog | head -20
"
,
return_output
=
True
)
changelog
=
do_execute
(
f
"
rpm -qp
{
temp_file
}
--changelog | head -20
"
,
return_output
=
True
)
...
@@ -160,7 +159,7 @@ def request_url(token, url, params=None, stream=False):
...
@@ -160,7 +159,7 @@ def request_url(token, url, params=None, stream=False):
def
get_upstream
(
token
,
feed
):
def
get_upstream
(
token
,
feed
):
"""
retrieve full list of packages from a cset / package url
"""
"""
retrieve full list of packages from a cset / package url
"""
packages
=
[]
packages
=
[]
matches
=
re
.
match
(
f
"
(\w+)-([0-9])-\w+-(\w+)-(\w+)
"
,
feed
)
matches
=
re
.
match
(
r
"
(\w+)-([0-9])-\w+-(\w+)-(\w+)
"
,
feed
)
arch
=
matches
.
group
(
3
)
arch
=
matches
.
group
(
3
)
# almalinux is simplier, so we process it earlier
# almalinux is simplier, so we process it earlier
if
'
almalinux
'
in
feed
:
if
'
almalinux
'
in
feed
:
...
@@ -173,9 +172,9 @@ def get_upstream(token, feed):
...
@@ -173,9 +172,9 @@ def get_upstream(token, feed):
# When querying 8 from a 9 host, libdnf spews warnings about modularity
# When querying 8 from a 9 host, libdnf spews warnings about modularity
# to stderr. We don't care about that so let's silence it.
# to stderr. We don't care about that so let's silence it.
original_stderr
=
sys
.
stderr
original_stderr
=
sys
.
stderr
f
=
open
(
'
/dev/null
'
,
'
w
'
)
with
open
(
'
/dev/null
'
,
encoding
=
'
utf-8
'
)
as
f
:
sys
.
stderr
=
f
sys
.
stderr
=
f
base
.
fill_sack
(
load_system_repo
=
False
)
base
.
fill_sack
(
load_system_repo
=
False
)
# We can care about stderr again
# We can care about stderr again
sys
.
stderr
=
original_stderr
sys
.
stderr
=
original_stderr
q
=
base
.
sack
.
query
()
q
=
base
.
sack
.
query
()
...
@@ -227,13 +226,13 @@ def get_local(feed):
...
@@ -227,13 +226,13 @@ def get_local(feed):
"""
read previously saved packages into a list
"""
"""
read previously saved packages into a list
"""
try
:
try
:
with
open
(
f
"
/work/
{
feed
}
.txt
"
,
"
rb
"
)
as
f
:
with
open
(
f
"
/work/
{
feed
}
.txt
"
,
"
rb
"
)
as
f
:
l
ocal_packages
=
[]
l
p
=
[]
for
line
in
f
:
for
line
in
f
:
x
=
line
[:
-
1
]
x
=
line
[:
-
1
]
l
ocal_packages
.
append
(
x
.
decode
())
l
p
.
append
(
x
.
decode
())
except
FileNotFoundError
:
except
FileNotFoundError
:
l
ocal_packages
=
[]
l
p
=
[]
return
l
ocal_packages
return
l
p
def
set_local
(
packages
,
feed
):
def
set_local
(
packages
,
feed
):
...
@@ -300,13 +299,12 @@ def format_release(p, f, token):
...
@@ -300,13 +299,12 @@ def format_release(p, f, token):
)
)
print
(
f
"
-- Payload sent:
{
payload
}
"
,
flush
=
True
)
print
(
f
"
-- Payload sent:
{
payload
}
"
,
flush
=
True
)
def
timeout_handler
(
num
,
stack
):
def
timeout_handler
():
"""
function to handle timeouts for long running function
"""
"""
function to handle timeouts for long running function
"""
print
(
"
Received SIGALRM
"
)
print
(
"
Received SIGALRM
"
)
raise
TimeoutError
raise
TimeoutError
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
"""
this is the main class, it
'
s amazing.
"""
for
feed
in
feeds
:
for
feed
in
feeds
:
if
'
rhel
'
in
feed
:
if
'
rhel
'
in
feed
:
token
=
get_token
(
offline_token
)
token
=
get_token
(
offline_token
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment