def modify_expected_output(self):
        """The golden files generated by generate_test_cases function will be
        in binary format. This function modifies them to text format and also
        to FlowInfoFromSensor proto from FlowInfoFromSensorList proto.
        Args:
            self: Instance of the class.
        Returns:
            True on success else False.
        Raises:
            NA.
        """
        return_status = True
        os.chdir(self.test_case_dir)
        files_list = glob.glob(os.path.join(self.test_case_dir, "*.golden"))
        if not files_list:
            logging.error("unable to get the golden file list")
            return False

        for file_name in files_list:
            logging.info("".join(["file name : ", file_name]))
            if file_name == "":
                continue
            sensor = flow_info_pb2.FlowInfoFromSensorList()
            status, file_content = general_functions.\
                read_file_contents(file_name)
            if not status:
                logging.error("Unable to fetch content for " + file_name)
                return_status = False
                continue
            reader = records.RecordIO(open(file_name, "rb"),
                                      flow_info_pb2.FlowInfoFromSensor)
            os.remove(file_name)
            fields_list = self.get_clear_fields_list()
            for flow_info_sensor in reader:
                if not general_functions.clear_field(flow_info_sensor,
                                                     fields_list):
                    logging.error("FAILED TO CLEAR fields FOR %s", file_name)
                    return_status = False
                general_functions.write(file_name, flow_info_sensor, "a")

            if not self.generate_collector_output(file_name):
                logging.error("Unable to generate collector output.")
                return_status = False
        return return_status
    def generate_test_configs(self):
        """ This function generates the integration test config files.
        Args:
            self: Instance of the class.
        Returns:
            True on success else False.
        Raises:
            NA.
        """
        return_status = True
        os.chdir(self.test_case_dir)
        # Fetch the unique test cases names.
        files_list = list(set([os.path.basename(f).split(".")[0]
                               for f in glob.glob("*.golden")]))
        if not files_list:
            logging.error("unable to get files list from it test cases dir")
            return False
        logging.info("Number of test case: %d", len(files_list))

        file_descriptor = open(self.test_cases_file, "w")
        file_descriptor.close()

        for file_name in files_list:
            if file_name == "":
                continue
            iterate_status = self.write_test_config(file_name)
            if not iterate_status:
                logging.error("Unable to generate config for %s test case",
                              file_name)
            return_status = return_status and iterate_status
            content = "".join(["proto_file_name: \"", self.test_case_dir, "/",
                               file_name, ".config\"\n"])
            iterate_status = general_functions.\
                write(self.test_cases_file, content, "a")
            if not iterate_status:
                logging.error("Unable to write config name for %s test case",
                              file_name)
            return_status = return_status and iterate_status
        content = "".join(["stats_server_ip: \"", str(self.stats_server_ip),
                           "\"\n", "stats_server_port: ",
                           str(self.stats_server_port), "\n"])
        status = general_functions.write(self.test_cases_file, content, "a")
        return_status = return_status and status

        return return_status
    def write_test_config(self, file_name):
        """This function is used to update and write the test config for a
        given test case.
        Args:
            self: Instance of the class.
            file_name: File name for which test case is being generated.
        Returns:
            True on success else False.
        Raises:
            NA.
        """
        self.template_config.test_name = file_name
        self.sft_sensor_config.tenant_id = 0

        if not self.generate_sw_sensor_config(file_name):
            logging.error("Software sensor config generation failed.")
            return False

        self.template_config.sensor_output_protobuf_file = \
            "".join([self.test_case_dir, "/", file_name, ".golden"])
        self.template_config.collector_output_protobuf_file = \
            "".join([self.test_case_dir, "/", file_name, ".collector"])
        self.template_config.asic_configs.config_file = \
            "".join([self.test_case_dir, "/", file_name, ".sensor_config"])
        self.template_config.asic_configs.packet_file = \
            "".join([self.test_case_dir, "/", file_name, ".packet"])
        self.template_config.asic_configs.output_file = \
            "".join([self.test_case_dir, "/", file_name, ".out"])
        self.template_config.asic_configs.events_file = \
            "".join([self.test_case_dir, "/", file_name, ".events"])
        self.template_config.asic_configs.rtl_dump_file = \
            "".join([self.test_case_dir, "/", file_name, ".rtldump"])
        self.template_config.asic_configs.rtl_config_dump_file = \
            "".join([self.test_case_dir, "/", file_name, ".rtl_config"])
        return general_functions.write("".join([file_name, ".config"]),
                                       str(self.template_config), 'w')
    def generate_sw_sensor_config(self, file_name):
        """Genertae the software sensor config for the given test case.
        Args:
            self: instance of the class.
            file_name: base file name(test case name).
        Returns:
            True on success else False.
        Raises:
            None
        """
        self.template_config.ClearField("sensor_config")
        sensor_list = list(set(glob.glob(file_name + ".eth[0-9][0-9].pcap")))
        sensor_list.extend(list(set(glob.glob(file_name + ".eth[0-9].pcap"))))
        sensor_list = set(sensor_list)
        for pcap in sensor_list:
            config_name = pcap.split(".")
            tenant_id = (int("".join(config_name[1][3:])) + 1)*10
            snsr_config_file = "".join(config_name[:2])
            snsr_config_file = "".join([self.test_case_dir, "/",
                                        snsr_config_file,
                                        ".sw_sensor_config"])
            self.sft_sensor_config.pcap_file = "".join([self.test_case_dir,
                                                        "/", pcap])
            self.sft_sensor_config.tenant_id = tenant_id
            if not general_functions.write(snsr_config_file,
                                           str(self.sft_sensor_config), "w"):
                logging.error("Unable to write sensor config file %s",
                              snsr_config_file)
                return False

            sensor_cfg = test_config_pb2.SensorTestConfig()
            sensor_cfg.sensor_binary = self.sensor_binary
            sensor_cfg.config_file = snsr_config_file
            self.template_config.sensor_config.extend([sensor_cfg])

        return True