From 11c0ba3ae4c227aa2935c0af8839ffee0ad00756 Mon Sep 17 00:00:00 2001 From: Yifan Xiong Date: Thu, 16 Sep 2021 15:06:29 +0800 Subject: [PATCH] CLI - Integrate system info for node (#199) Integrate system info for node, add `sb node info` command. --- superbench/cli/_commands.py | 2 ++ superbench/cli/_node_handler.py | 19 +++++++++++++++++++ tests/cli/test_sb.py | 4 ++++ 3 files changed, 25 insertions(+) create mode 100644 superbench/cli/_node_handler.py diff --git a/superbench/cli/_commands.py b/superbench/cli/_commands.py index 9ff323afb..b462235ab 100644 --- a/superbench/cli/_commands.py +++ b/superbench/cli/_commands.py @@ -23,6 +23,8 @@ def load_command_table(self, args): g.command('deploy', 'deploy_command_handler') g.command('exec', 'exec_command_handler') g.command('run', 'run_command_handler') + with CommandGroup(self, 'node', 'superbench.cli._node_handler#{}') as g: + g.command('info', 'info_command_handler') return super().load_command_table(args) def load_arguments(self, command): diff --git a/superbench/cli/_node_handler.py b/superbench/cli/_node_handler.py new file mode 100644 index 000000000..4a57b5b20 --- /dev/null +++ b/superbench/cli/_node_handler.py @@ -0,0 +1,19 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +"""SuperBench CLI node subgroup command handler.""" + +from superbench.tools import SystemInfo + + +def info_command_handler(): + """Get node hardware info. + + Returns: + dict: node info. + """ + try: + info = SystemInfo().get_all() + except Exception as ex: + raise RuntimeError('Failed to get node info.') from ex + return info diff --git a/tests/cli/test_sb.py b/tests/cli/test_sb.py index 327f0c3d1..b68665dc2 100644 --- a/tests/cli/test_sb.py +++ b/tests/cli/test_sb.py @@ -81,3 +81,7 @@ def test_sb_run_nonexist_host_file(self): """Test sb run, --host-file does not exist, should fail.""" result = self.cmd('sb run --host-file ./nonexist.yaml', expect_failure=True) self.assertEqual(result.exit_code, 1) + + def test_sb_node_info(self): + """Test sb node info, should fail.""" + self.cmd('sb node info', expect_failure=True)