Improved case 'Verify Get Channel Info via IPMI'

-The original way to verify this command was through the file
"/usr/share/ipmi-providers/channel_access.json".
However, this file may not exist for different projects.
Furthermore, the command "Set Channel Access" can changes the values but
it does not write to this file. Therefore, if the Channel Access setting
has changed and is different from this file, it will fail the test.

-The original way only validates attributes in 'volatile(active)_settings',
not 'Non-Volatile Settings'.

Signed-off-by: Tony Lee <tony.lee@quantatw.com>
Change-Id: I6dbf98e0fdffea98c39ca96708b71a93679e2579
diff --git a/ipmi/test_ipmi_general.robot b/ipmi/test_ipmi_general.robot
index 0c28039..bb69e0f 100644
--- a/ipmi/test_ipmi_general.robot
+++ b/ipmi/test_ipmi_general.robot
@@ -78,7 +78,8 @@
     [Tags]  Verify_Get_Channel_Info_via_IPMI
 
     # Get channel info via ipmi command "ipmitool channel info [channel number]".
-    # Verify channel info with files "channel_access.json" and "channel_config.json" in BMC.
+    # Verify channel info with files "channel_access_volatile.json", "channel_access_nv.json"
+    # and "channel_config.json" in BMC.
 
     # Example output from 'Get Channel Info':
     # channel_info:
@@ -88,16 +89,23 @@
     #     [session_support]:                            multi-session
     #     [active_session_count]:                       0
     #     [protocol_vendor_id]:                         7154
-    #     [volatile(active)_settings]:
-    #     [alerting]:                                   enabled
-    #     [per-message_auth]:                           enabled
-    #     [user_level_auth]:                            enabled
-    #     [access_mode]:                                always available
+    #   [volatile(active)_settings]:
+    #       [alerting]:                                 enabled
+    #       [per-message_auth]:                         enabled
+    #       [user_level_auth]:                          enabled
+    #       [access_mode]:                              always available
+    #   [Non-Volatile Settings]:
+    #       [alerting]:                                 enabled
+    #       [per-message_auth]:                         enabled
+    #       [user_level_auth]:                          enabled
+    #       [access_mode]:                              always available
 
     ${channel_info_ipmi}=  Get Channel Info  ${CHANNEL_NUMBER}
     ${active_channel_config}=  Get Active Channel Config
-    ${channel_access_config}=  Get Channel Access Config
-    Rprint Vars  channel_info_ipmi  active_channel_config  channel_access_config
+    ${channel_volatile_data_config}=  Get Channel Access Config  /run/ipmi/channel_access_volatile.json
+    ${channel_nv_data_config}=  Get Channel Access Config  /var/lib/ipmi/channel_access_nv.json
+
+    Rprint Vars  channel_info_ipmi  active_channel_config  channel_volatile_data_config  channel_nv_data_config
 
     Valid Value  medium_type_ipmi_conf_map['${channel_info_ipmi['channel_0x${CHANNEL_NUMBER}_info']['channel_medium_type']}']
     ...  ['${active_channel_config['${CHANNEL_NUMBER}']['channel_info']['medium_type']}']
@@ -113,14 +121,28 @@
     # IPMI Spec: The IPMI Enterprise Number is: 7154 (decimal)
     Valid Value  channel_info_ipmi['channel_0x${CHANNEL_NUMBER}_info']['protocol_vendor_id']  ['7154']
 
-    Valid Value  disabled_ipmi_conf_map['${channel_info_ipmi['channel_0x${CHANNEL_NUMBER}_info']['alerting']}']
-    ...  ['${channel_access_config['${CHANNEL_NUMBER}']['alerting_disabled']}']
+    # Verify volatile(active)_settings
+    Valid Value  disabled_ipmi_conf_map['${channel_info_ipmi['volatile(active)_settings']['alerting']}']
+    ...  ['${channel_volatile_data_config['${CHANNEL_NUMBER}']['alerting_disabled']}']
 
-    Valid Value  disabled_ipmi_conf_map['${channel_info_ipmi['channel_0x${CHANNEL_NUMBER}_info']['per-message_auth']}']
-    ...  ['${channel_access_config['${CHANNEL_NUMBER}']['per_msg_auth_disabled']}']
+    Valid Value  disabled_ipmi_conf_map['${channel_info_ipmi['volatile(active)_settings']['per-message_auth']}']
+    ...  ['${channel_volatile_data_config['${CHANNEL_NUMBER}']['per_msg_auth_disabled']}']
 
