Beispiel #1
0
    def body(self):
        if self.playback:
            subscription_id = MOCKED_SUBSCRIPTION_ID
        else:
            subscription_id = self.cmd(
                'account list --query "[?isDefault].id" -o tsv')

        # use 'network security group' for testing as it is fast to create
        nsg1 = 'nsg1'
        nsg1_id = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Network/' \
                  'networkSecurityGroups/{}'.format(subscription_id,
                                                    self.source_group,
                                                    nsg1)
        nsg2 = 'nsg2'
        nsg2_id = nsg1_id.replace(nsg1, nsg2)

        self.cmd('network nsg create -g {} --name {}'.format(
            self.source_group, nsg1))
        self.cmd('network nsg create -g {} --name {}'.format(
            self.source_group, nsg2))

        # move
        self.cmd('resource move --ids {} {} --destination-group {}'.format(
            nsg1_id, nsg2_id, self.destination_group))

        # see they show up at destination
        self.cmd(
            'network nsg show -g {} -n {}'.format(self.destination_group,
                                                  nsg1),
            [JMESPathCheck('name', nsg1)])
        self.cmd(
            'network nsg show -g {} -n {}'.format(self.destination_group,
                                                  nsg2),
            [JMESPathCheck('name', nsg2)])
Beispiel #2
0
    def body(self):
        curr_dir = os.path.dirname(os.path.realpath(__file__))
        # same copy of the sample template file under current folder, but it is uri based now
        template_uri = 'https://raw.githubusercontent.com/Azure/azure-cli/master/src/' \
                       'command_modules/azure-cli-resource/tests/simple_deploy.json'
        parameters_file = os.path.join(
            curr_dir, 'simple_deploy_parameters.json').replace('\\', '\\\\')
        deployment_name = 'simple_deploy'  # auto-gen'd by command
        result = self.cmd(
            'group deployment create -g {} --template-uri {} --parameters @{}'.
            format(self.resource_group, template_uri, parameters_file),
            checks=[
                JMESPathCheck('properties.provisioningState', 'Succeeded'),
                JMESPathCheck('resourceGroup', self.resource_group),
            ])

        result = self.cmd('group deployment show -g {} -n {}'.format(
            self.resource_group, deployment_name),
                          checks=[JMESPathCheck('name', deployment_name)])

        self.cmd('group deployment delete -g {} -n {}'.format(
            self.resource_group, deployment_name))
        result = self.cmd('group deployment list -g {}'.format(
            self.resource_group))
        self.assertFalse(bool(result))
    def body(self):
        self.cmd('batch task create --job-id {} --json-file "{}"'.format(
            self.job_id, self.create_task_file_path),
                 checks=[
                     JMESPathCheck('id', self.task_id),
                     JMESPathCheck('commandLine', 'cmd /c dir /s')
                 ])

        task = self.cmd('batch task show --job-id {} --task-id {}'.format(
            self.job_id, self.task_id))
        self.assertEqual(task['userIdentity']['autoUser']['scope'], 'pool')
        self.assertEqual(task['authenticationTokenSettings']['access'][0],
                         'job')

        self.cmd('batch task delete --job-id {} --task-id {} --yes'.format(
            self.job_id, self.task_id))

        self.cmd(
            'batch task create --job-id {} --task-id aaa --command-line "echo hello"'
            .format(self.job_id),
            checks=[
                JMESPathCheck('id', 'aaa'),
                JMESPathCheck('commandLine', 'echo hello')
            ])

        self.cmd('batch task delete --job-id {} --task-id aaa --yes'.format(
            self.job_id))

        result = self.cmd(
            'batch task create --job-id {} --json-file "{}"'.format(
                self.job_id, self.create_tasks_file_path),
            checks=[JMESPathCheck('length(@)', 3)])
        self.assertIsNotNone(
            [i for i in result if i['taskId'] == 'xplatTask1'])
Beispiel #4
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 --debug'
                 .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 #5
