Пример #1
0
    def body(self):
        s = self
        src_cont = s.src_container
        src_blob = s.src_blob
        dst_cont = s.dest_container
        dst_blob = s.dest_blob
        rg = s.resource_group
        _get_connection_string(self)
        s.cmd('storage container create --name {} --fail-on-exist'.format(
            src_cont))
        s.cmd(
            'storage container create -n {} --fail-on-exist'.format(dst_cont))

        s.cmd(
            'storage blob upload -n {} -c {} --type block --file "{}"'.format(
                src_blob, src_cont, os.path.join(TEST_DIR, 'testfile.rst')))
        s.cmd('storage blob exists -n {} -c {}'.format(src_blob, src_cont),
              checks=JMESPathCheck('exists', True))

        # test that a blob can be successfully copied
        src_uri = s.cmd('storage blob url -n {} -c {}'.format(
            src_blob, src_cont))
        copy_status = s.cmd(
            'storage blob copy start -c {0} -b {1} -u {2}'.format(
                dst_cont, dst_blob, src_uri))
        assert copy_status['status'] == 'success'
        copy_id = copy_status['id']
        s.cmd('storage blob show -c {} -n {}'.format(dst_cont, dst_blob),
              checks=[
                  JMESPathCheck('name', dst_blob),
                  JMESPathCheck('properties.copy.id', copy_id),
                  JMESPathCheck('properties.copy.status', 'success')
              ])
Пример #2
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)])
Пример #3
0
    def _storage_file_in_subdir_scenario(self, share, dir):
        source_file = os.path.join(TEST_DIR, 'testfile.rst')
        dest_file = os.path.join(TEST_DIR, 'download_test.rst')
        filename = 'testfile.rst'
        s = self
        s.cmd('storage file upload --share-name {} -p "{}/{}" --source "{}"'.
              format(share, dir, filename, source_file))
        s.cmd('storage file exists --share-name {} -p "{}/{}"'.format(
            share, dir, filename),
              checks=JMESPathCheck('exists', True))
        if os.path.isfile(dest_file):
            os.remove(dest_file)
        s.cmd('storage file download --share-name {} -p "{}/{}" --dest "{}"'.
              format(share, dir, filename, dest_file))
        if os.path.isfile(dest_file):
            os.remove(dest_file)
        else:
            io.print_('\nDownload failed. Test failed!')

        for res in s.cmd('storage file list -s {} -p {}'.format(share,
                                                                dir))['items']:
            assert filename in res['name']

        s.cmd('storage share stats --name {}'.format(share),
              checks=StringCheck('1'))
        s.cmd('storage file delete --share-name {} -p "{}/{}"'.format(
            share, dir, filename))
        s.cmd('storage file exists --share-name {} -p "{}"'.format(
            share, filename),
              checks=JMESPathCheck('exists', False))
Пример #4
0
    def _storage_message_scenario(self, queue):
        s = self
        s.cmd(
            'storage message put -q {} --content "test message"'.format(queue))
        s.cmd('storage message peek -q {}'.format(queue),
              checks=JMESPathCheck('[0].content', 'test message'))
        messages = s.cmd('storage message get -q {}'.format(queue))
        msg_id = messages[0]['id']
        pop_receipt = messages[0]['popReceipt']

        s.cmd(
            'storage message update -q {} --id {} --pop-receipt {} --visibility-timeout 1 --content "new message!"'
            .format(queue, msg_id, pop_receipt))
        time.sleep(2)  # ensures message should be back in queue
        s.cmd('storage message peek -q {}'.format(queue),
              checks=JMESPathCheck('[0].content', 'new message!'))
        s.cmd('storage message put -q {} --content "second message"'.format(
            queue))
        s.cmd('storage message put -q {} --content "third message"'.format(
            queue))
        s.cmd('storage message peek -q {} --num-messages 32'.format(queue),
              checks=JMESPathCheck('length(@)', 3))

        messages = s.cmd('storage message get -q {}'.format(queue))
        msg_id = messages[0]['id']
        pop_receipt = messages[0]['popReceipt']

        s.cmd('storage message delete -q {} --id {} --pop-receipt {}'.format(
            queue, msg_id, pop_receipt))
        s.cmd('storage message peek -q {} --num-messages 32'.format(queue),
              checks=JMESPathCheck('length(@)', 2))

        s.cmd('storage message clear -q {}'.format(queue))
        s.cmd('storage message peek -q {} --num-messages 32'.format(queue),
              checks=NoneCheck())
Пример #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())
Пример #6
0
    def _storage_file_scenario(self, share):
        source_file = os.path.join(TEST_DIR, 'testfile.rst')
        dest_file = os.path.join(TEST_DIR, 'download_test.rst')
        filename = 'testfile.rst'
        s = self
        s.cmd(
            'storage file upload --share-name {} --source "{}" -p "{}"'.format(
                share, source_file, filename))
        s.cmd('storage file exists --share-name {} -p "{}"'.format(
            share, filename),
              checks=JMESPathCheck('exists', True))
        if os.path.isfile(dest_file):
            os.remove(dest_file)
        s.cmd(
            'storage file download --share-name {} -p "{}" --dest "{}"'.format(
                share, filename, dest_file))
        if os.path.isfile(dest_file):
            os.remove(dest_file)
        else:
            raise CLIError('\nDownload failed. Test failed!')

        # test resize command
        s.cmd('storage file resize --share-name {} -p "{}" --size 1234'.format(
            share, filename))
        s.cmd('storage file show --share-name {} -p "{}"'.format(
            share, filename),
              checks=JMESPathCheck('properties.contentLength', 1234))

        # test ability to set and reset metadata
        s.cmd(
            'storage file metadata update --share-name {} -p "{}" --metadata a=b c=d'
            .format(share, filename))
        s.cmd('storage file metadata show --share-name {} -p "{}"'.format(
            share, filename),
              checks=[JMESPathCheck('a', 'b'),
                      JMESPathCheck('c', 'd')])
        s.cmd('storage file metadata update --share-name {} -p "{}"'.format(
            share, filename))
        s.cmd('storage file metadata show --share-name {} -p "{}"'.format(
            share, filename),
              checks=NoneCheck())

        file_url = 'https://{}.file.core.windows.net/{}/{}'.format(
            s.account, share, filename)
        s.cmd('storage file url --share-name {} -p "{}"'.format(
            share, filename),
              checks=StringCheck(file_url))

        for res in s.cmd('storage file list -s {}'.format(share))['items']:
            assert filename in res['name']

        s.cmd('storage file delete --share-name {} -p "{}"'.format(
            share, filename))
        s.cmd('storage file exists --share-name {} -p "{}"'.format(
            share, filename),
              checks=JMESPathCheck('exists', False))
