コード例 #1
0
    def test__call_method_redfish_2(self, ribcl_reset_ilo_mock, redfish_mock,
                                    ribcl_product_name_mock):
        ribcl_product_name_mock.return_value = 'Gen10'
        self.client = client.IloClient("1.2.3.4", "admin", "secret")

        self.client._call_method('reset_ilo')
        ribcl_reset_ilo_mock.assert_called_once_with()
コード例 #2
0
    def test_init(self, ris_mock, ribcl_mock):
        ribcl_obj_mock = mock.MagicMock()
        ribcl_mock.return_value = ribcl_obj_mock
        ribcl_obj_mock.get_product_name.return_value = 'product'

        c = client.IloClient("1.2.3.4",
                             "admin",
                             "Admin",
                             timeout=120,
                             port=4430,
                             bios_password='******',
                             cacert='/somewhere')

        ris_mock.assert_called_once_with("1.2.3.4",
                                         "admin",
                                         "Admin",
                                         bios_password='******',
                                         cacert='/somewhere')
        ribcl_mock.assert_called_once_with("1.2.3.4",
                                           "admin",
                                           "Admin",
                                           120,
                                           4430,
                                           cacert='/somewhere')
        self.assertEqual(
            {
                'address': "1.2.3.4",
                'username': "******",
                'password': "******"
            }, c.info)
        self.assertEqual('product', c.model)
コード例 #3
0
    def test_init_for_redfish_with_ribcl_enabled(self, redfish_mock,
                                                 ribcl_mock):
        ribcl_obj_mock = mock.MagicMock()
        ribcl_mock.return_value = ribcl_obj_mock
        ribcl_obj_mock.get_product_name.return_value = 'ProLiant DL180 Gen10'

        c = client.IloClient("1.2.3.4",
                             "admin",
                             "Admin",
                             timeout=120,
                             port=4430,
                             bios_password='******',
                             cacert='/somewhere')

        ribcl_mock.assert_called_once_with("1.2.3.4",
                                           "admin",
                                           "Admin",
                                           120,
                                           4430,
                                           cacert='/somewhere')
        redfish_mock.assert_called_once_with("1.2.3.4",
                                             "admin",
                                             "Admin",
                                             bios_password='******',
                                             cacert='/somewhere')
        self.assertEqual(
            {
                'address': "1.2.3.4",
                'username': "******",
                'password': "******"
            }, c.info)
        self.assertEqual('ProLiant DL180 Gen10', c.model)
        self.assertIsNotNone(c.redfish)
        self.assertTrue(c.is_ribcl_enabled)
        self.assertFalse(hasattr(c, 'ris'))
コード例 #4
0
    def test_init_with_use_redfish_only_set(self, redfish_mock, ribcl_mock):
        c = client.IloClient("1.2.3.4",
                             "admin",
                             "Admin",
                             timeout=120,
                             port=4430,
                             bios_password='******',
                             cacert='/somewhere',
                             use_redfish_only=True)

        ribcl_mock.assert_called_once_with("1.2.3.4",
                                           "admin",
                                           "Admin",
                                           120,
                                           4430,
                                           cacert='/somewhere')
        redfish_mock.assert_called_once_with("1.2.3.4",
                                             "admin",
                                             "Admin",
                                             bios_password='******',
                                             cacert='/somewhere')
        self.assertEqual(
            {
                'address': "1.2.3.4",
                'username': "******",
                'password': "******"
            }, c.info)
        self.assertIsNotNone(c.model)
        self.assertIsNotNone(c.redfish)
        self.assertIsNone(c.is_ribcl_enabled)
        self.assertFalse(hasattr(c, 'ris'))
        self.assertTrue(c.use_redfish_only)
コード例 #5
0
    def test__call_method_use_redfish_only_set_but_not_implemented(
            self, redfish_mock):
        self.client = client.IloClient("1.2.3.4",
                                       "admin",
                                       "secret",
                                       use_redfish_only=True)

        self.assertRaises(NotImplementedError, self.client._call_method,
                          'reset_ilo')