0
    def body(self):
        app_id_uri = 'http://azureclitest-graph'
        display_name = 'azureclitest'

        # crerate app through general option
        self.cmd(
            'ad app create --display-name {} --homepage {} --identifier-uris {}'
            .format(display_name, app_id_uri, app_id_uri),
            checks=[JMESPathCheck('identifierUris[0]', app_id_uri)])

        # show/list app
        self.cmd('ad app show --id {}'.format(app_id_uri),
                 checks=[JMESPathCheck('identifierUris[0]', app_id_uri)])
        self.cmd('ad app list --display-name {}'.format(display_name),
                 checks=[
                     JMESPathCheck('[0].identifierUris[0]', app_id_uri),
                     JMESPathCheck('length([*])', 1)
                 ])

        # update app
        reply_uri = "http://azureclitest-replyuri"
        self.cmd('ad app update --id {} --reply-urls {}'.format(
            app_id_uri, reply_uri))
        self.cmd('ad app show --id {}'.format(app_id_uri),
                 checks=[JMESPathCheck('replyUrls[0]', reply_uri)])

        # delete app
        self.cmd('ad app delete --id {}'.format(app_id_uri))
        self.cmd('ad app list --identifier-uri {}'.format(app_id_uri),
                 checks=NoneCheck())
Beispiel #6
0
    def body(self):
        rg = self.resource_group
        env_name = 'docdbenv'
        arm_template = 'documentdb-webapp'

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

        artifact_sources = self.cmd(
            'lab artifact-source list -g {} --lab-name {}'.format(
                rg, LAB_NAME))

        # Create environment in the lab
        self.cmd('lab environment create -g {} --lab-name {} --name {} '
                 '--arm-template {} --artifact-source-name {} --parameters {}'.
                 format(rg, LAB_NAME, env_name, arm_template,
                        artifact_sources[0]['name'], ENV_PARAMTERS),
                 checks=[
                     JMESPathCheck('provisioningState', 'Succeeded'),
                     JMESPathCheck(
                         'type',
                         'Microsoft.DevTestLab/labs/users/environments')
                 ])

        # Delete environment from the lab
        self.cmd('lab environment delete -g {} --lab-name {} --name {}'.format(
            rg, LAB_NAME, env_name),
                 checks=[NoneCheck()])

        # Delete the lab
        self.cmd('lab delete -g {} --name {}'.format(rg, LAB_NAME),
                 checks=[NoneCheck()])
Beispiel #7
0
    def body(self):
        self.cmd('feature list', checks=[
            JMESPathCheck("length([?name=='Microsoft.Xrm/uxdevelopment'])", 1)
        ])

        self.cmd('feature list --namespace {}'.format('Microsoft.Network'), checks=[
            JMESPathCheck("length([?name=='Microsoft.Network/SkipPseudoVipGeneration'])", 1)
        ])
    def body(self):
        plan = 'webapp-linux-plan'
        webapp = 'webapp-linux1'
        self.cmd(
            'appservice plan create -g {} -n {} --sku S1 --is-linux'.format(
                self.resource_group, plan),
            checks=[
                JMESPathCheck('reserved',
                              True),  # this weird field means it is a linux
                JMESPathCheck('sku.name', 'S1'),
            ])
        self.cmd('webapp create -g {} -n {} --plan {}'.format(
            self.resource_group, webapp, plan),
                 checks=[
                     JMESPathCheck('name', webapp),
                 ])
        self.cmd('webapp config set -g {} -n {} --startup-file {}'.format(
            self.resource_group, webapp, 'process.json'),
                 checks=[JMESPathCheck('appCommandLine', 'process.json')])
        result = self.cmd(
            'webapp config container set -g {} -n {} --docker-custom-image-name {} --docker-registry-server-password {} --docker-registry-server-user {} --docker-registry-server-url {}'
            .format(self.resource_group, webapp, 'foo-image', 'foo-password',
                    'foo-user', 'foo-url'))
        self.assertEqual(
            set(x['value'] for x in result
                if x['name'] == 'DOCKER_REGISTRY_SERVER_PASSWORD'),
            set([None]))  # we mask the password

        result = self.cmd('webapp config container show -g {} -n {} '.format(
            self.resource_group, webapp))
        self.assertEqual(
            set(x['name'] for x in result),
            set([
                'DOCKER_REGISTRY_SERVER_URL',
                'DOCKER_REGISTRY_SERVER_USERNAME', 'DOCKER_CUSTOM_IMAGE_NAME',
                'DOCKER_REGISTRY_SERVER_PASSWORD'
            ]))
        self.assertEqual(
            set(x['value'] for x in result
                if x['name'] == 'DOCKER_REGISTRY_SERVER_PASSWORD'),
            set([None]))  # we mask the password
        sample = next(
            (x for x in result if x['name'] == 'DOCKER_REGISTRY_SERVER_URL'))
        self.assertEqual(
            sample, {
                'name': 'DOCKER_REGISTRY_SERVER_URL',
                'slotSetting': False,
                'value': 'foo-url'
            })
        self.cmd('webapp config container delete -g {} -n {}'.format(
            self.resource_group, webapp))
        result2 = self.cmd('webapp config container show -g {} -n {} '.format(
            self.resource_group, webapp),
                           checks=NoneCheck())
        self.assertEqual(result2, [])