Пример #7
0
    def body(self):
        s = self
        queue = s.queue
        rg = s.resource_group
        _get_connection_string(self)

        s.cmd('storage queue create -n {} --fail-on-exist --metadata a=b c=d'.
              format(queue),
              checks=JMESPathCheck('success', True))
        s.cmd('storage queue exists -n {}'.format(queue),
              checks=JMESPathCheck('exists', True))

        res = s.cmd('storage queue list')
        assert queue in [x['name'] for x in res]

        s.cmd('storage queue metadata show -n {}'.format(queue),
              checks=[JMESPathCheck('a', 'b'),
                      JMESPathCheck('c', 'd')])
        s.cmd('storage queue metadata update -n {} --metadata e=f g=h'.format(
            queue))
        s.cmd('storage queue metadata show -n {}'.format(queue),
              checks=[JMESPathCheck('e', 'f'),
                      JMESPathCheck('g', 'h')])

        s._queue_acl_scenario(queue)

        s._storage_message_scenario(queue)

        # verify delete operation
        s.cmd('storage queue delete -n {} --fail-not-exist'.format(queue),
              checks=JMESPathCheck('success', True))
        s.cmd('storage queue exists -n {}'.format(queue),
              checks=JMESPathCheck('exists', False))
Пример #8
0
    def body(self):
        self.cmd('resource feature list',
                 checks=[
                     JMESPathCheck(
                         "length([?name=='Microsoft.Xrm/uxdevelopment'])", 1)
                 ])

        self.cmd(
            'resource feature list --namespace {}'.format('Microsoft.Network'),
            checks=[
                JMESPathCheck(
                    "length([?name=='Microsoft.Network/SkipPseudoVipGeneration'])",
                    1)
            ])
Пример #9
0
 def body(self):
     rg = self.resource_group
     hub = self.hub_name
     self.cmd('iot hub create -n {0} -g {1} --sku S1'.format(hub, rg),
              checks=[
                  JMESPathCheck('resourceGroup', rg),
                  JMESPathCheck('location', 'westus'),
                  JMESPathCheck('name', hub),
                  JMESPathCheck('sku.name', 'S1')
              ])
     connection_string = 'HostName=iot-hub-for-testing.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=P80tG5ljXUHtGYyc+oP3GCAazRCq8d0VUtJ4RGrSru4='
     self.cmd('iot hub show-connection-string -n {0} -g {1}'.format(hub, rg),
              checks=[
                  JMESPathCheck('connectionString', connection_string)
              ])
Пример #10
0
 def body(self):
     rg = self.resource_group
     hub = self.hub_name
     device_id = self.device_id
     self.cmd('iot device create --hub {0} -g {1} -d {2}'.format(hub, rg, device_id),
              checks=[
                  JMESPathCheck('deviceId', device_id),
                  JMESPathCheck('status', 'enabled'),
                  JMESPathCheck('connectionState', 'Disconnected')
              ])
     connection_string = 'HostName=iot-hub-for-testing.azure-devices.net;DeviceId=iot-device-for-test;SharedAccessKey=fj6CZB/IrYJI3BOk8X0tzfABo/tsYZJ9boOr4SeG5YU='
     self.cmd('iot device show-connection-string --hub {0} -g {1} -d {2}'.format(hub, rg, device_id),
              checks=[
                  JMESPathCheck('connectionString', connection_string)
              ])
Пример #11
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-role'
     template = {
         "Name":
         "Contoso On-call",
         "Description":
         "Can monitor compute, network and storage, and restart virtual machines",
         "Actions": [
             "Microsoft.Compute/*/read",
             "Microsoft.Compute/virtualMachines/start/action",
             "Microsoft.Compute/virtualMachines/restart/action",
             "Microsoft.Network/*/read", "Microsoft.Storage/*/read",
             "Microsoft.Authorization/*/read",
             "Microsoft.Resources/subscriptions/resourceGroups/read",
             "Microsoft.Resources/subscriptions/resourceGroups/resources/read",
             "Microsoft.Insights/alertRules/*", "Microsoft.Support/*"
         ],
         "AssignableScopes": ["/subscriptions/{}".format(subscription_id)]
     }
     template['Name'] = role_name
     _, temp_file = tempfile.mkstemp()
     with open(temp_file, 'w') as f:
         json.dump(template, f)
     role = self.cmd(
         'role create --role-definition {}'.format(
             temp_file.replace('\\', '\\\\')), None)
     self.cmd('role list -n {}'.format(role_name),
              checks=[JMESPathCheck('[0].properties.roleName', role_name)])
     self.cmd('role delete -n {}'.format(role_name), None)
     self.cmd('role list -n {}'.format(role_name), NoneCheck())
