Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simone Rossi
main
Commits
8e73d34a
Commit
8e73d34a
authored
Jan 24, 2017
by
Daniele Venzano
Browse files
Fix sonarqube warnings
parent
871b0414
Changes
4
Hide whitespace changes
Inline
Side-by-side
zoe_lib/applications.py
View file @
8e73d34a
...
...
@@ -80,6 +80,7 @@ def app_validate(data):
def
_service_check
(
data
):
"""Check the service description schema."""
required_keys
=
[
'name'
,
'docker_image'
,
'monitor'
,
'ports'
,
'required_resources'
,
'total_count'
,
'essential_count'
,
'startup_order'
]
for
k
in
required_keys
:
if
k
not
in
data
:
...
...
@@ -148,12 +149,12 @@ def _service_check(data):
if
not
isinstance
(
volume
[
2
],
bool
):
raise
InvalidApplicationDescription
(
msg
=
'readonly volume item (third) must be a boolean: {}'
.
format
(
volume
[
2
]))
if
'constraints'
in
data
:
if
not
hasattr
(
data
[
'constraints'
],
'__iter__'
):
raise
InvalidApplicationDescription
(
msg
=
'networks should be an iterable'
)
if
'constraints'
in
data
and
not
hasattr
(
data
[
'constraints'
],
'__iter__'
):
raise
InvalidApplicationDescription
(
msg
=
'networks should be an iterable'
)
def
_port_check
(
data
):
"""Check the port description schema."""
required_keys
=
[
'name'
,
'protocol'
,
'port_number'
,
'is_main_endpoint'
]
for
k
in
required_keys
:
if
k
not
in
data
:
...
...
zoe_lib/configargparse.py
View file @
8e73d34a
# pylint: skip-file
# Taken from https://github.com/bw2/ConfigArgParse
"""
Unified command line and configuration argument parsing.
Taken from https://github.com/bw2/ConfigArgParse
"""
import
argparse
import
os
import
re
...
...
@@ -18,7 +24,7 @@ ACTION_TYPES_THAT_DONT_NEED_A_VALUE = {argparse._StoreTrueAction, argparse._Stor
_parsers
=
{}
# type: Dict[Any, Any]
def
init
A
rgument
P
arser
(
name
=
None
,
**
kwargs
):
def
init
_a
rgument
_p
arser
(
name
=
None
,
**
kwargs
):
"""Creates a global ArgumentParser instance with the given name,
passing any args other than "name" to the ArgumentParser constructor.
This instance can then be retrieved using getArgumentParser(..)
...
...
@@ -37,7 +43,7 @@ def initArgumentParser(name=None, **kwargs):
_parsers
[
name
]
=
ArgumentParser
(
**
kwargs
)
def
get
A
rgument
P
arser
(
name
=
None
,
**
kwargs
):
def
get
_a
rgument
_p
arser
(
name
=
None
,
**
kwargs
):
"""Returns the global ArgumentParser instance with the given name. The 1st
time this function is called, a new ArgumentParser instance will be created
for the given name, and any args other than "name" will be passed on to the
...
...
@@ -47,7 +53,7 @@ def getArgumentParser(name=None, **kwargs):
name
=
"default"
if
len
(
kwargs
)
>
0
or
name
not
in
_parsers
:
init
A
rgument
P
arser
(
name
,
**
kwargs
)
init
_a
rgument
_p
arser
(
name
,
**
kwargs
)
return
_parsers
[
name
]
...
...
@@ -132,12 +138,15 @@ class DefaultConfigFileParser(ConfigFileParser):
"""
def
get_syntax_description
(
self
):
@
classmethod
def
get_syntax_description
(
cls
):
"""Return an help string about configuration syntax."""
msg
=
(
"Config file syntax allows: key=value, flag=true, stuff=[a,b,c] "
"(for details, see syntax at https://goo.gl/R74nmi)."
)
return
msg
def
parse
(
self
,
stream
):
@
classmethod
def
parse
(
cls
,
stream
):
"""Parses the keys + values from a config file."""
items
=
OrderedDict
()
...
...
@@ -168,11 +177,11 @@ class DefaultConfigFileParser(ConfigFileParser):
items
[
key
]
=
value
continue
raise
ConfigFileParserException
(
"Unexpected line %s in %s: %s"
%
(
i
,
getattr
(
stream
,
'name'
,
'stream'
),
line
))
raise
ConfigFileParserException
(
"Unexpected line %s in %s: %s"
%
(
i
,
getattr
(
stream
,
'name'
,
'stream'
),
line
))
return
items
def
serialize
(
self
,
items
):
@
classmethod
def
serialize
(
cls
,
items
):
"""Does the inverse of config parsing by taking parsed values and
converting them back to a string representing config file contents.
"""
...
...
@@ -185,67 +194,6 @@ class DefaultConfigFileParser(ConfigFileParser):
return
r
.
getvalue
()
class
YAMLConfigFileParser
(
ConfigFileParser
):
"""Parses YAML config files. Depends on the PyYAML module.
https://pypi.python.org/pypi/PyYAML
"""
def
get_syntax_description
(
self
):
msg
=
(
"The config file uses YAML syntax and must represent a YAML "
"'mapping' (for details, see http://learn.getgrav.org/advanced/yaml)."
)
return
msg
def
_load_yaml
(
self
):
"""lazy-import PyYAML so that configargparse doesn't have to dependend
on it unless this parser is used."""
try
:
import
yaml
except
ImportError
:
raise
ConfigFileParserException
(
"Could not import yaml. "
"It can be installed by running 'pip install PyYAML'"
)
return
yaml
def
parse
(
self
,
stream
):
"""Parses the keys and values from a config file."""
yaml
=
self
.
_load_yaml
()
try
:
parsed_obj
=
yaml
.
safe_load
(
stream
)
except
Exception
as
e
:
raise
ConfigFileParserException
(
"Couldn't parse config file: %s"
%
e
)
if
type
(
parsed_obj
)
!=
dict
:
raise
ConfigFileParserException
(
"The config file doesn't appear to "
"contain 'key: value' pairs (aka. a YAML mapping). "
"yaml.load('%s') returned type '%s' instead of 'dict'."
%
(
getattr
(
stream
,
'name'
,
'stream'
),
type
(
parsed_obj
).
__name__
))
result
=
OrderedDict
()
for
key
,
value
in
parsed_obj
.
items
():
if
type
(
value
)
==
list
:
result
[
key
]
=
value
else
:
result
[
key
]
=
str
(
value
)
return
result
def
serialize
(
self
,
items
,
default_flow_style
=
False
):
"""Does the inverse of config parsing by taking parsed values and
converting them back to a string representing config file contents.
Args:
default_flow_style: defines serialization format (see PyYAML docs)
"""
# lazy-import so there's no dependency on yaml unless this class is used
yaml
=
self
.
_load_yaml
()
# it looks like ordering can't be preserved: http://pyyaml.org/ticket/29
items
=
dict
(
items
)
return
yaml
.
dump
(
items
,
default_flow_style
=
default_flow_style
)
# used while parsing args to keep track of where they came from
_COMMAND_LINE_SOURCE_KEY
=
"command_line"
_ENV_VAR_SOURCE_KEY
=
"environment_variables"
...
...
@@ -711,6 +659,7 @@ class ArgumentParser(argparse.ArgumentParser):
# Otherwise it sys.exits(..) if, for example, config file
# is_required=True and user doesn't provide it.
def
error_method
(
self
,
message
):
"""Empty error handler."""
pass
arg_parser
.
error
=
types
.
MethodType
(
error_method
,
arg_parser
)
...
...
@@ -905,8 +854,8 @@ SUPPRESS = argparse.SUPPRESS
ZERO_OR_MORE
=
argparse
.
ZERO_OR_MORE
# create shorter aliases for the key methods and class names
getArgParser
=
get
A
rgument
P
arser
getParser
=
get
A
rgument
P
arser
getArgParser
=
get
_a
rgument
_p
arser
getParser
=
get
_a
rgument
_p
arser
ArgParser
=
ArgumentParser
Parser
=
ArgumentParser
...
...
zoe_master/backends/interface.py
View file @
8e73d34a
...
...
@@ -29,6 +29,7 @@ log = logging.getLogger(__name__)
def
_get_backend
()
->
BaseBackend
:
"""Return the right backend instance by reading the global configuration."""
backend_name
=
get_conf
().
backend
if
backend_name
==
'OldSwarm'
:
return
OldSwarmBackend
(
get_conf
())
...
...
zoe_master/preprocessing.py
View file @
8e73d34a
...
...
@@ -24,6 +24,7 @@ log = logging.getLogger(__name__)
def
_digest_application_description
(
state
:
SQLManager
,
execution
:
Execution
):
"""Read an application description and expand it into services that can be deployed."""
for
service_descr
in
execution
.
description
[
'services'
]:
essential_count
=
service_descr
[
'essential_count'
]
total_count
=
service_descr
[
'total_count'
]
...
...
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