Ejemplo n.º 1
0
    def check_expected_statistics(self,
                                  deployment_id,
                                  expected_status,
                                  expected_count,
                                  max_wait=1200,
                                  polling_frequency=.2):
        timeout = time.time() + max_wait
        seen = set()

        while time.time() <= timeout:
            time.sleep(polling_frequency)

            data = self.get_statistics(deployment_id)
            seen.add(str(data))

            if int(data["failure"]) > 0 and expected_status != "failure":
                all_failed_logs = ""
                for device in self.adm.get_devices():
                    try:
                        all_failed_logs += self.get_logs(
                            device["device_id"], deployment_id) + "\n" * 5
                    except Exception, e:
                        logger.warn("failed to get logs.")

                pytest.fail(
                    "deployment unexpectedly failed, here are the deployment logs: \n\n %s"
                    % (all_failed_logs))

            if data[expected_status] == expected_count:
                return
            continue
Ejemplo n.º 2
0
def common_update_procedure(install_image,
                            regenerate_image_id=True,
                            device_type=conftest.machine_name,
                            broken_image=False,
                            verify_status=True,
                            signed=False,
                            devices=None,
                            scripts=[],
                            pre_upload_callback=lambda: None,
                            pre_deployment_callback=lambda: None,
                            deployment_triggered_callback=lambda: None,
                            compression_type="gzip"):

    with artifact_lock:
        if broken_image:
            artifact_id = "broken_image_" + str(random.randint(0, 999999))
        elif regenerate_image_id:
            artifact_id = Helpers.artifact_id_randomize(install_image)
            logger.debug("randomized image id: " + artifact_id)
        else:
            artifact_id = Helpers.yocto_id_from_ext4(install_image)

        compression_arg = "--compression " + compression_type

        # create atrifact
        with tempfile.NamedTemporaryFile() as artifact_file:
            created_artifact = image.make_artifact(
                install_image,
                device_type,
                artifact_id,
                artifact_file,
                signed=signed,
                scripts=scripts,
                global_flags=compression_arg)

            if created_artifact:
                pre_upload_callback()
                deploy.upload_image(created_artifact)
                if devices is None:
                    devices = list(
                        set([
                            device["device_id"]
                            for device in adm.get_devices_status("accepted")
                        ]))
                pre_deployment_callback()
                deployment_id = deploy.trigger_deployment(
                    name="New valid update",
                    artifact_name=artifact_id,
                    devices=devices)
            else:
                logger.warn("failed to create artifact")
                pytest.fail("error creating artifact")

    deployment_triggered_callback()
    # wait until deployment is in correct state
    if verify_status:
        deploy.check_expected_status("inprogress", deployment_id)

    return deployment_id, artifact_id