Пример #12
0
    def body(self):
        s = self
        rg = self.resource_group
        s.cmd('resource list')
        s.cmd('resource list -l centralus',
              checks=JMESPathCheck(
                  "length([?location == 'centralus']) == length(@)", True))
        s.cmd(
            'resource list --tag displayName=PublicIPAddress',
            checks=JMESPathCheck(
                "length([?type == 'Microsoft.Network/publicIPAddresses']) == length(@)",
                True))
        s.cmd(
            'resource list --resource-type Microsoft.Network/networkInterfaces',
            checks=JMESPathCheck(
                "length([?type == 'Microsoft.Network/networkInterfaces']) == length(@)",
                True))

        s.cmd('resource list --name {}'.format(self.vnet_name),
              checks=JMESPathCheck(
                  "length([?name == '{}']) == length(@)".format(
                      self.vnet_name), True))

        all_tagged_displayname = s.cmd('resource list --tag displayName')
        storage_acc_tagged_displayname = \
            s.cmd('resource list --tag displayName=StorageAccount')
        assert len(all_tagged_displayname) > len(
            storage_acc_tagged_displayname)

        # check for simple resource with tag
        s.cmd(
            'resource show -n {} -g {} --resource-type Microsoft.Network/virtualNetworks'
            .format(self.vnet_name, rg),
            checks=[
                JMESPathCheck('name', self.vnet_name),
                JMESPathCheck('location', 'westus'),
                JMESPathCheck('resourceGroup', rg),
                JMESPathCheck('tags', {'cli-test': 'test'})
            ])

        # clear tag and verify
        s.cmd(
            'resource tag -n {} -g {} --resource-type Microsoft.Network/virtualNetworks --tags'
            .format(self.vnet_name, rg))
        s.cmd(
            'resource show -n {} -g {} --resource-type Microsoft.Network/virtualNetworks'
            .format(self.vnet_name, rg),
            checks=JMESPathCheck('tags', {}))
Пример #13
0
    def body(self):
        s = self
        src_share = s.src_share
        src_dir = s.src_dir
        src_file = s.src_file
        dst_share = s.dest_share
        dst_dir = s.dest_dir
        dst_file = s.dest_file
        rg = s.resource_group

        _get_connection_string(self)
        s.cmd(
            'storage share create --name {} --fail-on-exist'.format(src_share))
        s.cmd(
            'storage share create --name {} --fail-on-exist'.format(dst_share))
        s.cmd('storage directory create --share-name {} -n {}'.format(
            src_share, src_dir))
        s.cmd('storage directory create --share-name {} -n {}'.format(
            dst_share, dst_dir))

        s.cmd('storage file upload -p "{}/{}" --share-name {} --source "{}"'.
              format(src_dir, src_file, src_share,
                     os.path.join(TEST_DIR, 'testfile.rst')))
        s.cmd('storage file exists -p "{}/{}" --share-name {}'.format(
            src_dir, src_file, src_share),
              checks=JMESPathCheck('exists', True))

        # test that a file can be successfully copied to root
        src_uri = s.cmd('storage file url -p "{}" -s {}'.format(
            os.path.join(src_dir, src_file), src_share))
        copy_status = s.cmd(
            'storage file copy start -s {} -p "{}" -u {}'.format(
                dst_share, dst_file, src_uri))
        assert copy_status['status'] == 'success'
        copy_id = copy_status['id']
        s.cmd('storage file show --share-name {} -p "{}"'.format(
            dst_share, dst_file),
              checks=[
                  JMESPathCheck('name', dst_file),
                  JMESPathCheck('properties.copy.id', copy_id),
                  JMESPathCheck('properties.copy.status', 'success')
              ])

        # test that a file can be successfully copied to a directory
        copy_status = s.cmd(
            'storage file copy start -s {} -p "{}/{}" -u {}'.format(
                dst_share, dst_dir, dst_file, src_uri))
        assert copy_status['status'] == 'success'
        copy_id = copy_status['id']
        s.cmd('storage file show --share-name {} -p "{}/{}"'.format(
            dst_share, dst_dir, dst_file),
              checks=[
                  JMESPathCheck('name', dst_file),
                  JMESPathCheck('properties.copy.id', copy_id),
                  JMESPathCheck('properties.copy.status', 'success')
              ])
Пример #14
0
 def body(self):
     s = self
     rg = self.resource_group
     s.cmd('resource group create -n {} -l westus --tag a=b;c'.format(rg),
           checks=[
               JMESPathCheck('name', rg),
               JMESPathCheck('tags', {
                   'a': 'b',
                   'c': ''
               })
           ])
     s.cmd('resource group exists -n {}'.format(rg),
           checks=BooleanCheck(True))
     s.cmd('resource group show -n {}'.format(rg),
           checks=[
               JMESPathCheck('name', rg),
               JMESPathCheck('tags', {
                   'a': 'b',
                   'c': ''
               })
           ])
     s.cmd('resource group list --tag a=b',
           checks=[
               JMESPathCheck('[0].name', rg),
               JMESPathCheck('[0].tags', {
                   'a': 'b',
                   'c': ''
               })
           ])
     s.cmd('resource group delete -n {}'.format(rg))
     s.cmd('resource group exists -n {}'.format(rg), checks=NoneCheck())
Пример #15
0
    def body(self):
        s = self
        tn = s.tag_name

        s.cmd('tag list --query "[?tagName == \'{}\']"'.format(tn),
              checks=NoneCheck())
        s.cmd('tag create -n {}'.format(tn),
              checks=[
                  JMESPathCheck('tagName', tn),
                  JMESPathCheck('values', []),
                  JMESPathCheck('count.value', '0')
              ])
        s.cmd('tag add-value -n {} --value test'.format(tn))
        s.cmd('tag add-value -n {} --value test2'.format(tn))
        s.cmd('tag list --query "[?tagName == \'{}\']"'.format(tn),
              checks=[
                  JMESPathCheck('[].values[].tagValue', [u'test', u'test2'])
              ])
        s.cmd('tag remove-value -n {} --value test'.format(tn))
        s.cmd('tag list --query "[?tagName == \'{}\']"'.format(tn),
              checks=[JMESPathCheck('[].values[].tagValue', [u'test2'])])
        s.cmd('tag remove-value -n {} --value test2'.format(tn))
        s.cmd('tag list --query "[?tagName == \'{}\']"'.format(tn),
              checks=[JMESPathCheck('[].values[].tagValue', [])])
        s.cmd('tag delete -n {}'.format(tn))
        s.cmd('tag list --query "[?tagName == \'{}\']"'.format(self.tag_name),
              checks=NoneCheck())
