def create_local_config(args): config = pep3_pb2.Configuration() secrets = pep3_pb2.Secrets() fill_local_config_messages(config, secrets) args.config.write(pb.json_format.MessageToJson(config)) args.secrets.write(pb.json_format.MessageToJson(secrets))
def _get_config_and_secrets(): config = pep3_pb2.Configuration() secrets = pep3_pb2.Secrets() with open("config.json") as f: pb.json_format.Parse(f.read(), config) with open("secrets.json") as f: pb.json_format.Parse(f.read(), secrets) return config, secrets
def setUp(self): config = pep3_pb2.Configuration() secrets = pep3_pb2.Secrets() pep3.fill_local_config_messages(config, secrets) executor_type = concurrent.futures.ThreadPoolExecutor self.g = pep3.RunServers(config, secrets, executor_type=executor_type) self.g.__enter__() self.researcher = self.g.contexts[('researcher', None)] self.collector = self.g.contexts[('collector', None)] self.sf = self.g.contexts[('storage_facility', None)] self.investigator = self.g.contexts[('investigator', None)] self.secrets = secrets self.config = config
def run(self): method_name = f"benchmark_{self.args.name}" if method_name not in dir(self): sys.stderr.write(f"unknown benchmark {self.args.name};\n") options = [ s[10:] for s in dir(self) if s.startswith("benchmark_") ] sys.stderr.write(f"please choose from {options}\n") return if self.args.config==None: assert(self.args.secrets==None) config = pep3_pb2.Configuration() secrets = pep3_pb2.Secrets() pep3.fill_local_config_messages(config, secrets) self.args.config = config self.args.secrets = secrets with contextlib.ExitStack() as exitstack: if self.args.run_servers: g = exitstack.enter_context(pep3.RunServers(self.args.config, self.args.secrets, executor_type=self.args.executor_type)) self.investigator = pep3.PepContext(self.args.config, self.args.secrets, "investigator", None, allow_enrollment=False) self.collector = pep3.PepContext(self.args.config, self.args.secrets, "collector",None, allow_enrollment=False) try: getattr(self, method_name)(self.args.benchmark_args) except grpc.RpcError as err: if err.code()==grpc.StatusCode.UNAVAILABLE \ and not self.args.run_servers: raise Exception("One of the servers is unavailable; \n" "did you forget to use --run-servers?") raise err