Support the project argument in GCS
The Google credential object now requires that the project be supplied, so plumb that through in the GCS log upload role. Change-Id: I4519fbcb9ac7b8bbd34ab7f17aada3e50c1aaa4b
This commit is contained in:
parent
573ac0a9be
commit
feaf0f2ad5
@ -22,6 +22,10 @@ __metaclass__ = type
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Utility to upload files to google
|
Utility to upload files to google
|
||||||
|
|
||||||
|
Run this from the CLI from the zuul-jobs/roles directory with:
|
||||||
|
|
||||||
|
python -m upload-logs-base.library.zuul_google_storage_upload
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
@ -190,11 +194,12 @@ class Uploader():
|
|||||||
def run(container, files,
|
def run(container, files,
|
||||||
indexes=True, parent_links=True, topdir_parent_link=False,
|
indexes=True, parent_links=True, topdir_parent_link=False,
|
||||||
partition=False, footer='index_footer.html',
|
partition=False, footer='index_footer.html',
|
||||||
prefix=None, dry_run=False, credentials_file=None):
|
prefix=None, dry_run=False, credentials_file=None,
|
||||||
|
project=None):
|
||||||
|
|
||||||
if credentials_file:
|
if credentials_file:
|
||||||
cred = Credentials(credentials_file)
|
cred = Credentials(credentials_file)
|
||||||
client = storage.Client(credentials=cred)
|
client = storage.Client(credentials=cred, project=project)
|
||||||
else:
|
else:
|
||||||
client = storage.Client()
|
client = storage.Client()
|
||||||
|
|
||||||
@ -242,6 +247,7 @@ def ansible_main():
|
|||||||
footer=dict(type='str'),
|
footer=dict(type='str'),
|
||||||
prefix=dict(type='str'),
|
prefix=dict(type='str'),
|
||||||
credentials_file=dict(type='str'),
|
credentials_file=dict(type='str'),
|
||||||
|
project=dict(type='str'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -253,7 +259,8 @@ def ansible_main():
|
|||||||
partition=p.get('partition'),
|
partition=p.get('partition'),
|
||||||
footer=p.get('footer'),
|
footer=p.get('footer'),
|
||||||
prefix=p.get('prefix'),
|
prefix=p.get('prefix'),
|
||||||
credentials_file=p.get('credentials_file'))
|
credentials_file=p.get('credentials_file'),
|
||||||
|
project=p.get('project'))
|
||||||
module.exit_json(changed=True,
|
module.exit_json(changed=True,
|
||||||
url=url)
|
url=url)
|
||||||
|
|
||||||
@ -285,7 +292,10 @@ def cli_main():
|
|||||||
help='do not attempt to create containers or upload, '
|
help='do not attempt to create containers or upload, '
|
||||||
'useful with --verbose for debugging')
|
'useful with --verbose for debugging')
|
||||||
parser.add_argument('--credentials_file',
|
parser.add_argument('--credentials_file',
|
||||||
help='A file with Google cloud credentials')
|
help='A file with Google Cloud credentials')
|
||||||
|
parser.add_argument('--project',
|
||||||
|
help='Name of the Google Cloud project (required for '
|
||||||
|
'credential file)')
|
||||||
parser.add_argument('container',
|
parser.add_argument('container',
|
||||||
help='Name of the container to use when uploading')
|
help='Name of the container to use when uploading')
|
||||||
parser.add_argument('files', nargs='+',
|
parser.add_argument('files', nargs='+',
|
||||||
@ -310,7 +320,8 @@ def cli_main():
|
|||||||
footer=append_footer,
|
footer=append_footer,
|
||||||
prefix=args.prefix,
|
prefix=args.prefix,
|
||||||
dry_run=args.dry_run,
|
dry_run=args.dry_run,
|
||||||
credentials_file=args.credentials_file)
|
credentials_file=args.credentials_file,
|
||||||
|
project=args.project)
|
||||||
print(url)
|
print(url)
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,3 +59,22 @@ Google Cloud Application Default Credentials.
|
|||||||
|
|
||||||
More details can be found at
|
More details can be found at
|
||||||
:zuul:rolevar:`set-zuul-log-path-fact.zuul_log_path_shard_build`.
|
:zuul:rolevar:`set-zuul-log-path-fact.zuul_log_path_shard_build`.
|
||||||
|
|
||||||
|
.. zuul:rolevar:: zuul_log_credentials_file
|
||||||
|
|
||||||
|
This log upload role normally uses Google Cloud Application Default
|
||||||
|
Credentials, however it can also operate in a mode where it uses a
|
||||||
|
credential file written by gcp-authdaemon:
|
||||||
|
https://opendev.org/zuul/gcp-authdaemon
|
||||||
|
|
||||||
|
To use this mode of operation, supply a path to the credentials
|
||||||
|
file previously written by gcp-authdaemon.
|
||||||
|
|
||||||
|
Also supply :zuul:rolevar:`upload-logs-gcs.zuul_log_project`.
|
||||||
|
|
||||||
|
.. zuul:rolevar:: zuul_log_project
|
||||||
|
|
||||||
|
When using
|
||||||
|
:zuul:rolevar:`upload-logs-gcs.zuul_log_credentials_file`, the name
|
||||||
|
of the Google Cloud project of the log container must also be
|
||||||
|
supplied.
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
prefix: "{{ zuul_log_path }}"
|
prefix: "{{ zuul_log_path }}"
|
||||||
indexes: "{{ zuul_log_create_indexes }}"
|
indexes: "{{ zuul_log_create_indexes }}"
|
||||||
credentials_file: "{{ zuul_log_credentials_file }}"
|
credentials_file: "{{ zuul_log_credentials_file }}"
|
||||||
|
project: "{{ zuul_log_project }}"
|
||||||
files:
|
files:
|
||||||
- "{{ zuul.executor.log_root }}/"
|
- "{{ zuul.executor.log_root }}/"
|
||||||
register: upload_results
|
register: upload_results
|
||||||
|
Loading…
x
Reference in New Issue
Block a user