-    Valid Value  disabled_ipmi_conf_map['${channel_info_ipmi['channel_0x${CHANNEL_NUMBER}_info']['user_level_auth']}']
-    ...  ['${channel_access_config['${CHANNEL_NUMBER}']['user_auth_disabled']}']
+    Valid Value  disabled_ipmi_conf_map['${channel_info_ipmi['volatile(active)_settings']['user_level_auth']}']
+    ...  ['${channel_volatile_data_config['${CHANNEL_NUMBER}']['user_auth_disabled']}']
 
-    Valid Value  access_mode_ipmi_conf_map['${channel_info_ipmi['channel_0x${CHANNEL_NUMBER}_info']['access_mode']}']
-    ...  ['${channel_access_config['${CHANNEL_NUMBER}']['access_mode']}']
+    Valid Value  access_mode_ipmi_conf_map['${channel_info_ipmi['volatile(active)_settings']['access_mode']}']
+    ...  ['${channel_volatile_data_config['${CHANNEL_NUMBER}']['access_mode']}']
+
+    # Verify Non-Volatile Settings
+    Valid Value  disabled_ipmi_conf_map['${channel_info_ipmi['non-volatile_settings']['alerting']}']
+    ...  ['${channel_nv_data_config['${CHANNEL_NUMBER}']['alerting_disabled']}']
+
+    Valid Value  disabled_ipmi_conf_map['${channel_info_ipmi['non-volatile_settings']['per-message_auth']}']
+    ...  ['${channel_nv_data_config['${CHANNEL_NUMBER}']['per_msg_auth_disabled']}']
+
+    Valid Value  disabled_ipmi_conf_map['${channel_info_ipmi['non-volatile_settings']['user_level_auth']}']
+    ...  ['${channel_nv_data_config['${CHANNEL_NUMBER}']['user_auth_disabled']}']
+
+    Valid Value  access_mode_ipmi_conf_map['${channel_info_ipmi['non-volatile_settings']['access_mode']}']
+    ...  ['${channel_nv_data_config['${CHANNEL_NUMBER}']['access_mode']}']
diff --git a/lib/bmc_network_utils.py b/lib/bmc_network_utils.py
index 7e91604..f3c6fea 100644
--- a/lib/bmc_network_utils.py
+++ b/lib/bmc_network_utils.py
@@ -178,10 +178,14 @@
     return vf.filter_struct(get_channel_config(), "[('medium_type', 'other-lan|lan-802.3')]", regex=1)
 
 
-def get_channel_access_config():
+def get_channel_access_config(file_name):
     r"""
     Get the channel access config data and return as a dictionary.
 
+    Description of argument:
+    file_name     File name for channel access settings (e.g. '/run/ipmi/channel_access_volatile.json',
+                 '/var/lib/ipmi/channel_access_nv.json'.).
+
     Example:
 
     channel_access_config =  get_channel_access_config()
@@ -201,6 +205,6 @@
             [alerting_disabled]:                          False
             [user_auth_disabled]:                         False
     """
-    stdout, stderr, rc = bsu.bmc_execute_command("cat /usr/share/ipmi-providers/channel_access.json")
+    stdout, stderr, rc = bsu.bmc_execute_command("cat " + file_name)
 
     return json.loads(stdout)
diff --git a/lib/ipmi_utils.py b/lib/ipmi_utils.py
index d8c9be7..2a72fde 100644
--- a/lib/ipmi_utils.py
+++ b/lib/ipmi_utils.py
@@ -636,12 +636,12 @@
         [session_support]:                            multi-session
         [active_session_count]:                       0
         [protocol_vendor_id]:                         7154
-        [volatile(active)_settings]:
+      [volatile(active)_settings]:
         [alerting]:                                   enabled
         [per-message_auth]:                           enabled
         [user_level_auth]:                            enabled
         [access_mode]:                                always available
-        [non-volatile_settings]:
+      [non-volatile_settings]:
         [alerting]:                                   enabled
         [per-message_auth]:                           enabled
         [user_level_auth]:                            enabled
@@ -650,6 +650,10 @@
 
     status, ret_values = \
         grk.run_key_u("Run IPMI Standard Command  channel info " + str(channel_number))
-    result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1)
-
+    key_var_list = list(filter(None, ret_values.split("\n")))
+    # To match the dict format, add a colon after 'Volatile(active) Settings' and 'Non-Volatile Settings'
+    # respectively.
+    key_var_list[6] = 'Volatile(active) Settings:'
+    key_var_list[11] = 'Non-Volatile Settings:'
+    result = vf.key_value_list_to_dict(key_var_list, process_indent=1)
     return result