Skip to content

Commit 78afd36

Browse files
committed
fix(about): classify internal failures as UNKNOWN
1 parent e0e2806 commit 78afd36

1 file changed

Lines changed: 46 additions & 48 deletions

File tree

checkvsphere/vcmd/about.py

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,59 +25,57 @@
2525
import logging
2626
import os
2727
from monplugin import Status
28-
from pyVmomi import vim
2928
from ..tools import cli, service_instance
3029

3130

3231
def run():
33-
try:
34-
parser = cli.Parser()
35-
parser.add_optional_arguments({
36-
'name_or_flags': ['--skip-permission'],
37-
'options': {
38-
'action': 'store_true',
39-
'default': False,
40-
'help': 'skips the System.View permission check',
41-
}
42-
})
32+
parser = cli.Parser()
33+
parser.add_optional_arguments({
34+
'name_or_flags': ['--skip-permission'],
35+
'options': {
36+
'action': 'store_true',
37+
'default': False,
38+
'help': 'skips the System.View permission check',
39+
}
40+
})
4341

44-
args = parser.get_args()
45-
si = service_instance.connect(args)
46-
about = si.content.about
47-
status = Status.OK
48-
clock = True
49-
if not args.skip_permission:
50-
try:
51-
clock = si.serverClock
52-
except Exception:
53-
logging.debug("no server clock", exc_info=1)
54-
status = Status.CRITICAL
55-
clock = None
56-
if args.sessionfile:
57-
try:
58-
logging.debug(f"deleting {args.sessionfile}")
59-
os.unlink(args.sessionfile)
60-
except Exception:
61-
logging.debug(f"unlink {args.sessionfile} failed", exc_info=1)
42+
args = parser.get_args()
43+
si = service_instance.connect(args)
44+
about = si.content.about
45+
status = Status.OK
46+
clock = True
47+
if not args.skip_permission:
48+
try:
49+
clock = si.serverClock
50+
except Exception:
51+
logging.debug("no server clock", exc_info=1)
52+
status = Status.CRITICAL
53+
clock = None
54+
if args.sessionfile:
55+
try:
56+
logging.debug(f"deleting {args.sessionfile}")
57+
os.unlink(args.sessionfile)
58+
except Exception:
59+
logging.debug(f"unlink {args.sessionfile} failed", exc_info=1)
6260

63-
out = (
64-
f'{status.name}: '
65-
f'{ "No System.View permission, " if not clock else "" }'
66-
f'{ about.fullName }, '
67-
f'api: { about.apiType }/{ about.apiVersion }, '
68-
f'product: { about.licenseProductName } { about.licenseProductVersion }'
69-
)
70-
print(out)
71-
raise SystemExit(status.value)
72-
except vim.fault.VimFault as e:
73-
if hasattr(e, 'msg'):
74-
print(f"ERROR: {e.msg}")
75-
else:
76-
print(f"ERROR: {e}")
77-
raise SystemExit(2)
78-
except Exception as e:
79-
print(f"ERROR: {e}")
80-
raise SystemExit(2)
61+
out = (
62+
f'{status.name}: '
63+
f'{ "No System.View permission, " if not clock else "" }'
64+
f'{ about.fullName }, '
65+
f'api: { about.apiType }/{ about.apiVersion }, '
66+
f'product: { about.licenseProductName } { about.licenseProductVersion }'
67+
)
68+
print(out)
69+
raise SystemExit(status.value)
8170

8271
if __name__ == "__main__":
83-
run()
72+
try:
73+
run()
74+
except SystemExit as e:
75+
if not isinstance(e.code, int) or e.code > 3 or e.code < 0:
76+
print("UNKNOWN EXIT CODE")
77+
raise SystemExit(Status.UNKNOWN)
78+
raise
79+
except Exception as e:
80+
print("UNKNOWN - " + str(e))
81+
raise SystemExit(Status.UNKNOWN)

0 commit comments

Comments
 (0)