Add setup code for s3 back Trilio
Add code to prepare trilio applications to use an s3 backend.
This commit is contained in:
@@ -19,12 +19,16 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import boto3
|
||||
|
||||
import zaza.charm_lifecycle.utils as lifecycle_utils
|
||||
import zaza.model as zaza_model
|
||||
import zaza.openstack.utilities.juju as juju_utils
|
||||
import zaza.openstack.utilities.generic as generic_utils
|
||||
import zaza.openstack.utilities.openstack as openstack_utils
|
||||
|
||||
|
||||
def basic_setup():
|
||||
def nfs_setup():
|
||||
"""Run setup for testing Trilio.
|
||||
|
||||
Setup for testing Trilio is currently part of functional
|
||||
@@ -54,6 +58,9 @@ def basic_setup():
|
||||
target_status="active",
|
||||
)
|
||||
|
||||
|
||||
def trust_setup():
|
||||
"""Run setup Trilio trust setup."""
|
||||
logging.info("Executing create-cloud-admin-trust")
|
||||
password = juju_utils.leader_get("keystone", "admin_passwd")
|
||||
|
||||
@@ -66,6 +73,9 @@ def basic_setup():
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def license_setup():
|
||||
"""Run setup Trilio license setup."""
|
||||
logging.info("Executing create-license")
|
||||
test_license = os.environ.get("TEST_TRILIO_LICENSE")
|
||||
if test_license and os.path.exists(test_license):
|
||||
@@ -83,6 +93,75 @@ def basic_setup():
|
||||
logging.error("Unable to find Trilio License file")
|
||||
|
||||
|
||||
def s3_setup():
|
||||
"""Run setup of s3 options for Trilio."""
|
||||
session = openstack_utils.get_overcloud_keystone_session()
|
||||
ks_client = openstack_utils.get_keystone_session_client(
|
||||
session)
|
||||
|
||||
# Get token data so we can glean our user_id and project_id
|
||||
token_data = ks_client.tokens.get_token_data(session.get_token())
|
||||
project_id = token_data['token']['project']['id']
|
||||
user_id = token_data['token']['user']['id']
|
||||
|
||||
# Store URL to service providing S3 compatible API
|
||||
for entry in token_data['token']['catalog']:
|
||||
if entry['type'] == 's3':
|
||||
for endpoint in entry['endpoints']:
|
||||
if endpoint['interface'] == 'public':
|
||||
s3_region = endpoint['region']
|
||||
s3_endpoint = endpoint['url']
|
||||
|
||||
# Create AWS compatible application credentials in Keystone
|
||||
ec2_creds = ks_client.ec2.create(user_id, project_id)
|
||||
cacert = openstack_utils.get_cacert()
|
||||
kwargs = {
|
||||
'region_name': s3_region,
|
||||
'aws_access_key_id': ec2_creds.access,
|
||||
'aws_secret_access_key': ec2_creds.secret,
|
||||
'endpoint_url': s3_endpoint,
|
||||
'verify': cacert,
|
||||
}
|
||||
s3 = boto3.resource('s3', **kwargs)
|
||||
|
||||
# Create bucket
|
||||
bucket_name = 'zaza-trilio'
|
||||
logging.info("Creating bucket: {}".format(bucket_name))
|
||||
bucket = s3.Bucket(bucket_name)
|
||||
bucket.create()
|
||||
|
||||
s3_config = {
|
||||
'tv-s3-secret-key': ec2_creds.secret,
|
||||
'tv-s3-access-key': ec2_creds.access,
|
||||
'tv-s3-region-name': s3_region,
|
||||
'tv-s3-bucket': bucket_name,
|
||||
'tv-s3-endpoint-url': s3_endpoint}
|
||||
for app in ['trilio-wlm', 'trilio-data-mover']:
|
||||
logging.info("Setting s3 config for {}".format(app))
|
||||
zaza_model.set_application_config(app, s3_config)
|
||||
test_config = lifecycle_utils.get_charm_config(fatal=False)
|
||||
states = test_config.get('target_deploy_status', {})
|
||||
states['trilio-wlm'] = {
|
||||
'workload-status': 'blocked',
|
||||
'workload-status-message': 'application not trusted'}
|
||||
zaza_model.wait_for_application_states(
|
||||
states=test_config.get('target_deploy_status', {}),
|
||||
timeout=7200)
|
||||
zaza_model.block_until_all_units_idle()
|
||||
|
||||
|
||||
def basic_setup():
|
||||
"""Run basic setup for Trilio apps."""
|
||||
backup_target_type = zaza_model.get_application_config(
|
||||
'trilio-wlm')['backup-target-type']['value']
|
||||
if backup_target_type == "nfs":
|
||||
nfs_setup()
|
||||
if backup_target_type in ["s3", "experimental-s3"]:
|
||||
s3_setup()
|
||||
trust_setup()
|
||||
license_setup()
|
||||
|
||||
|
||||
def python2_workaround():
|
||||
"""Workaround for Bug #1915914.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user