Beispiel #1
0
    def body(self):
        import time
        webapp_name = 'webapp-e2e'
        plan = 'webapp-e2e-plan'
        self.cmd('appservice plan create -g {} -n {}'.format(
            self.resource_group, plan))
        time.sleep(60)

        self.cmd('appservice plan list -g {}'.format(self.resource_group),
                 checks=[
                     JMESPathCheck('length(@)', 1),
                     JMESPathCheck('[0].name', plan),
                     JMESPathCheck('[0].sku.tier', 'Basic'),
                     JMESPathCheck('[0].sku.name', 'B1')
                 ])
        self.cmd(
            'appservice plan list',
            checks=[JMESPathCheck("length([?name=='{}'])".format(plan), 1)])
        self.cmd('appservice plan show -g {} -n {}'.format(
            self.resource_group, plan),
                 checks=[JMESPathCheck('name', plan)])
        time.sleep(60)
        # scale up
        self.cmd('appservice plan update -g {} -n {} --sku S1'.format(
            self.resource_group, plan),
                 checks=[
                     JMESPathCheck('name', plan),
                     JMESPathCheck('sku.tier', 'Standard'),
                     JMESPathCheck('sku.name', 'S1')
                 ])
        self.cmd('webapp create -g {} -n {} --plan {}'.format(
            self.resource_group, webapp_name, plan),
                 checks=[
                     JMESPathCheck('state', 'Running'),
                     JMESPathCheck('name', webapp_name),
                     JMESPathCheck('hostNames[0]',
                                   webapp_name + '.azurewebsites.net')
                 ])
        self.cmd('webapp list -g {}'.format(self.resource_group),
                 checks=[
                     JMESPathCheck('length(@)', 1),
                     JMESPathCheck('[0].name', webapp_name),
                     JMESPathCheck('[0].hostNames[0]',
                                   webapp_name + '.azurewebsites.net')
                 ])
        self.cmd('webapp show -g {} -n {}'.format(self.resource_group,
                                                  webapp_name),
                 checks=[
                     JMESPathCheck('name', webapp_name),
                     JMESPathCheck('hostNames[0]',
                                   webapp_name + '.azurewebsites.net')
                 ])
        result = self.cmd(
            'webapp deployment source config-local-git -g {} -n {}'.format(
                self.resource_group, webapp_name))
        self.assertTrue(result['url'].endswith(webapp_name + '.git'))
        self.cmd(
            'webapp deployment source show -g {} -n {}'.format(
                self.resource_group, webapp_name),
            checks=[
                JMESPathCheck(
                    'repoUrl',
                    'https://{}.scm.azurewebsites.net'.format(webapp_name))
            ])
        # turn on diagnostics
        test_cmd = (
            'webapp log config -g {} -n {} --level verbose'.format(
                self.resource_group, webapp_name) + ' '
            '--application-logging true --detailed-error-messages true --failed-request-tracing true --web-server-logging filesystem'
        )
        self.cmd(test_cmd)
        self.cmd(
            'webapp config show -g {} -n {}'.format(self.resource_group,
                                                    webapp_name),
            checks=[
                JMESPathCheck('detailedErrorLoggingEnabled', True),
                JMESPathCheck('httpLoggingEnabled', True),
                JMESPathCheck('scmType', 'LocalGit'),
                JMESPathCheck('requestTracingEnabled', True)
                # TODO: contact webapp team for where to retrieve 'level'
            ])
        # show publish profile info
        result = self.cmd(
            'webapp deployment list-publishing-profiles -g {} -n {}'.format(
                self.resource_group, webapp_name))
        self.assertTrue(result[1]['publishUrl'].startswith('ftp://'))
        self.cmd('webapp stop -g {} -n {}'.format(self.resource_group,
                                                  webapp_name))
        self.cmd('webapp show -g {} -n {}'.format(self.resource_group,
                                                  webapp_name),
                 checks=[
                     JMESPathCheck('state', 'Stopped'),
                     JMESPathCheck('name', webapp_name)
                 ])
        self.cmd('webapp start -g {} -n {}'.format(self.resource_group,
                                                   webapp_name))
        self.cmd('webapp show -g {} -n {}'.format(self.resource_group,
                                                  webapp_name),
                 checks=[
                     JMESPathCheck('state', 'Running'),
                     JMESPathCheck('name', webapp_name)
                 ])
        self.cmd('webapp delete -g {} -n {}'.format(self.resource_group,
                                                    webapp_name))
        # test empty service plan should be automatically deleted.
        self.cmd('appservice plan list -g {}'.format(self.resource_group),
                 checks=[JMESPathCheck('length(@)', 0)])
Beispiel #2
0
    def body(self):
        s = self
        rg = self.resource_group
        vnet_count = s.cmd(
            "resource list --query \"length([?name=='{}'])\"".format(
                self.vnet_name)) or 0
        self.cmd(
            'network vnet create -g {} -n {} --subnet-name {} --tags cli-test=test'
            .format(self.resource_group, self.vnet_name, self.subnet_name))
        vnet_count += 1

        s.cmd('resource list',
              checks=JMESPathCheck(
                  "length([?name=='{}'])".format(self.vnet_name), vnet_count))
        s.cmd('resource list -l centralus',
              checks=JMESPathCheck(
                  "length([?location == 'centralus']) == length(@)", True))
        s.cmd(
            'resource list --resource-type Microsoft.Network/virtualNetworks',
            checks=JMESPathCheck(
                "length([?name=='{}'])".format(self.vnet_name), vnet_count))
        s.cmd('resource list --name {}'.format(self.vnet_name),
              checks=JMESPathCheck(
                  "length([?name=='{}'])".format(self.vnet_name), vnet_count))
        s.cmd('resource list --tag cli-test',
              checks=JMESPathCheck(
                  "length([?name=='{}'])".format(self.vnet_name), vnet_count))
        s.cmd('resource list --tag cli-test=test',
              checks=JMESPathCheck(
                  "length([?name=='{}'])".format(self.vnet_name), vnet_count))

        # 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'})
            ])
        # check for child resource
        s.cmd(
            'resource show -n {} -g {} --namespace Microsoft.Network --parent virtualNetworks/{}'
            ' --resource-type subnets'.format(self.subnet_name,
                                              self.resource_group,
                                              self.vnet_name),
            checks=[
                JMESPathCheck('name', self.subnet_name),
                JMESPathCheck('resourceGroup', rg),
            ])

        # 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', {}))
Beispiel #3
0
 def body(self):
     # site config testing
     # verify the baseline
     result = self.cmd('webapp config show -g {} -n {}'.format(
         self.resource_group, self.webapp_name),
                       checks=[
                           JMESPathCheck('alwaysOn', False),
                           JMESPathCheck('autoHealEnabled', False),
                           JMESPathCheck('phpVersion', '5.6'),
                           JMESPathCheck('netFrameworkVersion', 'v4.0'),
                           JMESPathCheck('pythonVersion', ''),
                           JMESPathCheck('use32BitWorkerProcess', True),
                           JMESPathCheck('webSocketsEnabled', False)
                       ])
     # update and verify
     checks = [
         JMESPathCheck('alwaysOn', True),
         JMESPathCheck('autoHealEnabled', True),
         JMESPathCheck('phpVersion', '7.0'),
         JMESPathCheck('netFrameworkVersion', 'v3.0'),
         JMESPathCheck('pythonVersion', '3.4'),
         JMESPathCheck('use32BitWorkerProcess', False),
         JMESPathCheck('webSocketsEnabled', True)
     ]
     self.cmd(
         'webapp config set -g {} -n {} --always-on true --auto-heal-enabled true --php-version 7.0 --net-framework-version v3.5 --python-version 3.4 --use-32bit-worker-process=false --web-sockets-enabled=true'
         .format(self.resource_group, self.webapp_name),
         checks=checks)
     self.cmd('webapp config show -g {} -n {}'.format(
         self.resource_group, self.webapp_name),
              checks=checks)
     # site appsettings testing
     # update
     self.cmd(
         'webapp config appsettings set -g {} -n {} --settings s1=foo s2=bar s3=bar2'
         .format(self.resource_group, self.webapp_name),
         checks=[
             JMESPathCheck('s1', 'foo'),
             JMESPathCheck('s2', 'bar'),
             JMESPathCheck('s3', 'bar2')
         ])
     # show
     result = self.cmd('webapp config appsettings list -g {} -n {}'.format(
         self.resource_group, self.webapp_name))
     s2 = next((x for x in result if x['name'] == 's2'))
     self.assertEqual(s2['name'], 's2')
     self.assertEqual(s2['slotSetting'], False)
     self.assertEqual(s2['value'], 'bar')
     self.assertEqual(
         set([x['name'] for x in result]),
         set(['s1', 's2', 's3', 'WEBSITE_NODE_DEFAULT_VERSION']))
     # delete
     self.cmd(
         'webapp config appsettings delete -g {} -n {} --setting-names s1 s2'
         .format(self.resource_group, self.webapp_name))
     result = self.cmd('webapp config appsettings list -g {} -n {}'.format(
         self.resource_group, self.webapp_name))
     self.assertEqual(set([x['name'] for x in result]),
                      set(['s3', 'WEBSITE_NODE_DEFAULT_VERSION']))
     # hostnames
     self.cmd('webapp config hostname list -g {} --webapp-name {}'.format(
         self.resource_group, self.webapp_name),
              checks=[
                  JMESPathCheck('length(@)', 1),
                  JMESPathCheck(
                      '[0].name',
                      '{0}.azurewebsites.net'.format(self.webapp_name))
              ])
     # site connection string tests
     self.cmd(
         'webapp config connection-string set -t mysql -g {} -n {} --settings c1="conn1" c2=conn2 --slot-settings c3=conn3'
         .format(self.resource_group, self.webapp_name))
     result = self.cmd(
         'webapp config connection-string list -g {} -n {}'.format(
             self.resource_group, self.webapp_name),
         checks=[
             JMESPathCheck('length([])', 3),
             JMESPathCheck("[?name=='c1']|[0].slotSetting", False),
             JMESPathCheck("[?name=='c1']|[0].value.type", 'MySql'),
             JMESPathCheck("[?name=='c1']|[0].value.value", 'conn1'),
             JMESPathCheck("[?name=='c2']|[0].slotSetting", False),
             JMESPathCheck("[?name=='c3']|[0].slotSetting", True),
         ])
     self.cmd(
         'webapp config connection-string delete -g {} -n {} --setting-names c1 c3'
         .format(self.resource_group, self.webapp_name))
     result = self.cmd(
         'webapp config connection-string list -g {} -n {}'.format(
             self.resource_group, self.webapp_name),
         checks=[
             JMESPathCheck('length([])', 1),
             JMESPathCheck('[0].slotSetting', False),
             JMESPathCheck('[0].name', 'c2')
         ])
     # see deployment user
     result = self.cmd('webapp deployment user show')
     self.assertTrue(
         result['type'])  # just make sure the command does return something
    def body(self):
        rg = self.resource_group
        adls1 = self.adls_names[0]
        adls2 = self.adls_names[1]
        adla = self.adla_name
        loc = self.location

        # compute policy variables
        user_policy_name = 'pycliuserpolicy'
        user_object_id = '8ce05900-7a9e-4895-b3f0-0fbcee507803'
        group_policy_name = 'pycligrouppolicy'
        group_object_id = '0583cfd7-60f5-43f0-9597-68b85591fc69'

        result = self.cmd('storage account keys list -g {} -n {}'.format(
            self.resource_group, self.wasb_name))
        wasb_key = result[0]['value']
        # test create keyvault with default access policy set
        self.cmd(
            'dla account create -g {} -n {} -l {} --default-data-lake-store {}'
            .format(rg, adla, loc, adls1),
            checks=[
                JMESPathCheck('name', adla),
                JMESPathCheck('location', loc),
                JMESPathCheck('resourceGroup', rg),
                JMESPathCheck('defaultDataLakeStoreAccount', adls1),
                JMESPathCheck('type(dataLakeStoreAccounts)', 'array'),
                JMESPathCheck('length(dataLakeStoreAccounts)', 1),
                JMESPathCheck('maxDegreeOfParallelism', 30),
                JMESPathCheck('maxJobCount', 3),
                JMESPathCheck('queryStoreRetention', 30),
            ])
        self.cmd('dla account show -n {} -g {}'.format(adla, rg),
                 checks=[
                     JMESPathCheck('name', adla),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('defaultDataLakeStoreAccount', adls1),
                     JMESPathCheck('type(dataLakeStoreAccounts)', 'array'),
                     JMESPathCheck('length(dataLakeStoreAccounts)', 1),
                     JMESPathCheck('maxDegreeOfParallelism', 30),
                     JMESPathCheck('maxJobCount', 3),
                     JMESPathCheck('queryStoreRetention', 30),
                 ])
        self.cmd('dla account list -g {}'.format(rg),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                     JMESPathCheck('[0].name', adla),
                     JMESPathCheck('[0].location', loc),
                     JMESPathCheck('[0].resourceGroup', rg),
                 ])
        result = self.cmd('dla account list')
        assert isinstance(result, list)
        assert len(result) >= 1

        # test update acct
        self.cmd(
            'dla account update -g {} -n {} --firewall-state Enabled --max-degree-of-parallelism 15 --max-job-count 2 --query-store-retention 15 --allow-azure-ips Enabled'
            .format(rg, adla))
        self.cmd(
            'dla account show -n {} -g {}'.format(adla, rg),
            checks=[
                JMESPathCheck('name', adla),
                JMESPathCheck('location', loc),
                JMESPathCheck('resourceGroup', rg),
                JMESPathCheck('defaultDataLakeStoreAccount', adls1),
                JMESPathCheck('type(dataLakeStoreAccounts)', 'array'),
                JMESPathCheck('length(dataLakeStoreAccounts)', 1),
                JMESPathCheck('maxDegreeOfParallelism', 15),
                JMESPathCheck('maxJobCount', 2),
                JMESPathCheck('queryStoreRetention', 15)
                # TODO: add validation for firewall rules once they are
                # live in production.
            ])

        # test adls acct add get, delete
        self.cmd(
            'dla account data-lake-store add -g {} -n {} --data-lake-store-account-name {}'
            .format(rg, adla, adls2))
        self.cmd(
            'dla account data-lake-store show -g {} -n {} --data-lake-store-account-name {}'
            .format(rg, adla, adls2),
            checks=[JMESPathCheck('name', adls2)])
        self.cmd('dla account data-lake-store list -g {} -n {}'.format(
            rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 2),
                 ])
        self.cmd(
            'dla account data-lake-store delete -g {} -n {} --data-lake-store-account-name {}'
            .format(rg, adla, adls2))
        self.cmd('dla account data-lake-store list -g {} -n {}'.format(
            rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])
        # test wasb add, get delete
        self.cmd(
            'dla account blob-storage add -g {} -n {} --storage-account-name {} --access-key {}'
            .format(rg, adla, self.wasb_name, wasb_key))
        self.cmd(
            'dla account blob-storage show -g {} -n {} --storage-account-name {}'
            .format(rg, adla, self.wasb_name),
            checks=[JMESPathCheck('name', self.wasb_name)])
        self.cmd('dla account blob-storage list -g {} -n {}'.format(rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])
        self.cmd(
            'dla account blob-storage delete -g {} -n {} --storage-account-name {}'
            .format(rg, adla, self.wasb_name))
        self.cmd('dla account blob-storage list -g {} -n {}'.format(rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 0),
                 ])

        # test compute policy
        # assert that it throws if I don't specify either of the policy types
        with self.assertRaises(CLIError):
            self.cmd(
                'dla account compute-policy create -g {} -n {} --compute-policy-name {} --object-id {} --object-type User'
                .format(rg, adla, user_policy_name, user_object_id))

        self.cmd(
            'dla account compute-policy create -g {} -n {} --compute-policy-name {} --object-id {} --object-type User --max-dop-per-job 2'
            .format(rg, adla, user_policy_name, user_object_id),
            checks=[
                JMESPathCheck('name', user_policy_name),
                JMESPathCheck('objectId', user_object_id),
                JMESPathCheck('objectType', 'User'),
                JMESPathCheck('maxDegreeOfParallelismPerJob', 2),
            ])

        # get the policy
        self.cmd(
            'dla account compute-policy show -g {} -n {} --compute-policy-name {}'
            .format(rg, adla, user_policy_name),
            checks=[
                JMESPathCheck('name', user_policy_name),
                JMESPathCheck('objectId', user_object_id),
                JMESPathCheck('objectType', 'User'),
                JMESPathCheck('maxDegreeOfParallelismPerJob', 2),
                JMESPathCheck('minPriorityPerJob', None),
            ])

        # add the group policy
        self.cmd(
            'dla account compute-policy create -g {} -n {} --compute-policy-name {} --object-id {} --object-type Group --max-dop-per-job 2'
            .format(rg, adla, group_policy_name, group_object_id),
            checks=[
                JMESPathCheck('name', group_policy_name),
                JMESPathCheck('objectId', group_object_id),
                JMESPathCheck('objectType', 'Group'),
                JMESPathCheck('maxDegreeOfParallelismPerJob', 2),
            ])

        # update the user policy
        self.cmd(
            'dla account compute-policy update -g {} -n {} --compute-policy-name {} --min-priority-per-job 2'
            .format(rg, adla, user_policy_name),
            checks=[
                JMESPathCheck('name', user_policy_name),
                JMESPathCheck('objectId', user_object_id),
                JMESPathCheck('objectType', 'User'),
                JMESPathCheck('maxDegreeOfParallelismPerJob', 2),
                JMESPathCheck('minPriorityPerJob', 2),
            ])

        # list the policies
        self.cmd('dla account compute-policy list -g {} -n {}'.format(
            rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 2),
                 ])

        # delete the user policy
        self.cmd(
            'dla account compute-policy delete -g {} -n {} --compute-policy-name {}'
            .format(rg, adla, user_policy_name))

        # list again and verify there is one less policy
        self.cmd('dla account compute-policy list -g {} -n {}'.format(
            rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])

        # test account deletion
        self.cmd('dla account delete -g {} -n {}'.format(rg, adla))
        self.cmd('dla account list -g {}'.format(rg),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 0),
                 ])
