Do not capture asyncio.CancelledError
remove unneeded loging. e.g. certificates
Change-Id: Ia4f8c19bf693b689aeaaaeb76b006cd25c7295e1
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
# parent class
Loggable.__init__(self, log=log, log_to_console=True, prefix='\nK8S')
# parent class
Loggable.__init__(self, log=log, log_to_console=True, prefix='\nK8S')
- self.log.info('Initializing generic K8S connector')
+ # self.log.info('Initializing generic K8S connector')
# the database and update callback
self.db = db
self.on_update_db = on_update_db
# the database and update callback
self.db = db
self.on_update_db = on_update_db
- self.log.info('K8S generic connector initialized')
+ # self.log.info('K8S generic connector initialized')
@abc.abstractmethod
async def init_env(
@abc.abstractmethod
async def init_env(
return '', -1
def _check_file_exists(self, filename: str, exception_if_not_exists: bool = False):
return '', -1
def _check_file_exists(self, filename: str, exception_if_not_exists: bool = False):
- self.log.debug('Checking if file {} exists...'.format(filename))
+ # self.log.debug('Checking if file {} exists...'.format(filename))
if os.path.exists(filename):
return True
else:
msg = 'File {} does not exist'.format(filename)
if exception_if_not_exists:
if os.path.exists(filename):
return True
else:
msg = 'File {} does not exist'.format(filename)
if exception_if_not_exists:
if fs is None:
raise N2VCBadArgumentsException('Argument fs is mandatory', ['fs'])
if fs is None:
raise N2VCBadArgumentsException('Argument fs is mandatory', ['fs'])
- self.log.info('url={}, username={}, vca_config={}'.format(url, username, vca_config))
+ self.log.info('url={}, username={}, vca_config={}'.format(
+ url, username, {k: v for k, v in vca_config.items() if k not in ("host", "port", "user", "secret",
+ "public_key", "ca_cert")}))
# store arguments into self
self.db = db
# store arguments into self
self.db = db
self.apt_mirror = None
self.cloud = vca_config.get('cloud')
self.apt_mirror = None
self.cloud = vca_config.get('cloud')
- self.log.debug('Arguments have been checked')
+ # self.log.debug('Arguments have been checked')
# juju data
self.controller = None # it will be filled when connect to juju
# juju data
self.controller = None # it will be filled when connect to juju
total_timeout=total_timeout
)
except Exception as e:
total_timeout=total_timeout
)
except Exception as e:
- self.log.info('Cannot execute action generate-ssh-key: {}\nContinuing...'.format(e))
+ self.log.info('Skipping exception while executing action generate-ssh-key: {}'.format(e))
# execute action: get-ssh-public-key
try:
# execute action: get-ssh-public-key
try:
except Exception as e:
msg = 'Cannot execute action get-ssh-public-key: {}\n'.format(e)
self.log.info(msg)
except Exception as e:
msg = 'Cannot execute action get-ssh-public-key: {}\n'.format(e)
self.log.info(msg)
+ raise N2VCException(msg)
# return public key if exists
return output["pubkey"] if "pubkey" in output else output
# return public key if exists
return output["pubkey"] if "pubkey" in output else output
):
self.log.debug('adding new relation between {} and {}, endpoints: {}, {}'
):
self.log.debug('adding new relation between {} and {}, endpoints: {}, {}'
- .format(ee_id_1, ee_id_2, endpoint_1, endpoint_2))
+ .format(ee_id_1, ee_id_2, endpoint_1, endpoint_2))
# check arguments
if not ee_id_1:
# check arguments
if not ee_id_1:
relation_2=endpoint_2
)
except Exception as e:
relation_2=endpoint_2
)
except Exception as e:
- message = 'Error adding relation between {} and {}'.format(ee_id_1, ee_id_2)
+ message = 'Error adding relation between {} and {}: {}'.format(ee_id_1, ee_id_2, e)
self.log.error(message)
raise N2VCException(message=message)
self.log.error(message)
raise N2VCException(message=message)
update_dict=update_dict,
fail_on_empty=True
)
update_dict=update_dict,
fail_on_empty=True
)
+ except asyncio.CancelledError:
+ raise
except Exception as e:
self.log.error('Error writing ee_id to database: {}'.format(e))
except Exception as e:
self.log.error('Error writing ee_id to database: {}'.format(e))
)
self.log.debug('Result: {}, output: {}'.format(ok, output))
return True
)
self.log.debug('Result: {}, output: {}'.format(ok, output))
return True
+ except asyncio.CancelledError:
+ raise
except Exception as e:
self.log.debug('Error executing verify-ssh-credentials: {}. Retrying...'.format(e))
await asyncio.sleep(retry_timeout)
except Exception as e:
self.log.debug('Error executing verify-ssh-credentials: {}. Retrying...'.format(e))
await asyncio.sleep(retry_timeout)
if total_timeout is None:
total_timeout = 3600
if total_timeout is None:
total_timeout = 3600
+ end = time.time() + total_timeout
model = await self._juju_get_model(model_name=model_name)
model = await self._juju_get_model(model_name=model_name)
for machine_id in machines:
try:
await self._juju_destroy_machine(model_name=model_name, machine_id=machine_id)
for machine_id in machines:
try:
await self._juju_destroy_machine(model_name=model_name, machine_id=machine_id)
+ except asyncio.CancelledError:
+ raise
except Exception as e:
# ignore exceptions destroying machine
pass
except Exception as e:
# ignore exceptions destroying machine
pass
self.log.debug('destroying model {}...'.format(model_name))
await self.controller.destroy_model(uuid)
self.log.debug('destroying model {}...'.format(model_name))
await self.controller.destroy_model(uuid)
- self.log.debug('model destroy requested {}'.format(model_name))
+ # self.log.debug('model destroy requested {}'.format(model_name))
# wait for model is completely destroyed
# wait for model is completely destroyed
- end = time.time() + total_timeout
+ self.log.debug('Waiting for model {} to be destroyed...'.format(model_name))
+ last_exception = ''
- self.log.debug('Waiting for model is destroyed...')
try:
# await self.controller.get_model(uuid)
models = await self.controller.list_models()
if model_name not in models:
self.log.debug('The model {} ({}) was destroyed'.format(model_name, uuid))
return
try:
# await self.controller.get_model(uuid)
models = await self.controller.list_models()
if model_name not in models:
self.log.debug('The model {} ({}) was destroyed'.format(model_name, uuid))
return
+ except asyncio.CancelledError:
+ raise
- pass
- await asyncio.sleep(1.0)
+ last_exception = e
+ await asyncio.sleep(5)
+ raise N2VCException("Timeout waiting for model {} to be destroyed {}".format(model_name, last_exception))
async def _juju_login(self):
"""Connect to juju controller
async def _juju_login(self):
"""Connect to juju controller
try:
self._connecting = True
self.log.info(
try:
self._connecting = True
self.log.info(
- 'connecting to juju controller: {} {}:{} ca_cert: {}'
- .format(self.url, self.username, self.secret, '\n'+self.ca_cert if self.ca_cert else 'None'))
+ 'connecting to juju controller: {} {}:{}{}'
+ .format(self.url, self.username, self.secret[:8] + '...', ' with ca_cert' if self.ca_cert else ''))
# Create controller object
self.controller = Controller(loop=self.loop)
# Create controller object
self.controller = Controller(loop=self.loop)