コード例 #6
0
    def test__call_method_redfish_1(self, redfish_mock,
                                    ribcl_product_name_mock):
        ribcl_product_name_mock.return_value = 'Gen10'
        self.client = client.IloClient("1.2.3.4", "admin", "secret")
        redfish_get_host_power_mock = (
            redfish.RedfishOperations.return_value.get_host_power_status)

        self.client._call_method('get_host_power_status')
        redfish_get_host_power_mock.assert_called_once_with()
コード例 #7
0
    def test__call_method_redfish_4(self, redfish_mock,
                                    ribcl_product_name_mock):
        ribcl_product_name_mock.side_effect = (
            exception.IloError('RIBCL is disabled'))
        redfish_mock.return_value.get_product_name.return_value = 'Gen10'
        self.client = client.IloClient("1.2.3.4", "admin", "secret")

        self.assertRaises(NotImplementedError, self.client._call_method,
                          'reset_ilo')
コード例 #8
0
    def test__call_method_with_use_redfish_only_set(self, redfish_mock):
        self.client = client.IloClient("1.2.3.4",
                                       "admin",
                                       "secret",
                                       use_redfish_only=True)
        redfish_get_host_power_mock = (
            redfish.RedfishOperations.return_value.get_host_power_status)

        self.client._call_method('get_host_power_status')
        redfish_get_host_power_mock.assert_called_once_with()
コード例 #9
0
def get_all_nodes_health(vault_key):
    """ This function will use the proliantutils library
    module "get_host_health_data" to derive the health status of
    the following components 'BIOS, Fans, Temperature Sensors,
    Battery, Processor, Memory, Network, Storage.

    If the health status of all component is ok then overall
    health of the physical node is returned as "OK"
    """
    try:
        result = get_all_nodes(vault_key)
        final = {}
        for key, value in result.items():
            dict_object = {}
            if type(value) == type(dict()):
                v = list(value.values())
                ilo_client = client.IloClient(v[1], v[2], v[3])
                dict_object = ilo_client.get_host_health_data()
                q = VaultJSONParser(dict_object, vault_key)
                bios = q.dict_query(
                    "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/BIOS_HARDWARE/STATUS"
                )
                fans = q.dict_query(
                    "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/FANS/STATUS")
                temperature = q.dict_query(
                    "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/TEMPERATURE/STATUS"
                )
                battery = q.dict_query(
                    "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/BATTERY/STATUS"
                )
                processor = q.dict_query(
                    "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/PROCESSOR/STATUS"
                )
                memory = q.dict_query(
                    "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/MEMORY/STATUS"
                )
                network = q.dict_query(
                    "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/NETWORK/STATUS"
                )
                storage = q.dict_query(
                    "GET_EMBEDDED_HEALTH_DATA/HEALTH_AT_A_GLANCE/STORAGE/STATUS"
                )
                total_health = [bios, fans, temperature, battery, processor,\
                    memory, network, storage]
                result1 = len(set(total_health)) == 1
                if result1:
                    final[v[0]] = "OK"
                else:
                    final[v[0]] = "Degraded"
    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise

    return (final)
コード例 #10
0
    def test__call_method_redfish_3(self, redfish_mock,
                                    ribcl_product_name_mock):
        ribcl_product_name_mock.side_effect = (
            exception.IloError('RIBCL is disabled'))
        redfish_mock.return_value.get_product_name.return_value = 'Gen10'
        self.client = client.IloClient("1.2.3.4", "admin", "secret")
        redfish_get_host_power_mock = (
            redfish.RedfishOperations.return_value.get_host_power_status)

        self.client._call_method('get_host_power_status')
        redfish_get_host_power_mock.assert_called_once_with()