Beispiel #5
0
    def body(self):
        rg = self.resource_group
        linux_vm_name = 'ubuntuvm5367'
        linux_image = 'Ubuntu\ Server\ 16.04\ LTS'
        windows_vm_name = 'winvm5367'
        windows_image = 'Windows\ Server\ 2008\ R2\ SP1'
        image_type = 'gallery'
        size = 'Standard_DS1_v2'
        password = '******'

        self.cmd('group deployment create -g {} --template-file {}'
                 .format(rg, TEMPLATE),
                 checks=[JMESPathCheck('properties.provisioningState', 'Succeeded')])

        # Create claimable linux vm in the lab
        self.cmd('lab vm create -g {} --lab-name {} --name {} '
                 '--image {} --image-type {} --size {} --admin-password {} --allow-claim'
                 .format(rg, LAB_NAME, linux_vm_name, linux_image, image_type, size, password),
                 checks=[NoneCheck()])

        self.cmd('lab vm show -g {} --lab-name {} --name {}'
                 .format(rg, LAB_NAME, linux_vm_name),
                 checks=[
                     JMESPathCheck('name', linux_vm_name),
                     JMESPathCheck('provisioningState', 'Succeeded'),
                     JMESPathCheck('osType', 'Linux'),
                     JMESPathCheck('virtualMachineCreationSource', 'FromGalleryImage'),
                     JMESPathCheck('size', size),
                     JMESPathCheck('disallowPublicIpAddress', True),
                     JMESPathCheck('artifactDeploymentStatus.totalArtifacts', 0),
                     JMESPathCheck('galleryImageReference.publisher', 'Canonical')
                 ])

        # Create windows vm in the lab
        self.cmd('lab vm create -g {} --lab-name {} --name {} '
                 '--image {} --image-type {} --size {} --admin-password {} --allow-claim'
                 .format(rg, LAB_NAME, windows_vm_name, windows_image, image_type, size, password),
                 checks=[NoneCheck()])

        self.cmd('lab vm show -g {} --lab-name {} --name {} '
                 .format(rg, LAB_NAME, windows_vm_name),
                 checks=[
                     JMESPathCheck('name', windows_vm_name),
                     JMESPathCheck('provisioningState', 'Succeeded'),
                     JMESPathCheck('osType', 'Windows'),
                     JMESPathCheck('virtualMachineCreationSource', 'FromGalleryImage'),
                     JMESPathCheck('size', size),
                     JMESPathCheck('disallowPublicIpAddress', True),
                     JMESPathCheck('artifactDeploymentStatus.totalArtifacts', 0),
                     JMESPathCheck('galleryImageReference.publisher', 'MicrosoftWindowsServer')
                 ])

        # List claimable vms
        self.cmd('lab vm list -g {} --lab-name {} --claimable'
                 .format(rg, LAB_NAME), checks=[JMESPathCheck('length(@)', 2)])

        # claim a specific vm
        self.cmd('lab vm claim -g {} --lab-name {} --name {}'
                 .format(rg, LAB_NAME, linux_vm_name), checks=[NoneCheck()])

        # List my vms - we have already claimed one VM
        self.cmd('lab vm list -g {} --lab-name {}'
                 .format(rg, LAB_NAME), checks=[JMESPathCheck('length(@)', 1)])

        # claim any vm
        self.cmd('lab vm claim -g {} --lab-name {}'.format(rg, LAB_NAME), checks=[NoneCheck()])

        # List my vms - we have claimed both VMs
        self.cmd('lab vm list -g {} --lab-name {}'
                 .format(rg, LAB_NAME), checks=[JMESPathCheck('length(@)', 2)])

        # Delete all the vms
        self.cmd('lab vm delete -g {} --lab-name {} --name {}'
                 .format(rg, LAB_NAME, linux_vm_name), checks=[NoneCheck()])
        self.cmd('lab vm delete -g {} --lab-name {} --name {}'
                 .format(rg, LAB_NAME, windows_vm_name), checks=[NoneCheck()])

        # Delete the lab
        self.cmd('lab delete -g {} --name {}'.format(rg, LAB_NAME), checks=[NoneCheck()])
