Skip to content

Commit

Permalink
Preparation for support of redundant HMCs
Browse files Browse the repository at this point in the history
Details:

* Changed the format of the exporter config file to prepare for future
  support of a set of redundant HMCs, since the config file format
  changes in 2.0 anyway. This avoids a future config file format
  change when we add the support for redundant HMCs.

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Aug 16, 2024
1 parent 0cc3cea commit e41106c
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 83 deletions.
10 changes: 5 additions & 5 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -853,11 +853,11 @@ The exporter config file is in YAML format and has the following structure:
version: 2
hmc:
host: {hmc-ip-address}
userid: {hmc-userid}
password: {hmc-password}
verify_cert: {hmc-verify-cert}
hmcs:
- host: {hmc-ip-address}
userid: {hmc-userid}
password: {hmc-password}
verify_cert: {hmc-verify-cert}
prometheus: # optional
port: {prom-port}
Expand Down
24 changes: 12 additions & 12 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,16 @@ def test_timeout(self):
hmc_api_version = (2, 37)
hmc_features = []
config_dict = {
"hmc": {
"host": "192.168.0.0", "userid": "user", "password": "pwd"
},
"hmcs": [
{"host": "192.168.0.0", "userid": "user", "password": "pwd"}
],
}
session = zhmc_prometheus_exporter.create_session(
config_dict, "filename")
config_dict = {
"hmc": {
"host": "192.168.0.0", "userid": "user", "password": "pwd"
},
"hmcs": [
{"host": "192.168.0.0", "userid": "user", "password": "pwd"}
],
"metric_groups": {}
}
yaml_metric_groups = {}
Expand Down Expand Up @@ -528,9 +528,9 @@ def test_init(self):

