Skip to content

Commit

Permalink
fix bios_profile_exists api
Browse files Browse the repository at this point in the history
Signed-off-by: Swapnil Wagh <waghswapnil@gmail.com>
  • Loading branch information
waghswapnil committed Jan 24, 2017
1 parent b4a70c0 commit 1b980ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
26 changes: 15 additions & 11 deletions imcsdk/apis/server/bios.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,37 +679,41 @@ def is_bios_profile_enabled(handle, name, server_id=1):
return mo.enabled.lower() in ['yes', 'true']


def bios_profile_exists(handle, **kwargs):
def bios_profile_exists(handle, name, server_id=1, **kwargs):
"""
Checks if the bios profile with the specified params exists
Args:
handle (ImcHandle)
kwargs: Key-Value paired arguments
name (str): Name of the bios profile.
Corresponds to the name field in the json file.
server_id (int): Id of the server to perform
this operation on C3260 platforms.
kwargs: Key-Value paired arguments relevant to BiosProfile object
Returns:
(True, BiosProfile) if the settings match, else (False, None)
Raises:
ImcOperationError if the bios profile is not found
Examples:
match, mo = bios_profile_exists(handle, name='simple',
enabled=True)
"""

mo = _get_bios_profile(handle, name=name, server_id=server_id)
params = {}
if _is_valid_arg('backup_on_activate', kwargs):
params['backup_on_activate'] = ('no', 'yes')[
kwargs.get('backup_on_activate')]

if _is_valid_arg('reboot_on_activate', kwargs):
params['reboot_on_activate'] = ('no', 'yes')[
kwargs.get('reboot_on_activate')]

if _is_valid_arg('enabled', kwargs):
params['enabled'] = ('no', 'yes')[kwargs.get('enabled')]
params['enabled'] = ('No', 'Yes')[kwargs.pop('enabled')]

if not mo.check_prop_match(**params):
return False, None

if not mo.check_prop_match(**kwargs):
return False, None

return True, mo


Expand Down Expand Up @@ -751,4 +755,4 @@ def bios_profile_generate_json(handle, name, server_id=1, file_name=None):
f.write(json.dumps(output))
f.close()

return output
return output
33 changes: 18 additions & 15 deletions tests/server/test_bios_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

from imcsdk.apis.server.bios import bios_profile_backup_running, \
bios_profile_upload, bios_profile_activate, bios_profile_delete,\
bios_profile_get, bios_profile_generate_json, is_bios_profile_enabled
bios_profile_get, bios_profile_generate_json, is_bios_profile_enabled,\
bios_profile_exists


handle = None
REMOTE_SERVER = ''
Expand All @@ -26,12 +28,12 @@
PASSWORD = ''

expected_output = {
"name": "simple",
"description": "Simple Profile",
"tokens": {
"TPMAdminCtrl":"Enabled",
"TerminalType":"PC-ANSI"
}
"name": "simple",
"description": "Simple Profile",
"tokens": {
"TPMAdminCtrl": "Enabled",
"TerminalType": "PC-ANSI"
}
}


Expand All @@ -47,7 +49,8 @@ def teardown_module():

def test_bios_profile_backup():
bios_profile_backup_running(handle, server_id=1)
assert_not_equal(bios_profile_get(handle, name='cisco_backup_profile'), None)
assert_not_equal(bios_profile_get(handle, name='cisco_backup_profile'),
None)


def test_bios_profile_upload():
Expand All @@ -68,6 +71,12 @@ def test_bios_profile_activate():
True)


def test_bios_profile_exists():
match, mo = bios_profile_exists(handle, name='simple',
enabled=True)
assert_equal(match, True)


def test_bios_profile_generate_json():
diff = []
output = bios_profile_generate_json(handle, name='simple')
Expand All @@ -77,16 +86,10 @@ def test_bios_profile_generate_json():
output[key] != expected_output[key]]
assert_equal(diff, [])
diff = [key for key in output_tokens if
key in expected_tokens and output_tokens[key] != expected_tokens[key]]
key in expected_tokens and output_tokens[key] != expected_tokens[key]]
assert_equal(diff, [])


def test_bios_profile_delete():
bios_profile_delete(handle, name='simple')
assert_equal(bios_profile_get(handle, name='simple'), None)
pass





0 comments on commit 1b980ae

Please sign in to comment.