Beispiel #6
0
    def body(self):
        sas_url = 'https://azureclistore.blob.core.windows.net/sitebackups?sv=2015-04-05&sr=c&sig=%2FjH1lEtbm3uFqtMI%2BfFYwgrntOs1qhGnpGv9uRibJ7A%3D&se=2017-02-14T04%3A53%3A28Z&sp=rwdl'
        frequency = '1d'
        db_conn_str = 'Server=tcp:cli-backup.database.windows.net,1433;Initial Catalog=cli-db;Persist Security Info=False;User ID=cliuser;Password=cli!password1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;'
        retention_period = 5

        # set without databases
        self.cmd(
            'webapp config backup update -g {} --webapp-name {} --frequency {} --container-url {}  --retain-one true --retention {}'
            .format(self.resource_group, self.webapp_name, frequency, sas_url,
                    retention_period),
            checks=NoneCheck())

        checks = [
            JMESPathCheck('backupSchedule.frequencyInterval', 1),
            JMESPathCheck('backupSchedule.frequencyUnit', 'Day'),
            JMESPathCheck('backupSchedule.keepAtLeastOneBackup', True),
            JMESPathCheck('backupSchedule.retentionPeriodInDays',
                          retention_period)
        ]
        self.cmd('webapp config backup show -g {} --webapp-name {}'.format(
            self.resource_group, self.webapp_name),
                 checks=checks)

        # update with databases
        database_name = 'cli-db'
        database_type = 'SqlAzure'
        self.cmd(
            'webapp config backup update -g {} --webapp-name {} --db-connection-string "{}" --db-name {} --db-type {} --retain-one true'
            .format(self.resource_group, self.webapp_name, db_conn_str,
                    database_name, database_type),
            checks=NoneCheck())

        checks = [
            JMESPathCheck('backupSchedule.frequencyInterval', 1),
            JMESPathCheck('backupSchedule.frequencyUnit', 'Day'),
            JMESPathCheck('backupSchedule.keepAtLeastOneBackup', True),
            JMESPathCheck('backupSchedule.retentionPeriodInDays',
                          retention_period),
            JMESPathCheck('databases[0].connectionString', db_conn_str),
            JMESPathCheck('databases[0].databaseType', database_type),
            JMESPathCheck('databases[0].name', database_name)
        ]
        self.cmd('webapp config backup show -g {} --webapp-name {}'.format(
            self.resource_group, self.webapp_name),
                 checks=checks)

        # update frequency and retention only
        frequency = '18h'
        retention_period = 7
        self.cmd(
            'webapp config backup update -g {} --webapp-name {} --frequency {} --retain-one false --retention {}'
            .format(self.resource_group, self.webapp_name, frequency,
                    retention_period),
            checks=NoneCheck())

        checks = [
            JMESPathCheck('backupSchedule.frequencyInterval', 18),
            JMESPathCheck('backupSchedule.frequencyUnit', 'Hour'),
            JMESPathCheck('backupSchedule.keepAtLeastOneBackup', False),
            JMESPathCheck('backupSchedule.retentionPeriodInDays',
                          retention_period),
            JMESPathCheck('databases[0].connectionString', db_conn_str),
            JMESPathCheck('databases[0].databaseType', database_type),
            JMESPathCheck('databases[0].name', database_name)
        ]
        self.cmd('webapp config backup show -g {} --webapp-name {}'.format(
            self.resource_group, self.webapp_name),
                 checks=checks)
    def body(self):
        adla = self.adla_name
        # get all the catalog items
        # list all DBs
        self.cmd(
            'dla catalog database list -n {}'.format(adla),
            checks=[
                JMESPathCheck('type(@)', 'array'),
                JMESPathCheck('length(@)',
                              2),  # because there is always the master DB
            ])
        # get a specific DB
        self.cmd('dla catalog database show -n {} --database-name {}'.format(
            adla, self.db_name),
                 checks=[
                     JMESPathCheck('name', self.db_name),
                 ])
        # list all schemas
        self.cmd('dla catalog schema list -n {} --database-name {}'.format(
            adla, self.db_name),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                 ])
        # get a specific schema
        self.cmd(
            'dla catalog schema show -n {} --database-name {} --schema-name dbo'
            .format(adla, self.db_name),
            checks=[
                JMESPathCheck('name', 'dbo'),
                JMESPathCheck('databaseName', self.db_name),
            ])
        # list all tables
        self.cmd(
            'dla catalog table list -n {} --database-name {} --schema-name dbo'
            .format(adla, self.db_name),
            checks=[
                JMESPathCheck('type(@)', 'array'),
                JMESPathCheck('length(@)', 1),
            ])
        # list all tables without specifying schema
        self.cmd('dla catalog table list -n {} --database-name {}'.format(
            adla, self.db_name),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])
        # get a specific table
        self.cmd(
            'dla catalog table show -n {} --database-name {} --schema-name dbo --table-name {}'
            .format(adla, self.db_name, self.table_name),
            checks=[
                JMESPathCheck('name', self.table_name),
                JMESPathCheck('databaseName', self.db_name),
                JMESPathCheck('schemaName', 'dbo'),
            ])
        # list all views
        self.cmd(
            'dla catalog view list -n {} --database-name {} --schema-name dbo'.
            format(adla, self.db_name),
            checks=[
                JMESPathCheck('type(@)', 'array'),
                JMESPathCheck('length(@)', 1),
            ])
        # list all views without specifying schema
        self.cmd('dla catalog view list -n {} --database-name {}'.format(
            adla, self.db_name),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])
        # get a specific view
        self.cmd(
            'dla catalog view show -n {} --database-name {} --schema-name dbo --view-name {}'
            .format(adla, self.db_name, self.view_name),
            checks=[
                JMESPathCheck('name', self.view_name),
                JMESPathCheck('databaseName', self.db_name),
                JMESPathCheck('schemaName', 'dbo'),
            ])
        # list all procs
        self.cmd(
            'dla catalog procedure list -n {} --database-name {} --schema-name dbo'
            .format(adla, self.db_name),
            checks=[
                JMESPathCheck('type(@)', 'array'),
                JMESPathCheck('length(@)', 1),
            ])
        # get a specific proc
        self.cmd(
            'dla catalog procedure show -n {} --database-name {} --schema-name dbo --procedure-name {}'
            .format(adla, self.db_name, self.proc_name),
            checks=[
                JMESPathCheck('name', self.proc_name),
                JMESPathCheck('databaseName', self.db_name),
                JMESPathCheck('schemaName', 'dbo'),
            ])
        # list all procs
        self.cmd(
            'dla catalog procedure list -n {} --database-name {} --schema-name dbo'
            .format(adla, self.db_name),
            checks=[
                JMESPathCheck('type(@)', 'array'),
                JMESPathCheck('length(@)', 1),
            ])
        # get a specific proc
        self.cmd(
            'dla catalog procedure show -n {} --database-name {} --schema-name dbo --procedure-name {}'
            .format(adla, self.db_name, self.proc_name),
            checks=[
                JMESPathCheck('name', self.proc_name),
                JMESPathCheck('databaseName', self.db_name),
                JMESPathCheck('schemaName', 'dbo'),
            ])
        # list all tvfs
        self.cmd(
            'dla catalog tvf list -n {} --database-name {} --schema-name dbo'.
            format(adla, self.db_name),
            checks=[
                JMESPathCheck('type(@)', 'array'),
                JMESPathCheck('length(@)', 1),
            ])
        # list all tvfs without specifying schema
        self.cmd('dla catalog tvf list -n {} --database-name {}'.format(
            adla, self.db_name),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])
        # get a specific proc
        self.cmd(
            'dla catalog tvf show -n {} --database-name {} --schema-name dbo --table-valued-function-name {}'
            .format(adla, self.db_name, self.tvf_name),
            checks=[
                JMESPathCheck('name', self.tvf_name),
                JMESPathCheck('databaseName', self.db_name),
                JMESPathCheck('schemaName', 'dbo'),
            ])

        # credential crud
        # create a credential
        self.cmd(
            'dla catalog credential create -n {} --database-name {} --credential-name {} --user-name {} --password {} --uri "http://adl.contoso.com:443"'
            .format(adla, self.db_name, self.cred_name, self.cred_user_name,
                    self.cred_user_pwd))

        # list credentials
        self.cmd('dla catalog credential list -n {} --database-name {}'.format(
            adla, self.db_name),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])

        # get the specific credential
        self.cmd(
            'dla catalog credential show -n {} --database-name {} --credential-name {}'
            .format(adla, self.db_name, self.cred_name),
            checks=[
                JMESPathCheck('name', self.cred_name),
            ])

        # delete the specific credential
        self.cmd(
            'dla catalog credential delete -n {} --database-name {} --credential-name {}'
            .format(adla, self.db_name, self.cred_name))

        # list credentials and validate they are gone.
        self.cmd('dla catalog credential list -n {} --database-name {}'.format(
            adla, self.db_name),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 0),
                 ])
Beispiel #8
0
    def body(self):
        plan_result = self.cmd(
            'appservice plan create -g {} -n {} --sku S1'.format(
                self.resource_group, self.plan))
        self.cmd('webapp create -g {} -n {} --plan {}'.format(
            self.resource_group, self.webapp, plan_result['id']))
        # 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'
        test_node_version = '6.6.0'

        # create a few app-settings to test they can be cloned
        self.cmd(
            'webapp config appsettings set -g {} -n {} --settings s1=v1 --slot-settings s2=v2'
            .format(self.resource_group, self.webapp))

        # create an empty slot
        self.cmd('webapp deployment slot create -g {} -n {} --slot {}'.format(
            self.resource_group, self.webapp, slot),
                 checks=[JMESPathCheck('name', slot)])
        self.cmd(
            'webapp deployment source config -g {} -n {} --repo-url {} --branch {} -s {} --manual-integration'
            .format(self.resource_group, self.webapp, test_git_repo, slot,
                    slot),
            checks=[
                JMESPathCheck('repoUrl', test_git_repo),
                JMESPathCheck('branch', slot)
            ])

        import time
        import requests

        # comment out the git sync testing as it requires to pre-load a git token
        # the rest test steps should be sufficient to verify the slot functionalities.

        # verify the slot wires up the git repo/branch
        # time.sleep(30) # 30 seconds should be enough for the deployment finished(Skipped under playback mode)
        # r = requests.get('http://{}-{}.azurewebsites.net'.format(self.webapp, slot))
        # self.assertTrue('Staging' in str(r.content))

        # swap with prod and verify the git branch also switched
        self.cmd('webapp deployment slot swap -g {} -n {} -s {}'.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))
        # self.assertTrue('Staging' in str(r.content))
        result = self.cmd(
            'webapp config appsettings list -g {} -n {} -s {}'.format(
                self.resource_group, self.webapp, slot))
        self.assertEqual(set([x['name'] for x in result]),
                         set(['WEBSITE_NODE_DEFAULT_VERSION', 's1']))

        # create a new slot by cloning from prod slot
        self.cmd('webapp config set -g {} -n {} --node-version {}'.format(
            self.resource_group, self.webapp, test_node_version))
        self.cmd(
            'webapp deployment slot create -g {} -n {} --slot {} --configuration-source {}'
            .format(self.resource_group, self.webapp, slot2, self.webapp))
        self.cmd('webapp config appsettings list -g {} -n {} --slot {}'.format(
            self.resource_group, self.webapp, slot2),
                 checks=[
                     JMESPathCheck("length([])", 1),
                     JMESPathCheck('[0].name', 'WEBSITE_NODE_DEFAULT_VERSION')
                 ])
        self.cmd('webapp config show -g {} -n {} --slot {}'.format(
            self.resource_group, self.webapp, slot2),
                 checks=[
                     JMESPathCheck("nodeVersion", test_node_version),
                 ])
        self.cmd(
            'webapp config appsettings set -g {} -n {} --slot {} --settings s3=v3 --slot-settings s4=v4'
            .format(self.resource_group, self.webapp, slot2))
        self.cmd(
            'webapp config connection-string set -g {} -n {} -t mysql --slot {} --settings c1=connection1 --slot-settings c2=connection2'
            .format(self.resource_group, self.webapp, slot2))

        # verify we can swap with non production slot
        self.cmd(
            'webapp deployment slot swap -g {} -n {} --slot {} --target-slot {}'
            .format(self.resource_group, self.webapp, slot, slot2),
            checks=NoneCheck())
        result = self.cmd(
            'webapp config appsettings list -g {} -n {} --slot {}'.format(
                self.resource_group, self.webapp, slot2))
        self.assertEqual(set([x['name'] for x in result]),
                         set(['WEBSITE_NODE_DEFAULT_VERSION', 's1', 's4']))
        result = self.cmd(
            'webapp config connection-string list -g {} -n {} --slot {}'.
            format(self.resource_group, self.webapp, slot2))
        self.assertEqual(set([x['name'] for x in result]), set(['c2']))

        result = self.cmd(
            'webapp config appsettings list -g {} -n {} --slot {}'.format(
                self.resource_group, self.webapp, slot))
        self.assertEqual(set([x['name'] for x in result]),
                         set(['WEBSITE_NODE_DEFAULT_VERSION', 's3']))
        result = self.cmd(
            'webapp config connection-string list -g {} -n {} --slot {}'.
            format(self.resource_group, self.webapp, slot))
        self.assertEqual(set([x['name'] for x in result]), set(['c1']))

        self.cmd('webapp deployment slot list -g {} -n {}'.format(
            self.resource_group, self.webapp),
                 checks=[
                     JMESPathCheck("length([])", 2),
                     JMESPathCheck("length([?name=='{}'])".format(slot2), 1),
                     JMESPathCheck("length([?name=='{}'])".format(slot), 1),
                 ])
        self.cmd('webapp deployment slot delete -g {} -n {} --slot {}'.format(
            self.resource_group, self.webapp, slot),
                 checks=NoneCheck())