session = setup_faked_session()
config_dict = {
"hmc": {
"host": "192.168.0.0", "userid": "user", "password": "pwd"
},
"hmcs": [
{"host": "192.168.0.0", "userid": "user", "password": "pwd"}
],
"metric_groups": {
"dpm-system-usage-overview": {"export": True},
}
Expand Down Expand Up @@ -583,9 +583,9 @@ def test_collect(self):

session = setup_faked_session()
config_dict = {
"hmc": {
"host": "192.168.0.0", "userid": "user", "password": "pwd"
},
"hmcs": [
{"host": "192.168.0.0", "userid": "user", "password": "pwd"}
],
"metric_groups": {
"dpm-system-usage-overview": {"export": True},
}
Expand Down
50 changes: 25 additions & 25 deletions tests/test_config_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
password: mypassword
""",
f"""version: 2
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
verify_cert: true
Expand All @@ -112,8 +112,8 @@
value: HMC1
""",
f"""version: 2
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
verify_cert: false
Expand Down Expand Up @@ -145,8 +145,8 @@
""",
f"""# exporter config file
version: 2
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
verify_cert: false
Expand All @@ -167,8 +167,8 @@
(
"Version 2 config file without metric_groups",
"""version: 2
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
verify_cert: false
Expand All @@ -177,8 +177,8 @@
value: HMC1
""",
"""version: 2
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
verify_cert: false
Expand All @@ -196,14 +196,14 @@
(
"Version 2 config file without verify_cert",
"""version: 2
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
""",
"""version: 2
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
""",
Expand All @@ -217,15 +217,15 @@
(
"Version 2 config file with metric_groups",
f"""version: 2
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
{DEFAULT_METRIC_GROUPS}
""",
f"""version: 2
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
{DEFAULT_METRIC_GROUPS}
Expand All @@ -246,35 +246,35 @@
None,
[],
zhmc_prometheus_exporter.ImproperExit,
r"^The exporter config file must specify either the new 'hmc' item "
r"^The exporter config file must specify either the new 'hmcs' item "
r"or the old 'metrics' item, but it specifies none\.$"
),

(
"Invalid version 1 config file with both 'metrics' and 'hmc' items",
"Invalid version 1 config file with both 'metrics' and 'hmcs' items",
"""metrics:
hmc: 9.10.11.12
userid: myuser
password: mypassword
verify_cert: false
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
verify_cert: false
""",
None,
[],
zhmc_prometheus_exporter.ImproperExit,
r"^The exporter config file must specify either the new 'hmc' item "
r"^The exporter config file must specify either the new 'hmcs' item "
r"or the old 'metrics' item, but it specifies both\.$"
),

(
"Config file with unknown version",
"""version: 3
hmc:
host: 9.10.11.12
hmcs:
- host: 9.10.11.12
userid: myuser
password: mypassword
verify_cert: false
Expand Down
45 changes: 24 additions & 21 deletions zhmc_prometheus_exporter/schemas/config_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,30 @@ properties:
version:
description: "Version of the config file format"
type: integer
hmc:
description: The HMC host and credentials
type: object
required:
- host
- userid
- password
additionalProperties: false
properties:
host:
description: "Hostname or IP address of HMC"
type: string
userid:
description: "Userid used by the exporter to log on to the HMC"
type: string
password:
description: "Password of the HCM userid"
type: string
verify_cert:
description: "Controls whether and how the HMC certificate is verified. For details, see doc section 'HMC certificate'"
type: [boolean, string]
hmcs:
description: The set of redundant HMCs
type: array
default: []
items:
type: object
required:
- host
- userid
- password
additionalProperties: false
properties:
host:
description: "Hostname or IP address of HMC"
type: string
userid:
description: "Userid used by the exporter to log on to the HMC"
type: string
password:
description: "Password of the HCM userid"
type: string
verify_cert:
description: "Controls whether and how the HMC certificate is verified. For details, see doc section 'HMC certificate'"
type: [boolean, string]
metrics:
description: "Deprecated: The HMC host and credentials"
type: object
Expand Down
45 changes: 25 additions & 20 deletions zhmc_prometheus_exporter/zhmc_prometheus_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,19 @@ def help_config():
# Version of config file format
version: 2
# HMC and its credentials
hmc:
host: 9.10.11.12
userid: userid
password: password
# Note: The verify_cert parameter controls whether and how the HMC server
# certificate is validated by the exporter. For more details,
# see doc section 'HMC certificate'.
# verify_cert: true # (default) Validate using default CA certs
# verify_cert: my_certs_file # Validate using this CA certs file
# verify_cert: my_certs_dir # Validate using this CA certs directory
# verify_cert: false # Disable validation
verify_cert: false
# Redundant HMCs and their credentials
hmcs:
- host: 9.10.11.12
userid: userid
password: password
# Note: The verify_cert parameter controls whether and how the HMC server
# certificate is validated by the exporter. For more details,
# see doc section 'HMC certificate'.
# verify_cert: true # (default) Validate using default CA certs
# verify_cert: my_certs_file # Validate using this CA certs file
# verify_cert: my_certs_dir # Validate using this CA certs directory
# verify_cert: false # Disable validation
verify_cert: false
# Communication with Prometheus
prometheus:
Expand Down Expand Up @@ -505,16 +505,16 @@ def upgrade_config_dict(config_dict, config_filename, upgrade_config=False):
Upgrade the config dict to the current exporter version.
"""

if 'metrics' not in config_dict and 'hmc' not in config_dict:
if 'metrics' not in config_dict and 'hmcs' not in config_dict:
new_exc = ImproperExit(
"The exporter config file must specify either the new 'hmc' "
"The exporter config file must specify either the new 'hmcs' "
"item or the old 'metrics' item, but it specifies none.")
new_exc.__cause__ = None # pylint: disable=invalid-name
raise new_exc

if 'metrics' in config_dict and 'hmc' in config_dict:
if 'metrics' in config_dict and 'hmcs' in config_dict:
new_exc = ImproperExit(
"The exporter config file must specify either the new 'hmc' "
"The exporter config file must specify either the new 'hmcs' "
"item or the old 'metrics' item, but it specifies both.")
new_exc.__cause__ = None # pylint: disable=invalid-name
raise new_exc
Expand All @@ -527,7 +527,7 @@ def upgrade_config_dict(config_dict, config_filename, upgrade_config=False):
new_exc.__cause__ = None # pylint: disable=invalid-name
raise new_exc

if 'metrics' in config_dict and 'hmc' not in config_dict:
if 'metrics' in config_dict and 'hmcs' not in config_dict:
# Exporter config file has version 1

if upgrade_config:
Expand All @@ -551,7 +551,7 @@ def upgrade_config_dict(config_dict, config_filename, upgrade_config=False):
'password': old_creds['password'],
'verify_cert': old_creds.get('verify_cert', True),
}
config_dict.insert(1, key='hmc', value=hmc_item)
config_dict.insert(1, key='hmcs', value=[hmc_item])
del config_dict['metrics']

if 'metric_groups' not in config_dict:
Expand Down Expand Up @@ -814,7 +814,12 @@ def create_session(config_dict, config_filename):
# These warnings do not concern us
urllib3.disable_warnings()

hmc_dict = config_dict["hmc"]
hmcs = config_dict["hmcs"]
if not hmcs:
raise ImproperExit(
"The 'hmcs' item in the exporter config file does not specify "
"any HMCs.")
hmc_dict = hmcs[0]

logprint(logging.INFO, PRINT_V,
f"HMC host: {hmc_dict['host']}")
Expand Down

0 comments on commit e41106c

Please sign in to comment.