コード例 #11
0
 def test_validate_snmp_auth_prot_priv_prot_missing(self, product_mock):
     cred = {
         'auth_user': '******',
         'auth_prot_pp': '1234',
         'auth_priv_pp': '4321',
         'snmp_inspection': True
     }
     self.client = client.IloClient("1.2.3.4",
                                    "admin",
                                    "Admin",
                                    snmp_credentials=cred)
     self.assertEqual(self.client.snmp_credentials, cred)
コード例 #12
0
def get_all_node_security_status(vault_key):
    """ This function will use the proliantutils library
    module "get_current_bios_settings" to derive the status of
    the following BIOS configuration which are important for
    the security: 'secure boot status (enabled), asset tag (locked),
    UEFI Shell Script Verification (enabled), 
    UEFI Shell Startup (disabled), Processor AES (enabled)"
    
    If the value of any of the configuration deviates from the 
    recommended value, overall security status will be marked as 
    degraded. Refer to BIOS user guide for recommended value of these
    configurations
    """
    try:
        result = get_all_nodes(vault_key)
        final = {}
        for key, value in result.items():
            dict_object = {}
            if type(value) == type(dict()):
                v = list(value.values())
                ilo_client = client.IloClient(v[1], v[2], v[3])
                dict_object = ilo_client.get_current_bios_settings()
                q = VaultJSONParser(dict_object, vault_key)
                secure_boot_status = q.dict_query("SecureBootStatus")
                asset_tag = q.dict_query("AssetTagProtection")
                shell_script_verify = q.dict_query(
                    "UefiShellScriptVerification")
                shell_startup = q.dict_query("UefiShellStartup")
                processor_aes = q.dict_query("ProcAes")
                if v[0] == "secphyworker1.sec.twentynet.local" and \
                    secure_boot_status.lower() == "disabled":
                    final[v[0]] = "OK"
                elif secure_boot_status.lower() == "enabled" and \
                    asset_tag.lower() == "locked" and \
                        shell_script_verify.lower() == "enabled" and \
                            shell_startup.lower() == "disabled" and \
                                processor_aes.lower() == "enabled":
                    final[v[0]] = "OK"
                else:
                    final[v[0]] = "Degraded"
    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise
    return (final)
コード例 #13
0
    def test_init_snmp(self, ris_mock, ribcl_mock, snmp_mock):
        ribcl_obj_mock = mock.MagicMock()
        ribcl_mock.return_value = ribcl_obj_mock
        ribcl_obj_mock.get_product_name.return_value = 'product'
        snmp_credentials = {
            'auth_user': '******',
            'auth_protocol': 'SHA',
            'auth_prot_pp': '1234',
            'priv_protocol': 'AES',
            'auth_priv_pp': '4321',
            'snmp_inspection': 'true'
        }
        c = client.IloClient("1.2.3.4",
                             "admin",
                             "Admin",
                             timeout=120,
                             port=4430,
                             bios_password='******',
                             cacert='/somewhere',
                             snmp_credentials=snmp_credentials)

        ris_mock.assert_called_once_with("1.2.3.4",
                                         "admin",
                                         "Admin",
                                         bios_password='******',
                                         cacert='/somewhere')
        ribcl_mock.assert_called_once_with("1.2.3.4",
                                           "admin",
                                           "Admin",
                                           120,
                                           4430,
                                           cacert='/somewhere')
        self.assertEqual(
            {
                'address': "1.2.3.4",
                'username': "******",
                'password': "******"
            }, c.info)
        self.assertEqual('product', c.model)
        self.assertTrue(snmp_mock.called)
コード例 #14
0
 def setUp(self, product_mock):
     super(IloClientTestCase, self).setUp()
     product_mock.return_value = 'Gen8'
     self.client = client.IloClient("1.2.3.4", "admin", "Admin")
コード例 #15
0
 def setUp(self, product_mock):
     super(UtilsTestCase, self).setUp()
     product_mock.return_value = 'Gen8'
     self.some_compact_fw_file = 'some_compact_fw_file.scexe'
     self.client = client.IloClient("1.2.3.4", "admin", "Admin")