Beispiel #9
0
    def body(self):
        adls = self.adls_name
        folder_name = 'adltestfolder01'
        move_folder_name = 'adltestfolder02'
        file_name = 'adltestfile01'
        upload_file_name = 'adltestfile02'
        join_file_name = 'adltestfile03'
        download_file_name = 'adltestfile04'
        file_content = '123456'

        # create local file
        if os.path.exists(self.local_folder):
            rmtree(self.local_folder)

        os.makedirs(self.local_folder)
        with open(self.local_file, 'w') as f:
            f.write(self.local_file_content)

        # file and folder manipulation
        # create a folder
        self.cmd('dls fs create -n {} --path "{}" --folder --force'.format(
            adls, folder_name))
        # get the folder
        self.cmd('dls fs show -n {} --path "{}"'.format(adls, folder_name),
                 checks=[
                     JMESPathCheck('name', folder_name),
                     JMESPathCheck('type', 'DIRECTORY'),
                     JMESPathCheck('length', 0),
                 ])

        # create a file
        self.cmd('dls fs create -n {} --path "{}/{}" --content {}'.format(
            adls, folder_name, file_name, file_content))
        # get the file
        result = self.cmd('dls fs show -n {} --path "{}/{}"'.format(
            adls, folder_name, file_name),
                          checks=[
                              JMESPathCheck('pathSuffix', file_name),
                              JMESPathCheck('type', 'FILE'),
                              JMESPathCheck('length', len(file_content)),
                          ])

        # set expiration time on the file
        # this future time gives the milliseconds since the epoch that have occured as of 01/31/2030 at noon
        epoch_time = datetime.datetime.utcfromtimestamp(0)
        final_time = datetime.datetime(2030, 1, 31, 12)
        time_in_milliseconds = (final_time - epoch_time).total_seconds() * 1000
        self.cmd('dls fs set-expiry -n {} --path "{}/{}" --expiration-time {}'.
                 format(adls, folder_name, file_name, time_in_milliseconds))
        self.cmd('dls fs show -n {} --path "{}/{}"'.format(
            adls, folder_name, file_name),
                 checks=[
                     JMESPathCheck('pathSuffix', file_name),
                     JMESPathCheck('type', 'FILE'),
                     JMESPathCheck('length', len(file_content)),
                     JMESPathCheck('msExpirationTime', time_in_milliseconds),
                 ])

        # remove the expiration time
        self.cmd('dls fs remove-expiry -n {} --path "{}/{}"'.format(
            adls, folder_name, file_name))
        self.cmd('dls fs show -n {} --path "{}/{}"'.format(
            adls, folder_name, file_name),
                 checks=[
                     JMESPathCheck('pathSuffix', file_name),
                     JMESPathCheck('type', 'FILE'),
                     JMESPathCheck('length', len(file_content)),
                     JMESPathCheck('msExpirationTime',
                                   result['msExpirationTime']),
                 ])

        # move the file
        # this requires that the folder exists
        self.cmd('dls fs create -n {} --path "{}" --folder --force'.format(
            adls, move_folder_name))
        self.cmd(
            'dls fs move -n {} --source-path "{}/{}" --destination-path "{}/{}"'
            .format(adls, folder_name, file_name, move_folder_name, file_name))
        # get the file at the new location
        self.cmd('dls fs show -n {} --path "{}/{}"'.format(
            adls, move_folder_name, file_name),
                 checks=[
                     JMESPathCheck('pathSuffix', file_name),
                     JMESPathCheck('type', 'FILE'),
                     JMESPathCheck('length', len(file_content)),
                 ])

        # preview the file
        result = self.cmd('dls fs preview -n {} --path "{}/{}"'.format(
            adls, move_folder_name, file_name))
        assert result == file_content

        # partial file preview
        result = self.cmd(
            'dls fs preview -n {} --path "{}/{}" --length 1 --offset 3'.format(
                adls, move_folder_name, file_name))
        assert len(result) == 1
        assert result == '4'

        # list the directory, which contains just the one file
        self.cmd('dls fs list -n {} --path "{}"'.format(
            adls, move_folder_name),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                     JMESPathCheck('[0].pathSuffix', file_name),
                     JMESPathCheck('[0].type', 'FILE'),
                     JMESPathCheck('[0].length', len(file_content)),
                 ])

        # append content to a file
        self.cmd('dls fs append -n {} --path "{}/{}" --content {}'.format(
            adls, move_folder_name, file_name, file_content))
        # get the file
        self.cmd('dls fs show -n {} --path "{}/{}"'.format(
            adls, move_folder_name, file_name),
                 checks=[
                     JMESPathCheck('pathSuffix', file_name),
                     JMESPathCheck('type', 'FILE'),
                     JMESPathCheck('length',
                                   len(file_content) * 2),
                 ])

        # upload a file
        self.cmd(
            'dls fs upload -n {} --destination-path "{}/{}" --source-path "{}"'
            .format(adls, folder_name, upload_file_name, self.local_file))
        # get the file
        self.cmd('dls fs show -n {} --path "{}/{}"'.format(
            adls, folder_name, upload_file_name),
                 checks=[
                     JMESPathCheck('pathSuffix', upload_file_name),
                     JMESPathCheck('type', 'FILE'),
                     JMESPathCheck('length', len(self.local_file_content)),
                 ])
        # join the uploaded file to the created file
        self.cmd(
            'dls fs join -n {} --destination-path "{}/{}" --source-paths "{}/{}","{}/{}"'
            .format(adls, folder_name, join_file_name, folder_name,
                    upload_file_name, move_folder_name, file_name))
        self.cmd(
            'dls fs show -n {} --path "{}/{}"'.format(adls, folder_name,
                                                      join_file_name),
            checks=[
                JMESPathCheck('pathSuffix', join_file_name),
                JMESPathCheck('type', 'FILE'),
                JMESPathCheck(
                    'length',
                    len(self.local_file_content) + (len(file_content) * 2)),
            ])

        # download the joined file
        self.cmd(
            'dls fs download -n {} --destination-path "{}" --source-path "{}/{}"'
            .format(adls, os.path.join(self.local_folder, download_file_name),
                    folder_name, join_file_name))
        assert os.path.getsize(
            os.path.join(self.local_folder, download_file_name)) == len(
                self.local_file_content) + (len(file_content) * 2)

        # delete the file and confirm it is gone.
        self.cmd('dls fs delete -n {} --path "{}/{}"'.format(
            adls, folder_name, join_file_name))
        self.cmd('dls fs list -n {} --path "{}"'.format(adls, folder_name),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 0),
                 ])

        # delete a folder that has contents and confirm it is gone.
        self.cmd('dls fs create -n {} --path "{}" --folder'.format(
            adls, move_folder_name))
        self.cmd('dls fs create -n {} --path "{}/{}"'.format(
            adls, move_folder_name, 'tempfile01.txt'))
        self.cmd('dls fs delete -n {} --path "{}" --recurse'.format(
            adls, move_folder_name))
        # test that the path is gone
        assert not self.cmd('dls fs test -n {} --path "{}"'.format(
            adls, move_folder_name))

        # test that the other folder still exists
        assert self.cmd('dls fs test -n {} --path "{}"'.format(
            adls, folder_name))

        if os.path.exists(self.local_folder):
            rmtree(self.local_folder)
    def body(self):
        with open(self.package_file_name, 'w') as f:
            f.write('storage blob test sample file')

        rg = self.resource_group
        name = self.account_name
        aname = self.application_name
        ver = self.application_package_name
        # test create application with default set
        self.cmd(
            'batch application create -g {} -n {} --application-id {} --allow-updates'
            .format(rg, name, aname),
            checks=[
                JMESPathCheck('id', aname),
                JMESPathCheck('allowUpdates', True)
            ])

        self.cmd('batch application list -g {} -n {}'.format(rg, name),
                 checks=[
                     JMESPathCheck('length(@)', 1),
                     JMESPathCheck('[0].id', aname),
                 ])

        self.cmd(
            'batch application package create -g {} -n {} --application-id {}'
            ' --version {} --package-file "{}"'.format(rg, name, aname, ver,
                                                       self.package_file_name),
            checks=[
                JMESPathCheck('id', aname),
                JMESPathCheck('storageUrl != null', True),
                JMESPathCheck('version', ver),
                JMESPathCheck('state', 'active')
            ])

        self.cmd(
            'batch application package activate -g {} -n {} --application-id {}'
            ' --version {} --format zip'.format(rg, name, aname, ver))

        self.cmd(
            'batch application package show -g {} -n {} --application-id {} --version {}'
            .format(rg, name, aname, ver),
            checks=[
                JMESPathCheck('id', aname),
                JMESPathCheck('format', 'zip'),
                JMESPathCheck('version', ver),
                JMESPathCheck('state', 'active')
            ])

        self.cmd('batch application set -g {} -n {} --application-id {} --default-version {}'.format(rg, name, aname, ver))  # pylint: disable=line-too-long

        self.cmd(
            'batch application show -g {} -n {} --application-id {}'.format(
                rg, name, aname),
            checks=[
                JMESPathCheck('id', aname),
                JMESPathCheck('defaultVersion', ver),
                JMESPathCheck('packages[0].format', 'zip'),
                JMESPathCheck('packages[0].state', 'active')
            ])

        # test batch applcation delete
        self.cmd(
            'batch application package delete -g {} -n {} --application-id {} --version {} --yes'
            .  # pylint: disable=line-too-long
            format(rg, name, aname, ver))
        self.cmd(
            'batch application delete -g {} -n {} --application-id {} --yes'.
            format(rg, name, aname))
        self.cmd('batch application list -g {} -n {}'.format(rg, name),
                 checks=NoneCheck())
    def body(self):
        rg = self.resource_group
        name = self.account_name
        loc = self.location

        # test create storage account with default set
        result = self.cmd(
            'storage account create -g {} -n {} -l {} --sku Standard_LRS'.
            format(rg, self.storage_account_name, loc),
            checks=[
                JMESPathCheck('name', self.storage_account_name),
                JMESPathCheck('location', loc),
                JMESPathCheck('resourceGroup', rg)
            ])
        sid = result['id']

        # test create keyvault for use with BYOS account
        self.cmd(
            'keyvault create -g {} -n {} -l {} --enabled-for-deployment true '
            '--enabled-for-disk-encryption true --enabled-for-template-deployment'
            ' true'.format(rg, self.keyvault_name, self.byos_location),
            checks=[
                JMESPathCheck('name', self.keyvault_name),
                JMESPathCheck('location', self.byos_location),
                JMESPathCheck('resourceGroup', rg),
                JMESPathCheck('type(properties.accessPolicies)', 'array'),
                JMESPathCheck('length(properties.accessPolicies)', 1),
                JMESPathCheck('properties.sku.name', 'standard')
            ])
        self.cmd(
            'keyvault set-policy -g {} -n {} --object-id {} --key-permissions all '
            '--secret-permissions all'.format(rg, self.keyvault_name,
                                              self.object_id))

        # test create account with default set
        self.cmd('batch account create -g {} -n {} -l {}'.format(
            rg, name, loc),
                 checks=[
                     JMESPathCheck('name', name),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg)
                 ])

        # test create account with BYOS
        self.cmd('batch account create -g {} -n {} -l {} --keyvault {}'.format(
            rg, self.byos_account_name, self.byos_location,
            self.keyvault_name),
                 checks=[
                     JMESPathCheck('name', self.byos_account_name),
                     JMESPathCheck('location', self.byos_location),
                     JMESPathCheck('resourceGroup', rg)
                 ])

        self.cmd('batch account set -g {} -n {} --storage-account {}'.format(
            rg, name, self.storage_account_name),
                 checks=[
                     JMESPathCheck('name', name),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg)
                 ])

        self.cmd('batch account show -g {} -n {}'.format(rg, name),
                 checks=[
                     JMESPathCheck('name', name),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('autoStorage.storageAccountId', sid)
                 ])

        self.cmd('batch account autostorage-keys sync -g {} -n {}'.format(
            rg, name))

        keys = self.cmd('batch account keys list -g {} -n {}'.format(rg, name),
                        checks=[
                            JMESPathCheck('primary != null', True),
                            JMESPathCheck('secondary != null', True)
                        ])

        keys2 = self.cmd(
            'batch account keys renew -g {} -n {} --key-name primary'.format(
                rg, name),
            checks=[
                JMESPathCheck('primary != null', True),
                JMESPathCheck('secondary', keys['secondary'])
            ])

        self.assertTrue(keys['primary'] != keys2['primary'])

        with mock.patch('azure.cli.core._config.GLOBAL_CONFIG_DIR', self.config_dir), \
             mock.patch('azure.cli.core._config.GLOBAL_CONFIG_PATH', self.config_path):  # noqa: F122
            self.cmd('batch account login -g {} -n {}'.format(rg, name),
                     checks=NoneCheck())
            self.assertEqual(az_config.config_parser.get('batch', 'auth_mode'),
                             'aad')
            self.assertEqual(az_config.config_parser.get('batch', 'account'),
                             name)
            self.assertFalse(
                az_config.config_parser.has_option('batch', 'access_key'))

            self.cmd(
                'batch account login -g {} -n {} --shared-key-auth'.format(
                    rg, name),
                checks=NoneCheck())
            self.assertEqual(az_config.config_parser.get('batch', 'auth_mode'),
                             'shared_key')
            self.assertEqual(az_config.config_parser.get('batch', 'account'),
                             name)
            self.assertEqual(
                az_config.config_parser.get('batch', 'access_key'),
                keys2['primary'])

        # test batch account delete
        self.cmd('batch account delete -g {} -n {} --yes'.format(rg, name))
        self.cmd('batch account delete -g {} -n {} --yes'.format(
            rg, self.byos_account_name))
        self.cmd('batch account list -g {}'.format(rg), checks=NoneCheck())

        self.cmd('batch location quotas show -l {}'.format(loc),
                 checks=[JMESPathCheck('accountQuota', 1)])
    def body(self):
        rg = self.resource_group
        adls1 = self.adls_names[0]
        adls2 = self.adls_names[1]
        adla = self.adla_name
        loc = self.location
        result = self.cmd('storage account keys list -g {} -n {}'.format(
            self.resource_group, self.wasb_name))
        wasb_key = result[0]['value']
        # test create keyvault with default access policy set
        self.cmd(
            'dla account create -g {} -n {} -l {} --default-data-lake-store {}'
            .format(rg, adla, loc, adls1),
            checks=[
                JMESPathCheck('name', adla),
                JMESPathCheck('location', loc),
                JMESPathCheck('resourceGroup', rg),
                JMESPathCheck('defaultDataLakeStoreAccount', adls1),
                JMESPathCheck('type(dataLakeStoreAccounts)', 'array'),
                JMESPathCheck('length(dataLakeStoreAccounts)', 1),
                JMESPathCheck('maxDegreeOfParallelism', 30),
                JMESPathCheck('maxJobCount', 3),
                JMESPathCheck('queryStoreRetention', 30),
            ])
        self.cmd('dla account show -n {} -g {}'.format(adla, rg),
                 checks=[
                     JMESPathCheck('name', adla),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('defaultDataLakeStoreAccount', adls1),
                     JMESPathCheck('type(dataLakeStoreAccounts)', 'array'),
                     JMESPathCheck('length(dataLakeStoreAccounts)', 1),
                     JMESPathCheck('maxDegreeOfParallelism', 30),
                     JMESPathCheck('maxJobCount', 3),
                     JMESPathCheck('queryStoreRetention', 30),
                 ])
        self.cmd('dla account list -g {}'.format(rg),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                     JMESPathCheck('[0].name', adla),
                     JMESPathCheck('[0].location', loc),
                     JMESPathCheck('[0].resourceGroup', rg),
                 ])
        result = self.cmd('dla account list')
        assert isinstance(result, list)
        assert len(result) >= 1

        # test update acct
        self.cmd(
            'dla account update -g {} -n {} --firewall-state Enabled --max-degree-of-parallelism 15 --max-job-count 2 --query-store-retention 15 --allow-azure-ips Enabled'
            .format(rg, adla))
        self.cmd(
            'dla account show -n {} -g {}'.format(adla, rg),
            checks=[
                JMESPathCheck('name', adla),
                JMESPathCheck('location', loc),
                JMESPathCheck('resourceGroup', rg),
                JMESPathCheck('defaultDataLakeStoreAccount', adls1),
                JMESPathCheck('type(dataLakeStoreAccounts)', 'array'),
                JMESPathCheck('length(dataLakeStoreAccounts)', 1),
                JMESPathCheck('maxDegreeOfParallelism', 15),
                JMESPathCheck('maxJobCount', 2),
                JMESPathCheck('queryStoreRetention', 15)
                # TODO: add validation for firewall rules once they are
                # live in production.
            ])

        # test adls acct add get, delete
        self.cmd(
            'dla account data-lake-store add -g {} -n {} --data-lake-store-account-name {}'
            .format(rg, adla, adls2))
        self.cmd(
            'dla account data-lake-store show -g {} -n {} --data-lake-store-account-name {}'
            .format(rg, adla, adls2),
            checks=[JMESPathCheck('name', adls2)])
        self.cmd('dla account data-lake-store list -g {} -n {}'.format(
            rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 2),
                 ])
        self.cmd(
            'dla account data-lake-store delete -g {} -n {} --data-lake-store-account-name {}'
            .format(rg, adla, adls2))
        self.cmd('dla account data-lake-store list -g {} -n {}'.format(
            rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])
        # test wasb add, get delete
        self.cmd(
            'dla account blob-storage add -g {} -n {} --storage-account-name {} --access-key {}'
            .format(rg, adla, self.wasb_name, wasb_key))
        self.cmd(
            'dla account blob-storage show -g {} -n {} --storage-account-name {}'
            .format(rg, adla, self.wasb_name),
            checks=[JMESPathCheck('name', self.wasb_name)])
        self.cmd('dla account blob-storage list -g {} -n {}'.format(rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])
        self.cmd(
            'dla account blob-storage delete -g {} -n {} --storage-account-name {}'
            .format(rg, adla, self.wasb_name))
        self.cmd('dla account blob-storage list -g {} -n {}'.format(rg, adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 0),
                 ])
        # test account deletion
        self.cmd('dla account delete -g {} -n {}'.format(rg, adla))
        self.cmd('dla account list -g {}'.format(rg),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 0),
                 ])
    def body(self):
        rg = self.resource_group
        adla = self.adla_name
        loc = self.location
        # create ADLS accounts
        self.cmd(
            'dls account create -g {} -n {} -l {} --disable-encryption'.format(
                self.resource_group, self.adls_name, loc))
        self.cmd('dls account show -g {} -n {}'.format(self.resource_group,
                                                       self.adls_name),
                 checks=[
                     JMESPathCheck('name', self.adls_name),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg)
                 ])

        self.cmd(
            'dla account create -g {} -n {} -l {} --default-data-lake-store {}'
            .format(self.resource_group, adla, loc, self.adls_name))
        self.cmd('dla account show -g {} -n {}'.format(self.resource_group,
                                                       self.adla_name),
                 checks=[
                     JMESPathCheck('name', adla),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg)
                 ])

        # submit job
        result = self.cmd(
            'dla job submit -n {} --job-name clijobtest --script "DROP DATABASE IF EXISTS FOO; CREATE DATABASE FOO;"'
            .format(adla),
            checks=[
                JMESPathCheck('name', 'clijobtest'),
            ])
        # cancel job
        job_id = result['jobId']
        self.cmd('dla job cancel -n {} --job-id {}'.format(adla, job_id))

        # get the job and confirm that it was cancelled
        self.cmd('dla job show -n {} --job-id {}'.format(adla, job_id),
                 checks=[
                     JMESPathCheck('name', 'clijobtest'),
                     JMESPathCheck('result', 'Cancelled'),
                 ])
        # re-submit job
        result = self.cmd(
            'dla job submit -n {} --job-name clijobtest --script "DROP DATABASE IF EXISTS FOO; CREATE DATABASE FOO;"'
            .format(adla),
            checks=[
                JMESPathCheck('name', 'clijobtest'),
            ])

        # wait for the job to finish
        job_id = result['jobId']
        result = self.cmd('dla job wait -n {} --job-id {}'.format(
            adla, job_id),
                          checks=[
                              JMESPathCheck('name', 'clijobtest'),
                              JMESPathCheck('result', 'Succeeded'),
                          ])

        # list all jobs
        self.cmd('dla job list -n {}'.format(adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 2)
                 ])
