Ejemplo n.º 1
0
    def test_create_for_rbac_with_secret(self, resource_group):

        subscription_id = self.cmd(
            'account list --query "[?isDefault].id"').get_output_in_json()
        scope = '/subscriptions/{}'.format(subscription_id[0])
        sp_name = 'http://{}'.format(resource_group)

        try:
            self.cmd(
                'ad sp create-for-rbac -n {0} --scopes {1} {1}/resourceGroups/{2}'
                .format(sp_name, scope, resource_group),
                checks=[JMESPathCheckV2('name', sp_name)])
            self.cmd('role assignment list --assignee {} --scope {}'.format(
                sp_name, scope),
                     checks=[JMESPathCheckV2("length([])", 1)])
            self.cmd('role assignment list --assignee {} -g {}'.format(
                sp_name, resource_group),
                     checks=[JMESPathCheckV2("length([])", 1)])
            self.cmd('role assignment delete --assignee {} -g {}'.format(
                sp_name, resource_group),
                     checks=NoneCheck())
            self.cmd('role assignment delete --assignee {}'.format(sp_name),
                     checks=NoneCheck())
        finally:
            self.cmd('ad app delete --id {}'.format(sp_name))
Ejemplo n.º 2
0
    def test_webapp_slot_swap(self, resource_group, resource_group_location):
        plan = 'slot-swap-plan2'
        webapp = 'slot-swap-web2'
        plan_result = self.cmd('appservice plan create -g {} -n {} --sku S1'.format(resource_group, plan)).get_output_in_json()
        self.cmd('webapp create -g {} -n {} --plan {}'.format(resource_group, 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'

        self.cmd('webapp config appsettings set -g {} -n {} --slot-settings s1=prod'.format(resource_group, webapp))

        # create an empty slot
        self.cmd('webapp deployment slot create -g {} -n {} --slot {}'.format(resource_group, webapp, slot))

        self.cmd('webapp config appsettings set -g {} -n {} --slot-settings s1=slot --slot {}'.format(resource_group, webapp, slot))

        # swap with preview
        self.cmd('webapp deployment slot swap -g {} -n {} -s {} --action preview'.format(resource_group, webapp, slot))
        self.cmd('webapp config appsettings list -g {} -n {} --slot {}'.format(resource_group, webapp, slot), checks=[
            JMESPathCheckV2("[?name=='s1']|[0].value", 'prod')
        ])

        # complete the swap
        self.cmd('webapp deployment slot swap -g {} -n {} -s {}'.format(resource_group, webapp, slot))
        self.cmd('webapp config appsettings list -g {} -n {} --slot {}'.format(resource_group, webapp, slot), checks=[
            JMESPathCheckV2("[?name=='s1']|[0].value", 'slot')
        ])

        # reset
        self.cmd('webapp deployment slot swap -g {} -n {} -s {} --action reset'.format(resource_group, webapp, slot))
        self.cmd('webapp config appsettings list -g {} -n {} --slot {}'.format(resource_group, webapp, slot), checks=[
            JMESPathCheckV2("[?name=='s1']|[0]", None)
        ])
Ejemplo n.º 3
0
 def test_traffic_routing(self, resource_group):
     webapp = 'clitestwebtraffic'
     plan_result = self.cmd(
         'appservice plan create -g {} -n {} --sku S1'.format(
             resource_group, 'clitesttrafficplan')).get_output_in_json()
     self.cmd('webapp create -g {} -n {} --plan {}'.format(
         resource_group, 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'
     # create an empty slot
     self.cmd('webapp deployment slot create -g {} -n {} --slot {}'.format(
         resource_group, webapp, slot))
     self.cmd('webapp traffic-routing set -g {} -n {} -d {}=15'.format(
         resource_group, webapp, slot),
              checks=[
                  JMESPathCheckV2("[0].actionHostName",
                                  slot + '.azurewebsites.net'),
                  JMESPathCheckV2("[0].reroutePercentage", 15.0)
              ])
     self.cmd('webapp traffic-routing show -g {} -n {}'.format(
         resource_group, webapp),
              checks=[
                  JMESPathCheckV2("[0].actionHostName",
                                  slot + '.azurewebsites.net'),
                  JMESPathCheckV2("[0].reroutePercentage", 15.0)
              ])
     self.cmd('webapp traffic-routing clear -g {} -n {}'.format(
         resource_group, webapp))
Ejemplo n.º 4
0
 def test_win_webapp_quick_create(self, resource_group, resource_group_location):
     webapp_name = 'webapp-quick'
     plan = 'plan-quick'
     self.cmd('appservice plan create -g {} -n {}'.format(resource_group, plan))
     r = self.cmd('webapp create -g {} -n {} --plan {} --deployment-local-git -r "node|6.1"'.format(resource_group, webapp_name, plan)).get_output_in_json()
     self.assertTrue(r['ftpPublishingUrl'].startswith('ftp://'))
     self.cmd('webapp config appsettings list -g {} -n {}'.format(resource_group, webapp_name, checks=[
         JMESPathCheckV2('[0].name', 'WEBSITE_NODE_DEFAULT_VERSION'),
         JMESPathCheckV2('[0].value', '6.1.0'),
     ]))
Ejemplo n.º 5
0
 def test_linux_webapp_quick_create(self, resource_group):
     webapp_name = 'webapp-quick-linux'
     plan = 'plan-quick-linux'
     self.cmd('appservice plan create -g {} -n {} --is-linux'.format(resource_group, plan))
     self.cmd('webapp create -g {} -n {} --plan {} -i naziml/ruby-hello'.format(resource_group, webapp_name, plan))
     import requests
     r = requests.get('http://{}.azurewebsites.net'.format(webapp_name), timeout=240)
     # verify the web page
     self.assertTrue('Ruby on Rails in Web Apps on Linux' in str(r.content))
     # verify app settings
     self.cmd('webapp config appsettings list -g {} -n {}'.format(resource_group, webapp_name, checks=[
         JMESPathCheckV2('[0].name', 'WEBSITES_ENABLE_APP_SERVICE_STORAGE'),
         JMESPathCheckV2('[0].value', 'false'),
     ]))
Ejemplo n.º 6
0
    def test_create_for_rbac_with_secret(self, resource_group):

        sp_name = 'http://{}'.format(resource_group)
        try:
            self.cmd('ad sp create-for-rbac -n {}2'.format(sp_name),
                     checks=[JMESPathCheckV2('name', sp_name)])
        finally:
            self.cmd('ad app delete --id {}2'.format(sp_name))
Ejemplo n.º 7
0
    def test_auto_delete_plan(self, resource_group):
        webapp_name = 'webapp-delete2'
        plan = 'webapp-delete-plan2'
        self.cmd('appservice plan create -g {} -n {} -l westus'.format(resource_group, plan))

        self.cmd('appservice plan update -g {} -n {} --sku S1'.format(resource_group, plan), checks=[
             JMESPathCheckV2('name', plan),
             JMESPathCheckV2('sku.tier', 'Standard'),
             JMESPathCheckV2('sku.name', 'S1')
        ])

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

        self.cmd('webapp delete -g {} -n {}'.format(resource_group, webapp_name))
        # test empty service plan should be automatically deleted.
        self.cmd('appservice plan list -g {}'.format(resource_group), checks=[
            JMESPathCheckV2('length(@)', 0)
        ])
Ejemplo n.º 8
0
 def test_retain_plan(self, resource_group):
     webapp_name = 'webapp-quick'
     plan = 'plan-quick'
     self.cmd('appservice plan create -g {} -n {}'.format(resource_group, plan))
     self.cmd('webapp create -g {} -n {} --plan {}'.format(resource_group, webapp_name, plan))
     self.cmd('webapp delete -g {} -n {} --keep-dns-registration --keep-empty-plan --keep-metrics'.format(resource_group, webapp_name))
     self.cmd('appservice plan list -g {}'.format(resource_group), checks=[
         JMESPathCheckV2('[0].name', plan)
     ])
Ejemplo n.º 9
0
    def test_webapp_simple_create(self, resource_group):
        webapp_name = 'cli-webapp-simple'
        webapp_name2 = 'cli-webapp-simple2'
        webapp_name3 = 'cli-webapp-simple3'

        # create web 1
        result = self.cmd(
            'appservice web create -g {} -n {} --is-linux'.format(
                resource_group, webapp_name)).get_output_in_json()
        self.assertEqual(webapp_name, result['name'])
        self.assertTrue(result['serverFarmId'].endswith('/' + webapp_name +
                                                        '_plan'))

        # create web 2
        result = self.cmd(
            'appservice web create -g {} -n {} --is-linux'.format(
                resource_group, webapp_name2)).get_output_in_json()
        self.assertEqual(webapp_name2, result['name'])
        self.assertTrue(result['serverFarmId'].endswith('/' + webapp_name +
                                                        '_plan'))

        # verify we reuse the plan for second web
        self.cmd('resource list -g {}'.format(resource_group),
                 checks=[
                     JMESPathCheckV2('length([])', 3),
                     JMESPathCheckV2(
                         "length([?name=='{}_plan'])".format(webapp_name), 1)
                 ])

        # create web 3 which explictly calls out the plan name
        result = self.cmd(
            'appservice web create -g {} -n {} --plan winplan --is-linux --sku b1'
            .format(resource_group, webapp_name3)).get_output_in_json()
        self.assertEqual(webapp_name3, result['name'])
        self.assertTrue(result['serverFarmId'].endswith('/winplan'))

        # verify we create a new plan
        self.cmd('resource list -g {}'.format(resource_group),
                 checks=[
                     JMESPathCheckV2('length([])', 5),
                     JMESPathCheckV2(
                         "length([?name=='winplan'])".format(webapp_name), 1)
                 ])
Ejemplo n.º 10
0
 def test_assignments_for_co_admins(self, resource_group):
     from azure_devtools.scenario_tests import LargeResponseBodyProcessor
     large_resp_body = next((r for r in self.recording_processors if isinstance(r, LargeResponseBodyProcessor)), None)
     if large_resp_body:
         large_resp_body._max_response_body = 1024
     result = self.cmd('role assignment list --include-classic-administrator').get_output_in_json()
     self.assertTrue([x for x in result if x['properties']['roleDefinitionName'] in ['CoAdministrator', 'AccountAdministrator']])
     self.cmd('role assignment list -g {}'.format(resource_group), checks=[
         JMESPathCheckV2("length([])", 0)
     ])
     result = self.cmd('role assignment list -g {} --include-classic-administrator'.format(resource_group)).get_output_in_json()
     self.assertTrue([x for x in result if x['properties']['roleDefinitionName'] in ['CoAdministrator', 'AccountAdministrator']])
Ejemplo n.º 11
0
 def test_create_in_different_group(self, resource_group,
                                    resource_group_location,
                                    resource_group2,
                                    resource_group_location2):
     plan = 'planInOneRG'
     self.cmd('group create -n {} -l {}'.format(resource_group2,
                                                resource_group_location))
     plan_id = self.cmd('appservice plan create -g {} -n {}'.format(
         resource_group, plan)).get_output_in_json()['id']
     self.cmd('webapp create -g {} -n webInOtherRG --plan {}'.format(
         resource_group2, plan_id),
              checks=[JMESPathCheckV2('name', 'webInOtherRG')])
Ejemplo n.º 12
0
    def test_linux_webapp(self, resource_group):
        runtime = 'node|6.4'
        plan = 'webapp-linux-plan'
        webapp = 'webapp-linux1'
        self.cmd(
            'appservice plan create -g {} -n {} --sku S1 --is-linux'.format(
                resource_group, plan),
            checks=[
                JMESPathCheckV2('reserved',
                                True),  # this weird field means it is a linux
                JMESPathCheckV2('sku.name', 'S1'),
            ])
        self.cmd('webapp create -g {} -n {} --plan {} --runtime {}'.format(
            resource_group, webapp, plan, runtime),
                 checks=[
                     JMESPathCheckV2('name', webapp),
                 ])
        self.cmd('webapp list -g {}'.format(resource_group),
                 checks=[
                     JMESPathCheckV2('length([])', 1),
                     JMESPathCheckV2('[0].name', webapp)
                 ])
        self.cmd('webapp config set -g {} -n {} --startup-file {}'.format(
            resource_group, webapp, 'process.json'),
                 checks=[JMESPathCheckV2('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(resource_group, webapp, 'foo-image', 'foo-password',
                    'foo-user', 'foo-url')).get_output_in_json()
        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(
            resource_group, webapp)).get_output_in_json()
        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(
            resource_group, webapp))
        result2 = self.cmd('webapp config container show -g {} -n {} '.format(
            resource_group, webapp)).get_output_in_json()
        self.assertEqual(result2, [])
Ejemplo n.º 13
0
 def test_acr_integration(self, resource_group):
     plan = 'plan11'
     webapp = 'webappacrtest11'
     runtime = 'node|6.4'
     acr_registry_name = webapp
     self.cmd('acr create --admin-enabled -g {} -n {} --sku Basic'.format(resource_group, acr_registry_name))
     self.cmd('appservice plan create -g {} -n {} --sku S1 --is-linux' .format(resource_group, plan))
     self.cmd('webapp create -g {} -n {} --plan {} --runtime {}'.format(resource_group, webapp, plan, runtime))
     creds = self.cmd('acr credential show -n {}'.format(acr_registry_name)).get_output_in_json()
     self.cmd('webapp config container set -g {0} -n {1} --docker-custom-image-name {2}.azurecr.io/image-name:latest --docker-registry-server-url https://{2}.azurecr.io'.format(
         resource_group, webapp, acr_registry_name), checks=[
             JMESPathCheckV2("[?name=='DOCKER_REGISTRY_SERVER_USERNAME']|[0].value", creds['username'])
     ])