datopian / ckan-cloud-operator

CKAN Cloud operator manages, provisions and configures Ckan Cloud instances and related infrastructure.
MIT License
19 stars 14 forks source link

Don't blow up if subprocess has no stderr / stdout #134

Closed shevron closed 3 years ago

shevron commented 4 years ago

I have seen this happen in one of the Gates deployment, I'm not sure why but depending on how the subprocess was run, the exception may have stdout / stderr set to None. In this case we have nothing to log so we should skip it.

NOTE: this is a suggestion, I did not test it and don't know how to test it, it's the first time I'm even looking at CCO code so please forgive me for being lazy about this ;)

I was getting:

Traceback (most recent call last):
  File "/usr/local/bin/ckan-cloud-operator", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/ckan_cloud_operator/providers/ckan/instance/cli.py", line 34, in create
    wait_ready=wait_ready, skip_deployment=skip_deployment, skip_route=skip_route, force=force)
  File "/usr/local/lib/python3.7/site-packages/ckan_cloud_operator/providers/ckan/instance/manager.py", line 70, in create
    dry_run=dry_run)
  File "/usr/local/lib/python3.7/site-packages/ckan_cloud_operator/providers/ckan/instance/manager.py", line 126, in update
    res = create_ckan_admin_user(instance_id, ckan_admin_name, ckan_admin_email, ckan_admin_password)
  File "/usr/local/lib/python3.7/site-packages/ckan_cloud_operator/providers/ckan/instance/manager.py", line 350, in create_ckan_admin_user
    deployment_manager.create_ckan_admin_user(instance_id, instance_type, instance, user)
  File "/usr/local/lib/python3.7/site-packages/ckan_cloud_operator/providers/ckan/deployment/manager.py", line 36, in create_ckan_admin_user
    _get_deployment_provider(instance_type).create_ckan_admin_user(instance_id, instance, user)
  File "/usr/local/lib/python3.7/site-packages/ckan_cloud_operator/providers/ckan/deployment/helm/manager.py", line 238, in create_ckan_admin_user
    shell=True
  File "/usr/local/lib/python3.7/site-packages/ckan_cloud_operator/logs.py", line 93, in subprocess_check_call
    log_subprocess_output(e.stdout, e.stderr)
  File "/usr/local/lib/python3.7/site-packages/ckan_cloud_operator/logs.py", line 66, in log_subprocess_output
    for line in stderr.decode('utf8').split('\n'):
AttributeError: 'NoneType' object has no attribute 'decode'

While we'll investigate the cause of the fact that stderr is None, this PR avoids the follow-up issue of trying to log it.