From 32de39fa4d13098a4326a241c0cd43349134a4a5 Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Tue, 1 Oct 2019 23:41:52 +1300 Subject: [PATCH] Use correct Swift credential for instance backup DevStack is deploying Trove in service tenant model, for swift backed instance backup, the swift container should be transparent to the end users. Story: 2006647 Task: 36883 Change-Id: I5859f4c9911fc2c129c8f23611c6607044fbc145 --- devstack/plugin.sh | 13 ++++- integration/scripts/conf/test_begin.conf | 2 +- trove/common/single_tenant_remote.py | 59 ++++++++-------------- trove/guestagent/guest_log.py | 4 +- trove/tests/api/mgmt/datastore_versions.py | 2 +- 5 files changed, 37 insertions(+), 43 deletions(-) diff --git a/devstack/plugin.sh b/devstack/plugin.sh index e6afa5c257..f5ee71ec1d 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -200,7 +200,7 @@ function configure_trove { cp $TROVE_LOCAL_API_PASTE_INI $TROVE_API_PASTE_INI # (Re)create trove conf files - rm -f $TROVE_CONF + rm -f $TROVE_CONF $TROVE_GUESTAGENT_CONF TROVE_AUTH_ENDPOINT=$KEYSTONE_AUTH_URI/v$IDENTITY_API_VERSION @@ -238,6 +238,7 @@ function configure_trove { iniset $TROVE_CONF DEFAULT remote_nova_client trove.common.single_tenant_remote.nova_client_trove_admin iniset $TROVE_CONF DEFAULT remote_cinder_client trove.common.single_tenant_remote.cinder_client_trove_admin iniset $TROVE_CONF DEFAULT remote_neutron_client trove.common.single_tenant_remote.neutron_client_trove_admin + iniset $TROVE_CONF DEFAULT remote_swift_client trove.common.single_tenant_remote.swift_client_trove_admin iniset $TROVE_CONF DEFAULT default_datastore $TROVE_DATASTORE_TYPE iniset $TROVE_CONF cassandra tcp_ports 7000,7001,7199,9042,9160 @@ -271,6 +272,16 @@ function configure_trove { iniset $TROVE_GUESTAGENT_CONF DEFAULT ignore_users os_admin iniset $TROVE_GUESTAGENT_CONF DEFAULT log_dir /var/log/trove/ iniset $TROVE_GUESTAGENT_CONF DEFAULT log_file trove-guestagent.log + iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_user trove + iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_tenant_name $SERVICE_PROJECT_NAME + iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_pass $SERVICE_PASSWORD + iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_user_domain_name default + iniset $TROVE_GUESTAGENT_CONF DEFAULT nova_proxy_admin_project_domain_name default + iniset $TROVE_GUESTAGENT_CONF DEFAULT os_region_name $REGION_NAME + iniset $TROVE_GUESTAGENT_CONF DEFAULT remote_nova_client trove.common.single_tenant_remote.nova_client_trove_admin + iniset $TROVE_GUESTAGENT_CONF DEFAULT remote_cinder_client trove.common.single_tenant_remote.cinder_client_trove_admin + iniset $TROVE_GUESTAGENT_CONF DEFAULT remote_neutron_client trove.common.single_tenant_remote.neutron_client_trove_admin + iniset $TROVE_GUESTAGENT_CONF DEFAULT remote_swift_client trove.common.single_tenant_remote.swift_client_trove_admin setup_trove_logging $TROVE_GUESTAGENT_CONF # To avoid 'Connection timed out' error of sudo command inside the guest agent diff --git a/integration/scripts/conf/test_begin.conf b/integration/scripts/conf/test_begin.conf index 370eba6068..4d9b92ba73 100644 --- a/integration/scripts/conf/test_begin.conf +++ b/integration/scripts/conf/test_begin.conf @@ -51,7 +51,7 @@ "tenant_id":"%service_tenant_id%", "requirements": { "is_admin":true, - "services": ["trove", "swift"] + "services": ["trove", "swift", "glance"] } }, { "auth_user":"alt_demo", diff --git a/trove/common/single_tenant_remote.py b/trove/common/single_tenant_remote.py index 74dec1bedc..7860b2994c 100644 --- a/trove/common/single_tenant_remote.py +++ b/trove/common/single_tenant_remote.py @@ -13,52 +13,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +from cinderclient.v2 import client as CinderClient +from keystoneauth1 import loading +from keystoneauth1 import session +from neutronclient.v2_0 import client as NeutronClient +from novaclient.client import Client as NovaClient +import swiftclient from trove.common import cfg from trove.common.remote import normalize_url -from keystoneauth1 import loading -from keystoneauth1 import session - -from cinderclient.v2 import client as CinderClient -from neutronclient.v2_0 import client as NeutronClient -from novaclient.client import Client as NovaClient - CONF = cfg.CONF - _SESSION = None -""" -trove.conf -... - -The following should be set in the trove CONF file for this -single_tenant_remote config to work correctly. - -nova_proxy_admin_user = -nova_proxy_admin_pass = -nova_proxy_admin_tenant_name = -nova_proxy_admin_tenant_id = -nova_proxy_admin_user_domain_name = -nova_proxy_admin_project_domain_name = -trove_auth_url = -nova_compute_service_type = -nova_compute_url = -cinder_service_type = -os_region_name = - -remote_nova_client = \ - trove.common.single_tenant_remote.nova_client_trove_admin -remote_cinder_client = \ - trove.common.single_tenant_remote.cinder_client_trove_admin -remote_neutron_client = \ - trove.common.single_tenant_remote.neutron_client_trove_admin -... - -""" - - def get_keystone_session(): global _SESSION @@ -143,3 +111,18 @@ def neutron_client_trove_admin(context, region_name=None): client.management_url = CONF.neutron_url return client + + +def swift_client_trove_admin(context, region_name=None): + ks_session = get_keystone_session() + client = swiftclient.Connection( + session=ks_session, + insecure=CONF.swift_api_insecure, + os_options={ + 'region_name': region_name or CONF.os_region_name, + 'service_type': CONF.swift_service_type, + 'endpoint_type': CONF.swift_endpoint_type + } + ) + + return client diff --git a/trove/guestagent/guest_log.py b/trove/guestagent/guest_log.py index c91db986db..ec84a55498 100644 --- a/trove/guestagent/guest_log.py +++ b/trove/guestagent/guest_log.py @@ -23,7 +23,7 @@ from swiftclient.client import ClientException from trove.common import cfg from trove.common import exception from trove.common.i18n import _ -from trove.common.remote import create_swift_client +from trove.common import remote from trove.common import stream_codecs from trove.common import timeutils from trove.guestagent.common import operating_system @@ -130,7 +130,7 @@ class GuestLog(object): def swift_client(self): if not self._cached_swift_client or ( self._cached_context != self.context): - self._cached_swift_client = create_swift_client(self.context) + self._cached_swift_client = remote.swift_client(self.context) self._cached_context = self.context return self._cached_swift_client diff --git a/trove/tests/api/mgmt/datastore_versions.py b/trove/tests/api/mgmt/datastore_versions.py index 903c4df697..a2112ab136 100644 --- a/trove/tests/api/mgmt/datastore_versions.py +++ b/trove/tests/api/mgmt/datastore_versions.py @@ -45,7 +45,7 @@ class MgmtDataStoreVersion(object): self.images = [] if test_config.glance_client is not None: glance_user = test_config.users.find_user( - Requirements(services=["glance"])) + Requirements(is_admin=True, services=["glance"])) self.glance_client = create_glance_client(glance_user) images = self.glance_client.images.list() for image in images: