Exemplo n.º 1
0
def oet_compose_sub():
    cdm_file_path = 'resources/test_data/OET_integration/example_allocate.json'
    LOGGER.info("cdm_file_path :" + str(cdm_file_path))
    update_resource_config_file(cdm_file_path)
    cdm_request_object = cdm_CODEC.load_from_file(AssignResourcesRequest, cdm_file_path)
    cdm_request_object.dish.receptor_ids = [str(x).zfill(4) for x in range(1, 5)]
    subarray = SubArray(1)
    LOGGER.info("Allocated Subarray is :" + str(subarray))
    return subarray.allocate_from_cdm(cdm_request_object)
Exemplo n.º 2
0
class pilot:
    def __init__(self, id):
        self.SubArray = SubArray(id)
        self.logs = ""
        self.agents = ResourceGroup(resource_names=subarray_devices)
        self.state = "Empty"
        self.rollback_order = {
            "Composed": self.and_release_all_resources,
            "Ready": self.and_end_sb_when_ready,
            # 'Configuring':restart_subarray,
            # 'Scanning':restart_subarray
        }

    def and_display_state(self):
        print("state at {} is:\n{}".format(datetime.now(),
                                           self.agents.get("State")))
        return self

    def and_display_obsState(self):
        print("state at {} is:\n{}".format(datetime.now(),
                                           self.agents.get("obsState")))
        return self

    ##the following methods are implemented versions of what gets tested
    ##unless a specic version  is tested they should be exactly the same

    def to_be_composed_out_of(
            self,
            dishes,
            file="resources/test_data/OET_integration/example_allocate.json"):
        ##Reference tests/acceptance/mvp/test_XR-13_A1.py
        @sync_assign_resources(dishes, 600)
        def assign():
            sdp_block = update_resource_config_file(file)
            resource_request: AssignResourcesRequest = cdm_CODEC.load_from_file(
                AssignResourcesRequest, file)
            resource_request.dish.receptor_ids = [
                str(x).zfill(4) for x in range(1, dishes + 1)
            ]
            self.SubArray.allocate_from_cdm(resource_request)
            return sdp_block

        sdp_block = assign()
        self.state = "Composed"
        LOGGER.info("_________Sdp block from composed function_______" +
                    str(self) + str(sdp_block))
        return self, sdp_block

    def and_configure_scan_by_file(
        self,
        sdp_block,
        file="resources/test_data/OET_integration/example_configure.json",
    ):
        ##Reference tests/acceptance/mvp/test_XR-13_A2-Test.py
        @sync_configure_oet
        @time_it(120)
        def config(file, sdp_block):
            update_scan_config_file(file, sdp_block)
            LOGGER.info("___________Input file in configure_oet_____________" +
                        str(file))
            self.state = "Configuring"
            self.SubArray.configure_from_file(file, 6, with_processing=False)

        LOGGER.info("___________SDP block from configure_oet_____________" +
                    str(sdp_block))
        config(file, sdp_block)
        self.state = "Ready"
        return self

    def and_run_a_scan(self):
        ##Reference tests/acceptance/mvp/test_XR-13_A3-Test.py
        ##note this is a different sync decorator as test since test performs the command as non blocking
        # @sync_scan_oet
        def scan():
            self.SubArray.scan()

        scan()
        self.state = "Ready"
        return self

    def and_release_all_resources(self):
        @sync_release_resources
        def de_allocate():
            self.SubArray.deallocate()

        de_allocate()
        self.state = "Empty"
        return self

    def and_end_sb_when_ready(self):
        @sync_end_sb
        def end_sb():
            self.SubArray.end()

        end_sb()
        self.state = "Composed"
        return self

    def restart_when_aborted(self):
        @sync_restart_sa
        def restart():
            self.SubArray.restart()

        restart()
        self.state = "EMPTY"
        return self

    def reset_when_aborted(self):
        @sync_reset_sa
        def reset():
            self.SubArray.reset()

        reset()
        self.state = "IDLE"
        return self

    def roll_back(self):
        if self.state != "Empty":
            self.rollback_order[self.state]()

    def reset(self):
        while self.state != "Empty":
            self.rollback_order[self.state]()