Beispiel #9
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 #10
0
    def body(self):
        functionapp_name = 'functionappconsumption'
        location = 'westus'
        storage = 'functionaconstorage'

        self.cmd('storage account create --name {} -g {} -l {} --sku Standard_LRS'.format(storage, self.resource_group, location))
        self.cmd('functionapp create -g {} -n {} -c {} -s {}'.format(self.resource_group, functionapp_name, location, storage), checks=[
            JMESPathCheck('state', 'Running'),
            JMESPathCheck('name', functionapp_name),
            JMESPathCheck('hostNames[0]', functionapp_name + '.azurewebsites.net')
        ])

        self.cmd('functionapp delete -g {} -n {}'.format(self.resource_group, functionapp_name))
Beispiel #11
0
 def body(self):
     self.cmd('provider operation show --namespace microsoft.compute', checks=[
         JMESPathCheck('id',
                       '/providers/Microsoft.Authorization/providerOperations/Microsoft.Compute'),
         JMESPathCheck('type', 'Microsoft.Authorization/providerOperations')
     ])
     self.cmd('provider operation show --namespace microsoft.compute --api-version 2015-07-01',
              checks=[
                  JMESPathCheck(
                      'id',
                      '/providers/Microsoft.Authorization/providerOperations/Microsoft.Compute'),
                  JMESPathCheck('type', 'Microsoft.Authorization/providerOperations')
              ])
    def body(self):
        # test create certificate with default set
        self.cmd(
            'batch certificate create --thumbprint {} --certificate-file "{}"'.
            format(self.cert_thumbprint, self.create_cert_file_path),
            checks=[
                JMESPathCheck('thumbprint', self.cert_thumbprint),
                JMESPathCheck('thumbprintAlgorithm', 'sha1'),
                JMESPathCheck('state', 'active')
            ])

        # test create account with default set
        self.cmd('batch certificate list',
                 checks=[
                     JMESPathCheck('length(@)', 1),
                     JMESPathCheck('[0].thumbprint', self.cert_thumbprint),
                 ])

        self.cmd("batch certificate delete --thumbprint {} --yes".format(
            self.cert_thumbprint))

        self.cmd('batch certificate show --thumbprint {}'.format(
            self.cert_thumbprint),
                 checks=[
                     JMESPathCheck('thumbprint', self.cert_thumbprint),
                     JMESPathCheck('thumbprintAlgorithm', 'sha1'),
                     JMESPathCheck('state', 'deleting')
                 ])
Beispiel #13
0
    def body(self):
        app_id_uri = 'http://azureclitest-graph'
        # create app through express option
        self.cmd('ad sp create-for-rbac -n {}'.format(app_id_uri),
                 checks=[JMESPathCheck('name', app_id_uri)])

        # show/list app
        self.cmd('ad app show --id {}'.format(app_id_uri),
                 checks=[JMESPathCheck('identifierUris[0]', app_id_uri)])
        self.cmd('ad app list --identifier-uri {}'.format(app_id_uri),
                 checks=[
                     JMESPathCheck('[0].identifierUris[0]', app_id_uri),
                     JMESPathCheck('length([*])', 1)
                 ])

        # show/list sp
        self.cmd(
            'ad sp show --id {}'.format(app_id_uri),
            checks=[JMESPathCheck('servicePrincipalNames[0]', app_id_uri)])
        self.cmd('ad sp list --spn {}'.format(app_id_uri),
                 checks=[
                     JMESPathCheck('[0].servicePrincipalNames[0]', app_id_uri),
                     JMESPathCheck('length([*])', 1),
                 ])
        self.cmd('ad sp reset-credentials -n {}'.format(app_id_uri),
                 checks=[JMESPathCheck('name', app_id_uri)])
        # cleanup
        self.cmd('ad sp delete --id {}'.format(app_id_uri), None)
        self.cmd('ad sp list --spn {}'.format(app_id_uri), checks=NoneCheck())
        self.cmd('ad app delete --id {}'.format(app_id_uri), None)
        self.cmd('ad app list --identifier-uri {}'.format(app_id_uri),
                 checks=NoneCheck())