Пример #16
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), None)

        #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),
                 ])

        #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())
Пример #17
0
    def _storage_entity_scenario(self, table):
        s = self
        s.cmd(
            'storage entity insert -t {} -e rowkey=001 partitionkey=001 name=test value=something'
            .format(table))
        s.cmd('storage entity show -t {} --row-key 001 --partition-key 001'.
              format(table),
              checks=[
                  JMESPathCheck('name', 'test'),
                  JMESPathCheck('value', 'something')
              ])
        s.cmd(
            'storage entity show -t {} --row-key 001 --partition-key 001 --select name'
            .format(table),
            checks=[
                JMESPathCheck('name', 'test'),
                JMESPathCheck('value', None)
            ])
        s.cmd(
            'storage entity merge -t {} -e rowkey=001 partitionkey=001 name=test value=newval'
            .format(table))
        s.cmd('storage entity show -t {} --row-key 001 --partition-key 001'.
              format(table),
              checks=[
                  JMESPathCheck('name', 'test'),
                  JMESPathCheck('value', 'newval')
              ])
        s.cmd(
            'storage entity replace -t {} -e rowkey=001 partitionkey=001 cat=hat'
            .format(table))
        s.cmd('storage entity show -t {} --row-key 001 --partition-key 001'.
              format(table),
              checks=[
                  JMESPathCheck('cat', 'hat'),
                  JMESPathCheck('name', None),
                  JMESPathCheck('value', None),
              ])

        s.cmd('storage entity delete -t {} --row-key 001 --partition-key 001'.
              format(table))
        s.cmd('storage entity show -t {} --row-key 001 --partition-key 001'.
              format(table),
              allowed_exceptions='Not Found')
Пример #18
0
 def _queue_acl_scenario(self, queue):
     s = self
     s.cmd('storage queue policy list -q {}'.format(queue),
           checks=NoneCheck())
     s.cmd(
         'storage queue policy create -q {} -n test1 --permission raup --start 2016-01-01T00:00Z --expiry 2016-05-01T00:00Z'
         .format(queue))
     acl = sorted(
         s.cmd('storage queue policy list -q {}'.format(queue)).keys())
     assert acl == ['test1']
     s.cmd('storage queue policy show -q {} -n test1'.format(queue),
           checks=[
               JMESPathCheck('start', '2016-01-01T00:00:00+00:00'),
               JMESPathCheck('expiry', '2016-05-01T00:00:00+00:00'),
               JMESPathCheck('permission', 'rpau')
           ])
     s.cmd('storage queue policy update -q {} -n test1 --permission ra'.
           format(queue))
     s.cmd('storage queue policy show -q {} -n test1'.format(queue),
           checks=JMESPathCheck('permission', 'ra'))
     s.cmd('storage queue policy delete -q {} -n test1'.format(queue))
     s.cmd('storage queue policy list -q {}'.format(queue),
           checks=NoneCheck())
Пример #19
0
    def body(self):
        s = self
        table = s.table
        rg = s.resource_group
        _get_connection_string(self)

        s.cmd('storage table create -n {} --fail-on-exist'.format(table),
              checks=JMESPathCheck('success', True))
        s.cmd('storage table exists -n {}'.format(table),
              checks=JMESPathCheck('exists', True))

        res = s.cmd('storage table list')
        assert table in [x['name'] for x in res]

        s._table_acl_scenario(table)

        s._storage_entity_scenario(table)

        # verify delete operation
        s.cmd('storage table delete --name {} --fail-not-exist'.format(table),
              checks=JMESPathCheck('success', True))
        s.cmd('storage table exists -n {}'.format(table),
              checks=JMESPathCheck('exists', False))
Пример #20
0
 def body(self):
     provider = 'TrendMicro.DeepSecurity'
     result = self.cmd('resource provider show -n {}'.format(provider),
                       checks=None)
     if result['registrationState'] == 'Unregistered':
         self.cmd('resource provider register -n {}'.format(provider),
                  checks=None)
         self.cmd('resource provider show -n {}'.format(provider),
                  checks=[JMESPathCheck('registrationState', 'Registered')])
         self.cmd('resource provider unregister -n {}'.format(provider),
                  checks=None)
         self.cmd(
             'resource provider show -n {}'.format(provider),
             checks=[JMESPathCheck('registrationState', 'Unregistered')])
     else:
         self.cmd('resource provider unregister -n {}'.format(provider),
                  checks=None)
         self.cmd(
             'resource provider show -n {}'.format(provider),
             checks=[JMESPathCheck('registrationState', 'Unregistered')])
         self.cmd('resource provider register -n {}'.format(provider),
                  checks=None)
         self.cmd('resource provider show -n {}'.format(provider),
                  checks=[JMESPathCheck('registrationState', 'Registered')])
Пример #21
0
def _acl_body(test):
    container = test.container
    service = test.service
    container_param = test.container_param
    s = test
    _get_connection_string(s)
    s.cmd('storage {} policy list {}'.format(service, container_param),
          checks=NoneCheck())
    s.cmd('storage {} policy create {} -n test1 --permission l'.format(
        service, container_param))
    s.cmd('storage {} policy create {} -n test2 --start 2016-01-01T00:00Z'.
          format(service, container_param))
    s.cmd('storage {} policy create {} -n test3 --expiry 2018-01-01T00:00Z'.
          format(service, container_param))
    s.cmd(
        'storage {} policy create {} -n test4 --permission rwdl --start 2016-01-01T00:00Z --expiry 2016-05-01T00:00Z'
        .format(service, container_param))
    acl = sorted(
        s.cmd('storage {} policy list {}'.format(service,
                                                 container_param)).keys())
    assert acl == ['test1', 'test2', 'test3', 'test4']
    s.cmd('storage {} policy show {} -n test1'.format(service,
                                                      container_param),
          checks=JMESPathCheck('permission', 'l'))
    s.cmd('storage {} policy show {} -n test2'.format(service,
                                                      container_param),
          checks=JMESPathCheck('start', '2016-01-01T00:00:00+00:00'))
    s.cmd('storage {} policy show {} -n test3'.format(service,
                                                      container_param),
          checks=JMESPathCheck('expiry', '2018-01-01T00:00:00+00:00'))
    s.cmd('storage {} policy show {} -n test4'.format(service,
                                                      container_param),
          checks=[
              JMESPathCheck('start', '2016-01-01T00:00:00+00:00'),
              JMESPathCheck('expiry', '2016-05-01T00:00:00+00:00'),
              JMESPathCheck('permission', 'rwdl')
          ])
    s.cmd('storage {} policy update {} -n test1 --permission r'.format(
        service, container_param))
    s.cmd('storage {} policy show {} -n test1'.format(service,
                                                      container_param),
          checks=JMESPathCheck('permission', 'r'))
    s.cmd('storage {} policy delete {} -n test1'.format(
        service, container_param))
    acl = sorted(
        s.cmd('storage {} policy list {}'.format(service,
                                                 container_param)).keys())
    assert acl == ['test2', 'test3', 'test4']
Пример #22
0
    def body(self):
        s = self
        share1 = s.share1
        share2 = s.share2
        _get_connection_string(self)

        s.cmd('storage share create --name {} --fail-on-exist'.format(share1),
              checks=JMESPathCheck('success', True))
        s.cmd(
            'storage share create -n {} --fail-on-exist --metadata foo=bar cat=hat'
            .format(share2),
            checks=JMESPathCheck('success', True))
        s.cmd('storage share exists -n {}'.format(share1),
              checks=JMESPathCheck('exists', True))
        s.cmd(
            'storage share metadata show --name {}'.format(share2),
            checks=[JMESPathCheck('cat', 'hat'),
                    JMESPathCheck('foo', 'bar')])
        res = [x['name'] for x in s.cmd('storage share list')]
        assert share1 in res
        assert share2 in res

        # verify metadata can be set, queried, and cleared
        s.cmd('storage share metadata update --name {} --metadata a=b c=d'.
              format(share1))
        s.cmd('storage share metadata show -n {}'.format(share1),
              checks=[JMESPathCheck('a', 'b'),
                      JMESPathCheck('c', 'd')])
        s.cmd('storage share metadata update -n {}'.format(share1))
        s.cmd('storage share metadata show -n {}'.format(share1),
              checks=NoneCheck())

        s.cmd('storage share update --name {} --quota 3'.format(share1))
        s.cmd('storage share show --name {}'.format(share1),
              checks=JMESPathCheck('properties.quota', 3))

        self._storage_file_scenario(share1)
        self._storage_directory_scenario(share1)
Пример #23
0
 def _table_acl_scenario(self, table):
     s = self
     s.cmd('storage table policy list -t {}'.format(table),
           checks=NoneCheck())
     s.cmd(
         'storage table policy create -t {} -n test1 --permission a'.format(
             table))
     s.cmd(
         'storage table policy create -t {} -n test2 --start 2016-01-01T00:00Z'
         .format(table))
     s.cmd(
         'storage table policy create -t {} -n test3 --expiry 2018-01-01T00:00Z'
         .format(table))
     s.cmd(
         'storage table policy create -t {} -n test4 --permission raud --start 2016-01-01T00:00Z --expiry 2016-05-01T00:00Z'
         .format(table))
     acl = sorted(
         s.cmd('storage table policy list -t {}'.format(table)).keys())
     assert acl == ['test1', 'test2', 'test3', 'test4']
     s.cmd('storage table policy show -t {} -n test1'.format(table),
           checks=JMESPathCheck('permission', 'a'))
     s.cmd('storage table policy show -t {} -n test2'.format(table),
           checks=JMESPathCheck('start', '2016-01-01T00:00:00+00:00'))
     s.cmd('storage table policy show -t {} -n test3'.format(table),
           checks=JMESPathCheck('expiry', '2018-01-01T00:00:00+00:00'))
     s.cmd('storage table policy show -t {} -n test4'.format(table),
           checks=[
               JMESPathCheck('start', '2016-01-01T00:00:00+00:00'),
               JMESPathCheck('expiry', '2016-05-01T00:00:00+00:00'),
               JMESPathCheck('permission', 'raud')
           ])
     s.cmd('storage table policy update -t {} -n test1 --permission au'.
           format(table))
     s.cmd('storage table policy show -t {} -n test1'.format(table),
           checks=JMESPathCheck('permission', 'au'))
     s.cmd('storage table policy delete -t {} -n test1'.format(table))
     acl = sorted(
         s.cmd('storage table policy list -t {}'.format(table)).keys())
     assert acl == ['test2', 'test3', 'test4']
Пример #24
0
    def body(self):
        s = self
        container = s.container
        rg = s.resource_group
        proposed_lease_id = s.proposed_lease_id
        new_lease_id = s.new_lease_id
        date = s.date
        _get_connection_string(self)

        s.cmd('storage container create --name {} --fail-on-exist'.format(
            container),
              checks=JMESPathCheck('success', True))
        s.cmd('storage container exists -n {}'.format(container),
              checks=JMESPathCheck('exists', True))

        s.cmd('storage container set-permission -n {} --public-access blob'.
              format(container))
        s.cmd('storage container show-permission -n {}'.format(container),
              checks=JMESPathCheck('publicAccess', 'blob'))
        s.cmd('storage container set-permission -n {} --public-access off'.
              format(container))
        s.cmd('storage container show-permission -n {}'.format(container),
              checks=JMESPathCheck('publicAccess', 'off'))

        s.cmd('storage container show -n {}'.format(container),
              checks=JMESPathCheck('name', container))
        res = s.cmd('storage container list')
        assert container in [x['name'] for x in res]

        s.cmd(
            'storage container metadata update -n {} --metadata foo=bar moo=bak'
            .format(container))
        s.cmd(
            'storage container metadata show -n {}'.format(container),
            checks=[JMESPathCheck('foo', 'bar'),
                    JMESPathCheck('moo', 'bak')])
        s.cmd('storage container metadata update -n {}'.format(
            container))  # reset metadata
        s.cmd('storage container metadata show -n {}'.format(container),
              checks=NoneCheck())
        s._storage_blob_scenario()

        # test lease operations
        s.cmd(
            'storage container lease acquire --lease-duration 60 -c {} --if-modified-since {} --proposed-lease-id {}'
            .format(container, date, proposed_lease_id))
        s.cmd('storage container show --name {}'.format(container),
              checks=[
                  JMESPathCheck('properties.lease.duration', 'fixed'),
                  JMESPathCheck('properties.lease.state', 'leased'),
                  JMESPathCheck('properties.lease.status', 'locked')
              ])
        s.cmd(
            'storage container lease change -c {} --lease-id {} --proposed-lease-id {}'
            .format(container, proposed_lease_id, new_lease_id))
        s.cmd('storage container lease renew -c {} --lease-id {}'.format(
            container, new_lease_id))
        s.cmd('storage container show -n {}'.format(container),
              checks=[
                  JMESPathCheck('properties.lease.duration', 'fixed'),
                  JMESPathCheck('properties.lease.state', 'leased'),
                  JMESPathCheck('properties.lease.status', 'locked')
              ])
        s.cmd('storage container lease break -c {} --lease-break-period 30'.
              format(container))
        s.cmd('storage container show --name {}'.format(container),
              checks=[
                  JMESPathCheck('properties.lease.duration', None),
                  JMESPathCheck('properties.lease.state', 'breaking'),
                  JMESPathCheck('properties.lease.status', 'locked')
              ])
        s.cmd('storage container lease release -c {} --lease-id {}'.format(
            container, new_lease_id))
        s.cmd('storage container show --name {}'.format(container),
              checks=[
                  JMESPathCheck('properties.lease.duration', None),
                  JMESPathCheck('properties.lease.state', 'available'),
                  JMESPathCheck('properties.lease.status', 'unlocked')
              ])

        # verify delete operation
        s.cmd('storage container delete --name {} --fail-not-exist'.format(
            container),
              checks=JMESPathCheck('success', True))
        s.cmd('storage container exists -n {}'.format(container),
              checks=JMESPathCheck('exists', False))
Пример #25
0
    def _storage_directory_scenario(self, share):
        s = self
        dir = 'testdir01'
        s.cmd(
            'storage directory create --share-name {} --name {} --fail-on-exist'
            .format(share, dir),
            checks=JMESPathCheck('success', True))
        s.cmd('storage directory exists --share-name {} -n {}'.format(
            share, dir),
              checks=JMESPathCheck('exists', True))
        s.cmd(
            'storage directory metadata update --share-name {} -n {} --metadata a=b c=d'
            .format(share, dir))
        s.cmd('storage directory metadata show --share-name {} -n {}'.format(
            share, dir),
              checks=[JMESPathCheck('a', 'b'),
                      JMESPathCheck('c', 'd')])
        s.cmd('storage directory show --share-name {} -n {}'.format(
            share, dir),
              checks=[
                  JMESPathCheck('metadata', {
                      'a': 'b',
                      'c': 'd'
                  }),
                  JMESPathCheck('name', dir)
              ])
        s.cmd('storage directory metadata update --share-name {} --name {}'.
              format(share, dir))
        s.cmd(
            'storage directory metadata show --share-name {} --name {}'.format(
                share, dir),
            checks=NoneCheck())
        s._storage_file_in_subdir_scenario(share, dir)
        s.cmd(
            'storage directory delete --share-name {} --name {} --fail-not-exist'
            .format(share, dir),
            checks=JMESPathCheck('success', True))
        s.cmd('storage directory exists --share-name {} --name {}'.format(
            share, dir),
              checks=JMESPathCheck('exists', False))

        # verify a directory can be created with metadata and then delete
        dir = 'testdir02'
        s.cmd(
            'storage directory create --share-name {} --name {} --fail-on-exist --metadata foo=bar cat=hat'
            .format(share, dir),
            checks=JMESPathCheck('success', True))
        s.cmd(
            'storage directory metadata show --share-name {} -n {}'.format(
                share, dir),
            checks=[JMESPathCheck('cat', 'hat'),
                    JMESPathCheck('foo', 'bar')])
        s.cmd(
            'storage directory delete --share-name {} --name {} --fail-not-exist'
            .format(share, dir),
            checks=JMESPathCheck('success', True))
Пример #26
0
 def body(self):
     account = self.account
     rg = self.resource_group
     s = self
     s.cmd('storage account check-name --name teststorageomega',
           checks=JMESPathCheck('nameAvailable', True))
     s.cmd(
         'storage account create --sku Standard_LRS -l westus -n {} -g {}'.
         format(account, rg),
         checks=[
             JMESPathCheck('location', 'westus'),
             JMESPathCheck('sku.name', 'Standard_LRS')
         ])
     s.cmd('storage account check-name --name {}'.format(account),
           checks=[
               JMESPathCheck('nameAvailable', False),
               JMESPathCheck('reason', 'AlreadyExists')
           ])
     s.cmd('storage account list -g {}'.format(rg, account),
           checks=[
               JMESPathCheck('[0].name', account),
               JMESPathCheck('[0].location', 'westus'),
               JMESPathCheck('[0].sku.name', 'Standard_LRS'),
               JMESPathCheck('[0].resourceGroup', rg)
           ])
     s.cmd('storage account show --resource-group {} --name {}'.format(
         rg, account),
           checks=[
               JMESPathCheck('name', account),
               JMESPathCheck('location', 'westus'),
               JMESPathCheck('sku.name', 'Standard_LRS'),
               JMESPathCheck('resourceGroup', rg)
           ])
     s.cmd('storage account show-usage',
           checks=JMESPathCheck('name.value', 'StorageAccounts'))
     s.cmd(
         'storage account show-connection-string -g {} -n {} --protocol http'
         .format(rg, account),
         checks=[
             JMESPathCheck("contains(connectionString, 'https')", False),
             JMESPathCheck(
                 "contains(connectionString, '{}')".format(account), True)
         ])
     keys_result = s.cmd('storage account keys list -g {} -n {}'.format(
         rg, account))
     key1 = keys_result['keys'][0]
     key2 = keys_result['keys'][1]
     assert key1 and key2
     keys_result = s.cmd(
         'storage account keys renew -g {} -n {} --key primary'.format(
             rg, account))
     renewed_key1 = keys_result['keys'][0]
     renewed_key2 = keys_result['keys'][1]
     assert key1 != renewed_key1
     assert key2 == renewed_key2
     key1 = renewed_key1
     keys_result = s.cmd(
         'storage account keys renew -g {} -n {} --key secondary'.format(
             rg, account))
     assert key1 == keys_result['keys'][0]
     assert key2 != keys_result['keys'][1]
     s.cmd('storage account update -g {} -n {} --tags foo=bar cat'.format(
         rg, account),
           checks=JMESPathCheck('tags', {
               'cat': '',
               'foo': 'bar'
           }))
     s.cmd('storage account update -g {} -n {} --tags'.format(rg, account),
           checks=JMESPathCheck('tags', {}))
     s.cmd('storage account update -g {} -n {} --sku Standard_GRS'.format(
         rg, account),
           checks=JMESPathCheck('sku.name', 'Standard_GRS'))
     s.cmd('storage account delete -g {} -n {}'.format(rg, account))
     s.cmd('storage account check-name --name {}'.format(account),
           checks=JMESPathCheck('nameAvailable', True))
Пример #27
0
    def body(self):
        rg = self.resource_group
        kv = self.keyvault_names[0]
        loc = self.location
        # test create keyvault with default access policy set
        self.cmd('keyvault create -g {} -n {} -l {}'.format(rg, kv, loc),
                 checks=[
                     JMESPathCheck('name', kv),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('type(properties.accessPolicies)', 'array'),
                     JMESPathCheck('length(properties.accessPolicies)', 1),
                 ])
        self.cmd('keyvault show -g {} -n {}'.format(rg, kv),
                 checks=[
                     JMESPathCheck('name', kv),
                     JMESPathCheck('location', loc),
                     JMESPathCheck('resourceGroup', rg),
                     JMESPathCheck('type(properties.accessPolicies)', 'array'),
                     JMESPathCheck('length(properties.accessPolicies)', 1),
                 ])
        self.cmd('keyvault list -g {}'.format(rg),
                 checks=[
                     JMESPathCheck('type(@)', 'array'),
                     JMESPathCheck('length(@)', 1),
                     JMESPathCheck('[0].name', kv),
                     JMESPathCheck('[0].location', loc),
                     JMESPathCheck('[0].resourceGroup', rg),
                 ])
        # test updating keyvault sku name
        self.cmd('keyvault show -g {} -n {}'.format(rg, kv),
                 checks=[
                     JMESPathCheck('name', kv),
                     JMESPathCheck('properties.sku.name', 'standard'),
                 ])
        self.cmd(
            'keyvault update -g {} -n {} --set properties.sku.name=premium'.
            format(rg, kv),
            checks=[
                JMESPathCheck('name', kv),
                JMESPathCheck('properties.sku.name', 'premium'),
            ])
        # test policy set/delete
        # the object id is mocked so we expect the service raise an error
        self.cmd(
            'keyvault set-policy -g {} -n {} --object-id {} --perms-to-secrets get list'
            .format(rg, kv, self.mock_object_id),
            allowed_exceptions=
            "An invalid value was provided for 'accessPolicies'.")
        self.cmd('keyvault delete-policy -g {} -n {} --object-id {}'.format(
            rg, kv, self.mock_object_id),
                 allowed_exceptions="No matching policies found")
        # test keyvault delete
        self.cmd('keyvault delete -g {} -n {}'.format(rg, kv))
        self.cmd('keyvault list -g {}'.format(rg), checks=NoneCheck())

        # test create keyvault further
        self.cmd('keyvault create -g {} -n {} -l {} --no-self-perms'.format(
            rg, self.keyvault_names[1], loc),
                 checks=[
                     JMESPathCheck('type(properties.accessPolicies)', 'array'),
                     JMESPathCheck('length(properties.accessPolicies)', 0),
                 ])
        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_names[2], loc), checks=[
            JMESPathCheck('properties.enabledForDeployment', True),
            JMESPathCheck('properties.enabledForDiskEncryption', True),
            JMESPathCheck('properties.enabledForTemplateDeployment', True),
        ])
        self.cmd('keyvault create -g {} -n {} -l {} --sku premium'.format(
            rg, self.keyvault_names[3], loc),
                 checks=[
                     JMESPathCheck('properties.sku.name', 'premium'),
                 ])
Пример #28
0
    def body(self):
        webapp_name = 'webapp-e2e'
        plan = 'webapp-e2e-plan'
        result = self.cmd('appservice plan create -g {} -n {} --sku B1'.format(
            self.resource_group, plan))
        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 show -g {} -n {}'.format(
            self.resource_group, plan),
                 checks=[JMESPathCheck('name', plan)])
        #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')
                 ])

        result = self.cmd('appservice web create -g {} -n {} --plan {}'.format(
            self.resource_group, webapp_name, plan),
                          checks=[
                              JMESPathCheck('resourceGroup',
                                            self.resource_group),
                              JMESPathCheck('state', 'Running'),
                              JMESPathCheck('name', webapp_name),
                              JMESPathCheck('hostNames[0]',
                                            webapp_name + '.azurewebsites.net')
                          ])
        result = self.cmd('appservice web list -g {}'.format(
            self.resource_group),
                          checks=[
                              JMESPathCheck('length(@)', 1),
                              JMESPathCheck('[0].name', webapp_name),
                              JMESPathCheck('[0].hostNames[0]',
                                            webapp_name + '.azurewebsites.net')
                          ])
        result = self.cmd('appservice web show -g {} -n {}'.format(
            self.resource_group, webapp_name),
                          checks=[
                              JMESPathCheck('name', webapp_name),
                              JMESPathCheck('hostNames[0]',
                                            webapp_name + '.azurewebsites.net')
                          ])

        self.cmd('appservice web git enable-local -g {} -n {}'.format(
            self.resource_group, webapp_name))
        result = self.cmd('appservice web git show-url -g {} -n {}'.format(
            self.resource_group, webapp_name))
        self.assertTrue(result['url'].endswith(webapp_name + '.git'))

        #turn on diagnostics
        test_cmd = (
            'appservice web log set -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)
        result = self.cmd(
            'appservice web 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'
            ])

        self.cmd('appservice web stop -g {} -n {}'.format(
            self.resource_group, webapp_name))
        self.cmd('appservice web show -g {} -n {}'.format(
            self.resource_group, webapp_name),
                 checks=[
                     JMESPathCheck('state', 'Stopped'),
                     JMESPathCheck('name', webapp_name)
                 ])
        self.cmd('appservice web delete -g {} -n {}'.format(
            self.resource_group, webapp_name))
        #test empty service plan should be automatically deleted.
        result = self.cmd('appservice plan list -g {}'.format(
            self.resource_group),
                          checks=[JMESPathCheck('length(@)', 0)])
Пример #29
0
    def body(self):
        #site config testing

        #verify the baseline
        result = self.cmd('appservice web config show -g {} -n {}'.format(
            self.resource_group, self.webapp_name),
                          checks=[
                              JMESPathCheck('alwaysOn', False),
                              JMESPathCheck('autoHealEnabled', False),
                              JMESPathCheck('phpVersion', '5.4'),
                              JMESPathCheck('netFrameworkVersion', 'v4.0'),
                              JMESPathCheck('pythonVersion', ''),
                              JMESPathCheck('use32BitWorkerProcess', True),
                              JMESPathCheck('webSocketsEnabled', False)
                          ])

        #update and verify
        checks = [
            JMESPathCheck('alwaysOn', True),
            JMESPathCheck('autoHealEnabled', True),
            JMESPathCheck('phpVersion', '5.5'),
            JMESPathCheck('netFrameworkVersion', 'v3.0'),
            JMESPathCheck('pythonVersion', '3.4'),
            JMESPathCheck('use32BitWorkerProcess', False),
            JMESPathCheck('webSocketsEnabled', True)
        ]
        result = self.cmd(
            'appservice web config update -g {} -n {} --always-on true --auto-heal-enabled true --php-version 5.5 --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)
        result = self.cmd('appservice web config show -g {} -n {}'.format(
            self.resource_group, self.webapp_name),
                          checks=checks)

        #site appsettings testing

        #update
        result = self.cmd(
            'appservice web config appsettings update -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')
            ])
        result = self.cmd(
            'appservice web config appsettings show -g {} -n {}'.format(
                self.resource_group, self.webapp_name),
            checks=[
                JMESPathCheck('s1', 'foo'),
                JMESPathCheck('s2', 'bar'),
                JMESPathCheck('s3', 'bar2')
            ])

        #delete
        self.cmd(
            'appservice web config appsettings delete -g {} -n {} --setting-names s1 s2'
            .format(self.resource_group, self.webapp_name))
        result = self.cmd(
            'appservice web config appsettings show -g {} -n {}'.format(
                self.resource_group, self.webapp_name))
        self.assertTrue('s1' not in result)
        self.assertTrue('s2' not in result)
        self.assertTrue('s3' in result)
Пример #30
0
    def body(self):
        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(
            'resource policy create -n {} --rules {} --display-name {} --description {}'
            .format(policy_name, rules_file, policy_display_name,
                    policy_description),
            checks=[
                JMESPathCheck('name', policy_name),
                JMESPathCheck('displayName', policy_display_name),
                JMESPathCheck('description', policy_description)
            ])

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

        #list and show it
        self.cmd('resource policy list',
                 checks=[
                     JMESPathCheck("length([?name=='{}'])".format(policy_name),
                                   1)
                 ])
        self.cmd('resource policy show -n {}'.format(policy_name),
                 checks=[
                     JMESPathCheck('name', policy_name),
                     JMESPathCheck('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(
            'resource policy assignment create --policy {} -n {} --display-name {} -g {}'
            .format(policy_name, policy_assignment_name,
                    policy_assignment_display_name, self.resource_group),
            checks=[
                JMESPathCheck('name', policy_assignment_name),
                JMESPathCheck('displayName', policy_assignment_display_name),
            ])

        # listing at subscription level won't find the assignment made at a resource group
        import jmespath
        try:
            self.cmd(
                'resource policy assignment list',
                checks=[
                    JMESPathCheck(
                        "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(
            'resource policy assignment list --show-all',
            checks=[
                JMESPathCheck(
                    "length([?name=='{}'])".format(policy_assignment_name), 1),
            ])

        # delete the assignment
        self.cmd('resource policy assignment delete -n {} -g {}'.format(
            policy_assignment_name, self.resource_group))
        self.cmd('resource policy assignment list --show-all')

        # delete the policy
        self.cmd('resource policy delete -n {}'.format(policy_name))
        time.sleep(10)  # ensure the policy is gone when run live.
        self.cmd('resource policy list',
                 checks=[
                     JMESPathCheck("length([?name=='{}'])".format(policy_name),
                                   0)
                 ])