Beispiel #14
0
    def body(self):
        nsg_name = 'nsg1'
        self.cmd(
            'network nsg create -n {} -g {}'.format(nsg_name,
                                                    self.resource_group), None)
        result = self.cmd(
            'network nsg show -n {} -g {}'.format(nsg_name,
                                                  self.resource_group), None)
        resource_id = result['id']

        # test role assignments on a resource group
        self.cmd(
            'role assignment create --assignee {} --role contributor -g {}'.
            format(self.user, self.resource_group), None)
        self.cmd('role assignment list -g {}'.format(self.resource_group),
                 checks=[JMESPathCheck("length([])", 1)])
        self.cmd('role assignment list --assignee {} --role contributor -g {}'.
                 format(self.user, self.resource_group),
                 checks=[JMESPathCheck("length([])", 1)])

        # test couple of more general filters
        result = self.cmd(
            'role assignment list -g {} --include-inherited'.format(
                self.resource_group), None)
        self.assertTrue(len(result) >= 1)

        result = self.cmd(
            'role assignment list --all'.format(self.user,
                                                self.resource_group), None)
        self.assertTrue(len(result) >= 1)

        self.cmd(
            'role assignment delete --assignee {} --role contributor -g {}'.
            format(self.user, self.resource_group), None)
        self.cmd('role assignment list -g {}'.format(self.resource_group),
                 checks=NoneCheck())

        # test role assignments on a resource
        self.cmd(
            'role assignment create --assignee {} --role contributor --scope {}'
            .format(self.user, resource_id), None)
        self.cmd(
            'role assignment list --assignee {} --role contributor --scope {}'.
            format(self.user, resource_id),
            checks=[JMESPathCheck("length([])", 1)])
        self.cmd(
            'role assignment delete --assignee {} --role contributor --scope {}'
            .format(self.user, resource_id), None)
        self.cmd('role assignment list --scope {}'.format(resource_id),
                 checks=NoneCheck())

        # test role assignment on subscription level
        self.cmd(
            'role assignment create --assignee {} --role reader'.format(
                self.user), None)
        self.cmd('role assignment list --assignee {} --role reader'.format(
            self.user),
                 checks=[JMESPathCheck("length([])", 1)])
        self.cmd('role assignment list --assignee {}'.format(self.user),
                 checks=[JMESPathCheck("length([])", 1)])
        self.cmd(
            'role assignment delete --assignee {} --role reader'.format(
                self.user), None)
Beispiel #15
0
 def body(self):
     plan = 'webapp-scale-plan'
     # start with shared sku
     self.cmd(
         'appservice plan create -g {} -n {} --sku SHARED'.format(
             self.resource_group, plan),
         checks=[
             JMESPathCheck('sku.name', 'D1'),
             JMESPathCheck('sku.tier', 'Shared'),
             JMESPathCheck('sku.size', 'D1'),
             JMESPathCheck('sku.family', 'D'),
             JMESPathCheck('sku.capacity',
                           0)  # 0 means the default value: 1 instance
         ])
     # scale up
     self.cmd('appservice plan update -g {} -n {} --sku S2'.format(
         self.resource_group, plan),
              checks=[
                  JMESPathCheck('sku.name', 'S2'),
                  JMESPathCheck('sku.tier', 'Standard'),
                  JMESPathCheck('sku.size', 'S2'),
                  JMESPathCheck('sku.family', 'S')
              ])
     # scale down
     self.cmd('appservice plan update -g {} -n {} --sku B1'.format(
         self.resource_group, plan),
              checks=[
                  JMESPathCheck('sku.name', 'B1'),
                  JMESPathCheck('sku.tier', 'Basic'),
                  JMESPathCheck('sku.size', 'B1'),
                  JMESPathCheck('sku.family', 'B')
              ])
     # scale out
     self.cmd(
         'appservice plan update -g {} -n {} --number-of-workers 2'.format(
             self.resource_group, plan),
         checks=[
             JMESPathCheck('sku.name', 'B1'),
             JMESPathCheck('sku.tier', 'Basic'),
             JMESPathCheck('sku.size', 'B1'),
             JMESPathCheck('sku.family', 'B'),
             JMESPathCheck('sku.capacity', 2)
         ])
Beispiel #16
0
    def body(self):
        rg = self.resource_group
        adls = self.adls_name
        loc = self.location
        # test create keyvault with default access policy set
        self.cmd('dls account create -g {} -n {} -l {}'.format(rg, adls, loc),
                 checks=[
                     JMESPathCheck('name', adls),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('encryptionState', 'Enabled'),
                 ])
        self.cmd('dls account show -n {} -g {}'.format(adls, rg),
                 checks=[
                     JMESPathCheck('name', adls),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('encryptionState', 'Enabled'),
                 ])

        # attempt to enable the key vault when it is already enabled, which should throw
        with self.assertRaises(CloudError):
            self.cmd('dls account enable-key-vault -n {} -g {}'.format(
                adls, rg))

        self.cmd('dls account list -g {}'.format(rg),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                     JMESPathCheck('[0].name', adls),
                     JMESPathCheck('[0].location', loc),
                     JMESPathCheck('[0].resourceGroup', rg),
                 ])
        result = self.cmd('dls account list')
        assert isinstance(result, list)
        assert len(result) >= 1

        # test update acct
        self.cmd(
            'dls account update -g {} -n {} --firewall-state Enabled --trusted-id-provider-state Enabled'
            .format(rg, adls))
        self.cmd('dls account show -n {} -g {}'.format(adls, rg),
                 checks=[
                     JMESPathCheck('name', adls),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('firewallState', 'Enabled'),
                     JMESPathCheck('trustedIdProviderState', 'Enabled'),
                 ])

        # test firewall crud
        fw_name = 'testfirewallrule01'
        start_ip = '127.0.0.1'
        end_ip = '127.0.0.2'
        new_end_ip = '127.0.0.3'
        self.cmd(
            'dls account firewall create -g {} -n {} --firewall-rule-name {} --start-ip-address {} --end-ip-address {}'
            .format(rg, adls, fw_name, start_ip, end_ip))
        self.cmd(
            'dls account firewall show -g {} -n {} --firewall-rule-name {}'.
            format(rg, adls, fw_name),
            checks=[
                JMESPathCheck('name', fw_name),
                JMESPathCheck('startIpAddress', start_ip),
                JMESPathCheck('endIpAddress', end_ip),
            ])

        self.cmd(
            'dls account firewall update -g {} -n {} --firewall-rule-name {} --end-ip-address {}'
            .format(rg, adls, fw_name, new_end_ip))
        self.cmd(
            'dls account firewall show -g {} -n {} --firewall-rule-name {}'.
            format(rg, adls, fw_name),
            checks=[
                JMESPathCheck('name', fw_name),
                JMESPathCheck('startIpAddress', start_ip),
                JMESPathCheck('endIpAddress', new_end_ip),
            ])

        self.cmd('dls account firewall list -g {} -n {}'.format(rg, adls),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])
        self.cmd(
            'dls account firewall delete -g {} -n {} --firewall-rule-name {}'.
            format(rg, adls, fw_name))
        self.cmd('dls account firewall list -g {} -n {}'.format(rg, adls),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 0),
                 ])
        # test trusted id provider CRUD
        trusted_provider = 'https://sts.windows.net/9d5b43a0-804c-4c82-8791-36aca2f72342'
        new_provider = 'https://sts.windows.net/fceb709f-96f1-4c65-b06f-2541114bffb3'
        provider_name = 'testprovider01'
        self.cmd(
            'dls account trusted-provider create -g {} -n {} --trusted-id-provider-name {} --id-provider {}'
            .format(rg, adls, provider_name, trusted_provider))
        self.cmd(
            'dls account trusted-provider show -g {} -n {} --trusted-id-provider-name {}'
            .format(rg, adls, provider_name),
            checks=[
                JMESPathCheck('name', provider_name),
                JMESPathCheck('idProvider', trusted_provider),
            ])

        self.cmd(
            'dls account trusted-provider update -g {} -n {} --trusted-id-provider-name {} --id-provider {}'
            .format(rg, adls, provider_name, new_provider))
        self.cmd(
            'dls account trusted-provider show -g {} -n {} --trusted-id-provider-name {}'
            .format(rg, adls, provider_name),
            checks=[
                JMESPathCheck('name', provider_name),
                JMESPathCheck('idProvider', new_provider),
            ])

        self.cmd('dls account trusted-provider list -g {} -n {}'.format(
            rg, adls),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                 ])
        self.cmd(
            'dls account trusted-provider delete -g {} -n {} --trusted-id-provider-name {}'
            .format(rg, adls, provider_name))
        self.cmd('dls account trusted-provider list -g {} -n {}'.format(
            rg, adls),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 0),
                 ])

        # test account deletion
        self.cmd('dls account delete -g {} -n {}'.format(rg, adls))
        self.cmd('dls account list -g {}'.format(rg),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 0),
                 ])
