Beispiel #1
0
def fwupdate_command(args):
    """update firmware on a cluster or host"""
    def do_update():
        """ Do a single firmware check+update. Returns True on failure. """
        if not args.force:
            if not args.quiet:
                print "Checking hosts..."

            _, errors = run_command(args, nodes, "_check_firmware", package,
                                    args.partition, args.priority)
            if errors:
                print "ERROR: Firmware update aborted."
                return True

        if not args.quiet:
            print "Updating firmware..."

        _, errors = run_command(args, nodes, "update_firmware", package,
                                args.partition, args.priority)
        if errors:
            print "ERROR: Firmware update failed."
            return True

        return False

    def do_reset():
        """ Reset and wait. Returns True on failure. """
        if not args.quiet:
            print "Checking ECME versions..."

        results, errors = run_command(args, nodes, "get_versions")
        if errors:
            print "ERROR: MC reset aborted. Backup partitions not updated."
            return True

        for result in results.values():
            version = result.ecme_version.lstrip("v")
            if parse_version(version) < parse_version("1.2.0"):
                print "ERROR: MC reset is unsafe on ECME version v%s" % version
                print "Please power cycle the system and start a new fwupdate."
                return True

        if not args.quiet:
            print "Resetting nodes..."

        results, errors = run_command(args, nodes, "mc_reset", True)
        if errors:
            print "ERROR: MC reset failed. Backup partitions not updated."
            return True

        return False

    if args.image_type == "PACKAGE":
        package = FirmwarePackage(args.filename)
    else:
        try:
            simg = None
            if args.force_simg:
                simg = False
            elif args.skip_simg:
                simg = True

            image = Image(args.filename, args.image_type, simg, args.daddr,
                          args.skip_crc32, args.fw_version)
            package = FirmwarePackage()
            package.images.append(image)
        except ValueError as err:
            print "ERROR: %s" % err
            return True

    if not args.all_nodes:
        if args.force:
            print('WARNING: Updating firmware without --all-nodes' +
                  ' is dangerous.')
        else:
            if not prompt_yes('WARNING: Updating firmware without ' +
                              '--all-nodes is dangerous. Continue?'):
                return 1

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp, verify_prompt=True)

    errors = do_update()

    if args.full and not errors:
        errors = do_reset()
        if not errors:
            errors = do_update()

    if not args.quiet and not errors:
        print "Command completed successfully.\n"

    return errors
Beispiel #2
0
def fwupdate_command(args):
    """update firmware on a cluster or host"""
    def do_update():
        """ Do a single firmware check+update. Returns True on failure. """
        if not args.force:
            if not args.quiet:
                print "Checking hosts..."

            _, errors = run_command(args, nodes, "_check_firmware",
                    package, args.partition, args.priority)
            if errors:
                print "ERROR: Firmware update aborted."
                return True

        if not args.quiet:
            print "Updating firmware..."

        _, errors = run_command(args, nodes, "update_firmware", package,
            args.partition, args.priority)
        if errors:
            print "ERROR: Firmware update failed."
            return True

        return False

    def do_reset():
        """ Reset and wait. Returns True on failure. """
        if not args.quiet:
            print "Checking ECME versions..."

        results, errors = run_command(args, nodes, "get_versions")
        if errors:
            print "ERROR: MC reset aborted. Backup partitions not updated."
            return True

        for result in results.values():
            version = result.ecme_version.lstrip("v")
            if parse_version(version) < parse_version("1.2.0"):
                print "ERROR: MC reset is unsafe on ECME version v%s" % version
                print "Please power cycle the system and start a new fwupdate."
                return True

        if not args.quiet:
            print "Resetting nodes..."

        results, errors = run_command(args, nodes, "mc_reset", True)
        if errors:
            print "ERROR: MC reset failed. Backup partitions not updated."
            return True

        return False

    if args.image_type == "PACKAGE":
        package = FirmwarePackage(args.filename)
    else:
        try:
            simg = None
            if args.force_simg:
                simg = False
            elif args.skip_simg:
                simg = True

            image = Image(args.filename, args.image_type, simg, args.daddr,
                    args.skip_crc32, args.fw_version)
            package = FirmwarePackage()
            package.images.append(image)
        except ValueError as err:
            print "ERROR: %s" % err
            return True

    if not args.all_nodes:
        if args.force:
            print(
                'WARNING: Updating firmware without --all-nodes' +
                ' is dangerous.'
            )
        else:
            if not prompt_yes(
                'WARNING: Updating firmware without ' +
                '--all-nodes is dangerous. Continue?'
                ):
                return 1

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp, verify_prompt=True)

    errors = do_update()

    if args.full and not errors:
        errors = do_reset()
        if not errors:
            errors = do_update()

    if not args.quiet and not errors:
        print "Command completed successfully.\n"

    return errors
Beispiel #3
0
def eepromupdate_command(args):
    """Updates the EEPROM's on a cluster or host"""
    def validate_config():
        """Makes sure the system type is applicable to EEPROM updates"""
        for node in  nodes:
            if('Dual Node' not in node.get_versions().hardware_version):
                print 'ERROR: eepromupdate is only valid on TerraNova systems'
                return True

        return False

    def validate_images():
        """Makes sure all the necessary images have been provided"""
        if(args.eeprom_location == 'node'):
            for node in nodes:
                node_hw_ver = node.get_versions().hardware_version
                if('Uplink' in node_hw_ver):
                    image = 'dual_uplink_node_%s' % (node.node_id % 4)
                else:
                    image = 'dual_node_%s' % (node.node_id % 4)
                if(not [img for img in args.images if image in img]):
                    print 'ERROR: no valid image for node %s' % node.node_id
                    return True

        else:
            image = args.images[0]
            if('tn_storage.single_slot' not in image):
                print 'ERROR: %s is an invalid image for slot EEPROM' % image
                return True

        return False

    def do_update():
        """Updates the EEPROM images"""
        if(args.eeprom_location == 'node'):
            for node in nodes:
                node_hw_ver = node.get_versions().hardware_version
                if('Uplink' in node_hw_ver):
                    needed_image = 'dual_uplink_node_%s' % (node.node_id % 4)
                else:
                    needed_image = 'dual_node_%s' % (node.node_id % 4)
                image = [img for img in args.images if needed_image in img][0]
                print 'Updating node EEPROM on node %s' % node.node_id
                if(args.verbose):
                    print '    %s' % image
                try:
                    node.update_node_eeprom(image)
                except Exception as err:
                    print 'ERROR: %s' % str(err)
                    return True

            print ''  # for readability
        else:
            image = args.images[0]
            # First node in every slot gets the slot image
            slot_nodes = [node for node in nodes if node.node_id % 4 == 0]
            _, errors = run_command(
                args, slot_nodes, "update_slot_eeprom", image
            )
            if(errors):
                print 'ERROR: EEPROM update failed'
                return True

        return False

    if not args.all_nodes:
        if args.force:
            print(
                'WARNING: Updating EEPROM without --all-nodes' +
                ' is dangerous.'
            )
        else:
            if not prompt_yes(
                'WARNING: Updating EEPROM without ' +
                '--all-nodes is dangerous. Continue?'
                ):
                return 1

    tftp = get_tftp(args)
    nodes = get_nodes(args, tftp, verify_prompt=True)

    errors = validate_config()

    if(not errors):
        errors = validate_images()

    if(not errors):
        errors = do_update()

    if not args.quiet and not errors:
        print "Command completed successfully."
        print "A power cycle is required for the update to take effect.\n"

    return errors