コード例 #1
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:
            raise CLIError('\nDownload failed. Test failed!')

        for res in s.cmd('storage file list -s {} -p {}'.format(share, dir)):
            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))
コード例 #2
0
ファイル: test_storage.py プロジェクト: rickrain/azure-cli
    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))
コード例 #3
0
    def _storage_blob_scenario(self):
        s = self
        container = s.container
        account = s.account
        block_blob = 'testblockblob'
        page_blob = 'testpageblob'
        append_blob = 'testappendblob'
        blob = block_blob
        dest_file = os.path.join(TEST_DIR, 'download-blob.rst')
        proposed_lease_id = s.proposed_lease_id
        new_lease_id = s.new_lease_id
        date = s.date

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

        # test page blob upload
        s.cmd('storage blob upload -n {} -c {} --type page --file "{}"'.format(
            page_blob, container, os.path.join(TEST_DIR, 'testpage.rst')))
        s.cmd('storage blob exists -n {} -c {}'.format(page_blob, container),
              checks=JMESPathCheck('exists', True))

        # test append blob upload
        s.cmd(
            'storage blob upload -n {} -c {} --type append --file "{}"'.format(
                append_blob, container, os.path.join(TEST_DIR,
                                                     'testfile.rst')))
        s.cmd(
            'storage blob upload -n {} -c {} --type append --file "{}"'.format(
                append_blob, container, os.path.join(TEST_DIR,
                                                     'testfile.rst')))
        s.cmd('storage blob exists -n {} -c {}'.format(append_blob, container),
              checks=JMESPathCheck('exists', True))

        # test generate a sas
        sas = s.cmd(
            'storage blob generate-sas -n {} -c {} --expiry 2046-12-31T08:23Z --permissions r --https-only'
        )
        sas_keys = dict(pair.split('=') for pair in sas.split('&'))
        assert u'se' in sas_keys

        blob_url = 'https://{}.blob.core.windows.net/{}/{}'.format(
            account, container, blob)
        s.cmd('storage blob url -n {} -c {}'.format(blob, container),
              checks=StringCheck(blob_url))

        s.cmd('storage blob metadata update -n {} -c {} --metadata a=b c=d'.
              format(blob, container))
        s.cmd('storage blob metadata show -n {} -c {}'.format(blob, container),
              checks=[JMESPathCheck('a', 'b'),
                      JMESPathCheck('c', 'd')])
        s.cmd('storage blob metadata update -n {} -c {}'.format(
            blob, container))
        s.cmd('storage blob metadata show -n {} -c {}'.format(blob, container),
              checks=NoneCheck())

        res = s.cmd('storage blob list --container-name {}'.format(container))
        blob_list = [block_blob, append_blob, page_blob]
        for item in res:
            assert item['name'] in blob_list

        s.cmd('storage blob show --container-name {} --name {}'.format(
            container, block_blob),
              checks=[
                  JMESPathCheck('name', block_blob),
                  JMESPathCheck('properties.blobType', 'BlockBlob')
              ])

        s.cmd('storage blob update -c {} -n {} --content-type "test/type"'.
              format(container, block_blob))
        s.cmd('storage blob show -c {} -n {}'.format(container, block_blob),
              checks=JMESPathCheck('properties.contentSettings.contentType',
                                   'test/type'))

        s.cmd('storage blob service-properties show',
              checks=JMESPathCheck('hourMetrics.enabled', True))

        s.cmd('storage blob download -n {} -c {} --file "{}"'.format(
            blob, container, dest_file))
        if os.path.isfile(dest_file):
            os.remove(dest_file)
        else:
            raise CLIError('Download failed. Test failed!')

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

        s.cmd('storage blob delete --container-name {} --name {}'.format(
            container, blob))
        s.cmd('storage blob exists -n {} -c {}'.format(blob, container),
              checks=JMESPathCheck('exists', False))