Beispiel #14
0
    def body(self):
        functionapp_name = 'functionapp-e2e3'
        plan = 'functionapp-e2e-plan'
        storage = 'functionappplanstorage'
        self.cmd('appservice plan create -g {} -n {}'.format(self.resource_group, plan))
        self.cmd('appservice plan list -g {}'.format(self.resource_group))

        self.cmd('storage account create --name {} -g {} -l westus --sku Standard_LRS'.format(storage, self.resource_group))

        self.cmd('functionapp create -g {} -n {} -p {} -s {}'.format(self.resource_group, functionapp_name, plan, storage), checks=[
            JMESPathCheck('state', 'Running'),
            JMESPathCheck('name', functionapp_name),
            JMESPathCheck('hostNames[0]', functionapp_name + '.azurewebsites.net')
        ])

        self.cmd('functionapp delete -g {} -n {}'.format(self.resource_group, functionapp_name))
Beispiel #15
0
    def body(self):
        if self.playback:
            subscription_id = MOCKED_SUBSCRIPTION_ID
        else:
            subscription_id = self.cmd('account list --query "[?isDefault].id" -o tsv')
        role_name = 'cli-test-role3'
        template = {
            "Name": role_name,
            "Description": "Can monitor compute, network and storage, and restart virtual machines",
            "Actions": ["Microsoft.Compute/*/read",
                        "Microsoft.Compute/virtualMachines/start/action",
                        "Microsoft.Compute/virtualMachines/restart/action",
                        "Microsoft.Network/*/read",
                        "Microsoft.Storage/*/read",
                        "Microsoft.Authorization/*/read",
                        "Microsoft.Resources/subscriptions/resourceGroups/read",
                        "Microsoft.Resources/subscriptions/resourceGroups/resources/read",
                        "Microsoft.Insights/alertRules/*",
                        "Microsoft.Support/*"],
            "AssignableScopes": ["/subscriptions/{}".format(subscription_id)]
        }
        _, temp_file = tempfile.mkstemp()
        with open(temp_file, 'w') as f:
            json.dump(template, f)

        self.cmd('role definition create --role-definition {}'.format(temp_file.replace('\\', '\\\\')), None)
        self.cmd('role definition list -n {}'.format(role_name),
                 checks=[JMESPathCheck('[0].properties.roleName', role_name)])
        self.cmd('role definition delete -n {}'.format(role_name), None)
        self.cmd('role definition list -n {}'.format(role_name), NoneCheck())
Beispiel #16
0
    def body(self):
        vault = _create_keyvault(self, self.keyvault_name, self.resource_group, self.location,
                                 additional_args='--enable-soft-delete true')
        kv = self.keyvault_name

        # add all purge permissions to default the access policy
        default_policy = vault['properties']['accessPolicies'][0]
        certPerms = default_policy['permissions']['certificates']
        keyPerms = default_policy['permissions']['keys']
        secretPerms = default_policy['permissions']['secrets']

        for p in [certPerms, keyPerms, secretPerms]:
            p.append('purge')

        cmdstr = 'keyvault set-policy -n {} --object-id {} --key-permissions {} --secret-permissions {} --certificate-permissions {}'.format(
            kv, default_policy['objectId'], ' '.join(keyPerms), ' '.join(secretPerms), ' '.join(certPerms))
        print(cmdstr)

        self.cmd(cmdstr)

        # create, delete, restore, and purge a secret
        self.cmd('keyvault secret set --vault-name {} -n secret1 --value ABC123'.format(kv),
                 checks=JMESPathCheck('value', 'ABC123'))
        self._delete_entity('secret', 'secret1')
        self._recover_entity('secret', 'secret1')
        self._delete_entity('secret', 'secret1')
        self.cmd('keyvault secret purge --vault-name {} -n secret1'.format(kv))

        # create, delete, restore, and purge a key
        self.cmd('keyvault key create --vault-name {} -n key1 -p software'.format(kv),
                 checks=JMESPathCheck('attributes.enabled', True))
        self._delete_entity('key', 'key1')
        self._recover_entity('key', 'key1')
        self._delete_entity('key', 'key1')
        self.cmd('keyvault key purge --vault-name {} -n key1'.format(kv))

        # create, delete, restore, and purge a certificate
        pem_plain_file = os.path.join(TEST_DIR, 'import_pem_plain.pem')
        pem_policy_path = os.path.join(TEST_DIR, 'policy_import_pem.json')
        self.cmd('keyvault certificate import --vault-name {} -n cert1 --file "{}" -p @"{}"'.format(kv,
                                                                                                    pem_plain_file,
                                                                                                    pem_policy_path))
        self._delete_entity('certificate', 'cert1')
        self.cmd('keyvault certificate purge --vault-name {} -n cert1'.format(kv))

        self.cmd('keyvault delete -n {}'.format(kv))
        self.cmd('keyvault purge -n {} -l {}'.format(kv, self.location))