Beispiel #17
0
 def body(self):
     plan_result = self.cmd(
         'appservice plan create -g {} -n {} --sku S1'.format(
             self.resource_group, self.plan))
     self.cmd('webapp create -g {} -n {} --plan {}'.format(
         self.resource_group, self.webapp, plan_result['id']))
     # 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'
     test_php_version = '5.6'
     # create a few app-settings to test they can be cloned
     self.cmd(
         'webapp config appsettings set -g {} -n {} --settings s1=v1 --slot-settings s2=v2'
         .format(self.resource_group, self.webapp))
     # create an empty slot
     self.cmd('webapp deployment slot create -g {} -n {} --slot {}'.format(
         self.resource_group, self.webapp, slot),
              checks=[JMESPathCheck('name', slot)])
     self.cmd(
         'webapp deployment source config -g {} -n {} --repo-url {} --branch {} -s {} --manual-integration'
         .format(self.resource_group, self.webapp, test_git_repo, slot,
                 slot),
         checks=[
             JMESPathCheck('repoUrl', test_git_repo),
             JMESPathCheck('branch', slot)
         ])
     # swap with prod and verify the git branch also switched
     self.cmd('webapp deployment slot swap -g {} -n {} -s {}'.format(
         self.resource_group, self.webapp, slot))
     result = self.cmd(
         'webapp config appsettings list -g {} -n {} -s {}'.format(
             self.resource_group, self.webapp, slot))
     self.assertEqual(set([x['name'] for x in result]), set(['s1']))
     # create a new slot by cloning from prod slot
     self.cmd('webapp config set -g {} -n {} --php-version {}'.format(
         self.resource_group, self.webapp, test_php_version))
     self.cmd(
         'webapp deployment slot create -g {} -n {} --slot {} --configuration-source {}'
         .format(self.resource_group, self.webapp, slot2, self.webapp))
     self.cmd('webapp config show -g {} -n {} --slot {}'.format(
         self.resource_group, self.webapp, slot2),
              checks=[
                  JMESPathCheck("phpVersion", test_php_version),
              ])
     self.cmd(
         'webapp config appsettings set -g {} -n {} --slot {} --settings s3=v3 --slot-settings s4=v4'
         .format(self.resource_group, self.webapp, slot2))
     self.cmd(
         'webapp config connection-string set -g {} -n {} -t mysql --slot {} --settings c1=connection1 --slot-settings c2=connection2'
         .format(self.resource_group, self.webapp, slot2))
     # verify we can swap with non production slot
     self.cmd(
         'webapp deployment slot swap -g {} -n {} --slot {} --target-slot {}'
         .format(self.resource_group, self.webapp, slot, slot2),
         checks=NoneCheck())
     result = self.cmd(
         'webapp config appsettings list -g {} -n {} --slot {}'.format(
             self.resource_group, self.webapp, slot2))
     self.assertEqual(set([x['name'] for x in result]), set(['s1', 's4']))
     result = self.cmd(
         'webapp config connection-string list -g {} -n {} --slot {}'.
         format(self.resource_group, self.webapp, slot2))
     self.assertEqual(set([x['name'] for x in result]), set(['c2']))
     result = self.cmd(
         'webapp config appsettings list -g {} -n {} --slot {}'.format(
             self.resource_group, self.webapp, slot))
     self.assertTrue(set(['s3']).issubset(set([x['name'] for x in result])))
     result = self.cmd(
         'webapp config connection-string list -g {} -n {} --slot {}'.
         format(self.resource_group, self.webapp, slot))
     self.assertEqual(set([x['name'] for x in result]), set(['c1']))
     self.cmd('webapp deployment slot list -g {} -n {}'.format(
         self.resource_group, self.webapp),
              checks=[
                  JMESPathCheck("length([])", 2),
                  JMESPathCheck("length([?name=='{}'])".format(slot2), 1),
                  JMESPathCheck("length([?name=='{}'])".format(slot), 1),
              ])
     self.cmd('webapp deployment slot delete -g {} -n {} --slot {}'.format(
         self.resource_group, self.webapp, slot),
              checks=NoneCheck())
Beispiel #18
0
    def body(self):
        # define variables
        adls = self.adls_name
        folder_name = 'adltestfolder01'
        user_id = '470c0ccf-c91a-4597-98cd-48507d2f1486'
        acl_to_add = 'user:{}:rwx'.format(user_id)
        acl_to_modify = 'user:{}:-w-'.format(user_id)
        acl_to_remove = 'user:{}'.format(user_id)

        # create a folder
        self.cmd('dls fs create -n {} --path "{}" --folder --force'.format(
            adls, folder_name))
        # get the folder
        self.cmd('dls fs show -n {} --path "{}"'.format(adls, folder_name),
                 checks=[
                     JMESPathCheck('name', folder_name),
                     JMESPathCheck('type', 'DIRECTORY'),
                     JMESPathCheck('length', 0),
                 ])

        # set the owner and owning group for the file and confirm them
        group_id = '80a3ed5f-959e-4696-ba3c-d3c8b2db6766'
        user_id = '6361e05d-c381-4275-a932-5535806bb323'
        self.cmd(
            'dls fs access set-owner -n {} --path "{}" --group {} --owner {}'.
            format(adls, folder_name, group_id, user_id))

        # get the file and confirm those values
        result = self.cmd('dls fs show -n {} --path "{}"'.format(
            adls, folder_name),
                          checks=[
                              JMESPathCheck('name', folder_name),
                              JMESPathCheck('type', 'DIRECTORY'),
                              JMESPathCheck('length', 0),
                              JMESPathCheck('owner', user_id),
                              JMESPathCheck('group', group_id),
                          ])

        # set the permissions on the file
        self.cmd(
            'dls fs access set-permission -n {} --path "{}" --permission {}'.
            format(adls, folder_name, 777))
        # get the file and confirm those values
        result = self.cmd('dls fs show -n {} --path "{}"'.format(
            adls, folder_name),
                          checks=[
                              JMESPathCheck('name', folder_name),
                              JMESPathCheck('type', 'DIRECTORY'),
                              JMESPathCheck('length', 0),
                              JMESPathCheck('permission', '777'),
                          ])

        # get the initial ACE
        result = self.cmd('dls fs access show -n {} --path "{}"'.format(
            adls, folder_name))
        inital_acl_length = len(result['entries'])
        new_acl = ','.join(result['entries'])
        new_acl += ',{}'.format(acl_to_add)
        # set the full ACL
        self.cmd('dls fs access set -n {} --path "{}" --acl-spec {}'.format(
            adls, folder_name, new_acl))
        # get the ACL and confirm that it has grown
        set_result = self.cmd('dls fs access show -n {} --path "{}"'.format(
            adls, folder_name))
        assert len(set_result['entries']) > inital_acl_length
        assert acl_to_add in set_result['entries']

        # modify that ACE with set-entry
        self.cmd(
            'dls fs access set-entry -n {} --path "{}" --acl-spec {}'.format(
                adls, folder_name, acl_to_modify))
        # get the ACL and confirm it has been modified
        modify_result = self.cmd('dls fs access show -n {} --path "{}"'.format(
            adls, folder_name))
        assert len(set_result['entries']) > inital_acl_length
        assert acl_to_modify in modify_result['entries']
        # remove an ACE
        self.cmd('dls fs access remove-entry -n {} --path "{}" --acl-spec {}'.
                 format(adls, folder_name, acl_to_remove))
        # get ACL and ensure that it is smaller than before
        remove_result = self.cmd('dls fs access show -n {} --path "{}"'.format(
            adls, folder_name))
        assert len(remove_result['entries']) < len(modify_result['entries'])
        assert acl_to_modify not in remove_result['entries']
        # remove default ACL
        self.cmd(
            'dls fs access remove-all -n {} --path "{}" --default-acl'.format(
                adls, folder_name))
        remove_result = self.cmd('dls fs access show -n {} --path "{}"'.format(
            adls, folder_name))
        # there should be four entries left
        assert 4 == len(remove_result['entries'])

        # remove ACL
        self.cmd('dls fs access remove-all -n {} --path "{}"'.format(
            adls, folder_name))
        remove_result = self.cmd('dls fs access show -n {} --path "{}"'.format(
            adls, folder_name))
        # there should be three entries left
        assert 3 == len(remove_result['entries'])
Beispiel #19
0
 def body(self):
     sas_url = 'https://azureclistore.blob.core.windows.net/sitebackups?sv=2015-04-05&sr=c&sig=PJpE6swgZ6oZNFTlUz0GOIl87KKdvvgX7Ap8YXKHRp8%3D&se=2017-03-10T23%3A40%3A24Z&sp=rwdl'
     db_conn_str = 'Server=tcp:cli-backup.database.windows.net,1433;Initial Catalog=cli-db;Persist Security Info=False;User ID=cliuser;Password=cli!password1;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;'
     database_name = 'cli-db'
     database_type = 'SqlAzure'
     backup_name = 'mybackup'
     create_checks = [
         JMESPathCheck('backupItemName', backup_name),
         JMESPathCheck('storageAccountUrl', sas_url),
         JMESPathCheck('databases[0].connectionString', db_conn_str),
         JMESPathCheck('databases[0].databaseType', database_type),
         JMESPathCheck('databases[0].name', database_name)
     ]
     self.cmd(
         'webapp config backup create -g {} --webapp-name {} --container-url {} --db-connection-string "{}" --db-name {} --db-type {} --backup-name {}'
         .format(self.resource_group, self.webapp_name, sas_url,
                 db_conn_str, database_name, database_type, backup_name),
         checks=create_checks)
     list_checks = [
         JMESPathCheck('[-1].backupItemName', backup_name),
         JMESPathCheck('[-1].storageAccountUrl', sas_url),
         JMESPathCheck('[-1].databases[0].connectionString', db_conn_str),
         JMESPathCheck('[-1].databases[0].databaseType', database_type),
         JMESPathCheck('[-1].databases[0].name', database_name)
     ]
     self.cmd('webapp config backup list -g {} --webapp-name {}'.format(
         self.resource_group, self.webapp_name),
              checks=list_checks)
     import time
     time.sleep(
         300
     )  # Allow plenty of time for a backup to finish -- database backup takes a while (skipped in playback)
     self.cmd(
         'webapp config backup restore -g {} --webapp-name {} --container-url {} --backup-name {} --db-connection-string "{}" --db-name {} --db-type {} --ignore-hostname-conflict --overwrite'
         .format(self.resource_group, self.webapp_name, sas_url,
                 backup_name, db_conn_str, database_name, database_type),
         checks=JMESPathCheck('name', self.webapp_name))
