def __init__(self, command):
        super(UpdateDeviceOtaTool, self).__init__(command)

        self.unzip_path = tempfile.mkdtemp()
        utils.unzip_maintain_permissions(self.command, self.unzip_path)

        self.command = os.path.join(self.unzip_path, 'update_device.py')
    def test_modem_power_anomaly_file_existence(self):
        """Verify if the power anomaly file exists

        1. Collect Bugreport
        2. unzip bugreport
        3. remane the .bin file to .tar
        4. unzip dumpstate.tar
        5. Verify if the file exists

        """
        ad = self.android_devices[0]
        cmd = ("am broadcast -a "
               "com.google.gservices.intent.action.GSERVICES_OVERRIDE "
               "-e \"ce.cm.power_anomaly_data_enable\" \"true\"")
        ad.adb.shell(cmd)
        time.sleep(60)
        begin_time = get_current_epoch_time()
        for i in range(3):
            try:
                ad.take_bug_report(self.test_name, begin_time)
                bugreport_path = ad.device_log_path
                break
            except Exception as e:
                ad.log.error("bugreport attempt %s error: %s", i + 1, e)
        ad.log.info("Bugreport Path is %s" % bugreport_path)
        try:
            list_of_files = os.listdir(bugreport_path)
            ad.log.info(list_of_files)
            for filename in list_of_files:
                if ".zip" in filename:
                    ad.log.info(filename)
                    file_path = os.path.join(bugreport_path, filename)
                    ad.log.info(file_path)
                    unzip_maintain_permissions(file_path, bugreport_path)
            dumpstate_path = os.path.join(bugreport_path,
                                          "dumpstate_board.bin")
            if os.path.isfile(dumpstate_path):
                os.rename(dumpstate_path,
                          bugreport_path + "/dumpstate_board.tar")
                os.chmod(bugreport_path + "/dumpstate_board.tar", 0o777)
                current_dir = os.getcwd()
                os.chdir(bugreport_path)
                exe_cmd("tar -xvf %s" %
                        (bugreport_path + "/dumpstate_board.tar"))
                os.chdir(current_dir)
            else:
                ad.log.info("The dumpstate_path file %s does not exist" %
                            dumpstate_path)
            if os.path.isfile(bugreport_path + "/power_anomaly_data.txt"):
                ad.log.info("Modem Power Anomaly File Exists!!")
                return True
            ad.log.info("Modem Power Anomaly File DO NOT Exist!!")
            return False
        except Exception as e:
            ad.log.error(e)
            return False
Пример #3
0
    def test_push_new_radio_or_mbn(self):
        """Verify new mdn and radio can be push to device.

        Steps:
        1. If new radio path is given, flash new radio on the device.
        2. Verify the radio version.
        3. If new mbn path is given, push new mbn to device.
        4. Verify the installed mbn version.

        Expected Results:
        radio and mbn can be pushed to device and mbn.ver is available.
        """
        result = True
        paths = {}
        for path_key, dst_name in zip(["radio_image", "mbn_path"],
                                      ["radio.img", "mcfg_sw"]):
            path = self.user_params.get(path_key)
            if not path:
                continue
            elif isinstance(path, list):
                if not path[0]:
                    continue
                path = path[0]
            if "dev/null" in path:
                continue
            if not os.path.exists(path):
                self.log.error("path %s does not exist", path)
                self.log.info(self.user_params)
                path = os.path.join(self.user_params[Config.key_config_path],
                                    path)
                if not os.path.exists(path):
                    self.log.error("path %s does not exist", path)
                    continue

            self.log.info("%s path = %s", path_key, path)
            if "zip" in path:
                self.log.info("Unzip %s", path)
                file_path, file_name = os.path.split(path)
                dest_path = os.path.join(file_path, dst_name)
                os.system("rm -rf %s" % dest_path)
                unzip_maintain_permissions(path, file_path)
                path = dest_path
            os.system("chmod -R 777 %s" % path)
            paths[path_key] = path
        if not paths:
            self.log.info("No radio_path or mbn_path is provided")
            raise signals.TestSkip("No radio_path or mbn_path is provided")
        self.log.info("paths = %s", paths)
        for ad in self.android_devices:
            if paths.get("radio_image"):
                print_radio_info(ad, "Before flash radio, ")
                flash_radio(ad, paths["radio_image"])
                print_radio_info(ad, "After flash radio, ")
            if not paths.get("mbn_path") or "mbn" not in ad.adb.shell(
                    "ls /vendor"):
                ad.log.info("No need to push mbn files")
                continue
            push_result = True
            try:
                mbn_ver = ad.adb.shell(
                    "cat /vendor/mbn/mcfg/configs/mcfg_sw/mbn.ver")
                if mbn_ver:
                    ad.log.info("Before push mbn, mbn.ver = %s", mbn_ver)
                else:
                    ad.log.info(
                        "There is no mbn.ver before push, unmatching device")
                    continue
            except:
                ad.log.info(
                    "There is no mbn.ver before push, unmatching device")
                continue
            print_radio_info(ad, "Before push mbn, ")
            for i in range(2):
                if not system_file_push(ad, paths["mbn_path"],
                                        "/vendor/mbn/mcfg/configs/"):
                    if i == 1:
                        ad.log.error("Failed to push mbn file")
                        push_result = False
                else:
                    ad.log.info("The mbn file is pushed to device")
                    break
            if not push_result:
                result = False
                continue
            print_radio_info(ad, "After push mbn, ")
            try:
                new_mbn_ver = ad.adb.shell(
                    "cat /vendor/mbn/mcfg/configs/mcfg_sw/mbn.ver")
                if new_mbn_ver:
                    ad.log.info("new mcfg_sw mbn.ver = %s", new_mbn_ver)
                    if new_mbn_ver == mbn_ver:
                        ad.log.error(
                            "mbn.ver is the same before and after push")
                        result = False
                else:
                    ad.log.error("Unable to get new mbn.ver")
                    result = False
            except Exception as e:
                ad.log.error("cat mbn.ver with error %s", e)
                result = False
        return result