зеркало из https://github.com/Azure/Avere.git
Merge pull request #221 from Azure/script_updates
SSH functionality (first step)
This commit is contained in:
Коммит
76706243a7
|
@ -15,6 +15,11 @@ steps:
|
|||
versionSpec: '3.7'
|
||||
architecture: 'x64'
|
||||
|
||||
- script: |
|
||||
ssh-keygen -t rsa -N "" -f id_rsa
|
||||
cat ~/id_rsa.pub
|
||||
displayName: 'Generate SSH keys'
|
||||
|
||||
- script: |
|
||||
python3 --version
|
||||
pip install --upgrade pip setuptools wheel
|
||||
|
|
|
@ -37,6 +37,7 @@ class AvereTemplateDeploy:
|
|||
self.resource_group = self.deploy_params.pop('resourceGroup',
|
||||
resource_group)
|
||||
self.location = self.deploy_params.pop('location', location)
|
||||
self.ssh_pub_key_path = os.path.expanduser('~/.ssh/id_rsa.pub')
|
||||
|
||||
self._debug('> Loading Azure credentials')
|
||||
self.rm_client = ResourceManagementClient(
|
||||
|
@ -59,7 +60,7 @@ class AvereTemplateDeploy:
|
|||
'virtualNetworkSubnetName': gen_id + '-subnet',
|
||||
'avereBackedStorageAccountName': gen_id + 'sa',
|
||||
'controllerName': gen_id + '-con',
|
||||
'controllerAuthenticationType': 'password'
|
||||
'controllerAuthenticationType': 'sshPublicKey'
|
||||
}
|
||||
self._debug('> Generated deploy parameters: \n{}'.format(
|
||||
json.dumps(self.deploy_params, indent=4)))
|
||||
|
@ -77,18 +78,24 @@ class AvereTemplateDeploy:
|
|||
self._debug('> Deleting resource group: ' + self.resource_group)
|
||||
return self.rm_client.resource_groups.delete(self.resource_group)
|
||||
|
||||
def deploy(self):
|
||||
def deploy(self, add_secrets_params=True):
|
||||
"""Deploys the Avere vFXT template."""
|
||||
self._debug('> Deploying template')
|
||||
|
||||
deploy_secrets = {
|
||||
'adminPassword': os.environ['AVERE_ADMIN_PW'],
|
||||
'controllerPassword': os.environ['AVERE_CONTROLLER_PW'],
|
||||
'servicePrincipalAppId': os.environ['AZURE_CLIENT_ID'],
|
||||
'servicePrincipalPassword': os.environ['AZURE_CLIENT_SECRET'],
|
||||
'servicePrincipalTenant': os.environ['AZURE_TENANT_ID']
|
||||
}
|
||||
params = {**deploy_secrets, **self.deploy_params}
|
||||
params = {**self.deploy_params}
|
||||
if add_secrets_params:
|
||||
with open(self.ssh_pub_key_path, 'r') as ssh_pub_key_file:
|
||||
ssh_pub_key = ssh_pub_key_file.read()
|
||||
|
||||
deploy_secrets = {
|
||||
'adminPassword': os.environ['AVERE_ADMIN_PW'],
|
||||
'controllerPassword': os.environ['AVERE_CONTROLLER_PW'],
|
||||
'servicePrincipalAppId': os.environ['AZURE_CLIENT_ID'],
|
||||
'servicePrincipalPassword': os.environ['AZURE_CLIENT_SECRET'],
|
||||
'servicePrincipalTenant': os.environ['AZURE_TENANT_ID'],
|
||||
'controllerSSHKeyData': ssh_pub_key
|
||||
}
|
||||
params = {**deploy_secrets, **params}
|
||||
|
||||
return self.rm_client.deployments.create_or_update(
|
||||
resource_group_name=self.resource_group,
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
azure.mgmt.resource
|
||||
requests
|
||||
pytest
|
||||
pytest-cov
|
||||
pytest-cov
|
||||
paramiko
|
||||
scp
|
|
@ -6,14 +6,28 @@ Driver for testing template-based deployment of the Avere vFXT product.
|
|||
|
||||
from time import time
|
||||
|
||||
import paramiko
|
||||
import pytest
|
||||
from scp import SCPClient
|
||||
|
||||
from avere_template_deploy import AvereTemplateDeploy
|
||||
|
||||
|
||||
# TEST CASES ##################################################################
|
||||
class TestDeployment:
|
||||
def test_deploy_template(self, atd, resource_group):
|
||||
wait_for_op(atd.deploy())
|
||||
op = atd.deploy()
|
||||
try:
|
||||
wait_for_op(op)
|
||||
finally:
|
||||
result = op.result()
|
||||
print('>> operation result: {}'.format(result))
|
||||
if result:
|
||||
print('>> result.properties: {}'.format(result.properties))
|
||||
user, server = result.properties.outputs['ssH_STRING'].split('@')
|
||||
ssh = createSSHClient(server, user)
|
||||
scp = SCPClient(ssh.get_transport())
|
||||
scp.get(r'~/vfxt.log', r'./vfxt.' + atd.resource_group + '.log')
|
||||
|
||||
|
||||
# FIXTURES ####################################################################
|
||||
|
@ -48,6 +62,16 @@ def wait_for_op(op, timeout_sec=60):
|
|||
result = op.result()
|
||||
if result:
|
||||
print('>> operation result: {}'.format(result))
|
||||
print('>> result.properties: {}'.format(result.properties))
|
||||
return result
|
||||
|
||||
|
||||
def createSSHClient(server, user):
|
||||
client = paramiko.SSHClient()
|
||||
client.load_system_host_keys()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
client.connect(server, 22, user)
|
||||
return client
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Загрузка…
Ссылка в новой задаче