Beispiel #20
0
    def test_resource_policy(self, resource_group):
        policy_name = self.create_random_name('azure-cli-test-policy', 30)
        policy_display_name = self.create_random_name('test_policy', 20)
        policy_description = 'desc_for_test_policy_123'
        curr_dir = os.path.dirname(os.path.realpath(__file__))
        rules_file = os.path.join(curr_dir, 'sample_policy_rule.json').replace(
            '\\', '\\\\')
        params_def_file = os.path.join(curr_dir,
                                       'sample_policy_param_def.json').replace(
                                           '\\', '\\\\')
        params_file = os.path.join(curr_dir,
                                   'sample_policy_param.json').replace(
                                       '\\', '\\\\')
        mode = 'Indexed'

        # create a policy
        self.cmd(
            'policy definition create -n {} --rules {} --params {} --display-name {} --description {} --mode {}'
            .format(policy_name, rules_file, params_def_file,
                    policy_display_name, policy_description, mode),
            checks=[
                JCheck('name', policy_name),
                JCheck('displayName', policy_display_name),
                JCheck('description', policy_description),
                JCheck('mode', mode)
            ])

        # update it
        new_policy_description = policy_description + '_new'
        self.cmd('policy definition update -n {} --description {}'.format(
            policy_name, new_policy_description),
                 checks=JCheck('description', new_policy_description))

        # list and show it
        self.cmd('policy definition list',
                 checks=JMESPathCheck(
                     "length([?name=='{}'])".format(policy_name), 1))
        self.cmd('policy definition show -n {}'.format(policy_name),
                 checks=[
                     JCheck('name', policy_name),
                     JCheck('displayName', policy_display_name)
                 ])

        # create a policy assignment on a resource group
        policy_assignment_name = self.create_random_name(
            'azurecli-test-policy-assignment', 40)
        policy_assignment_display_name = self.create_random_name(
            'test_assignment', 20)
        self.cmd(
            'policy assignment create --policy {} -n {} --display-name {} -g {} --params {}'
            .format(policy_name, policy_assignment_name,
                    policy_assignment_display_name, resource_group,
                    params_file),
            checks=[
                JCheck('name', policy_assignment_name),
                JCheck('displayName', policy_assignment_display_name),
                JCheck('sku.name', 'A0'),
                JCheck('sku.tier', 'Free'),
            ])

        # create a policy assignment with not scopes and standard sku
        get_cmd = 'group show -n {}'
        rg = self.cmd(get_cmd.format(resource_group)).get_output_in_json()
        vnet_name = self.create_random_name('azurecli-test-policy-vnet', 40)
        subnet_name = self.create_random_name('azurecli-test-policy-subnet',
                                              40)
        vnetcreatecmd = 'network vnet create -g {} -n {} --subnet-name {}'
        self.cmd(vnetcreatecmd.format(resource_group, vnet_name, subnet_name))
        notscope = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Network/virtualNetworks'.format(
            rg['id'].split("/")[2], resource_group)
        self.cmd(
            'policy assignment create --policy {} -n {} --display-name {} -g {} --not-scopes {} --params {} --sku {}'
            .format(policy_name, policy_assignment_name,
                    policy_assignment_display_name, resource_group, notscope,
                    params_file, 'standard'),
            checks=[
                JCheck('name', policy_assignment_name),
                JCheck('displayName', policy_assignment_display_name),
                JCheck('sku.name', 'A1'),
                JCheck('sku.tier', 'Standard'),
                JCheck('notScopes[0]', notscope)
            ])

        # listing at subscription level won't find the assignment made at a resource group
        import jmespath
        try:
            self.cmd(
                'policy assignment list',
                checks=JCheck(
                    "length([?name=='{}'])".format(policy_assignment_name), 0))
        except jmespath.exceptions.JMESPathTypeError:  # ok if query fails on None result
            pass

        # but enable --show-all works
        self.cmd('policy assignment list --disable-scope-strict-match',
                 checks=JCheck(
                     "length([?name=='{}'])".format(policy_assignment_name),
                     1))

        # delete the assignment
        self.cmd('policy assignment delete -n {} -g {}'.format(
            policy_assignment_name, resource_group))
        self.cmd('policy assignment list --disable-scope-strict-match')

        # delete the policy
        self.cmd('policy definition delete -n {}'.format(policy_name))
        time.sleep(10)  # ensure the policy is gone when run live.
        self.cmd('policy definition list',
                 checks=JCheck("length([?name=='{}'])".format(policy_name), 0))
    def body(self):
        rg = self.resource_group
        adla = self.adla_name
        loc = self.location
        # job relation ship variables
        pipeline_id = '3f9a237a-325e-4ec8-9e10-60222a71354d'
        pipeline_name = 'py_pipeline_name'
        pipeline_uri = 'https://begoldsm.contoso.com/jobs'
        recurrence_id = '58cab1f7-fe29-46ce-89ab-628a1e09c5bf'
        recurrence_name = 'py_recurrence_name'
        run_id = 'a3f300fc-4496-40ad-b76d-7696e3723b77'

        # create ADLS accounts
        self.cmd(
            'dls account create -g {} -n {} -l {} --disable-encryption'.format(
                self.resource_group, self.adls_name, loc))
        self.cmd('dls account show -g {} -n {}'.format(self.resource_group,
                                                       self.adls_name),
                 checks=[
                     JMESPathCheck('name', self.adls_name),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg)
                 ])

        self.cmd(
            'dla account create -g {} -n {} -l {} --default-data-lake-store {}'
            .format(self.resource_group, adla, loc, self.adls_name))
        self.cmd('dla account show -g {} -n {}'.format(self.resource_group,
                                                       self.adla_name),
                 checks=[
                     JMESPathCheck('name', adla),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg)
                 ])

        # submit job - should work with no relationship params
        result = self.cmd(
            'dla job submit -n {} --job-name clijobtest --script "DROP DATABASE IF EXISTS FOO; CREATE DATABASE FOO;"'
            .format(adla),
            checks=[
                JMESPathCheck('name', 'clijobtest'),
            ])
        # cancel job
        job_id = result['jobId']
        self.cmd('dla job cancel -n {} --job-id {}'.format(adla, job_id))

        # get the job and confirm that it was cancelled
        self.cmd('dla job show -n {} --job-id {}'.format(adla, job_id),
                 checks=[
                     JMESPathCheck('name', 'clijobtest'),
                     JMESPathCheck('result', 'Cancelled'),
                 ])

        # job relationship. Attempt to submit a job with invalid job relationship param combos
        with self.assertRaises(CLIError):
            self.cmd(
                'dla job submit -n {} --job-name clijobtest --script "DROP DATABASE IF EXISTS FOO; CREATE DATABASE FOO;" --recurrence-name {}'
                .format(adla, recurrence_name))

        with self.assertRaises(CLIError):
            self.cmd(
                'dla job submit -n {} --job-name clijobtest --script "DROP DATABASE IF EXISTS FOO; CREATE DATABASE FOO;" --recurrence-name {} --recurrence-id {} --pipeline-name {}'
                .format(adla, recurrence_name, recurrence_id, pipeline_name))

        # re-submit job with a fully populated relationship
        result = self.cmd(
            'dla job submit -n {} --job-name clijobtest --script "DROP DATABASE IF EXISTS FOO; CREATE DATABASE FOO;" --recurrence-name {} --recurrence-id {} --pipeline-name {} --pipeline-id {} --pipeline-uri {} --run-id {}'
            .format(adla, recurrence_name, recurrence_id, pipeline_name,
                    pipeline_id, pipeline_uri, run_id),
            checks=[JMESPathCheck('name', 'clijobtest')])

        # wait for the job to finish
        job_id = result['jobId']
        result = self.cmd(
            'dla job wait -n {} --job-id {}'.format(adla, job_id),
            checks=[
                JMESPathCheck('name', 'clijobtest'),
                JMESPathCheck('result', 'Succeeded'),
                JMESPathCheck('related.recurrenceId', recurrence_id),
                JMESPathCheck('related.recurrenceName', recurrence_name),
                JMESPathCheck('related.pipelineId', pipeline_id),
                JMESPathCheck('related.pipelineName', pipeline_name),
                JMESPathCheck('related.pipelineUri', pipeline_uri),
                JMESPathCheck('related.runId', run_id),
            ])

        # list all jobs
        self.cmd('dla job list -n {}'.format(adla),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 2)
                 ])

        # get and list job relationships (recurrence and pipeline)
        result = self.cmd('dla job recurrence list -n {}'.format(adla))
        assert isinstance(result, list)
        assert len(result) >= 1

        result = self.cmd(
            'dla job recurrence show -n {} --recurrence-id {}'.format(
                adla, recurrence_id),
            checks=[
                JMESPathCheck('recurrenceId', recurrence_id),
                JMESPathCheck('recurrenceName', recurrence_name),
            ])

        result = self.cmd('dla job pipeline list -n {}'.format(adla))
        assert isinstance(result, list)
        assert len(result) >= 1

        result = self.cmd(
            'dla job pipeline show -n {} --pipeline-id {}'.format(
                adla, pipeline_id),
            checks=[
                JMESPathCheck('pipelineId', pipeline_id),
                JMESPathCheck('pipelineName', pipeline_name),
                JMESPathCheck('pipelineUri', pipeline_uri),
            ])

        assert isinstance(result['runs'], list)
        assert len(result['runs']) >= 1
Beispiel #22
0
    def test_resource_policyset(self, resource_group):
        policy_name = self.create_random_name('azure-cli-test-policy', 30)
        policy_display_name = self.create_random_name('test_policy', 20)
        policy_description = 'desc_for_test_policy_123'
        policyset_name = self.create_random_name('azure-cli-test-policyset',
                                                 30)
        policyset_display_name = self.create_random_name('test_policyset', 20)
        policyset_description = 'desc_for_test_policyset_123'
        curr_dir = os.path.dirname(os.path.realpath(__file__))
        rules_file = os.path.join(curr_dir, 'sample_policy_rule.json').replace(
            '\\', '\\\\')
        policyset_file = os.path.join(curr_dir,
                                      'sample_policy_set.json').replace(
                                          '\\', '\\\\')
        params_def_file = os.path.join(curr_dir,
                                       'sample_policy_param_def.json').replace(
                                           '\\', '\\\\')

        # create a policy
        policycreatecmd = 'policy definition create -n {} --rules {} --params {} --display-name {} --description {}'
        policy = self.cmd(
            policycreatecmd.format(policy_name, rules_file, params_def_file,
                                   policy_display_name,
                                   policy_description)).get_output_in_json()

        # create a policy set
        policyset = get_file_json(policyset_file)
        policyset[0]['policyDefinitionId'] = policy['id']
        with open(os.path.join(curr_dir, 'sample_policy_set.json'),
                  'w') as outfile:
            json.dump(policyset, outfile)
        self.cmd(
            'policy set-definition create -n {} --definitions @"{}" --display-name {} --description {}'
            .format(policyset_name, policyset_file, policyset_display_name,
                    policyset_description),
            checks=[
                JCheck('name', policyset_name),
                JCheck('displayName', policyset_display_name),
                JCheck('description', policyset_description)
            ])

        # update it
        new_policyset_description = policy_description + '_new'
        self.cmd('policy set-definition update -n {} --description {}'.format(
            policyset_name, new_policyset_description),
                 checks=JCheck('description', new_policyset_description))

        # list and show it
        self.cmd('policy set-definition list',
                 checks=JMESPathCheck(
                     "length([?name=='{}'])".format(policyset_name), 1))
        self.cmd('policy set-definition show -n {}'.format(policyset_name),
                 checks=[
                     JCheck('name', policyset_name),
                     JCheck('displayName', policyset_display_name)
                 ])

        # create a policy assignment on a resource group
        policy_assignment_name = self.create_random_name(
            'azurecli-test-policy-assignment', 40)
        policy_assignment_display_name = self.create_random_name(
            'test_assignment', 20)
        self.cmd(
            'policy assignment create -d {} -n {} --display-name {} -g {}'.
            format(policyset_name, policy_assignment_name,
                   policy_assignment_display_name, resource_group),
            checks=[
                JCheck('name', policy_assignment_name),
                JCheck('displayName', policy_assignment_display_name),
                JCheck('sku.name', 'A0'),
                JCheck('sku.tier', 'Free'),
            ])

        # delete the assignment
        self.cmd('policy assignment delete -n {} -g {}'.format(
            policy_assignment_name, resource_group))
        self.cmd('policy assignment list --disable-scope-strict-match')

        # delete the policy set
        self.cmd('policy set-definition delete -n {}'.format(policyset_name))
        time.sleep(10)  # ensure the policy is gone when run live.
        self.cmd('policy set-definition list',
                 checks=JCheck("length([?name=='{}'])".format(policyset_name),
                               0))
Beispiel #23
0
    def test_resource_policy(self, resource_group):
        policy_name = 'azure-cli-test-policy'
        policy_display_name = 'test_policy_123'
        policy_description = 'test_policy_123'
        curr_dir = os.path.dirname(os.path.realpath(__file__))
        rules_file = os.path.join(curr_dir, 'sample_policy_rule.json').replace(
            '\\', '\\\\')
        # create a policy
        self.cmd(
            'policy definition create -n {} --rules {} --display-name {} --description {}'
            .format(policy_name, rules_file, policy_display_name,
                    policy_description),
            checks=[
                JCheck('name', policy_name),
                JCheck('displayName', policy_display_name),
                JCheck('description', policy_description)
            ])

        # update it
        new_policy_description = policy_description + '_new'
        self.cmd('policy definition update -n {} --description {}'.format(
            policy_name, new_policy_description),
                 checks=JCheck('description', new_policy_description))

        # list and show it
        self.cmd('policy definition list',
                 checks=JMESPathCheck(
                     "length([?name=='{}'])".format(policy_name), 1))
        self.cmd('policy definition show -n {}'.format(policy_name),
                 checks=[
                     JCheck('name', policy_name),
                     JCheck('displayName', policy_display_name)
                 ])

        # create a policy assignment on a resource group
        policy_assignment_name = 'azurecli-test-policy-assignment'
        policy_assignment_display_name = 'test_assignment_123'
        self.cmd(
            'policy assignment create --policy {} -n {} --display-name {} -g {}'
            .format(policy_name, policy_assignment_name,
                    policy_assignment_display_name, resource_group),
            checks=[
                JCheck('name', policy_assignment_name),
                JCheck('displayName', policy_assignment_display_name),
            ])

        # listing at subscription level won't find the assignment made at a resource group
        import jmespath
        try:
            self.cmd(
                'policy assignment list',
                checks=JCheck(
                    "length([?name=='{}'])".format(policy_assignment_name), 0))
        except jmespath.exceptions.JMESPathTypeError:  # ok if query fails on None result
            pass

        # but enable --show-all works
        self.cmd('policy assignment list --disable-scope-strict-match',
                 checks=JCheck(
                     "length([?name=='{}'])".format(policy_assignment_name),
                     1))

        # delete the assignment
        self.cmd('policy assignment delete -n {} -g {}'.format(
            policy_assignment_name, resource_group))
        self.cmd('policy assignment list --disable-scope-strict-match')

        # delete the policy
        self.cmd('policy definition delete -n {}'.format(policy_name))
        time.sleep(10)  # ensure the policy is gone when run live.
        self.cmd('policy definition list',
                 checks=JCheck("length([?name=='{}'])".format(policy_name), 0))