Beispiel #17
0
 def _test_keyvault_certificate_contacts(self):
     kv = self.keyvault_name
     self.cmd(
         'keyvault certificate contact add --vault-name {} --email [email protected] --name "John Doe" --phone 123-456-7890'.format(
             kv))
     self.cmd(
         'keyvault certificate contact add --vault-name {} --email [email protected] '.format(
             kv))
     self.cmd('keyvault certificate contact list --vault-name {}'.format(kv),
              checks=JMESPathCheck('length(contactList)', 2))
     self.cmd(
         'keyvault certificate contact delete --vault-name {} --email [email protected]'.format(
             kv))
     self.cmd('keyvault certificate contact list --vault-name {}'.format(kv), checks=[
         JMESPathCheck('length(contactList)', 1),
         JMESPathCheck('contactList[0].emailAddress', '*****@*****.**')
     ])
Beispiel #18
0
    def body(self):
        rg = 'sfcli6'
        name = 'sfcli6'

        self.cmd(
            'sf cluster node remove -g {} -n {} --node-type nt1vm  --number-of-nodes-to-remove 1'
            .format(rg, name),
            checks=[JMESPathCheck('nodeTypes[0].vmInstanceCount', 5)])
Beispiel #19
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 #20
0
 def body(self):
     plan = 'webapp-git-plan5'
     webapp = 'web-git-test2'
     # You can create and use any repros with the 3 files under "./sample_web"
     test_git_repo = 'https://github.com/yugangw-msft/azure-site-test'
     self.cmd('appservice plan create -g {} -n {} --sku S1'.format(
         self.resource_group, plan))
     self.cmd('webapp create -g {} -n {} --plan {}'.format(
         self.resource_group, webapp, plan))
     self.cmd(
         'webapp deployment source config -g {} -n {} --repo-url {} --branch {} --manual-integration'
         .format(self.resource_group, webapp, test_git_repo, 'master'),
         checks=[
             JMESPathCheck('repoUrl', test_git_repo),
             JMESPathCheck('isMercurial', False),
             JMESPathCheck('branch', 'master')
         ])
     self.cmd('webapp deployment source show -g {} -n {}'.format(
         self.resource_group, webapp),
              checks=[
                  JMESPathCheck('repoUrl', test_git_repo),
                  JMESPathCheck('isMercurial', False),
                  JMESPathCheck('branch', 'master')
              ])
     self.cmd('webapp deployment source delete -g {} -n {}'.format(
         self.resource_group, webapp),
              checks=[JMESPathCheck('repoUrl', None)])
    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), checks=[
            JMESPathCheck("[?name=='s4']|[0].slotSetting", True),
            JMESPathCheck("[?name=='s3']|[0].slotSetting", False),
        ])

        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 #22
0
    def body(self):
        plan = 'webapp-git-plan5'
        webapp = 'web-git-test2'

        # You can create and use any repros with the 3 files under "./sample_web"
        test_git_repo = 'https://github.com/yugangw-msft/azure-site-test'

        self.cmd('appservice plan create -g {} -n {} --sku S1'.format(self.resource_group, plan))
        self.cmd('webapp create -g {} -n {} --plan {}'.format(self.resource_group, webapp, plan))

        self.cmd('webapp deployment source config -g {} -n {} --repo-url {} --branch {} --manual-integration'.format(self.resource_group, webapp, test_git_repo, 'master'), checks=[
            JMESPathCheck('repoUrl', test_git_repo),
            JMESPathCheck('isMercurial', False),
            JMESPathCheck('branch', 'master')
        ])

        '''
        import time
        time.sleep(30) # 30 seconds should be enough for the deployment finished(Skipped under playback mode)

        import requests
        r = requests.get('http://{}.azurewebsites.net'.format(webapp))
        #verify the web page
        self.assertTrue('Hello world' in str(r.content))
        '''

        self.cmd('webapp deployment source show -g {} -n {}'.format(self.resource_group, webapp), checks=[
            JMESPathCheck('repoUrl', test_git_repo),
            JMESPathCheck('isMercurial', False),
            JMESPathCheck('branch', 'master')
        ])
        self.cmd('webapp deployment source delete -g {} -n {}'.format(self.resource_group, webapp), checks=[
            JMESPathCheck('repoUrl', None)
        ])
