Provide option to read SSH credentials from test env

Currently the SSH user and private key is assumed to be taken
from the local account (e.g., /home/ubuntu/.ssh). This change
proposes to add 2 environment variables so that a tox test of
Trove can use an arbitrary SSH user and key file for testing.
Obviously, this assumes that the test setup has already
installed those credentials in the image under test.

Change-Id: Ibc83cb7fcd291a13706550965fe2dd1d5ca3504e
Closes-Bug: 1469775
This commit is contained in:
Peter MacKinnon 2015-06-29 12:22:36 -04:00
parent 1e3e31d30e
commit ae2d9ecf67
2 changed files with 11 additions and 1 deletions

View File

@ -1,5 +1,10 @@
import os
DBAAS_API = "dbaas.api"
PRE_INSTANCES = "dbaas.api.pre_instances"
INSTANCES = "dbaas.api.instances"
POST_INSTANCES = "dbaas.api.post_instances"
SSH_CMD = 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
SSH_CMD = ('ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '
+ ('-o LogLevel=quiet -i '
+ os.environ.get('TROVE_TEST_SSH_KEY_FILE')
if 'TROVE_TEST_SSH_KEY_FILE' in os.environ else ""))

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
from trove import tests
from trove.tests import util
from trove.tests.util.users import Requirements
@ -32,6 +34,9 @@ class ServerSSHConnection(object):
self.dbaas_admin = util.create_dbaas_client(self.user)
self.instance = self.dbaas_admin.management.show(self.instance_id)
self.ip_address = self.instance.ip[0]
TROVE_TEST_SSH_USER = os.environ.get('TROVE_TEST_SSH_USER')
if TROVE_TEST_SSH_USER and '@' not in self.ip_address:
self.ip_address = TROVE_TEST_SSH_USER + '@' + self.ip_address
def execute(self, cmd):
exe_cmd = "%s %s %s" % (tests.SSH_CMD, self.ip_address, cmd)