-
Notifications
You must be signed in to change notification settings - Fork 816
[Config] Update config command of kdump #1700
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6a235b8
[kdump] Update config command of kdump.
yozhao101 590bc1c
[config] Use `sys.exit(...)` instead of `return` statement.
yozhao101 78c0b84
[config] Delete the unused `import os`.
yozhao101 2c9d2f5
[config] This commit includes the following changes:
yozhao101 aae9cfb
[config] Add the unit test cases and update the implementation.
yozhao101 841fd11
[kdump] Create a separate function to check whether the `kdump` table
yozhao101 4eed738
[config] Fix the indentation issue.
yozhao101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,86 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| import click | ||
| import utilities_common.cli as clicommon | ||
| from swsscommon.swsscommon import ConfigDBConnector | ||
| from utilities_common.cli import AbbreviationGroup, pass_db | ||
|
|
||
|
|
||
| @click.group(cls=clicommon.AbbreviationGroup, name="kdump") | ||
| # | ||
| # 'kdump' group ('sudo config kdump ...') | ||
| # | ||
| @click.group(cls=AbbreviationGroup, name="kdump") | ||
| def kdump(): | ||
| """ Configure kdump """ | ||
| if os.geteuid() != 0: | ||
| exit("Root privileges are required for this operation") | ||
|
|
||
| @kdump.command() | ||
| def disable(): | ||
| """Disable kdump operation""" | ||
| config_db = ConfigDBConnector() | ||
| if config_db is not None: | ||
| config_db.connect() | ||
| config_db.mod_entry("KDUMP", "config", {"enabled": "false"}) | ||
|
|
||
| @kdump.command() | ||
| def enable(): | ||
| """Enable kdump operation""" | ||
| config_db = ConfigDBConnector() | ||
| if config_db is not None: | ||
| config_db.connect() | ||
| config_db.mod_entry("KDUMP", "config", {"enabled": "true"}) | ||
|
|
||
| @kdump.command() | ||
| """Configure the KDUMP mechanism""" | ||
| pass | ||
|
|
||
|
|
||
| def check_kdump_table_existence(kdump_table): | ||
| """Checks whether the 'KDUMP' table is configured in Config DB. | ||
|
|
||
| Args: | ||
| kdump_table: A dictionary represents the key-value pair in sub-table | ||
| of 'KDUMP'. | ||
|
|
||
| Returns: | ||
| None. | ||
| """ | ||
| if not kdump_table: | ||
| click.echo("Unable to retrieve 'KDUMP' table from Config DB.") | ||
| sys.exit(1) | ||
|
|
||
| if "config" not in kdump_table: | ||
| click.echo("Unable to retrieve key 'config' from KDUMP table.") | ||
| sys.exit(2) | ||
|
|
||
|
|
||
| # | ||
| # 'disable' command ('sudo config kdump disable') | ||
| # | ||
| @kdump.command(name="disable", short_help="Disable the KDUMP mechanism") | ||
| @pass_db | ||
| def kdump_disable(db): | ||
| """Disable the KDUMP mechanism""" | ||
| kdump_table = db.cfgdb.get_table("KDUMP") | ||
| check_kdump_table_existence(kdump_table) | ||
|
|
||
| db.cfgdb.mod_entry("KDUMP", "config", {"enabled": "false"}) | ||
|
|
||
|
|
||
| # | ||
| # 'enable' command ('sudo config kdump enable') | ||
| # | ||
| @kdump.command(name="enable", short_help="Enable the KDUMP mechanism") | ||
| @pass_db | ||
| def kdump_enable(db): | ||
| """Enable the KDUMP mechanism""" | ||
| kdump_table = db.cfgdb.get_table("KDUMP") | ||
| check_kdump_table_existence(kdump_table) | ||
|
|
||
| db.cfgdb.mod_entry("KDUMP", "config", {"enabled": "true"}) | ||
|
|
||
|
|
||
| # | ||
| # 'memory' command ('sudo config kdump memory ...') | ||
| # | ||
| @kdump.command(name="memory", short_help="Configure the memory for KDUMP mechanism") | ||
| @click.argument('kdump_memory', metavar='<kdump_memory>', required=True) | ||
| def memory(kdump_memory): | ||
| """Set memory allocated for kdump capture kernel""" | ||
| config_db = ConfigDBConnector() | ||
| if config_db is not None: | ||
| config_db.connect() | ||
| config_db.mod_entry("KDUMP", "config", {"memory": kdump_memory}) | ||
|
|
||
| @kdump.command('num-dumps') | ||
| @pass_db | ||
| def kdump_memory(db, kdump_memory): | ||
| """Reserve memory for kdump capture kernel""" | ||
| kdump_table = db.cfgdb.get_table("KDUMP") | ||
| check_kdump_table_existence(kdump_table) | ||
|
|
||
| db.cfgdb.mod_entry("KDUMP", "config", {"memory": kdump_memory}) | ||
|
|
||
|
|
||
| # | ||
| # 'num_dumps' command ('sudo config keump num_dumps ...') | ||
| # | ||
| @kdump.command(name="num_dumps", short_help="Configure the maximum dump files of KDUMP mechanism") | ||
| @click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int) | ||
| def num_dumps(kdump_num_dumps): | ||
| """Set max number of dump files for kdump""" | ||
| config_db = ConfigDBConnector() | ||
| if config_db is not None: | ||
| config_db.connect() | ||
| config_db.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps}) | ||
| @pass_db | ||
| def kdump_num_dumps(db, kdump_num_dumps): | ||
| """Set maximum number of dump files for kdump""" | ||
| kdump_table = db.cfgdb.get_table("KDUMP") | ||
| check_kdump_table_existence(kdump_table) | ||
|
|
||
| db.cfgdb.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import importlib | ||
|
|
||
| from click.testing import CliRunner | ||
| from utilities_common.db import Db | ||
|
|
||
|
|
||
| class TestKdump(object): | ||
| @classmethod | ||
| def setup_class(cls): | ||
| print("SETUP") | ||
|
|
||
| def test_config_kdump_disable(self, get_cmd_module): | ||
| (config, show) = get_cmd_module | ||
| db = Db() | ||
| runner = CliRunner() | ||
| result = runner.invoke(config.config.commands["kdump"].commands["disable"], obj=db) | ||
| print(result.exit_code) | ||
| assert result.exit_code == 0 | ||
|
|
||
| # Delete the 'KDUMP' table. | ||
| db.cfgdb.delete_table("KDUMP") | ||
|
|
||
| result = runner.invoke(config.config.commands["kdump"].commands["disable"], obj=db) | ||
| print(result.exit_code) | ||
| assert result.exit_code == 1 | ||
|
|
||
| def test_config_kdump_enable(self, get_cmd_module): | ||
| (config, show) = get_cmd_module | ||
| db = Db() | ||
| runner = CliRunner() | ||
| result = runner.invoke(config.config.commands["kdump"].commands["enable"], obj=db) | ||
| print(result.exit_code) | ||
| assert result.exit_code == 0 | ||
|
|
||
| # Delete the 'KDUMP' table. | ||
| db.cfgdb.delete_table("KDUMP") | ||
|
|
||
| result = runner.invoke(config.config.commands["kdump"].commands["enable"], obj=db) | ||
| print(result.exit_code) | ||
| assert result.exit_code == 1 | ||
|
|
||
| def test_config_kdump_memory(self, get_cmd_module): | ||
| (config, show) = get_cmd_module | ||
| db = Db() | ||
| runner = CliRunner() | ||
| result = runner.invoke(config.config.commands["kdump"].commands["memory"], ["256MB"], obj=db) | ||
| print(result.exit_code) | ||
| assert result.exit_code == 0 | ||
|
|
||
| # Delete the 'KDUMP' table. | ||
| db.cfgdb.delete_table("KDUMP") | ||
|
|
||
| result = runner.invoke(config.config.commands["kdump"].commands["memory"], ["256MB"], obj=db) | ||
| print(result.exit_code) | ||
| assert result.exit_code == 1 | ||
|
|
||
| def test_config_kdump_num_dumps(self, get_cmd_module): | ||
| (config, show) = get_cmd_module | ||
| db = Db() | ||
| runner = CliRunner() | ||
| result = runner.invoke(config.config.commands["kdump"].commands["num_dumps"], ["10"], obj=db) | ||
| print(result.exit_code) | ||
| assert result.exit_code == 0 | ||
|
|
||
| # Delete the 'KDUMP' table. | ||
| db.cfgdb.delete_table("KDUMP") | ||
|
|
||
| result = runner.invoke(config.config.commands["kdump"].commands["num_dumps"], ["10"], obj=db) | ||
| print(result.exit_code) | ||
| assert result.exit_code == 1 | ||
|
|
||
| @classmethod | ||
| def teardown_class(cls): | ||
| print("TEARDOWN") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.