Beispiel #23
0
    def body(self):
        rg = 'sfcli2'
        name = 'sfcli2'

        self.cmd(
            'sf cluster setting set --resource-group {} --name {} --section NamingService --parameter MaxOperationTimeout --value 10001'
            .format(rg, name),
            checks=[
                JMESPathCheck('fabricSettings[1].name', 'NamingService'),
                JMESPathCheck('fabricSettings[1].parameters[0].name',
                              'MaxOperationTimeout'),
                JMESPathCheck('fabricSettings[1].parameters[0].value', '10001')
            ])

        self.cmd(
            'sf cluster setting remove --resource-group {} --name {} --section NamingService --parameter MaxOperationTimeout'
            .format(rg, name),
            checks=[JMESPathCheck('length(fabricSettings)', 1)])
Beispiel #24
0
    def body(self):
        rg = 'sfcli7'
        name = 'sfcli7'
        location = 'westus'

        self.cmd(
            'sf cluster create --resource-group {} --location {} --cluster-size 1 --secret-identifier https://sfcli4.vault.azure.net/secrets/sfcli4201708250843/2b9981be18164360a21e6face7b67a77 --vm-password User@123456789'
            .format(rg, location),
            checks=[JMESPathCheck('cluster.name', name)])
Beispiel #25
0
    def body(self):
        rg = 'sfcli6'
        name = 'sfcli6'

        reliability_level = 'Silver'
        self.cmd(
            'sf cluster reliability update --resource-group {} --name {} --reliability-level {}'
            .format(rg, name, reliability_level),
            checks=[JMESPathCheck('reliabilityLevel', reliability_level)])
Beispiel #26
0
    def body(self):
        plan = 'webapp-ssl-test-plan'

        # Cert Generated using
        # https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-configure-ssl-certificate#bkmk_ssopenssl

        pfx_file = os.path.join(TEST_DIR, 'server.pfx')
        cert_password = '******'
        cert_thumbprint = 'DB2BA6898D0B330A93E7F69FF505C61EF39921B6'
        self.cmd('appservice plan create -g {} -n {} --sku B1'.format(
            self.resource_group, plan))
        self.cmd('appservice web create -g {} -n {} --plan {}'.format(
            self.resource_group, self.webapp_name, plan, self.location))
        self.cmd(
            'appservice web config ssl upload -g {} -n {} --certificate-file "{}" --certificate-password {}'
            .format(self.resource_group, self.webapp_name, pfx_file,
                    cert_password),
            checks=[JMESPathCheck('thumbprint', cert_thumbprint)])
        self.cmd(
            'appservice web config ssl bind -g {} -n {} --certificate-thumbprint {} --ssl-type {}'
            .format(self.resource_group, self.webapp_name, cert_thumbprint,
                    'SNI'),
            checks=[
                JMESPathCheck(
                    "hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].sslState"
                    .format(self.webapp_name), 'SniEnabled'),
                JMESPathCheck(
                    "hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].thumbprint"
                    .format(self.webapp_name), cert_thumbprint)
            ])
        self.cmd(
            'appservice web config ssl unbind -g {} -n {} --certificate-thumbprint {}'
            .format(self.resource_group, self.webapp_name, cert_thumbprint),
            checks=[
                JMESPathCheck(
                    "hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].sslState"
                    .format(self.webapp_name), 'Disabled'),
            ])
        self.cmd(
            'appservice web config ssl delete -g {} --certificate-thumbprint {}'
            .format(self.resource_group, cert_thumbprint))
        self.cmd('appservice web delete -g {} -n {}'.format(
            self.resource_group, self.webapp_name))
