Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
58bc5efb
Commit
58bc5efb
authored
Dec 18, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Plain Diff
util: make buildout.download log as debug level when fetching schema
See merge request
!721
parents
1386dba9
52e1abf3
Pipeline
#38632
failed with stage
in 0 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
89 additions
and
51 deletions
+89
-51
slapos/cli/cache_pypi.py
slapos/cli/cache_pypi.py
+3
-3
slapos/cli/cache_url.py
slapos/cli/cache_url.py
+3
-3
slapos/cli/command.py
slapos/cli/command.py
+14
-2
slapos/cli/computer_info.py
slapos/cli/computer_info.py
+11
-12
slapos/cli/computer_list.py
slapos/cli/computer_list.py
+8
-8
slapos/cli/computer_token.py
slapos/cli/computer_token.py
+10
-11
slapos/cli/info.py
slapos/cli/info.py
+2
-2
slapos/cli/list.py
slapos/cli/list.py
+7
-7
slapos/tests/test_slapproxy.py
slapos/tests/test_slapproxy.py
+0
-1
slapos/tests/test_util.py
slapos/tests/test_util.py
+22
-1
slapos/util.py
slapos/util.py
+9
-1
No files found.
slapos/cli/cache_pypi.py
View file @
58bc5efb
...
@@ -86,9 +86,9 @@ def do_lookup(logger, cache_dir, cache_url, signature_certificate_list,
...
@@ -86,9 +86,9 @@ def do_lookup(logger, cache_dir, cache_url, signature_certificate_list,
logger
.
info
(
'Python egg %s version %s'
,
name
,
version
)
logger
.
info
(
'Python egg %s version %s'
,
name
,
version
)
logger
.
info
(
'SHADIR URL: %s/%s
\
n
'
,
cache_dir
,
key
)
logger
.
info
(
'SHADIR URL: %s/%s
\
n
'
,
cache_dir
,
key
)
resetLogger
(
logger
)
with
resetLogger
(
logger
):
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
logger
.
info
(
line
)
logger
.
info
(
line
)
except
HTTPError
as
e
:
except
HTTPError
as
e
:
if
e
.
code
==
404
:
if
e
.
code
==
404
:
logger
.
info
(
'Object not found in cache.'
)
logger
.
info
(
'Object not found in cache.'
)
...
...
slapos/cli/cache_url.py
View file @
58bc5efb
...
@@ -84,9 +84,9 @@ def do_lookup(logger, cache_dir, cache_url, signature_certificate_list,
...
@@ -84,9 +84,9 @@ def do_lookup(logger, cache_dir, cache_url, signature_certificate_list,
logger
.
info
(
'Software source URL: %s'
,
url
)
logger
.
info
(
'Software source URL: %s'
,
url
)
logger
.
info
(
'SHADIR URL: %s/%s
\
n
'
,
cache_dir
,
key
)
logger
.
info
(
'SHADIR URL: %s/%s
\
n
'
,
cache_dir
,
key
)
resetLogger
(
logger
)
with
resetLogger
(
logger
):
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
logger
.
info
(
line
)
logger
.
info
(
line
)
except
HTTPError
as
e
:
except
HTTPError
as
e
:
if
e
.
code
==
404
:
if
e
.
code
==
404
:
logger
.
info
(
'Object not found in cache.'
)
logger
.
info
(
'Object not found in cache.'
)
...
...
slapos/cli/command.py
View file @
58bc5efb
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
##############################################################################
##############################################################################
import
argparse
import
argparse
import
contextlib
import
functools
import
functools
import
logging
import
logging
import
os
import
os
...
@@ -36,9 +37,20 @@ import sys
...
@@ -36,9 +37,20 @@ import sys
from
cliff
import
command
from
cliff
import
command
@
contextlib
.
contextmanager
def
resetLogger
(
logger
):
def
resetLogger
(
logger
):
logger
.
propagate
=
False
has_propagate
=
hasattr
(
logger
,
'propagate'
)
# XXX mocked Loggers do not have this
logger
.
addHandler
(
logging
.
StreamHandler
(
sys
.
stdout
))
if
has_propagate
:
propagate
=
logger
.
propagate
logger
.
propagate
=
False
stdout_handler
=
logging
.
StreamHandler
(
sys
.
stdout
)
logger
.
addHandler
(
stdout_handler
)
try
:
yield
finally
:
if
has_propagate
:
logger
.
propagate
=
propagate
logger
.
removeHandler
(
stdout_handler
)
class
Command
(
command
.
Command
):
class
Command
(
command
.
Command
):
...
...
slapos/cli/computer_info.py
View file @
58bc5efb
...
@@ -58,16 +58,15 @@ class InfoCommand(ClientConfigCommand):
...
@@ -58,16 +58,15 @@ class InfoCommand(ClientConfigCommand):
def
do_info
(
logger
,
conf
,
local
):
def
do_info
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
with
resetLogger
(
logger
):
try
:
try
:
computer
=
local
[
'slap'
].
registerComputer
(
conf
.
reference
).
getInformation
()
computer
=
local
[
'slap'
].
registerComputer
(
conf
.
reference
).
getInformation
()
except
ResourceNotReady
:
except
ResourceNotReady
:
logger
.
warning
(
'Computer does not exist or is not ready yet.'
)
logger
.
warning
(
'Computer does not exist or is not ready yet.'
)
return
(
2
)
return
(
2
)
except
NotFoundError
:
except
NotFoundError
:
logger
.
warning
(
'Computer %s does not exist.'
,
conf
.
reference
)
logger
.
warning
(
'Computer %s does not exist.'
,
conf
.
reference
)
return
(
2
)
return
(
2
)
logger
.
info
(
'Computer Reference: %s'
,
computer
.
_reference
)
logger
.
info
(
'Computer Title : %s'
,
computer
.
_title
)
logger
.
info
(
'Computer Reference: %s'
,
computer
.
_reference
)
logger
.
info
(
'Computer Title : %s'
,
computer
.
_title
)
slapos/cli/computer_list.py
View file @
58bc5efb
...
@@ -51,11 +51,11 @@ class ListCommand(ClientConfigCommand):
...
@@ -51,11 +51,11 @@ class ListCommand(ClientConfigCommand):
def
do_list
(
logger
,
conf
,
local
):
def
do_list
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
with
resetLogger
(
logger
):
computer_dict
=
local
[
'slap'
].
getComputerDict
()
computer_dict
=
local
[
'slap'
].
getComputerDict
()
if
computer_dict
==
{}:
if
computer_dict
==
{}:
logger
.
info
(
'No existing computer.'
)
logger
.
info
(
'No existing computer.'
)
return
return
logger
.
info
(
'List of Computers:'
)
logger
.
info
(
'List of Computers:'
)
for
title
,
computer
in
six
.
iteritems
(
computer_dict
):
for
title
,
computer
in
six
.
iteritems
(
computer_dict
):
logger
.
info
(
'%s %s'
,
computer
.
_reference
,
title
)
logger
.
info
(
'%s %s'
,
computer
.
_reference
,
title
)
slapos/cli/computer_token.py
View file @
58bc5efb
...
@@ -54,15 +54,14 @@ class TokenCommand(ClientConfigCommand):
...
@@ -54,15 +54,14 @@ class TokenCommand(ClientConfigCommand):
def
do_token
(
logger
,
conf
,
local
):
def
do_token
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
with
resetLogger
(
logger
):
try
:
try
:
token
=
local
[
'slap'
].
registerToken
().
request
()
token
=
local
[
'slap'
].
registerToken
().
request
()
except
ResourceNotReady
:
except
ResourceNotReady
:
logger
.
warning
(
'Computer does not exist or is not ready yet.'
)
logger
.
warning
(
'Computer does not exist or is not ready yet.'
)
return
(
2
)
return
(
2
)
except
NotFoundError
:
except
NotFoundError
:
logger
.
warning
(
'Computer %s does not exist.'
,
conf
.
reference
)
logger
.
warning
(
'Computer %s does not exist.'
,
conf
.
reference
)
return
(
2
)
return
(
2
)
logger
.
info
(
'Computer token: %s'
,
token
)
logger
.
info
(
'Computer token: %s'
,
token
)
slapos/cli/info.py
View file @
58bc5efb
...
@@ -70,7 +70,6 @@ class InfoCommand(ClientConfigCommand):
...
@@ -70,7 +70,6 @@ class InfoCommand(ClientConfigCommand):
def
do_info
(
logger
,
conf
,
local
):
def
do_info
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
try
:
try
:
instance
=
local
[
'slap'
].
registerOpenOrder
().
getInformation
(
instance
=
local
[
'slap'
].
registerOpenOrder
().
getInformation
(
partition_reference
=
conf
.
reference
,
partition_reference
=
conf
.
reference
,
...
@@ -126,5 +125,6 @@ def do_info(logger, conf, local):
...
@@ -126,5 +125,6 @@ def do_info(logger, conf, local):
if
conf
.
news
:
if
conf
.
news
:
info
[
'news'
]
=
news
info
[
'news'
]
=
news
logger
.
info
(
json
.
dumps
(
info
,
indent
=
2
))
with
resetLogger
(
logger
):
logger
.
info
(
json
.
dumps
(
info
,
indent
=
2
))
slapos/cli/list.py
View file @
58bc5efb
...
@@ -52,12 +52,12 @@ class ListCommand(ClientConfigCommand):
...
@@ -52,12 +52,12 @@ class ListCommand(ClientConfigCommand):
def
do_list
(
logger
,
conf
,
local
):
def
do_list
(
logger
,
conf
,
local
):
resetLogger
(
logger
)
# XXX catch exception
# XXX catch exception
instance_dict
=
local
[
'slap'
].
getOpenOrderDict
()
instance_dict
=
local
[
'slap'
].
getOpenOrderDict
()
logger
.
info
(
with
resetLogger
(
logger
):
json
.
dumps
(
logger
.
info
(
{
title
:
instance
.
_software_release_url
json
.
dumps
(
for
(
title
,
instance
)
in
six
.
iteritems
(
instance_dict
)},
{
title
:
instance
.
_software_release_url
sort_keys
=
True
,
for
(
title
,
instance
)
in
six
.
iteritems
(
instance_dict
)},
indent
=
2
))
sort_keys
=
True
,
indent
=
2
))
slapos/tests/test_slapproxy.py
View file @
58bc5efb
...
@@ -80,7 +80,6 @@ class BasicMixin(object):
...
@@ -80,7 +80,6 @@ class BasicMixin(object):
"""
"""
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
_tempdir
=
tempfile
.
mkdtemp
()
self
.
_rootdir
=
self
.
initRootDir
()
self
.
_rootdir
=
self
.
initRootDir
()
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
self
.
setFiles
()
self
.
setFiles
()
self
.
startProxy
()
self
.
startProxy
()
os
.
environ
.
pop
(
'SLAPGRID_INSTANCE_ROOT'
,
None
)
os
.
environ
.
pop
(
'SLAPGRID_INSTANCE_ROOT'
,
None
)
...
...
slapos/tests/test_util.py
View file @
58bc5efb
...
@@ -36,6 +36,7 @@ import warnings
...
@@ -36,6 +36,7 @@ import warnings
from
pwd
import
getpwnam
from
pwd
import
getpwnam
from
six.moves
import
SimpleHTTPServer
from
six.moves
import
SimpleHTTPServer
import
six
import
slapos.util
import
slapos.util
from
slapos.testing.utils
import
ManagedHTTPServer
from
slapos.testing.utils
import
ManagedHTTPServer
...
@@ -469,13 +470,33 @@ class TestSoftwareReleaseSchemaEdgeCases(unittest.TestCase):
...
@@ -469,13 +470,33 @@ class TestSoftwareReleaseSchemaEdgeCases(unittest.TestCase):
self
.
assertIn
(
"Unable to load JSON"
,
str
(
w
[
0
].
message
))
self
.
assertIn
(
"Unable to load JSON"
,
str
(
w
[
0
].
message
))
def
test_software_schema_wrong_URL
(
self
):
def
test_software_schema_wrong_URL
(
self
):
schema
=
SoftwareReleaseSchema
(
'http://slapos.invalid/software.cfg'
,
None
)
schema
=
SoftwareReleaseSchema
(
'http://slapos.invalid/
wrong-url/
software.cfg'
,
None
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
"always"
)
warnings
.
simplefilter
(
"always"
)
self
.
assertIsNone
(
schema
.
getSoftwareSchema
())
self
.
assertIsNone
(
schema
.
getSoftwareSchema
())
self
.
assertEqual
(
len
(
w
),
1
)
self
.
assertEqual
(
len
(
w
),
1
)
self
.
assertIn
(
"Unable to load JSON"
,
str
(
w
[
0
].
message
))
self
.
assertIn
(
"Unable to load JSON"
,
str
(
w
[
0
].
message
))
def
test_software_schema_download_does_no_log
(
self
):
schema
=
SoftwareReleaseSchema
(
'http://slapos.invalid/no-log/software.cfg'
,
None
)
debug_level_log_stream
=
six
.
StringIO
()
debug_level_handler
=
logging
.
StreamHandler
(
debug_level_log_stream
)
debug_level_handler
.
setLevel
(
logging
.
DEBUG
)
default_level_log_stream
=
six
.
StringIO
()
default_level_handler
=
logging
.
StreamHandler
(
default_level_log_stream
)
default_level_handler
.
setLevel
(
logging
.
INFO
)
logger
=
logging
.
getLogger
()
self
.
addCleanup
(
functools
.
partial
(
logger
.
setLevel
,
logger
.
getEffectiveLevel
()))
logger
.
setLevel
(
logging
.
DEBUG
)
logger
.
addHandler
(
debug_level_handler
)
self
.
addCleanup
(
functools
.
partial
(
logger
.
removeHandler
,
debug_level_handler
))
logger
.
addHandler
(
default_level_handler
)
self
.
addCleanup
(
functools
.
partial
(
logger
.
removeHandler
,
default_level_handler
))
self
.
assertIsNone
(
schema
.
getSoftwareSchema
())
self
.
assertEqual
(
default_level_log_stream
.
getvalue
(),
""
)
self
.
assertEqual
(
debug_level_log_stream
.
getvalue
(),
"Downloading http://slapos.invalid/no-log/software.cfg.json
\
n
"
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
slapos/util.py
View file @
58bc5efb
...
@@ -31,6 +31,7 @@ import enum
...
@@ -31,6 +31,7 @@ import enum
import
errno
import
errno
import
hashlib
import
hashlib
import
json
import
json
import
logging
import
os
import
os
import
pprint
import
pprint
import
shutil
import
shutil
...
@@ -476,7 +477,14 @@ class SoftwareReleaseSchema(object):
...
@@ -476,7 +477,14 @@ class SoftwareReleaseSchema(object):
software_type
=
None
software_type
=
None
self
.
software_type
=
software_type
or
DEFAULT_SOFTWARE_TYPE
self
.
software_type
=
software_type
or
DEFAULT_SOFTWARE_TYPE
if
download
is
None
:
if
download
is
None
:
download
=
zc
.
buildout
.
download
.
Download
()
logger
=
logging
.
getLogger
(
'{__name__}.{self.__class__.__name__}.download'
.
format
(
__name__
=
__name__
,
self
=
self
))
# zc.buildout.download logs in level info "Downloading from <URL>", which is
# fine for normal buildout usage, but when downloading software release schemas
# we want these messages to be logged with level debug
logger
.
info
=
logger
.
debug
# type: ignore
download
=
zc
.
buildout
.
download
.
Download
(
logger
=
logger
)
self
.
_download
=
download
.
download
self
.
_download
=
download
.
download
def
_warn
(
self
,
message
,
e
):
def
_warn
(
self
,
message
,
e
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment