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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Gambier
slapos.core
Commits
530f422b
Commit
530f422b
authored
Oct 24, 2018
by
Jérome Perrin
Committed by
Rafael Monnerat
Oct 24, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy show: output on stdout
It was set to output on stderr, which is not natural and inconvenient
parent
5aec3d03
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
16 deletions
+50
-16
slapos/cli/proxy_show.py
slapos/cli/proxy_show.py
+15
-3
slapos/tests/cli.py
slapos/tests/cli.py
+35
-13
No files found.
slapos/cli/proxy_show.py
View file @
530f422b
...
...
@@ -30,6 +30,8 @@
import
collections
import
hashlib
import
json
import
logging
import
sys
import
lxml.etree
import
prettytable
...
...
@@ -198,7 +200,17 @@ def log_network(logger, conn):
def
do_show
(
conf
):
conf
.
logger
.
debug
(
'Using database: %s'
,
conf
.
database_uri
)
# Because this command uses logging facility to output,
# setup a logger which displays on stdout.
proxy_show_logger
=
logging
.
getLogger
(
__name__
)
handler
=
logging
.
StreamHandler
(
sys
.
stdout
)
handler
.
setLevel
(
logging
.
DEBUG
)
formatter
=
logging
.
Formatter
(
'%(message)s'
)
handler
.
setFormatter
(
formatter
)
proxy_show_logger
.
addHandler
(
handler
)
proxy_show_logger
.
propagate
=
False
proxy_show_logger
.
debug
(
'Using database: %s'
,
conf
.
database_uri
)
conn
=
sqlite_connect
(
conf
.
database_uri
)
conn
.
row_factory
=
sqlite3
.
Row
...
...
@@ -219,6 +231,6 @@ def do_show(conf):
to_call
=
[
func
for
flag
,
func
in
call_table
if
flag
]
for
idx
,
func
in
enumerate
(
to_call
):
func
(
conf
.
logger
,
conn
)
func
(
proxy_show_
logger
,
conn
)
if
idx
<
len
(
to_call
)
-
1
:
conf
.
logger
.
info
(
' '
)
proxy_show_
logger
.
info
(
' '
)
slapos/tests/cli.py
View file @
530f422b
...
...
@@ -104,14 +104,7 @@ class TestCliProxyShow(CliMixin):
db
.
cursor
().
executescript
(
schema
.
read
())
db
.
commit
()
def
tearDown
(
self
):
super
(
TestCliProxyShow
,
self
).
tearDown
()
os
.
remove
(
self
.
db_file
.
name
)
def
test_proxy_show
(
self
):
# simulate "show all" arguments
# by default we simulate being invoked with "show all" arguments
self
.
conf
.
computers
=
True
self
.
conf
.
software
=
True
self
.
conf
.
partitions
=
True
...
...
@@ -119,30 +112,59 @@ class TestCliProxyShow(CliMixin):
self
.
conf
.
params
=
True
self
.
conf
.
network
=
True
slapos
.
cli
.
proxy_show
.
do_show
(
self
.
conf
)
def
tearDown
(
self
):
super
(
TestCliProxyShow
,
self
).
tearDown
()
os
.
remove
(
self
.
db_file
.
name
)
def
test_proxy_show
(
self
):
logger
=
create_autospec
(
logging
.
Logger
)
with
mock
.
patch
(
'slapos.cli.proxy_show.logging.getLogger'
,
return_value
=
logger
):
slapos
.
cli
.
proxy_show
.
do_show
(
self
.
conf
)
# installed softwares are listed
self
.
logger
.
info
.
assert_any_call
(
logger
.
info
.
assert_any_call
(
' /srv/slapgrid/slappart8/srv/runner/project/slapos/software/erp5/software.cfg slaprunner 287375f0cba269902ba1bc50242839d7 '
)
# instance parameters are listed
# _ parameter is json formatted
self
.
logger
.
info
.
assert_any_call
(
logger
.
info
.
assert_any_call
(
' %s = %s'
,
'_'
,
'{
\
n
"url": "memcached://10.0.30.235:2003/",
\
n
"monitor-base-url": ""
\
n
}'
)
# other parameters are displayed as simple string
self
.
logger
.
info
.
assert_any_call
(
logger
.
info
.
assert_any_call
(
' %s = %s'
,
'url'
,
'http://10.0.30.235:4444/wd/hub'
)
# if _ cannot be decoded as json, it is displayed "as is"
self
.
logger
.
info
.
assert_any_call
(
logger
.
info
.
assert_any_call
(
' %s = %s'
,
'_'
,
u'Ahah this is not json
\
U0001f61c
'
)
# Nothing was output on application logger, because this command uses
# its own logger.
self
.
logger
.
info
.
assert_not_called
()
def
test_proxy_show_displays_on_stdout
(
self
):
saved_stderr
=
sys
.
stderr
saved_stdout
=
sys
.
stdout
sys
.
stderr
=
stderr
=
StringIO
.
StringIO
()
sys
.
stdout
=
stdout
=
StringIO
.
StringIO
()
try
:
slapos
.
cli
.
proxy_show
.
do_show
(
self
.
conf
)
finally
:
sys
.
stderr
=
saved_stderr
sys
.
stdout
=
saved_stdout
# 287375f0cba269902ba1bc50242839d7 is the hash of an installed software
# in our setup database
# pytest users, be sure to use --log-level=DEBUG
self
.
assertIn
(
'287375f0cba269902ba1bc50242839d7'
,
stdout
.
getvalue
())
self
.
assertEqual
(
''
,
stderr
.
getvalue
())
class
TestCliNode
(
CliMixin
):
...
...
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