コード例 #16
0
import sys
import time
import proliantutils.ilo.client as client

ilo_ip = sys.argv[1]

cl = client.IloClient(ilo_ip, "Administrator", "weg0th@ce@r")

#add certificate
cl.add_tls_certificate(['/home/ubuntu/ssl_files/uefi_signed.crt'])
time.sleep(10)

print("Certificate upload completed. Now resetting the server.")

#Server reboot
#cl.reset_server()
#time.sleep(600)
コード例 #17
0
def update_firmware(node):
    """Performs SUM based firmware update on the node.

    This method performs SUM firmware update by mounting the
    SPP ISO on the node. It performs firmware update on all or
    some of the firmware components.

    :param node: A node object of type dict.
    :returns: Operation Status string.
    :raises: SUMOperationError, when the vmedia device is not found or
        when the mount operation fails or when the image validation fails.
    :raises: IloConnectionError, when the iLO connection fails.
    :raises: IloError, when vmedia eject or insert operation fails.
    """
    sum_update_iso = node['clean_step']['args'].get('url')

    # Validates the http image reference for SUM update ISO.
    try:
        utils.validate_href(sum_update_iso)
    except exception.ImageRefValidationFailed as e:
        raise exception.SUMOperationError(reason=e)

    # Ejects the CDROM device in the iLO and inserts the SUM update ISO
    # to the CDROM device.
    info = node.get('driver_info')
    ilo_object = client.IloClient(info.get('ilo_address'),
                                  info.get('ilo_username'),
                                  info.get('ilo_password'))

    ilo_object.eject_virtual_media('CDROM')
    ilo_object.insert_virtual_media(sum_update_iso, 'CDROM')

    # Waits for the OS to detect the disk and update the label file. SPP ISO
    # is identified by matching its label.
    time.sleep(WAIT_TIME_DISK_LABEL_TO_BE_VISIBLE)
    vmedia_device_dir = "/dev/disk/by-label/"
    for file in os.listdir(vmedia_device_dir):
        if fnmatch.fnmatch(file, 'SPP*'):
            vmedia_device_file = os.path.join(vmedia_device_dir, file)

    if not os.path.exists(vmedia_device_file):
        msg = "Unable to find the virtual media device for SUM"
        raise exception.SUMOperationError(reason=msg)

    # Validates the SPP ISO image for any file corruption using the checksum
    # of the ISO file.
    expected_checksum = node['clean_step']['args'].get('checksum')
    try:
        utils.verify_image_checksum(vmedia_device_file, expected_checksum)
    except exception.ImageRefValidationFailed as e:
        raise exception.SUMOperationError(reason=e)

    # Mounts SPP ISO on a temporary directory.
    vmedia_mount_point = tempfile.mkdtemp()
    try:
        try:
            processutils.execute("mount", vmedia_device_file,
                                 vmedia_mount_point)
        except processutils.ProcessExecutionError as e:
            msg = ("Unable to mount virtual media device %(device)s: "
                   "%(error)s" % {
                       'device': vmedia_device_file,
                       'error': e
                   })
            raise exception.SUMOperationError(reason=msg)

        # Executes the SUM based firmware update by passing the 'smartupdate'
        # executable path if exists else 'hpsum' executable path and the
        # components specified (if any).
        sum_file_path = os.path.join(vmedia_mount_point, SUM_LOCATION)
        if not os.path.exists(sum_file_path):
            sum_file_path = os.path.join(vmedia_mount_point, HPSUM_LOCATION)

        components = node['clean_step']['args'].get('components')
        result = _execute_sum(sum_file_path,
                              vmedia_mount_point,
                              components=components)

        processutils.trycmd("umount", vmedia_mount_point)
    finally:
        shutil.rmtree(vmedia_mount_point, ignore_errors=True)

    return result