plugin: validate lint

Make python linter happy.

Signed-off-by: Sébastien Han <seb@redhat.com>
(cherry picked from commit e2467272f8)
pull/3857/head
Sébastien Han 2018-10-11 17:59:31 +02:00 committed by mergify[bot]
parent d6d2a3b040
commit b2298753ae
1 changed files with 66 additions and 48 deletions

View File

@ -13,7 +13,7 @@ except ImportError:
try: try:
import notario import notario
except ImportError: except ImportError:
msg = "The python-notario library is missing. Please install it on the node you are running ceph-ansible to continue." msg = "The python-notario library is missing. Please install it on the node you are running ceph-ansible to continue." # noqa E501
display.error(msg) display.error(msg)
raise SystemExit(msg) raise SystemExit(msg)
@ -47,36 +47,44 @@ class ActionModule(ActionBase):
try: try:
notario_store["groups"] = host_vars["groups"] notario_store["groups"] = host_vars["groups"]
notario_store["containerized_deployment"] = host_vars["containerized_deployment"] notario_store["containerized_deployment"] = host_vars["containerized_deployment"] # noqa E501
notario.validate(host_vars, install_options, defined_keys=True) notario.validate(host_vars, install_options, defined_keys=True)
if host_vars["ceph_origin"] == "repository" and not host_vars["containerized_deployment"]: if host_vars["ceph_origin"] == "repository" and not host_vars["containerized_deployment"]:
notario.validate(host_vars, ceph_origin_repository, defined_keys=True) notario.validate(
host_vars, ceph_origin_repository, defined_keys=True)
if host_vars["ceph_repository"] == "community": if host_vars["ceph_repository"] == "community":
notario.validate(host_vars, ceph_repository_community, defined_keys=True) notario.validate(
host_vars, ceph_repository_community, defined_keys=True) # noqa E501
if host_vars["ceph_repository"] == "rhcs": if host_vars["ceph_repository"] == "rhcs":
notario.validate(host_vars, ceph_repository_rhcs, defined_keys=True) notario.validate(
host_vars, ceph_repository_rhcs, defined_keys=True)
if host_vars["ceph_repository"] == "dev": if host_vars["ceph_repository"] == "dev":
notario.validate(host_vars, ceph_repository_dev, defined_keys=True) notario.validate(
host_vars, ceph_repository_dev, defined_keys=True)
if host_vars["ceph_repository"] == "uca": # store these values because one must be defined
notario.validate(host_vars, ceph_repository_uca, defined_keys=True) # and the validation method
# store these values because one must be defined and the validation method
# will need access to all three through the store # will need access to all three through the store
notario_store["monitor_address"] = host_vars.get("monitor_address", None) notario_store["monitor_address"] = host_vars.get(
notario_store["monitor_address_block"] = host_vars.get("monitor_address_block", None) "monitor_address", None)
notario_store["monitor_interface"] = host_vars.get("monitor_interface", None) notario_store["monitor_address_block"] = host_vars.get(
"monitor_address_block", None)
notario_store["monitor_interface"] = host_vars.get(
"monitor_interface", None)
if host_vars["mon_group_name"] in host_vars["group_names"]: if host_vars["mon_group_name"] in host_vars["group_names"]:
notario.validate(host_vars, monitor_options, defined_keys=True) notario.validate(host_vars, monitor_options, defined_keys=True)
notario_store["radosgw_address"] = host_vars.get("radosgw_address", None) notario_store["radosgw_address"] = host_vars.get(
notario_store["radosgw_address_block"] = host_vars.get("radosgw_address_block", None) "radosgw_address", None)
notario_store["radosgw_interface"] = host_vars.get("radosgw_interface", None) notario_store["radosgw_address_block"] = host_vars.get(
"radosgw_address_block", None)
notario_store["radosgw_interface"] = host_vars.get(
"radosgw_interface", None)
if host_vars["rgw_group_name"] in host_vars["group_names"]: if host_vars["rgw_group_name"] in host_vars["group_names"]:
notario.validate(host_vars, rados_options, defined_keys=True) notario.validate(host_vars, rados_options, defined_keys=True)
@ -87,30 +95,30 @@ class ActionModule(ActionBase):
notario_store['osd_objectstore'] = host_vars["osd_objectstore"] notario_store['osd_objectstore'] = host_vars["osd_objectstore"]
if host_vars["osd_scenario"] == "collocated": if host_vars["osd_scenario"] == "collocated":
if not host_vars.get("osd_auto_discovery", False): if not host_vars.get("osd_auto_discovery", False):
notario.validate(host_vars, collocated_osd_scenario, defined_keys=True) notario.validate(
host_vars, collocated_osd_scenario, defined_keys=True) # noqa E501
if host_vars["osd_scenario"] == "non-collocated": if host_vars["osd_scenario"] == "non-collocated":
notario.validate(host_vars, non_collocated_osd_scenario, defined_keys=True) notario.validate(
host_vars, non_collocated_osd_scenario, defined_keys=True) # noqa E501
if host_vars["osd_scenario"] == "lvm": if host_vars["osd_scenario"] == "lvm":
if not host_vars.get("osd_auto_discovery", False):
if host_vars.get("devices"): if host_vars.get("devices"):
notario.validate(host_vars, lvm_batch_scenario, defined_keys=True) notario.validate(
host_vars, lvm_batch_scenario, defined_keys=True)
elif notario_store['osd_objectstore'] == 'filestore': elif notario_store['osd_objectstore'] == 'filestore':
notario.validate(host_vars, lvm_filestore_scenario, defined_keys=True) notario.validate(
host_vars, lvm_filestore_scenario, defined_keys=True) # noqa E501
elif notario_store['osd_objectstore'] == 'bluestore': elif notario_store['osd_objectstore'] == 'bluestore':
notario.validate(host_vars, lvm_bluestore_scenario, defined_keys=True) notario.validate(
host_vars, lvm_bluestore_scenario, defined_keys=True) # noqa E501
except Invalid as error: except Invalid as error:
display.vvv("Notario Failure: %s" % str(error)) display.vvvv("Notario Failure: %s" % str(error))
msg = "" msg = "[{}] Validation failed for variable: {}".format(
if error.path: host, error.path[0])
msg = "[{}] Validation failed for variable: {}".format(host, error.path[0])
display.error(msg) display.error(msg)
reason = "[{}] Reason: {}".format(host, error.reason) reason = "[{}] Reason: {}".format(host, error.reason)
else:
reason = "[{}] Reason: {}".format(host, str(error))
given = ""
try: try:
if "schema is missing" not in error.message: if "schema is missing" not in error.message:
for i in range(0, len(error.path)): for i in range(0, len(error.path)):
@ -159,12 +167,14 @@ class ActionModule(ActionBase):
def osd_objectstore_choices(value): def osd_objectstore_choices(value):
assert value in ['bluestore', 'filestore'], "osd_objectstore must be either 'bluestore' or 'filestore'" assert value in [
'bluestore', 'filestore'], "osd_objectstore must be either 'bluestore' or 'filestore'" # noqa E501
def ceph_origin_choices(value): def ceph_origin_choices(value):
if not notario_store["containerized_deployment"]: if not notario_store["containerized_deployment"]:
assert value in ['repository', 'distro', 'local'], "ceph_origin must be either 'repository', 'distro' or 'local'" assert value in ['repository', 'distro',
'local'], "ceph_origin must be either 'repository', 'distro' or 'local'" # noqa E501
def ceph_repository_choices(value): def ceph_repository_choices(value):
@ -173,7 +183,8 @@ def ceph_repository_choices(value):
def ceph_repository_type_choices(value): def ceph_repository_type_choices(value):
assert value in ['cdn', 'iso'], "ceph_repository_type must be either 'cdn' or 'iso'" assert value in [
'cdn', 'iso'], "ceph_repository_type must be either 'cdn' or 'iso'"
def validate_monitor_options(value): def validate_monitor_options(value):
@ -182,32 +193,38 @@ def validate_monitor_options(value):
be defined. be defined.
""" """
monitor_address_given = notario_store["monitor_address"] != "0.0.0.0" monitor_address_given = notario_store["monitor_address"] != "0.0.0.0"
monitor_address_block_given = notario_store["monitor_address_block"] != "subnet" monitor_address_block_given = notario_store["monitor_address_block"] != "subnet" # noqa E501
monitor_interface_given = notario_store["monitor_interface"] != "interface" monitor_interface_given = notario_store["monitor_interface"] != "interface"
msg = "Either monitor_address, monitor_address_block or monitor_interface must be provided" msg = "Either monitor_address, monitor_address_block or monitor_interface must be provided" # noqa E501
assert any([monitor_address_given, monitor_address_block_given, monitor_interface_given]), msg assert any([monitor_address_given, monitor_address_block_given,
monitor_interface_given]), msg
def validate_dmcrypt_bool_value(value): def validate_dmcrypt_bool_value(value):
assert value in ["true", True, "false", False], "dmcrypt can be set to true/True or false/False (default)" assert value in ["true", True, "false",
False], "dmcrypt can be set to true/True or false/False (default)"
def validate_osd_auto_discovery_bool_value(value): def validate_osd_auto_discovery_bool_value(value):
assert value in ["true", True, "false", False], "osd_auto_discovery can be set to true/True or false/False (default)" assert value in ["true", True, "false",
False], "osd_auto_discovery can be set to true/True or false/False (default)"
def validate_osd_scenarios(value): def validate_osd_scenarios(value):
assert value in ["collocated", "non-collocated", "lvm"], "osd_scenario must be set to 'collocated', 'non-collocated' or 'lvm'" assert value in ["collocated", "non-collocated",
"lvm"], "osd_scenario must be set to 'collocated', 'non-collocated' or 'lvm'" # noqa E501
def validate_objectstore(value): def validate_objectstore(value):
assert value in ["filestore", "bluestore"], "objectstore must be set to 'filestore' or 'bluestore'" assert value in [
"filestore", "bluestore"], "objectstore must be set to 'filestore' or 'bluestore'" # noqa E501
def validate_ceph_stable_release(value): def validate_ceph_stable_release(value):
assert value in CEPH_RELEASES, "ceph_stable_release must be set to one of the following: %s" % ", ".join(CEPH_RELEASES) assert value in CEPH_RELEASES, "ceph_stable_release must be set to one of the following: %s" % ", ".join( # noqa E501
CEPH_RELEASES)
def validate_rados_options(value): def validate_rados_options(value):
@ -219,9 +236,10 @@ def validate_rados_options(value):
radosgw_address_block_given = notario_store["radosgw_address_block"] != "subnet" radosgw_address_block_given = notario_store["radosgw_address_block"] != "subnet"
radosgw_interface_given = notario_store["radosgw_interface"] != "interface" radosgw_interface_given = notario_store["radosgw_interface"] != "interface"
msg = "Either radosgw_address, radosgw_address_block or radosgw_interface must be provided" msg = "Either radosgw_address, radosgw_address_block or radosgw_interface must be provided" # noqa E501
assert any([radosgw_address_given, radosgw_address_block_given, radosgw_interface_given]), msg assert any([radosgw_address_given, radosgw_address_block_given,
radosgw_interface_given]), msg
install_options = ( install_options = (