def write_config(self): server_config_filename = os.path.join( self.config_dir, self.server_config_filename) if os.access(server_config_filename, os.R_OK): yield dict( Message="Server config at %s exists. Remove to regenerate." % ( server_config_filename)) # Load existing server config. server_config_data = open(server_config_filename, "rb").read() config = agent.Configuration.from_primitive( yaml.safe_load(server_config_data), session=self.session) else: # Make a new configuration config = agent.Configuration(session=self.session) self.session.SetParameter("agent_config_obj", config) self._build_config(config) yield dict(Message="Writing server config file %s" % server_config_filename) with open(server_config_filename, "wb") as fd: fd.write(yaml_utils.safe_dump(config.to_primitive())) # The client gets just the client part of the configuration. client_config = agent.Configuration(session=self.session) client_config.client = config.client client_config.ca_certificate = config.ca_certificate client_config_filename = os.path.join( self.config_dir, self.client_config_filename) yield dict( Message="Writing client config file %s" % ( client_config_filename)) with open(client_config_filename, "wb") as fd: fd.write(self.client_config_warning + yaml_utils.safe_dump(client_config.to_primitive())) # Now load the server config file to make sure it is validly written. self.session.SetParameter("agent_configuration", server_config_filename) self._config = self.session.GetParameter( "agent_config_obj", cached=False) if self._config == None: raise RuntimeError("Unable to parse provided configuration.")
def setUp(self): self.session = self.MakeUserSession() self.session.SetParameter("agent_config_obj", agent.Configuration(session=self.session))