Beispiel #24
0
    def body(self):
        rg = self.resource_group
        location = self.location
        hub = self.hub_name

        # Test 'az iot hub create'
        self.cmd('iot hub create -n {0} -g {1} --sku S1'.format(hub, rg),
                 checks=[
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('location', location),
                     JMESPathCheck('name', hub),
                     JMESPathCheck('sku.name', 'S1')
                 ])

        # Test 'az iot hub show-connection-string'
        conn_str_pattern = r'^HostName={0}\.azure-devices\.net;SharedAccessKeyName=iothubowner;SharedAccessKey='.format(
            hub)
        self.cmd('iot hub show-connection-string -n {0}'.format(hub),
                 checks=[
                     JMESPathPatternCheck('connectionString', conn_str_pattern)
                 ])

        self.cmd('iot hub show-connection-string -g {0}'.format(rg),
                 checks=[
                     JMESPathCheck('length([*])', 1),
                     JMESPathCheck('[0].name', hub),
                     JMESPathPatternCheck('[0].connectionString',
                                          conn_str_pattern)
                 ])

        # Test 'az iot hub update'
        property_to_update = 'properties.operationsMonitoringProperties.events.DeviceTelemetry'
        updated_value = 'Error, Information'
        self.cmd('iot hub update -n {0} --set {1}="{2}"'.format(
            hub, property_to_update, updated_value),
                 checks=[
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('location', location),
                     JMESPathCheck('name', hub),
                     JMESPathCheck('sku.name', 'S1'),
                     JMESPathCheck(property_to_update, updated_value)
                 ])

        # Test 'az iot hub show'
        self.cmd('iot hub show -n {0}'.format(hub),
                 checks=[
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('location', location),
                     JMESPathCheck('name', hub),
                     JMESPathCheck('sku.name', 'S1'),
                     JMESPathCheck(property_to_update, updated_value)
                 ])

        # Test 'az iot hub list'
        self.cmd('iot hub list -g {0}'.format(rg),
                 checks=[
                     JMESPathCheck('length([*])', 1),
                     JMESPathCheck('[0].resourceGroup', rg),
                     JMESPathCheck('[0].location', location),
                     JMESPathCheck('[0].name', hub),
                     JMESPathCheck('[0].sku.name', 'S1')
                 ])

        # Test 'az iot hub sku list'
        self.cmd('iot hub list-skus -n {0}'.format(hub),
                 checks=[
                     JMESPathCheck('length([*])', 3),
                     JMESPathCheck('[0].sku.name', 'S1'),
                     JMESPathCheck('[1].sku.name', 'S2'),
                     JMESPathCheck('[2].sku.name', 'S3')
                 ])

        # Test 'az iot hub policy create'
        policy_name = 'test_policy'
        permissions = 'RegistryWrite ServiceConnect DeviceConnect'
        self.cmd(
            'iot hub policy create --hub-name {0} -n {1} --permissions {2}'.
            format(hub, policy_name, permissions),
            checks=NoneCheck())

        # Test 'az iot hub policy list'
        self.cmd('iot hub policy list --hub-name {0}'.format(hub),
                 checks=[JMESPathCheck('length([*])', 6)])

        # Test 'az iot hub policy show'
        self.cmd('iot hub policy show --hub-name {0} -n {1}'.format(
            hub, policy_name),
                 checks=[
                     JMESPathCheck('keyName', policy_name),
                     JMESPathCheck(
                         'rights',
                         'RegistryWrite, ServiceConnect, DeviceConnect')
                 ])

        # Test 'az iot hub policy delete'
        self.cmd('iot hub policy delete --hub-name {0} -n {1}'.format(
            hub, policy_name),
                 checks=NoneCheck())
        self.cmd('iot hub policy list --hub-name {0}'.format(hub),
                 checks=[JMESPathCheck('length([*])', 5)])

        # Test 'az iot hub consumer-group create'
        consumer_group_name = 'cg1'
        self.cmd('iot hub consumer-group create --hub-name {0} -n {1}'.format(
            hub, consumer_group_name),
                 checks=[JMESPathCheck('name', consumer_group_name)])

        # Test 'az iot hub consumer-group show'
        self.cmd('iot hub consumer-group show --hub-name {0} -n {1}'.format(
            hub, consumer_group_name),
                 checks=[JMESPathCheck('name', consumer_group_name)])

        # Test 'az iot hub consumer-group list'
        self.cmd('iot hub consumer-group list --hub-name {0}'.format(hub),
                 checks=[
                     JMESPathCheck('length([*])', 2),
                     JMESPathCheck('[0]', '$Default'),
                     JMESPathCheck('[1]', consumer_group_name)
                 ])

        # Test 'az iot hub consumer-group delete'
        self.cmd('iot hub consumer-group delete --hub-name {0} -n {1}'.format(
            hub, consumer_group_name),
                 checks=NoneCheck())

        self.cmd('iot hub consumer-group list --hub-name {0}'.format(hub),
                 checks=[
                     JMESPathCheck('length([*])', 1),
                     JMESPathCheck('[0]', '$Default')
                 ])

        # Test 'az iot hub job list'
        self.cmd('iot hub job list --hub-name {0}'.format(hub),
                 checks=NoneCheck())

        # Test 'az iot hub job show'
        job_id = 'fake-job'
        expected_exception = 'Job not found with ID'
        self.cmd('iot hub job show --hub-name {0} --job-id {1}'.format(
            hub, job_id),
                 allowed_exceptions=expected_exception)

        # Test 'az iot hub job cancel'
        expected_exception = 'JobNotFound'
        self.cmd('iot hub job cancel --hub-name {0} --job-id {1}'.format(
            hub, job_id),
                 allowed_exceptions=expected_exception)

        # Test 'az iot device create'
        device_1 = self.device_id_1
        self.cmd('iot device create --hub-name {0} -d {1}'.format(
            hub, device_1),
                 checks=[
                     JMESPathCheck('deviceId', device_1),
                     JMESPathCheck('status', 'enabled'),
                     JMESPathCheck('statusReason', None),
                     JMESPathCheck('connectionState', 'Disconnected')
                 ])

        device_2 = self.device_id_2
        primary_thumbprint = 'A361EA6A7119A8B0B7BBFFA2EAFDAD1F9D5BED8C'
        secondary_thumbprint = '14963E8F3BA5B3984110B3C1CA8E8B8988599087'
        self.cmd(
            'iot device create --hub-name {0} -d {1} --x509 --primary-thumbprint {2} --secondary-thumbprint {3}'
            .format(hub, device_2, primary_thumbprint, secondary_thumbprint),
            checks=[
                JMESPathCheck('deviceId', device_2),
                JMESPathCheck('status', 'enabled'),
                JMESPathCheck('statusReason', None),
                JMESPathCheck('connectionState', 'Disconnected'),
                JMESPathCheck('authentication.symmetricKey.primaryKey', None),
                JMESPathCheck('authentication.symmetricKey.secondaryKey',
                              None),
                JMESPathCheck(
                    'authentication.x509Thumbprint.primaryThumbprint',
                    primary_thumbprint),
                JMESPathCheck(
                    'authentication.x509Thumbprint.secondaryThumbprint',
                    secondary_thumbprint)
            ])

        # Test 'az iot device show-connection-string'
        conn_str_pattern = r'^HostName={0}\.azure-devices\.net;DeviceId={1};SharedAccessKey='.format(
            hub, device_1)
        self.cmd(
            'iot device show-connection-string --hub-name {0} -d {1}'.format(
                hub, device_1),
            checks=[
                JMESPathPatternCheck('connectionString', conn_str_pattern)
            ])

        connection_string = 'HostName={0}.azure-devices.net;DeviceId={1};x509=true'.format(
            hub, device_2)
        self.cmd(
            'iot device show-connection-string --hub-name {0} -d {1}'.format(
                hub, device_2),
            checks=[JMESPathCheck('connectionString', connection_string)])

        device_id_pattern = r'^test\-device\-\d$'
        self.cmd(
            'iot device show-connection-string --hub-name {0}'.format(hub),
            checks=[
                JMESPathCheck('length([*])', 2),
                JMESPathPatternCheck('[0].deviceId', device_id_pattern),
                JMESPathPatternCheck('[1].deviceId', device_id_pattern)
            ])

        # Test 'az iot device show'
        self.cmd('iot device show --hub-name {0} -d {1}'.format(hub, device_1),
                 checks=[
                     JMESPathCheck('deviceId', device_1),
                     JMESPathCheck('status', 'enabled'),
                     JMESPathCheck('statusReason', None),
                     JMESPathCheck('connectionState', 'Disconnected')
                 ])

        # Test 'az iot device update'
        status_reason = 'TestReason'
        self.cmd(
            'iot device update --hub-name {0} -d {1} --set statusReason={2}'.
            format(hub, device_2, status_reason),
            checks=[
                JMESPathCheck('deviceId', device_2),
                JMESPathCheck('status', 'enabled'),
                JMESPathCheck('statusReason', status_reason),
                JMESPathCheck('connectionState', 'Disconnected'),
                JMESPathCheck('authentication.symmetricKey.primaryKey', None),
                JMESPathCheck('authentication.symmetricKey.secondaryKey',
                              None),
                JMESPathCheck(
                    'authentication.x509Thumbprint.primaryThumbprint',
                    primary_thumbprint),
                JMESPathCheck(
                    'authentication.x509Thumbprint.secondaryThumbprint',
                    secondary_thumbprint)
            ])

        # Test 'az iot device list'
        self.cmd('iot device list --hub-name {0}'.format(hub),
                 checks=[
                     JMESPathCheck('length([*])', 2),
                     JMESPathPatternCheck('[0].deviceId', device_id_pattern),
                     JMESPathPatternCheck('[1].deviceId', device_id_pattern)
                 ])

        # Test 'az iot device message send'
        self.cmd('iot device message send --hub-name {0} -d {1}'.format(
            hub, device_1),
                 checks=NoneCheck())

        # Test 'az iot device message receive'
        self.cmd('iot device message receive --hub-name {0} -d {1}'.format(
            hub, device_1),
                 checks=NoneCheck())

        # Test 'az iot device message complete'
        lock_token = '00000000-0000-0000-0000-000000000000'
        expected_exception = 'PreconditionFailed'
        self.cmd(
            'iot device message complete --hub-name {0} -d {1} --lock-token {2}'
            .format(hub, device_1, lock_token),
            allowed_exceptions=expected_exception)

        # Test 'az iot device message reject'
        self.cmd(
            'iot device message reject --hub-name {0} -d {1} --lock-token {2}'.
            format(hub, device_1, lock_token),
            allowed_exceptions=expected_exception)

        # Test 'az iot device message abandon'
        self.cmd(
            'iot device message abandon --hub-name {0} -d {1} --lock-token {2}'
            .format(hub, device_1, lock_token),
            allowed_exceptions=expected_exception)

        # Test 'az iot hub show-quota-metrics'
        self.cmd('iot hub show-quota-metrics -n {0}'.format(hub),
                 checks=[
                     JMESPathCheck('length([*])', 2),
                     JMESPathCheck('[0].name', 'TotalMessages'),
                     JMESPathCheck('[0].maxValue', 400000),
                     JMESPathCheck('[1].name', 'TotalDeviceCount'),
                     JMESPathCheck('[1].maxValue', 500000)
                 ])

        # Test 'az iot hub show-stats'
        device_count_pattern = r'^\d$'
        self.cmd('iot hub show-stats -n {0}'.format(hub),
                 checks=[
                     JMESPathPatternCheck('disabledDeviceCount',
                                          device_count_pattern),
                     JMESPathPatternCheck('enabledDeviceCount',
                                          device_count_pattern),
                     JMESPathPatternCheck('totalDeviceCount',
                                          device_count_pattern)
                 ])

        # Test 'az iot device delete'
        self.cmd('iot device delete --hub-name {0} -d {1}'.format(
            hub, device_1),
                 checks=NoneCheck())
        self.cmd('iot device delete --hub-name {0} -d {1}'.format(
            hub, device_2),
                 checks=NoneCheck())

        # Test 'az iot hub delete'
        self.cmd('iot hub delete -n {0}'.format(hub), checks=NoneCheck())