Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check list range to avoid exception #3576

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion insights/parsers/pcs_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def parse_content(self, content):
if not dc_key == "" and dc_key not in self.data.keys():
self.data[dc_key] = list_data
for in_line in in_line_tuple:
if isinstance(self.data.get(in_line), list):
if isinstance(self.data.get(in_line), list) and self.data[in_line]:
self.data[in_line] = self.data[in_line][0].split()

def get(self, key):
Expand Down
52 changes: 52 additions & 0 deletions insights/tests/parsers/test_pcs_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,53 @@
stonith-enabled: false
""".strip()

PCS_CONFIG_ON_REMOTE = """
Cluster Name: test_cluster
Corosync Nodes:
Pacemaker Nodes:
node1 node2 node3

Resources:
Resource: dummy1 (class=ocf provider=heartbeat type=Dummy)
Operations: migrate_from interval=0s timeout=20s (dummy1-migrate_from-interval-0s)
migrate_to interval=0s timeout=20s (dummy1-migrate_to-interval-0s)
monitor interval=10s timeout=20s (dummy1-monitor-interval-10s)
reload interval=0s timeout=20s (dummy1-reload-interval-0s)
start interval=0s timeout=20s (dummy1-start-interval-0s)
stop interval=0s timeout=20s (dummy1-stop-interval-0s)
Resource: remote1 (class=ocf provider=pacemaker type=remote)
Attributes: server=remote1
Operations: migrate_from interval=0s timeout=60s (remote1-migrate_from-interval-0s)
migrate_to interval=0s timeout=60s (remote1-migrate_to-interval-0s)
monitor interval=60s timeout=30s (remote1-monitor-interval-60s)
reload interval=0s timeout=60s (remote1-reload-interval-0s)
start interval=0s timeout=60s (remote1-start-interval-0s)
stop interval=0s timeout=60s (remote1-stop-interval-0s)

Stonith Devices:
Fencing Levels:

Location Constraints:
Ordering Constraints:
Colocation Constraints:
Ticket Constraints:

Alerts:
No alerts defined

Resources Defaults:
No defaults set
Operations Defaults:
No defaults set

Cluster Properties:
cluster-infrastructure: corosync
cluster-name: my_cluster
dc-version: 2.0.3-5.el8-4b1f869f0f
have-watchdog: false
last-lrm-refresh: 1667289123
""".strip()


def test_pcs_config_basic():
pcs = PCSConfig(context_wrap(NORMAL_PCS_CONFIG))
Expand All @@ -85,6 +132,11 @@ def test_pcs_config_normal():
assert pcs.cluster_properties.get("have-watchdog") == "false"


def test_pcs_config_on_remote():
pcs = PCSConfig(context_wrap(PCS_CONFIG_ON_REMOTE))
assert pcs.get("Corosync Nodes") == []


def test_pcs_config_documentation():
env = {
'pcs_config': PCSConfig(context_wrap(NORMAL_PCS_CONFIG)),
Expand Down