Add system BIOS management command
Adds three BIOS management commands: sushycli system bios show # show BIOS attributes sushycli system bios reset # reset BIOS attributes to default sushycli system bios set BootMode=Bios [key=value] # update attributes Likely, system reboot will be required for the changes to take effect. Change-Id: If02304177c914146b78e731b085fe988685e5b85 Story: 2006608 Task: 36776
This commit is contained in:
parent
2970a0252e
commit
a08845dda4
5
releasenotes/notes/add-system-bios-3751837665544231.yaml
Normal file
5
releasenotes/notes/add-system-bios-3751837665544231.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds ``system bios`` family of commands. These commands allow to list
|
||||
BIOS attribues, as exposed by the BMC, and change them.
|
@ -33,6 +33,9 @@ sushycli =
|
||||
manager_vmedia_eject = sushycli.manager_vmedia:ManagerVmediaEject
|
||||
manager_vmedia_insert = sushycli.manager_vmedia:ManagerVmediaInsert
|
||||
manager_vmedia_list = sushycli.manager_vmedia:ManagerVmediaList
|
||||
system_bios_reset = sushycli.system_bios:SystemBiosReset
|
||||
system_bios_set = sushycli.system_bios:SystemBiosSet
|
||||
system_bios_show = sushycli.system_bios:SystemBiosShow
|
||||
system_boot_set = sushycli.system_boot:SystemBootSet
|
||||
system_boot_show = sushycli.system_boot:SystemBootShow
|
||||
system_inventory_show = sushycli.system_inventory:SystemInventoryShow
|
||||
|
121
sushycli/system_bios.py
Normal file
121
sushycli/system_bios.py
Normal file
@ -0,0 +1,121 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2010-2020 OpenStack Foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
|
||||
from sushycli import base_system
|
||||
|
||||
|
||||
class SystemBiosShow(base_system.BaseLister):
|
||||
"""Show machine BIOS attributes"""
|
||||
def take_action(self, args):
|
||||
"""System BIOS show command action
|
||||
|
||||
:param args: a namespace of command-line attribute-value
|
||||
pairs that come from the user
|
||||
:returns: columns, values of data to be listed.
|
||||
"""
|
||||
|
||||
root = super(SystemBiosShow, self).take_action(args)
|
||||
|
||||
sys_inst = root.get_system(args.system_id)
|
||||
|
||||
return (['BIOS attribute', 'BIOS value'],
|
||||
[[attribute[0], attribute[1]]
|
||||
for attribute in sys_inst.bios.attributes.items()])
|
||||
|
||||
|
||||
class SystemBiosReset(base_system.BaseCommand):
|
||||
"""Reset machine BIOS attributes to default"""
|
||||
|
||||
def take_action(self, args):
|
||||
"""System BIOS reset command action
|
||||
|
||||
:param args: a namespace of command-line attribute-value pairs that
|
||||
come from the user
|
||||
:returns: CLI process exit code
|
||||
"""
|
||||
root = super(SystemBiosReset, self).take_action(args)
|
||||
|
||||
sys_inst = root.get_system(args.system_id)
|
||||
|
||||
sys_inst.bios.reset_bios()
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
class SystemBiosSet(base_system.BaseCommand):
|
||||
"""Update the system BIOS attribute(s)
|
||||
|
||||
This command allows updating BIOS attributes, On the command line,
|
||||
a declaration should typically be a number of key-value pairs.
|
||||
|
||||
:Example: foo=hello or foo="hello"
|
||||
|
||||
.. note:: Attributes update is not immediate but might require
|
||||
system restart.
|
||||
"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
"""Set system BIOS command parser
|
||||
|
||||
:param prog_name: name of the cliff command being executed
|
||||
:returns: an `argparse.ArgumentParser` instance
|
||||
"""
|
||||
parser = super(SystemBiosSet, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'set',
|
||||
nargs='+',
|
||||
metavar="KEY=VALUE",
|
||||
action=ParseDict,
|
||||
help='Set BIOS attributes, Note that you should not '
|
||||
'put spaces before or after the = sign.\n'
|
||||
'If a value contains spaces, you should define '
|
||||
'it with double quotes, for example:\n '
|
||||
'foo="this is a sentence".')
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, args):
|
||||
"""Set system BIOS command action
|
||||
|
||||
:param args: a namespace of command-line attribute-value pairs that
|
||||
come from the user
|
||||
:returns: CLI process exit code
|
||||
"""
|
||||
root = super(SystemBiosSet, self).take_action(args)
|
||||
|
||||
sys_inst = root.get_system(args.system_id)
|
||||
|
||||
sys_inst.bios.set_attributes(args.set)
|
||||
return 0
|
||||
|
||||
|
||||
class ParseDict(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
d = {}
|
||||
|
||||
if values:
|
||||
for item in values:
|
||||
split_items = item.split("=", 1)
|
||||
# we remove blanks around keys
|
||||
key = split_items[0].strip()
|
||||
value = split_items[1]
|
||||
|
||||
d[key] = value
|
||||
|
||||
setattr(namespace, self.dest, d)
|
@ -216,6 +216,108 @@ class SuchyCliTestCase(base.TestCase):
|
||||
|
||||
mock_write.assert_has_calls(expected_calls)
|
||||
|
||||
@mock.patch('sys.stdout.write', autospec=True)
|
||||
def test_system_bios_show(self, mock_write, mock_sushy):
|
||||
mock_root = mock_sushy.return_value
|
||||
|
||||
mock_system = mock_root.get_system.return_value
|
||||
mock_system.bios.description = None
|
||||
mock_system.bios.attributes = {'BootMode': 'Uefi',
|
||||
'EmbeddedSata': 'Raid',
|
||||
'NicBoot1': 'NetworkBoot',
|
||||
'ProcTurboMode': 'Enabled'}
|
||||
|
||||
main(['system', 'bios', 'show',
|
||||
'--username', 'jelly', '--password', 'fish',
|
||||
'--service-endpoint', 'http://fish.me',
|
||||
'--system-id', '/redfish/v1/Systems/1'])
|
||||
|
||||
mock_sushy.assert_called_once_with(
|
||||
'http://fish.me', password='fish', username='jelly')
|
||||
|
||||
expected_calls = [
|
||||
mock.call('+----------------+-------------+\n'
|
||||
'| BIOS attribute | BIOS value |\n'
|
||||
'+----------------+-------------+\n'
|
||||
'| BootMode | Uefi |\n'
|
||||
'| EmbeddedSata | Raid |\n'
|
||||
'| NicBoot1 | NetworkBoot |\n'
|
||||
'| ProcTurboMode | Enabled |\n'
|
||||
'+----------------+-------------+'),
|
||||
mock.call('\n')
|
||||
]
|
||||
|
||||
mock_write.assert_has_calls(expected_calls)
|
||||
|
||||
def test_system_bios_reset(self, mock_sushy):
|
||||
|
||||
main(['system', 'bios', 'reset',
|
||||
'--username', 'jelly', '--password', 'fish',
|
||||
'--service-endpoint', 'http://fish.me',
|
||||
'--system-id', '/redfish/v1/Systems/1'])
|
||||
mock_sushy.assert_called_once_with(
|
||||
'http://fish.me', password='fish', username='jelly')
|
||||
|
||||
mock_root = mock_sushy.return_value
|
||||
|
||||
mock_root.get_system.assert_called_once_with(
|
||||
'/redfish/v1/Systems/1')
|
||||
|
||||
mock_system = mock_root.get_system.return_value
|
||||
|
||||
mock_system.bios.reset_bios.assert_called_once()
|
||||
|
||||
def test_system_bios_set(self, mock_sushy):
|
||||
|
||||
main(['system', 'bios', 'set',
|
||||
'--username', 'jelly', '--password', 'fish',
|
||||
'--service-endpoint', 'http://fish.me',
|
||||
'--system-id', '/redfish/v1/Systems/1',
|
||||
'BootMode=Uefi', 'EmbeddedSata=Raid',
|
||||
'NicBoot1=NetworkBoot', 'ProcTurboMode=Enabled'])
|
||||
mock_sushy.assert_called_once_with(
|
||||
'http://fish.me', password='fish', username='jelly')
|
||||
|
||||
mock_root = mock_sushy.return_value
|
||||
|
||||
mock_root.get_system.assert_called_once_with(
|
||||
'/redfish/v1/Systems/1')
|
||||
|
||||
mock_system = mock_root.get_system.return_value
|
||||
|
||||
mock_system.bios.set_attributes.assert_called_once_with(
|
||||
{
|
||||
"BootMode": "Uefi",
|
||||
"EmbeddedSata": "Raid",
|
||||
"NicBoot1": "NetworkBoot",
|
||||
"ProcTurboMode": "Enabled"
|
||||
}
|
||||
)
|
||||
|
||||
def test_system_bios_set_with_keys_blanks(self, mock_sushy):
|
||||
|
||||
main(['system', 'bios', 'set',
|
||||
'--username', 'jelly', '--password', 'fish',
|
||||
'--service-endpoint', 'http://fish.me',
|
||||
'--system-id', '/redfish/v1/Systems/1',
|
||||
'BootMode =Uefi', ' EmbeddedSata=Raid'])
|
||||
mock_sushy.assert_called_once_with(
|
||||
'http://fish.me', password='fish', username='jelly')
|
||||
|
||||
mock_root = mock_sushy.return_value
|
||||
|
||||
mock_root.get_system.assert_called_once_with(
|
||||
'/redfish/v1/Systems/1')
|
||||
|
||||
mock_system = mock_root.get_system.return_value
|
||||
|
||||
mock_system.bios.set_attributes.assert_called_once_with(
|
||||
{
|
||||
"BootMode": "Uefi",
|
||||
"EmbeddedSata": "Raid",
|
||||
}
|
||||
)
|
||||
|
||||
def test_system_boot_set(self, mock_sushy):
|
||||
|
||||
main(['system', 'boot', 'set',
|
||||
|
Loading…
x
Reference in New Issue
Block a user