Exemplo n.º 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.rg
        _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 --upload-from "{}"'.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=BooleanCheck(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} -n {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')
        ])
Exemplo n.º 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)])
Exemplo n.º 3
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
        result = self.cmd(
            'role assignment create --assignee {} --role contributor -g {}'.
            format(self.user, self.resource_group), None)
        scope = result['properties']['scope']
        self.cmd('role assignment list-for-resource-group -g {}'.format(
            self.resource_group),
                 checks=[
                     JMESPathCheck(
                         "length([?properties.scope == '{}'])".format(scope),
                         1)
                 ])
        self.cmd(
            'role assignment delete -n {} --scope {}'.format(
                result['name'], result['properties']['scope']), None)
        self.cmd('role assignment list-for-resource-group -g {}'.format(
            self.resource_group),
                 checks=[
                     JMESPathCheck(
                         "length([?properties.scope == '{}'])".format(scope),
                         0)
                 ])

        #test role assignments on a resource
        result2 = self.cmd(
            'role assignment create --assignee {} --role contributor --resource-id {}'
            .format(self.user, resource_id), None)
        scope = result2['properties']['scope']
        self.cmd('role assignment list-for-scope --scope {}'.format(scope),
                 checks=[
                     JMESPathCheck(
                         "length([?properties.scope == '{}'])".format(scope),
                         1)
                 ])
        self.cmd(
            'role assignment delete -n {} --scope {}'.format(
                result2['name'], scope), None)
        self.cmd('role assignment list-for-scope --scope {}'.format(scope),
                 checks=[
                     JMESPathCheck(
                         "length([?properties.scope == '{}'])".format(scope),
                         0)
                 ])
Exemplo n.º 4
0
 def body(self):
     account = self.account
     rg = RESOURCE_GROUP_NAME
     s = self
     s.cmd('storage account create --type 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 delete -g {} -n {}'.format(RESOURCE_GROUP_NAME, account))
     s.cmd('storage account check-name --name {}'.format(account), checks=JMESPathCheck('nameAvailable', True))
Exemplo n.º 5
0
    def body(self):
        s = self
        scope = '/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590'
        role_def_id = 'de139f84-1756-47ae-9be6-808fbbe84772'
        full_role_def_id = '{}/providers/Microsoft.Authorization/roleDefinitions/{}'.format(
            scope, role_def_id)

        s.cmd('role list --scope {}'.format(scope),
              checks=JMESPathCheck(
                  "length([].contains(id, '{}')) == length(@)".format(scope),
                  True))

        s.cmd('role show --scope {} --role-definition-id {}'.format(
            scope, role_def_id),
              checks=[
                  JMESPathCheck('name', role_def_id),
                  JMESPathCheck('properties.roleName', 'Website Contributor'),
                  JMESPathCheck('properties.type', 'BuiltInRole')
              ])

        s.cmd(
            'role show-by-id --role-definition-id {}'.format(full_role_def_id),
            checks=[
                JMESPathCheck('name', role_def_id),
                JMESPathCheck('properties.roleName', 'Website Contributor'),
                JMESPathCheck('properties.type', 'BuiltInRole')
            ])
Exemplo n.º 6
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 {} --policy test1 --permission l'.format(service, container_param))
    s.cmd('storage {} policy create {} --policy test2 --start 2016-01-01T00:00Z'.format(service, container_param))
    s.cmd('storage {} policy create {} --policy test3 --expiry 2018-01-01T00:00Z'.format(service, container_param))
    s.cmd('storage {} policy create {} --policy test4 --permission rwdl --start 2016-01-01T00:00Z --expiry 2016-05-01T00:00Z'.format(service, container_param))
    acl = sorted(ast.literal_eval(json.dumps(s.cmd('storage {} policy list {}'.format(service, container_param)))))
    assert acl == ['test1', 'test2', 'test3', 'test4']
    s.cmd('storage {} policy show {} --policy test1'.format(service, container_param),
        checks=JMESPathCheck('permission', 'l'))
    s.cmd('storage {} policy show {} --policy test2'.format(service, container_param),
        checks=JMESPathCheck('start', '2016-01-01T00:00:00+00:00'))
    s.cmd('storage {} policy show {} --policy test3'.format(service, container_param),
        checks=JMESPathCheck('expiry', '2018-01-01T00:00:00+00:00'))
    s.cmd('storage {} policy show {} --policy 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 {} --policy test1 --permission r'.format(service, container_param))
    s.cmd('storage {} policy show {} --policy test1'.format(service, container_param),
        checks=JMESPathCheck('permission', 'r'))
    s.cmd('storage {} policy delete {} --policy test1'.format(service, container_param))
    acl = sorted(ast.literal_eval(json.dumps(s.cmd('storage {} policy list {}'.format(service, container_param)))))
    assert acl == ['test2', 'test3', 'test4']
