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
This commit is contained in:
Lingxian Kong 2019-10-01 23:41:52 +13:00
parent 5bfa414223
commit 32de39fa4d
5 changed files with 37 additions and 43 deletions

View File

@ -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

View File

@ -51,7 +51,7 @@
"tenant_id":"%service_tenant_id%",
"requirements": {
"is_admin":true,
"services": ["trove", "swift"]
"services": ["trove", "swift", "glance"]
}
},
{ "auth_user":"alt_demo",

View File

@ -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

View File

@ -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

View File

@ -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: