pyvcloud icon indicating copy to clipboard operation
pyvcloud copied to clipboard

Client constructor should create any missing parent directories specified in *log_file* parameter

Open andrew-ni opened this issue 6 years ago • 0 comments

Currently, Client initialization fails if we provide a filepath that includes directories that don't exist. Client initialization should instead create any missing parents of this path.

Current behavior:

Client(vcd_dict['host'],
       api_version=vcd_dict['api_version'],
       verify_ssl_certs=vcd_dict['verify'],
       log_file='path/to/logs/mylog.log',
       log_requests=True,
       log_headers=True,
       log_bodies=True)

results in FileNotFoundException, because directory 'path' doesn't not exist. We should instead create the parent directories.

How to do so using pathlib (during client log_file initialization):

import pathlib
pathlib.Path(self.log_file).mkdir(parents=True, exist_ok=True)

This is important for CSE development, as we're running into many cases where CSE crashes unless we initialize our loggers (that handle directory creation) before initializing any pyvcloud Client.

@rocknes

andrew-ni avatar Jan 31 '19 21:01 andrew-ni