def body(self): # test create certificate with default set self.cmd( 'batch certificate create --thumbprint {} --certificate-file "{}"'. format(self.cert_thumbprint, self.create_cert_file_path), checks=[ JMESPathCheck('thumbprint', self.cert_thumbprint), JMESPathCheck('thumbprintAlgorithm', 'sha1'), JMESPathCheck('state', 'active') ]) # test create account with default set self.cmd('batch certificate list', checks=[ JMESPathCheck('length(@)', 1), JMESPathCheck('[0].thumbprint', self.cert_thumbprint), ]) self.cmd("batch certificate delete --thumbprint {} --yes".format( self.cert_thumbprint)) self.cmd('batch certificate show --thumbprint {}'.format( self.cert_thumbprint), checks=[ JMESPathCheck('thumbprint', self.cert_thumbprint), JMESPathCheck('thumbprintAlgorithm', 'sha1'), JMESPathCheck('state', 'deleting') ])
def body(self): s = self queue = s.queue rg = s.resource_group _get_connection_string(self) s.cmd('storage queue create -n {} --fail-on-exist --metadata a=b c=d'. format(queue), checks=JMESPathCheck('success', True)) s.cmd('storage queue exists -n {}'.format(queue), checks=JMESPathCheck('exists', True)) res = s.cmd('storage queue list') assert queue in [x['name'] for x in res] s.cmd('storage queue metadata show -n {}'.format(queue), checks=[JMESPathCheck('a', 'b'), JMESPathCheck('c', 'd')]) s.cmd('storage queue metadata update -n {} --metadata e=f g=h'.format( queue)) s.cmd('storage queue metadata show -n {}'.format(queue), checks=[JMESPathCheck('e', 'f'), JMESPathCheck('g', 'h')]) s._queue_acl_scenario(queue) s._storage_message_scenario(queue) # verify delete operation s.cmd('storage queue delete -n {} --fail-not-exist'.format(queue), checks=JMESPathCheck('success', True)) s.cmd('storage queue exists -n {}'.format(queue), checks=JMESPathCheck('exists', False))
def body(self): app_id_uri = 'http://azureclitest-graph' # create app through express option self.cmd('ad sp create-for-rbac -n {}'.format(app_id_uri), checks=[JMESPathCheck('name', app_id_uri)]) # show/list app self.cmd('ad app show --id {}'.format(app_id_uri), checks=[JMESPathCheck('identifierUris[0]', app_id_uri)]) self.cmd('ad app list --identifier-uri {}'.format(app_id_uri), checks=[ JMESPathCheck('[0].identifierUris[0]', app_id_uri), JMESPathCheck('length([*])', 1) ]) # show/list sp self.cmd( 'ad sp show --id {}'.format(app_id_uri), checks=[JMESPathCheck('servicePrincipalNames[0]', app_id_uri)]) self.cmd('ad sp list --spn {}'.format(app_id_uri), checks=[ JMESPathCheck('[0].servicePrincipalNames[0]', app_id_uri), JMESPathCheck('length([*])', 1), ]) self.cmd('ad sp reset-credentials -n {}'.format(app_id_uri), checks=[JMESPathCheck('name', app_id_uri)]) # cleanup self.cmd('ad sp delete --id {}'.format(app_id_uri), None) self.cmd('ad sp list --spn {}'.format(app_id_uri), checks=NoneCheck()) self.cmd('ad app delete --id {}'.format(app_id_uri), None) self.cmd('ad app list --identifier-uri {}'.format(app_id_uri), checks=NoneCheck())
def body(self): plan = 'webapp-linux-plan' webapp = 'webapp-linux1' plan_result = self.cmd( 'appservice plan create -g {} -n {} --sku S1 --is-linux'.format( self.resource_group, plan), checks=[ JMESPathCheck('reserved', True), # this weird field means it is a linux JMESPathCheck('sku.name', 'S1'), ]) self.cmd('appservice web create -g {} -n {} --plan {} -l {}'.format( self.resource_group, webapp, plan_result['id'], self.location), checks=[ JMESPathCheck('name', webapp), ]) self.cmd('appservice web config update -g {} -n {} --startup-file {}'. format(self.resource_group, webapp, 'process.json'), checks=[JMESPathCheck('appCommandLine', 'process.json')]) self.cmd( 'appservice web config container update -g {} -n {} --docker-custom-image-name {} --docker-registry-server-password {} --docker-registry-server-user {} --docker-registry-server-url {}' .format(self.resource_group, webapp, 'foo-image', 'foo-password', 'foo-user', 'foo-url')) result = self.cmd( 'appservice web config container show -g {} -n {} '.format( self.resource_group, webapp)) self.assertEqual( set(x['name'] for x in result), set([ 'DOCKER_REGISTRY_SERVER_URL', 'DOCKER_REGISTRY_SERVER_USERNAME', 'DOCKER_CUSTOM_IMAGE_NAME', 'DOCKER_REGISTRY_SERVER_PASSWORD' ])) sample = next( (x for x in result if x['name'] == 'DOCKER_REGISTRY_SERVER_URL')) self.assertEqual( sample, { 'name': 'DOCKER_REGISTRY_SERVER_URL', 'slotSetting': 'False', 'value': 'foo-url' }) self.cmd('appservice web config container delete -g {} -n {}'.format( self.resource_group, webapp)) result2 = self.cmd( 'appservice web config container show -g {} -n {} '.format( self.resource_group, webapp), checks=NoneCheck()) self.assertEqual(result2, [])
def _queue_acl_scenario(self, queue): s = self s.cmd('storage queue policy list -q {}'.format(queue), checks=NoneCheck()) s.cmd('storage queue policy create -q {} -n test1 --permission raup --start 2016-01-01T00:00Z --expiry 2016-05-01T00:00Z'.format(queue)) acl = sorted(s.cmd('storage queue policy list -q {}'.format(queue)).keys()) assert acl == ['test1'] s.cmd('storage queue policy show -q {} -n test1'.format(queue), checks=[ JMESPathCheck('start', '2016-01-01T00:00:00+00:00'), JMESPathCheck('expiry', '2016-05-01T00:00:00+00:00'), JMESPathCheck('permission', 'rpau') ]) s.cmd('storage queue policy update -q {} -n test1 --permission ra'.format(queue)) s.cmd('storage queue policy show -q {} -n test1'.format(queue), checks=JMESPathCheck('permission', 'ra')) s.cmd('storage queue policy delete -q {} -n test1'.format(queue)) s.cmd('storage queue policy list -q {}'.format(queue), checks=NoneCheck())
def body(self): if self.playback: subscription_id = MOCKED_SUBSCRIPTION_ID else: subscription_id = self.cmd( 'account list --query "[?isDefault].id" -o tsv') role_name = 'cli-test-role' template = { "Name": "Contoso On-call", "Description": "Can monitor compute, network and storage, and restart virtual machines", "Actions": [ "Microsoft.Compute/*/read", "Microsoft.Compute/virtualMachines/start/action", "Microsoft.Compute/virtualMachines/restart/action", "Microsoft.Network/*/read", "Microsoft.Storage/*/read", "Microsoft.Authorization/*/read", "Microsoft.Resources/subscriptions/resourceGroups/read", "Microsoft.Resources/subscriptions/resourceGroups/resources/read", "Microsoft.Insights/alertRules/*", "Microsoft.Support/*" ], "AssignableScopes": ["/subscriptions/{}".format(subscription_id)] } template['Name'] = role_name _, temp_file = tempfile.mkstemp() with open(temp_file, 'w') as f: json.dump(template, f) role = self.cmd( 'role create --role-definition {}'.format( temp_file.replace('\\', '\\\\')), None) self.cmd('role list -n {}'.format(role_name), checks=[JMESPathCheck('[0].properties.roleName', role_name)]) self.cmd('role delete -n {}'.format(role_name), None) self.cmd('role list -n {}'.format(role_name), NoneCheck())
def body(self): plan = 'webapp-git-plan5' webapp = 'web-git-test' #You can create and use any repros with the 3 files under "./sample_web" test_git_repo = 'https://github.com/yugangw-msft/azure-site-test' self.cmd('appservice plan create -g {} -n {} --sku S1'.format( self.resource_group, plan)) self.cmd('appservice web create -g {} -n {} --plan {}'.format( self.resource_group, webapp, plan)) self.cmd( 'appservice web source-control config -g {} -n {} --repo-url {} --branch {}' .format(self.resource_group, webapp, test_git_repo, 'master'), checks=[ JMESPathCheck('repoUrl', test_git_repo), JMESPathCheck('isManualIntegration', False), JMESPathCheck('isMercurial', False), JMESPathCheck('branch', 'master') ]) import time time.sleep( 30 ) # 30 seconds should be enough for the deployment finished(Skipped under playback mode) import requests r = requests.get('http://{}.azurewebsites.net'.format(webapp)) #verify the web page self.assertTrue('Hello world' in str(r.content)) self.cmd('appservice web source-control show -g {} -n {}'.format( self.resource_group, webapp), checks=[ JMESPathCheck('repoUrl', test_git_repo), JMESPathCheck('isManualIntegration', False), JMESPathCheck('isMercurial', False), JMESPathCheck('branch', 'master') ]) self.cmd( 'appservice web source-control config -g {} -n {} --repo-url {} --manual-integration' .format(self.resource_group, webapp, test_git_repo), checks=[JMESPathCheck('isManualIntegration', True)]) self.cmd('appservice web source-control delete -g {} -n {}'.format( self.resource_group, webapp), checks=[JMESPathCheck('repoUrl', None)])
def _table_acl_scenario(self, table): s = self s.cmd('storage table policy list -t {}'.format(table), checks=NoneCheck()) s.cmd('storage table policy create -t {} -n test1 --permission a'.format(table)) s.cmd('storage table policy create -t {} -n test2 --start 2016-01-01T00:00Z'.format(table)) s.cmd('storage table policy create -t {} -n test3 --expiry 2018-01-01T00:00Z'.format(table)) s.cmd('storage table policy create -t {} -n test4 --permission raud --start 2016-01-01T00:00Z --expiry 2016-05-01T00:00Z'.format(table)) acl = sorted(s.cmd('storage table policy list -t {}'.format(table)).keys()) assert acl == ['test1', 'test2', 'test3', 'test4'] s.cmd('storage table policy show -t {} -n test1'.format(table), checks=JMESPathCheck('permission', 'a')) s.cmd('storage table policy show -t {} -n test2'.format(table), checks=JMESPathCheck('start', '2016-01-01T00:00:00+00:00')) s.cmd('storage table policy show -t {} -n test3'.format(table), checks=JMESPathCheck('expiry', '2018-01-01T00:00:00+00:00')) s.cmd('storage table policy show -t {} -n test4'.format(table), checks=[ JMESPathCheck('start', '2016-01-01T00:00:00+00:00'), JMESPathCheck('expiry', '2016-05-01T00:00:00+00:00'), JMESPathCheck('permission', 'raud') ]) s.cmd('storage table policy update -t {} -n test1 --permission au'.format(table)) s.cmd('storage table policy show -t {} -n test1'.format(table), checks=JMESPathCheck('permission', 'au')) s.cmd('storage table policy delete -t {} -n test1'.format(table)) acl = sorted(s.cmd('storage table policy list -t {}'.format(table)).keys()) assert acl == ['test2', 'test3', 'test4']
def body(self): s = self queue = s.queue _get_connection_string(self) s.cmd('storage queue create -n {} --fail-on-exist --metadata a=b c=d'.format(queue), checks=JMESPathCheck('created', True)) s.cmd('storage queue exists -n {}'.format(queue), checks=JMESPathCheck('exists', True)) res = s.cmd('storage queue list') assert queue in [x['name'] for x in res] sas = s.cmd('storage queue generate-sas -n {} --permissions r'.format(queue)) sas_keys = dict(pair.split('=') for pair in sas.split('&')) assert u'sig' in sas_keys s.cmd('storage queue metadata show -n {}'.format(queue), checks=[ JMESPathCheck('a', 'b'), JMESPathCheck('c', 'd') ]) s.cmd('storage queue metadata update -n {} --metadata e=f g=h'.format(queue)) s.cmd('storage queue metadata show -n {}'.format(queue), checks=[ JMESPathCheck('e', 'f'), JMESPathCheck('g', 'h') ]) s._queue_acl_scenario(queue) s._storage_message_scenario(queue) # verify delete operation s.cmd('storage queue delete -n {} --fail-not-exist'.format(queue), checks=JMESPathCheck('deleted', True)) s.cmd('storage queue exists -n {}'.format(queue), checks=JMESPathCheck('exists', False))
def _acl_body(test): service = test.service container_param = test.container_param s = test _get_connection_string(s) s.cmd('storage {} policy list {}'.format(service, container_param), checks=NoneCheck()) s.cmd('storage {} policy create {} -n test1 --permission l'.format(service, container_param)) s.cmd('storage {} policy create {} -n test2 --start 2016-01-01T00:00Z'.format(service, container_param)) s.cmd('storage {} policy create {} -n test3 --expiry 2018-01-01T00:00Z'.format(service, container_param)) s.cmd('storage {} policy create {} -n test4 --permission rwdl --start 2016-01-01T00:00Z --expiry 2016-05-01T00:00Z'.format(service, container_param)) acl = sorted(s.cmd('storage {} policy list {}'.format(service, container_param)).keys()) assert acl == ['test1', 'test2', 'test3', 'test4'] s.cmd('storage {} policy show {} -n test1'.format(service, container_param), checks=JMESPathCheck('permission', 'l')) s.cmd('storage {} policy show {} -n test2'.format(service, container_param), checks=JMESPathCheck('start', '2016-01-01T00:00:00+00:00')) s.cmd('storage {} policy show {} -n test3'.format(service, container_param), checks=JMESPathCheck('expiry', '2018-01-01T00:00:00+00:00')) s.cmd('storage {} policy show {} -n test4'.format(service, container_param), checks=[ JMESPathCheck('start', '2016-01-01T00:00:00+00:00'), JMESPathCheck('expiry', '2016-05-01T00:00:00+00:00'), JMESPathCheck('permission', 'rwdl') ]) s.cmd('storage {} policy update {} -n test1 --permission r'.format(service, container_param)) s.cmd('storage {} policy show {} -n test1'.format(service, container_param), checks=JMESPathCheck('permission', 'r')) s.cmd('storage {} policy delete {} -n test1'.format(service, container_param)) acl = sorted(s.cmd('storage {} policy list {}'.format(service, container_param)).keys()) assert acl == ['test2', 'test3', 'test4']
def body(self): plan = 'webapp-ssl-test-plan' # Cert Generated using # https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-configure-ssl-certificate#bkmk_ssopenssl pfx_file = os.path.join(TEST_DIR, 'server.pfx') cert_password = '******' cert_thumbprint = 'DB2BA6898D0B330A93E7F69FF505C61EF39921B6' plan_result = self.cmd( 'appservice plan create -g {} -n {} --sku B1'.format( self.resource_group, plan)) self.cmd('appservice web create -g {} -n {} --plan {} -l {}'.format( self.resource_group, self.webapp_name, plan_result['id'], self.location)) self.cmd( 'appservice web config ssl upload -g {} -n {} --certificate-file "{}" --certificate-password {}' .format(self.resource_group, self.webapp_name, pfx_file, cert_password), checks=[JMESPathCheck('thumbprint', cert_thumbprint)]) self.cmd( 'appservice web config ssl bind -g {} -n {} --certificate-thumbprint {} --ssl-type {}' .format(self.resource_group, self.webapp_name, cert_thumbprint, 'SNI'), checks=[ JMESPathCheck( "hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].sslState" .format(self.webapp_name), 'SniEnabled'), JMESPathCheck( "hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].thumbprint" .format(self.webapp_name), cert_thumbprint) ]) self.cmd( 'appservice web config ssl unbind -g {} -n {} --certificate-thumbprint {}' .format(self.resource_group, self.webapp_name, cert_thumbprint), checks=[ JMESPathCheck( "hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].sslState" .format(self.webapp_name), 'Disabled'), ]) self.cmd( 'appservice web config ssl delete -g {} --certificate-thumbprint {}' .format(self.resource_group, cert_thumbprint)) self.cmd('appservice web delete -g {} -n {}'.format( self.resource_group, self.webapp_name))
def body(self): s = self table = s.table _get_connection_string(self) s.cmd('storage table create -n {} --fail-on-exist'.format(table), checks=JMESPathCheck('created', True)) s.cmd('storage table exists -n {}'.format(table), checks=JMESPathCheck('exists', True)) res = s.cmd('storage table list') assert table in [x['name'] for x in res] s._table_acl_scenario(table) s._storage_entity_scenario(table) # verify delete operation s.cmd('storage table delete --name {} --fail-not-exist'.format(table), checks=JMESPathCheck('deleted', True)) s.cmd('storage table exists -n {}'.format(table), checks=JMESPathCheck('exists', False))
def body(self): kv = self.keyvault_name # create a secret secret = self.cmd('keyvault secret set --vault-name {} -n secret1 --value ABC123'.format(kv), checks=JMESPathCheck('value', 'ABC123')) first_kid = secret['id'] first_version = first_kid.rsplit('/', 1)[1] # list secrets self.cmd('keyvault secret list --vault-name {}'.format(kv), checks=JMESPathCheck('length(@)', 1)) # create a new secret version secret = self.cmd('keyvault secret set --vault-name {} -n secret1 --value DEF456 --tags test=foo --description "test type"'.format(kv), checks=[ JMESPathCheck('value', 'DEF456'), JMESPathCheck('tags', {'file-encoding': 'utf-8', 'test':'foo'}), JMESPathCheck('contentType', 'test type') ]) second_kid = secret['id'] # list secret versions self.cmd('keyvault secret list-versions --vault-name {} -n secret1'.format(kv), checks=JMESPathCheck('length(@)', 2)) # show secret (latest) self.cmd('keyvault secret show --vault-name {} -n secret1'.format(kv), checks=JMESPathCheck('id', second_kid)) # show secret (specific version) self.cmd('keyvault secret show --vault-name {} -n secret1 -v {}'.format(kv, first_version), checks=JMESPathCheck('id', first_kid)) # set secret attributes self.cmd('keyvault secret set-attributes --vault-name {} -n secret1 --enabled false'.format(kv), checks=[ JMESPathCheck('id', second_kid), JMESPathCheck('attributes.enabled', False) ]) # delete secret self.cmd('keyvault secret delete --vault-name {} -n secret1'.format(kv)) self.cmd('keyvault secret list --vault-name {}'.format(kv), checks=NoneCheck()) self._test_download_secret()
def body(self): self.cmd('appservice plan create -g {} -n {} --sku S1'.format(self.resource_group, self.plan)) self.cmd('appservice web create -g {} -n {} --plan {}'.format(self.resource_group, self.webapp, self.plan)) #You can create and use any repros with the 3 files under "./sample_web" and with a 'staging 'branch slot = 'staging' slot2 = 'dev' test_git_repo = 'https://github.com/yugangw-msft/azure-site-test' self.cmd('appservice web deployment slot create -g {} -n {} --slot {}'.format(self.resource_group, self.webapp, slot), checks=[ JMESPathCheck('name', self.webapp + '/' + slot) ]) self.cmd('appservice web source-control config -g {} -n {} --repo-url {} --branch {} --slot {}'.format(self.resource_group, self.webapp, test_git_repo, slot, slot), checks=[ JMESPathCheck('repoUrl', test_git_repo), JMESPathCheck('branch', slot) ]) self.cmd('appservice web deployment slot create -g {} -n {} --slot {}'.format(self.resource_group, self.webapp, slot2)) import time time.sleep(30) # 30 seconds should be enough for the deployment finished(Skipped under playback mode) import requests r = requests.get('http://{}-{}.azurewebsites.net'.format(self.webapp, slot)) #verify the web page contains content from the staging branch self.assertTrue('Staging' in str(r.content)) self.cmd('appservice web deployment slot swap -g {} -n {} --slot {}'.format(self.resource_group, self.webapp, slot)) time.sleep(30) # 30 seconds should be enough for the slot swap finished(Skipped under playback mode) r = requests.get('http://{}.azurewebsites.net'.format(self.webapp)) #verify the web page contains content from the staging branch self.assertTrue('Staging' in str(r.content)) #verify we can switch with non production slot self.cmd('appservice web deployment slot swap -g {} -n {} --slot {} --target-slot {}'.format(self.resource_group, self.webapp, slot, slot2), checks=NoneCheck()) self.cmd('appservice web deployment slot list -g {} -n {}'.format(self.resource_group, self.webapp), checks=[ JMESPathCheck("length([])", 2), JMESPathCheck('[0].name', self.webapp + '/' + slot), ]) self.cmd('appservice web deployment slot delete -g {} -n {} --slot {}'.format(self.resource_group, self.webapp, slot), checks=NoneCheck())
def body(self): functionapp_name = 'functionappconsumption' location = 'westus' storage = 'functionaconstorage' self.cmd( 'storage account create --name {} -g {} -l {} --sku Standard_LRS'. format(storage, self.resource_group, location)) self.cmd('functionapp create -g {} -n {} -c {} -s {}'.format( self.resource_group, functionapp_name, location, storage), checks=[ JMESPathCheck('state', 'Running'), JMESPathCheck('name', functionapp_name), JMESPathCheck('hostNames[0]', functionapp_name + '.azurewebsites.net') ]) self.cmd('functionapp delete -g {} -n {}'.format( self.resource_group, functionapp_name))
def body(self): appservice_plan = 'cli_res_create_plan' webapp = 'clirescreateweb' self.cmd( 'resource create -g {} -n {} --resource-type Microsoft.web/serverFarms --is-full-object --properties "{{\\"location\\":\\"{}\\",\\"sku\\":{{\\"name\\":\\"B1\\",\\"tier\\":\\"BASIC\\"}}}}"' .format(self.resource_group, appservice_plan, self.location), checks=[JMESPathCheck('name', appservice_plan)]) result = self.cmd( 'resource create -g {} -n {} --resource-type Microsoft.web/sites --properties "{{\\"serverFarmId\\":\\"{}\\"}}"' .format(self.resource_group, webapp, appservice_plan), checks=[JMESPathCheck('name', webapp)]) app_settings_id = result['id'] + '/config/appsettings' self.cmd( 'resource create --id {} --properties "{{\\"key2\\":\\"value12\\"}}"' .format(app_settings_id), checks=[JMESPathCheck('properties.key2', 'value12')])
def body(self): curr_dir = os.path.dirname(os.path.realpath(__file__)) #same copy of the sample template file under current folder, but it is uri based now template_uri = 'https://raw.githubusercontent.com/Azure/azure-cli/master/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/tests/simple_deploy.json' parameters_file = os.path.join(curr_dir, 'simple_deploy_parameters.json').replace('\\', '\\\\') deployment_name = 'simple_deploy' #auto-gen'd by command result = self.cmd('resource group deployment create -g {} --template-uri {} --parameters @{}'.format( self.resource_group, template_uri, parameters_file), checks=[ JMESPathCheck('properties.provisioningState', 'Succeeded'), JMESPathCheck('resourceGroup', self.resource_group), ]) result = self.cmd('resource group deployment show -g {} -n {}'.format(self.resource_group, deployment_name), checks=[ JMESPathCheck('name', deployment_name) ]) self.cmd('resource group deployment delete -g {} -n {}'.format(self.resource_group, deployment_name)) result = self.cmd('resource group deployment list -g {}'.format(self.resource_group)) self.assertFalse(bool(result))
def body(self): s = self rg = self.resource_group s.cmd('resource list') s.cmd('resource list -l centralus', checks=JMESPathCheck( "length([?location == 'centralus']) == length(@)", True)) s.cmd( 'resource list --tag displayName=PublicIPAddress', checks=JMESPathCheck( "length([?type == 'Microsoft.Network/publicIPAddresses']) == length(@)", True)) s.cmd( 'resource list --resource-type Microsoft.Network/networkInterfaces', checks=JMESPathCheck( "length([?type == 'Microsoft.Network/networkInterfaces']) == length(@)", True)) s.cmd('resource list --name {}'.format(self.vnet_name), checks=JMESPathCheck( "length([?name == '{}']) == length(@)".format( self.vnet_name), True)) all_tagged_displayname = s.cmd('resource list --tag displayName') storage_acc_tagged_displayname = \ s.cmd('resource list --tag displayName=StorageAccount') assert len(all_tagged_displayname) > len( storage_acc_tagged_displayname) # check for simple resource with tag s.cmd( 'resource show -n {} -g {} --resource-type Microsoft.Network/virtualNetworks' .format(self.vnet_name, rg), checks=[ JMESPathCheck('name', self.vnet_name), JMESPathCheck('location', 'westus'), JMESPathCheck('resourceGroup', rg), JMESPathCheck('tags', {'cli-test': 'test'}) ]) # clear tag and verify s.cmd( 'resource tag -n {} -g {} --resource-type Microsoft.Network/virtualNetworks --tags' .format(self.vnet_name, rg)) s.cmd( 'resource show -n {} -g {} --resource-type Microsoft.Network/virtualNetworks' .format(self.vnet_name, rg), checks=JMESPathCheck('tags', {}))
def body(self): s = self rg = self.resource_group s.cmd('group create -n {} -l westus'.format(rg), checks=[ JMESPathCheck('name', rg), ]) s.cmd('group exists -n {}'.format(rg), checks=BooleanCheck(True)) s.cmd('group wait --exists -n {}'.format(rg), checks=NoneCheck()) s.cmd('group delete -n {} --no-wait --force'.format(rg), checks=NoneCheck()) s.cmd('group wait --deleted -n {}'.format(rg), checks=NoneCheck()) s.cmd('group exists -n {}'.format(rg), checks=NoneCheck())
def body(self): ssh_pubkey_file = generate_ssh_keys() acs_name = 'kuberacstest' ssh_pubkey_file = ssh_pubkey_file.replace('\\', '\\\\') self.cmd( 'acs create -g {} -n {} --orchestrator-type Kubernetes --service-principal {} --client-secret {} --ssh-key-value {}' .format(self.resource_group, acs_name, self.sp_name, self.sp_secret, ssh_pubkey_file), checks=[ JMESPathCheck('properties.provisioningState', 'Succeeded') ])
def _storage_file_scenario(self, share): source_file = os.path.join(TEST_DIR, 'testfile.rst') dest_file = os.path.join(TEST_DIR, 'download_test.rst') filename = 'testfile.rst' s = self s.cmd('storage file upload --share-name {} --source "{}" -p "{}"'.format(share, source_file, filename)) s.cmd('storage file exists --share-name {} -p "{}"'.format(share, filename), checks=JMESPathCheck('exists', True)) if os.path.isfile(dest_file): os.remove(dest_file) s.cmd('storage file download --share-name {} -p "{}" --dest "{}"'.format(share, filename, dest_file)) if os.path.isfile(dest_file): os.remove(dest_file) else: raise CLIError('\nDownload failed. Test failed!') # test resize command s.cmd('storage file resize --share-name {} -p "{}" --size 1234'.format(share, filename)) s.cmd('storage file show --share-name {} -p "{}"'.format(share, filename), checks=JMESPathCheck('properties.contentLength', 1234)) # test ability to set and reset metadata s.cmd('storage file metadata update --share-name {} -p "{}" --metadata a=b c=d'.format(share, filename)) s.cmd('storage file metadata show --share-name {} -p "{}"'.format(share, filename), checks=[ JMESPathCheck('a', 'b'), JMESPathCheck('c', 'd') ]) s.cmd('storage file metadata update --share-name {} -p "{}"'.format(share, filename)) s.cmd('storage file metadata show --share-name {} -p "{}"'.format(share, filename), checks=NoneCheck()) file_url = 'https://{}.file.core.windows.net/{}/{}'.format(s.account, share, filename) s.cmd('storage file url --share-name {} -p "{}"'.format(share, filename), checks=StringCheck(file_url)) for res in s.cmd('storage file list -s {}'.format(share)): assert filename in res['name'] s.cmd('storage file delete --share-name {} -p "{}"'.format(share, filename)) s.cmd('storage file exists --share-name {} -p "{}"'.format(share, filename), checks=JMESPathCheck('exists', False))
def body(self): s = self src_share = s.src_share src_dir = s.src_dir src_file = s.src_file dst_share = s.dest_share dst_dir = s.dest_dir dst_file = s.dest_file rg = s.resource_group _get_connection_string(self) s.cmd( 'storage share create --name {} --fail-on-exist'.format(src_share)) s.cmd( 'storage share create --name {} --fail-on-exist'.format(dst_share)) s.cmd('storage directory create --share-name {} -n {}'.format( src_share, src_dir)) s.cmd('storage directory create --share-name {} -n {}'.format( dst_share, dst_dir)) s.cmd('storage file upload -p "{}/{}" --share-name {} --source "{}"'. format(src_dir, src_file, src_share, os.path.join(TEST_DIR, 'testfile.rst'))) s.cmd('storage file exists -p "{}/{}" --share-name {}'.format( src_dir, src_file, src_share), checks=JMESPathCheck('exists', True)) # test that a file can be successfully copied to root src_uri = s.cmd('storage file url -p "{}" -s {}'.format( os.path.join(src_dir, src_file), src_share)) copy_status = s.cmd( 'storage file copy start -s {} -p "{}" -u {}'.format( dst_share, dst_file, src_uri)) assert copy_status['status'] == 'success' copy_id = copy_status['id'] s.cmd('storage file show --share-name {} -p "{}"'.format( dst_share, dst_file), checks=[ JMESPathCheck('name', dst_file), JMESPathCheck('properties.copy.id', copy_id), JMESPathCheck('properties.copy.status', 'success') ]) # test that a file can be successfully copied to a directory copy_status = s.cmd( 'storage file copy start -s {} -p "{}/{}" -u {}'.format( dst_share, dst_dir, dst_file, src_uri)) assert copy_status['status'] == 'success' copy_id = copy_status['id'] s.cmd('storage file show --share-name {} -p "{}/{}"'.format( dst_share, dst_dir, dst_file), checks=[ JMESPathCheck('name', dst_file), JMESPathCheck('properties.copy.id', copy_id), JMESPathCheck('properties.copy.status', 'success') ])
def body(self): ssh_pubkey_file = generate_ssh_keys() acs_name = 'acstest123' dns_prefix = 'myacs1234' # create ssh_pubkey_file = ssh_pubkey_file.replace('\\', '\\\\') self.cmd( 'acs create -g {} -n {} --dns-prefix {} --ssh-key-value {}'.format( self.resource_group, acs_name, dns_prefix, ssh_pubkey_file), checks=[ JMESPathCheck( 'properties.outputs.masterFQDN.value', '{}mgmt.{}.cloudapp.azure.com'.format( dns_prefix, self.location)), JMESPathCheck( 'properties.outputs.agentFQDN.value', '{}agents.{}.cloudapp.azure.com'.format( dns_prefix, self.location)) ]) # show self.cmd('acs show -g {} -n {}'.format(self.resource_group, acs_name), checks=[ JMESPathCheck('agentPoolProfiles[0].count', 3), JMESPathCheck('agentPoolProfiles[0].vmSize', 'Standard_D2_v2'), JMESPathCheck('masterProfile.dnsPrefix', dns_prefix + 'mgmt'), JMESPathCheck('orchestratorProfile.orchestratorType', 'DCOS'), JMESPathCheck('name', acs_name), ]) # scale-up self.cmd('acs scale -g {} -n {} --new-agent-count 5'.format( self.resource_group, acs_name), checks=[ JMESPathCheck('agentPoolProfiles[0].count', 5), ]) # show again self.cmd('acs show -g {} -n {}'.format(self.resource_group, acs_name), checks=[ JMESPathCheck('agentPoolProfiles[0].count', 5), ])
def _test_keyvault_certificate_contacts(self): kv = self.keyvault_name self.cmd( 'keyvault certificate contact add --vault-name {} --email [email protected] --name "John Doe" --phone 123-456-7890' .format(kv)) self.cmd( 'keyvault certificate contact add --vault-name {} --email [email protected] ' .format(kv)) self.cmd( 'keyvault certificate contact list --vault-name {}'.format(kv), checks=JMESPathCheck('length(contactList)', 2)) self.cmd( 'keyvault certificate contact delete --vault-name {} --email [email protected]' .format(kv)) self.cmd( 'keyvault certificate contact list --vault-name {}'.format(kv), checks=[ JMESPathCheck('length(contactList)', 1), JMESPathCheck('contactList[0].emailAddress', '*****@*****.**') ])
def body(self): self.cmd( 'provider operation show --namespace microsoft.compute', checks=[ JMESPathCheck( 'id', '/providers/Microsoft.Authorization/providerOperations/Microsoft.Compute' ), JMESPathCheck('type', 'Microsoft.Authorization/providerOperations') ]) self.cmd( 'provider operation show --namespace microsoft.compute --api-version 2015-07-01', checks=[ JMESPathCheck( 'id', '/providers/Microsoft.Authorization/providerOperations/Microsoft.Compute' ), JMESPathCheck('type', 'Microsoft.Authorization/providerOperations') ])
def body(self): subscription_id = self.cmd( 'account list --query "[?isDefault].id" -o tsv') self.cmd('ad sp create-for-rbac -n {} --password verySecret'.format( self.sp_name), checks=[JMESPathCheck('name', self.sp_name)]) self.cmd( 'ad sp create-for-rbac -n {} --scopes /subscriptions/{}/resourceGroups/{}' .format(self.sp_name, subscription_id, self.resource_group), checks=[JMESPathCheck('name', self.sp_name)]) self.cmd('role assignment list --assignee {}'.format(self.sp_name), checks=[JMESPathCheck("length([])", 1)]) self.cmd('role assignment list --assignee {} -g {}'.format( self.sp_name, self.resource_group), checks=[JMESPathCheck("length([])", 1)]) self.cmd('role assignment delete --assignee {} -g {}'.format( self.sp_name, self.resource_group), checks=NoneCheck()) self.cmd('role assignment delete --assignee {}'.format(self.sp_name), checks=NoneCheck()) self.cmd('ad app delete --id {}'.format(self.sp_name))
def body(self): connection_string = self.cmd('storage account show-connection-string -n {} -g {} -otsv'.format( self.account, self.resource_group)) self.cmd('storage cors list --connection-string {}'.format(connection_string), checks=JMESPathCheck('length(@)', 0)) self.cmd('storage cors add --method POST --origins http://example.com --services bfq --max-age 60 --connection-string {}'.format(connection_string)) self.cmd('storage cors list --connection-string {}'.format(connection_string), checks=JMESPathCheck('length(@)', 3)) self.cmd('storage cors clear --services bf --connection-string {}'.format(connection_string)) self.cmd('storage cors list --connection-string {}'.format(connection_string), checks=JMESPathCheck('length(@)', 1)) self.cmd('storage cors clear --services bfq --connection-string {}'.format(connection_string)) self.cmd('storage cors list --connection-string {}'.format(connection_string), checks=JMESPathCheck('length(@)', 0))
def body(self): s = self rg = self.resource_group s.cmd('group create -n {} -l westus --tag a=b c'.format(rg), checks=[ JMESPathCheck('name', rg), JMESPathCheck('tags', { 'a': 'b', 'c': '' }) ]) s.cmd('group exists -n {}'.format(rg), checks=BooleanCheck(True)) s.cmd('group show -n {}'.format(rg), checks=[ JMESPathCheck('name', rg), JMESPathCheck('tags', { 'a': 'b', 'c': '' }) ]) s.cmd('group list --tag a=b', checks=[ JMESPathCheck('[0].name', rg), JMESPathCheck('[0].tags', { 'a': 'b', 'c': '' }) ]) s.cmd('group delete -n {} --yes'.format(rg)) s.cmd('group exists -n {}'.format(rg), checks=NoneCheck())
def body(self): s = self tn = s.tag_name s.cmd('tag list --query "[?tagName == \'{}\']"'.format(tn), checks=NoneCheck()) s.cmd('tag create -n {}'.format(tn), checks=[ JMESPathCheck('tagName', tn), JMESPathCheck('values', []), JMESPathCheck('count.value', '0') ]) s.cmd('tag add-value -n {} --value test'.format(tn)) s.cmd('tag add-value -n {} --value test2'.format(tn)) s.cmd('tag list --query "[?tagName == \'{}\']"'.format(tn), checks=[ JMESPathCheck('[].values[].tagValue', [u'test', u'test2']) ]) s.cmd('tag remove-value -n {} --value test'.format(tn)) s.cmd('tag list --query "[?tagName == \'{}\']"'.format(tn), checks=[JMESPathCheck('[].values[].tagValue', [u'test2'])]) s.cmd('tag remove-value -n {} --value test2'.format(tn)) s.cmd('tag list --query "[?tagName == \'{}\']"'.format(tn), checks=[JMESPathCheck('[].values[].tagValue', [])]) s.cmd('tag delete -n {}'.format(tn)) s.cmd('tag list --query "[?tagName == \'{}\']"'.format(self.tag_name), checks=NoneCheck())
def body(self): s = self share1 = s.share1 share2 = s.share2 _get_connection_string(self) s.cmd('storage share create --name {} --fail-on-exist'.format(share1), checks=JMESPathCheck('created', True)) s.cmd( 'storage share create -n {} --fail-on-exist --metadata foo=bar cat=hat' .format(share2), checks=JMESPathCheck('created', True)) s.cmd('storage share exists -n {}'.format(share1), checks=JMESPathCheck('exists', True)) s.cmd( 'storage share metadata show --name {}'.format(share2), checks=[JMESPathCheck('cat', 'hat'), JMESPathCheck('foo', 'bar')]) res = [x['name'] for x in s.cmd('storage share list')] assert share1 in res assert share2 in res # verify metadata can be set, queried, and cleared s.cmd('storage share metadata update --name {} --metadata a=b c=d'. format(share1)) s.cmd('storage share metadata show -n {}'.format(share1), checks=[JMESPathCheck('a', 'b'), JMESPathCheck('c', 'd')]) s.cmd('storage share metadata update -n {}'.format(share1)) s.cmd('storage share metadata show -n {}'.format(share1), checks=NoneCheck()) s.cmd('storage share update --name {} --quota 3'.format(share1)) s.cmd('storage share show --name {}'.format(share1), checks=JMESPathCheck('properties.quota', 3)) sas = s.cmd( 'storage share generate-sas -n {} --permissions r --expiry 2046-08-23T10:30Z' .format(share1)) sas_keys = dict(pair.split('=') for pair in sas.split('&')) assert u'sig' in sas_keys self._storage_file_scenario(share1) self._storage_directory_scenario(share1) s.cmd('storage share delete -n {}'.format(share1), checks=JMESPathCheck('deleted', True))