Beispiel #27
0
    def body(self):
        curr_dir = os.path.dirname(os.path.realpath(__file__))
        template_file = os.path.join(curr_dir, 'test-template.json').replace(
            '\\', '\\\\')
        parameters_file = os.path.join(curr_dir, 'test-params.json').replace(
            '\\', '\\\\')
        object_file = os.path.join(curr_dir,
                                   'test-object.json').replace('\\', '\\\\')
        deployment_name = 'azure-cli-deployment'

        subnet_id = self.cmd(
            'network vnet create -g {} -n vnet1 --subnet-name subnet1'.format(
                self.resource_group))['newVNet']['subnets'][0]['id']

        self.cmd(
            'group deployment validate -g {} --template-file {} --parameters @"{}" --parameters subnetId="{}" --parameters backendAddressPools=@"{}"'
            .format(self.resource_group, template_file, parameters_file,
                    subnet_id, object_file),
            checks=[
                JMESPathCheck('properties.provisioningState', 'Succeeded')
            ])

        self.cmd(
            'group deployment create -g {} -n {} --template-file {} --parameters @"{}" --parameters subnetId="{}" --parameters backendAddressPools=@"{}"'
            .format(self.resource_group, deployment_name, template_file,
                    parameters_file, subnet_id, object_file),
            checks=[
                JMESPathCheck('properties.provisioningState', 'Succeeded'),
                JMESPathCheck('resourceGroup', self.resource_group),
            ])

        self.cmd('group deployment list -g {}'.format(self.resource_group),
                 checks=[
                     JMESPathCheck('[0].name', deployment_name),
                     JMESPathCheck('[0].resourceGroup', self.resource_group)
                 ])
        self.cmd('group deployment show -g {} -n {}'.format(
            self.resource_group, deployment_name),
                 checks=[
                     JMESPathCheck('name', deployment_name),
                     JMESPathCheck('resourceGroup', self.resource_group)
                 ])
        self.cmd('group deployment operation list -g {} -n {}'.format(
            self.resource_group, deployment_name),
                 checks=[
                     JMESPathCheck('length([])', 2),
                     JMESPathCheck('[0].resourceGroup', self.resource_group)
                 ])
Beispiel #28
0
 def body(self):
     s = self
     rg = self.resource_group
     s.cmd('group create -n {} -l westus'.format(rg), checks=[
         JMESPathCheck('name', rg),
     ])
     s.cmd('group exists -n {}'.format(rg), checks=BooleanCheck(True))
     s.cmd('group wait --exists -n {}'.format(rg), checks=NoneCheck())
     s.cmd('group delete -n {} --no-wait --yes'.format(rg), checks=NoneCheck())
     s.cmd('group wait --deleted -n {}'.format(rg), checks=NoneCheck())
     s.cmd('group exists -n {}'.format(rg), checks=NoneCheck())
Beispiel #29
0
    def body(self):
        rg = 'appcanary-rg'
        name = 'appcanary'

        durability_level = 'Bronze'
        self.cmd(
            'sf cluster durability update --resource-group {} --name {} --durability-level {} --node-type FE'
            .format(rg, name, durability_level),
            checks=[
                JMESPathCheck('nodeTypes[0].durabilityLevel', durability_level)
            ])
Beispiel #30
0
    def body(self):
        appservice_plan = 'cli_res_create_plan'
        webapp = 'clirescreateweb'

        self.cmd('resource create -g {} -n {} --resource-type Microsoft.web/serverFarms '
                 '--is-full-object --properties "{{\\"location\\":\\"{}\\",\\"sku\\":{{\\"name\\":'
                 '\\"B1\\",\\"tier\\":\\"BASIC\\"}}}}"'.format(self.resource_group,
                                                               appservice_plan,
                                                               self.location),
                 checks=[JMESPathCheck('name', appservice_plan)])

        result = self.cmd(
            'resource create -g {} -n {} --resource-type Microsoft.web/sites --properties '
            '"{{\\"serverFarmId\\":\\"{}\\"}}"'.format(self.resource_group,
                                                       webapp,
                                                       appservice_plan),
            checks=[JMESPathCheck('name', webapp)])

        app_settings_id = result['id'] + '/config/appsettings'
        self.cmd('resource create --id {} --properties "{{\\"key2\\":\\"value12\\"}}"'.format(
            app_settings_id), checks=[JMESPathCheck('properties.key2', 'value12')])