Exemplo n.º 7
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 {} --local-file-name "{}" --name "{}"'.format(share, source_file, filename))
        s.cmd('storage file exists --share-name {} -n {}'.format(share, filename),
            checks=BooleanCheck(True))
        if os.path.isfile(dest_file):
            os.remove(dest_file)
        s.cmd('storage file download --share-name {} -n {} --local-file-name "{}"'.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 {} --name {} --content-length 1234'.format(share, filename))
        s.cmd('storage file show --share-name {} --name {}'.format(share, filename),
            checks=JMESPathCheck('properties.contentLength', 1234))

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

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

        res = [x['name'] for x in s.cmd('storage share contents -n {}'.format(share))['items']]
        assert filename in res

        s.cmd('storage file delete --share-name {} --name {}'.format(share, filename))
        s.cmd('storage file exists --share-name {} -n {}'.format(share, filename),
            checks=BooleanCheck(False))
Exemplo n.º 8
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())
Exemplo n.º 9
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())
Exemplo n.º 10
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=BooleanCheck(True))
        s.cmd('storage directory exists --share-name {} -n {}'.format(share, dir),
            checks=BooleanCheck(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=BooleanCheck(True))
        s.cmd('storage directory exists --share-name {} --name {}'.format(share, dir),
            checks=BooleanCheck(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=BooleanCheck(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=BooleanCheck(True))
Exemplo n.º 11
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')])
Exemplo n.º 12
0
    def body(self):
        s = self
        share1 = s.share1
        share2 = s.share2
        _get_connection_string(self)
        # TODO: Re-enable testing of SAS tokens after playback issues resolved
        #sas_token = self.cmd('storage account generate-sas --services f --resource-types sco --permission rwdl --expiry 2100-01-01t00:00z -o list')
        #self.set_env('AZURE_SAS_TOKEN', sas_token)
        #self.set_env('AZURE_STORAGE_ACCOUNT', STORAGE_ACCOUNT_NAME)
        #self.pop_env('AZURE_STORAGE_CONNECTION_STRING')

        s.cmd('storage share create --name {} --fail-on-exist'.format(share1),
            checks=BooleanCheck(True))
        s.cmd('storage share create -n {} --fail-on-exist --metadata foo=bar;cat=hat'.format(share2),
            checks=BooleanCheck(True))
        s.cmd('storage share exists -n {}'.format(share1),
            checks=BooleanCheck(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')['items']]
        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)

        s.cmd('storage file service-properties show', checks=[
            JMESPathCheck('cors', []),
            JMESPathCheck('hourMetrics.enabled', True),
            JMESPathCheck('minuteMetrics.enabled', False)
        ])
Exemplo n.º 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.rg

        _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 -n {} --share-name {} -d {} --local-file-name "{}"'.format(src_file, src_share, src_dir, os.path.join(TEST_DIR, 'testfile.rst')))
        s.cmd('storage file exists -n {} --share-name {} -d {}'.format(src_file, src_share, src_dir),
            checks=BooleanCheck(True))

        # test that a file can be successfully copied to root
        src_uri = s.cmd('storage file url -n {} -s {} -d {}'.format(src_file, src_share, src_dir))
        copy_status = s.cmd('storage file copy start -s {0} -n {1} -u {2}'.format(
            dst_share, dst_file, src_uri))
        assert copy_status['status'] == 'success'
        copy_id = copy_status['id']
        s.cmd('storage file show --share-name {} -n {}'.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 {0} -n {1} -d {3} -u {2}'.format(
            dst_share, dst_file, src_uri, dst_dir))
        assert copy_status['status'] == 'success'
        copy_id = copy_status['id']
        s.cmd('storage file show --share-name {} -n {} -d {}'.format(dst_share, dst_file, dst_dir),  checks=[
            JMESPathCheck('name', dst_file),
            JMESPathCheck('properties.copy.id', copy_id),
            JMESPathCheck('properties.copy.status', 'success')
        ])
Exemplo n.º 14
0
    def body(self):
        s = self
        rg = 'travistestresourcegroup'
        all_resources = s.cmd('resource list')
        some_resources = s.cmd('resource list -l centralus')
        assert len(all_resources) > len(some_resources)

        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 TravisTestResourceGroup',
              checks=JMESPathCheck(
                  "length([?name == 'TravisTestResourceGroup']) == length(@)",
                  True))

        s.cmd('resource list -g yugangw',
              checks=JMESPathCheck(
                  "length([?resourceGroup == 'yugangw']) == length(@)", 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)

        s.cmd(
            'resource tag -n testserver23456 -g {} --resource-type Microsoft.Sql/servers --tags test=pass'
            .format(rg))

        # check for simple resource with tag
        s.cmd(
            'resource show -n testserver23456 -g {} --resource-type Microsoft.Sql/servers'
            .format(rg),
            checks=[
                JMESPathCheck('name', 'testserver23456'),
                JMESPathCheck('location', 'West US'),
                JMESPathCheck('resourceGroup', rg),
                JMESPathCheck('tags', {'test': 'pass'})
            ])

        # check for child resource
        s.cmd(
            'resource show -n testsql23456 -g {} --parent servers/testserver23456 --resource-type Microsoft.Sql/databases'
            .format(rg),
            checks=[
                JMESPathCheck('name', 'testsql23456'),
                JMESPathCheck('location', 'West US'),
                JMESPathCheck('resourceGroup', rg)
            ])

        # Check that commands succeeds regardless of parameter order
        s.cmd(
            'resource show -n testsql23456 -g {} --resource-type Microsoft.Sql/databases --parent servers/testserver23456 '
            .format(rg),
            checks=[
                JMESPathCheck('name', 'testsql23456'),
                JMESPathCheck('location', 'West US'),
                JMESPathCheck('resourceGroup', rg)
            ])

        # clear tag and verify
        s.cmd(
            'resource tag -n testserver23456 -g {} --resource-type Microsoft.Sql/servers --tags'
            .format(rg))
        s.cmd(
            'resource show -n testserver23456 -g {} --resource-type Microsoft.Sql/servers'
            .format(rg),
            checks=JMESPathCheck('tags', {}))
Exemplo n.º 15
0
    def _storage_blob_scenario(self):
        s = self
        container = s.container
        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
        s.cmd('storage blob service-properties show', checks=[
            JMESPathCheck('cors', []),
            JMESPathCheck('hourMetrics.enabled', True),
            JMESPathCheck('logging.delete', False),
            JMESPathCheck('minuteMetrics.enabled', False)
        ])

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

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

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

        blob_url = 'https://{}.blob.core.windows.net/{}/{}'.format(STORAGE_ACCOUNT_NAME, 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))['items']
        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 download -n {} -c {} --download-to "{}"'.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 -n {} -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 -n {} -c {} --id {} --proposed-lease-id {}'.format(blob, container, proposed_lease_id, new_lease_id))
        s.cmd('storage blob lease renew -n {} -c {} --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 -n {} -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 -n {} -c {} --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=BooleanCheck(True))
        
        s.cmd('storage blob delete --container-name {} --name {}'.format(container, blob))
        s.cmd('storage blob exists -n {} -c {}'.format(blob, container), checks=BooleanCheck(False))
Exemplo n.º 16
0
 def body(self):
     s = self
     rg = self.rg
     account = self.account
     s.cmd('storage account check-name --name teststorageomega', checks=JMESPathCheck('nameAvailable', True))
     s.cmd('storage account check-name --name {}'.format(account), checks=[
         JMESPathCheck('nameAvailable', False),
         JMESPathCheck('reason', 'AlreadyExists')
     ])
     s.cmd('storage account list -g {} --query "[?name == \'{}\']"'.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 connection-string -g {} -n {} --use-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 {}'.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 {} --type Standard_GRS'.format(rg, account),
         checks=JMESPathCheck('sku.name', 'Standard_GRS'))
Exemplo n.º 17
0
    def body(self):
        s = self
        container = s.container
        rg = s.rg
        proposed_lease_id = s.proposed_lease_id
        new_lease_id = s.new_lease_id
        date = s.date
        _get_connection_string(self)
        # TODO: Re-enable testing of SAS tokens after playback issues resolved
        #sas_token = self.cmd('storage account generate-sas --services b --resource-types sco --permission rwdl --expiry 2100-01-01t00:00z -o list')
        #self.set_env('AZURE_SAS_TOKEN', sas_token)
        #self.set_env('AZURE_STORAGE_ACCOUNT', STORAGE_ACCOUNT_NAME)
        #self.pop_env('AZURE_STORAGE_CONNECTION_STRING')

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

        s.cmd('storage container show -n {}'.format(container), checks=JMESPathCheck('name', container))
        res = s.cmd('storage container list')['items']
        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 -n {} --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 --name {} --id {} --proposed-lease-id {}'.format(container, proposed_lease_id, new_lease_id))
        s.cmd('storage container lease renew --name {} --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 --name {} --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 -n {} --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=BooleanCheck(True))
        s.cmd('storage container exists -n {}'.format(container), checks=BooleanCheck(False))