Beispiel #1
0
 def test_update_firmware(self):
     """ Test update_firmware command """
     package = FirmwarePackage()
     self.fabric.update_firmware(package)
     for node in self.nodes:
         self.assertEqual(node.method_calls,
                          [call.update_firmware(package, "INACTIVE", None)])
Beispiel #2
0
    def test_update_firmware(self):
        """ Test node.update_firmware method """
        filename = "%s/%s" % (self.work_dir, "image.bin")
        open(filename, "w").write("")

        package = FirmwarePackage()
        package.images = [
            TestImage(filename, "SOC_ELF"),
            TestImage(filename, "CDB"),
            TestImage(filename, "UBOOTENV")
        ]
        package.version = "0.0.1"

        for node in self.nodes:
            node.update_firmware(package)

            partitions = node.bmc.partitions
            unchanged_partitions = [partitions[x] for x in [0, 1, 4]]
            changed_partitions = [partitions[x] for x in [2, 3, 6]]
            ubootenv_partition = partitions[5]

            for partition in unchanged_partitions:
                self.assertEqual(partition.updates, 0)
                self.assertEqual(partition.retrieves, 0)
                self.assertEqual(partition.checks, 0)
                self.assertEqual(partition.activates, 0)

            for partition in changed_partitions:
                self.assertEqual(partition.updates, 1)
                self.assertEqual(partition.retrieves, 0)
                self.assertEqual(partition.checks, 2)
                self.assertEqual(partition.activates, 1)

            self.assertEqual(ubootenv_partition.updates, 1)
            self.assertEqual(ubootenv_partition.retrieves, 1)
            self.assertEqual(ubootenv_partition.checks, 2)
            self.assertEqual(ubootenv_partition.activates, 1)

            node.bmc.set_firmware_version.assert_called_once_with("0.0.1")
Beispiel #3
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 #4
0
    def test_is_updatable(self):
        """ Test node.is_updatable method """
        for node in self.nodes:
            max_size = 12288 - 60
            filename = random_file(max_size)
            images = [
                TestImage(filename, "SOC_ELF"),
                TestImage(filename, "CDB"),
                TestImage(filename, "UBOOTENV")
            ]

            # should pass
            package = FirmwarePackage()
            package.images = images
            self.assertTrue(node.is_updatable(package))

            # should fail if the firmware version is wrong
            package = FirmwarePackage()
            package.images = images
            package.version = "ECX-31415-v0.0.0"
            self.assertFalse(node.is_updatable(package))

            # should fail if we specify a socman version
            package = FirmwarePackage()
            package.images = images
            package.required_socman_version = "0.0.1"
            self.assertFalse(node.is_updatable(package))

            # should fail if we try to upload a slot2
            package = FirmwarePackage()
            package.images = images
            package.config = "slot2"
            self.assertFalse(node.is_updatable(package))

            # should fail if we upload an image that's too large
            package = FirmwarePackage()
            package.images = [TestImage(random_file(max_size + 1), "UBOOTENV")]
            self.assertFalse(node.is_updatable(package))

            # should fail if we upload to a CDB partition that's in use
            package = FirmwarePackage()
            package.images = images
            self.assertFalse(node.is_updatable(package, partition_arg="ACTIVE"))