Ejemplo n.º 1
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())
Ejemplo n.º 2
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())
Ejemplo n.º 3
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())
Ejemplo n.º 4
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())
Ejemplo n.º 5
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())
Ejemplo n.º 6
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())
Ejemplo 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 {} --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))
Ejemplo n.º 8
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))
Ejemplo n.º 9
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())
Ejemplo n.º 10
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']
Ejemplo n.º 11
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']
Ejemplo n.º 12
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)
Ejemplo n.º 13
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'),
                 ])
Ejemplo n.º 14
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))
Ejemplo n.º 15
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))

        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 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))
Ejemplo n.º 16
0
    def body(self):
        nsg_name = 'nsg1'
        self.cmd(
            'network nsg create -n {} -g {}'.format(nsg_name,
                                                    self.resource_group), None)
        result = self.cmd(
            'network nsg show -n {} -g {}'.format(nsg_name,
                                                  self.resource_group), None)
        resource_id = result['id']

        #test role assignments on a resource group
        self.cmd(
            'role assignment create --assignee {} --role contributor -g {}'.
            format(self.user, self.resource_group), None)
        self.cmd('role assignment list -g {}'.format(self.resource_group),
                 checks=[JMESPathCheck("length([])", 1)])
        self.cmd('role assignment list --assignee {} --role contributor -g {}'.
                 format(self.user, self.resource_group),
                 checks=[JMESPathCheck("length([])", 1)])

        #test couple of more general filters
        result = self.cmd(
            'role assignment list -g {} --include-inherited'.format(
                self.resource_group), None)
        self.assertTrue(len(result) >= 1)

        result = self.cmd(
            'role assignment list --all'.format(self.user,
                                                self.resource_group), None)
        self.assertTrue(len(result) >= 1)

        self.cmd(
            'role assignment delete --assignee {} --role contributor -g {}'.
            format(self.user, self.resource_group), None)
        self.cmd('role assignment list -g {}'.format(self.resource_group),
                 checks=NoneCheck())

        #test role assignments on a resource
        self.cmd(
            'role assignment create --assignee {} --role contributor --scope {}'
            .format(self.user, resource_id), None)
        self.cmd(
            'role assignment list --assignee {} --role contributor --scope {}'.
            format(self.user, resource_id),
            checks=[JMESPathCheck("length([])", 1)])
        self.cmd(
            'role assignment delete --assignee {} --role contributor --scope {}'
            .format(self.user, resource_id), None)
        self.cmd('role assignment list --scope {}'.format(resource_id),
                 checks=NoneCheck())

        #test role assignment on subscription level
        self.cmd(
            'role assignment create --assignee {} --role reader'.format(
                self.user), None)
        self.cmd('role assignment list --assignee {} --role reader'.format(
            self.user),
                 checks=[JMESPathCheck("length([])", 1)])
        self.cmd('role assignment list --assignee {}'.format(self.user),
                 checks=[JMESPathCheck("length([])", 1)])
        self.cmd(
            'role assignment delete --assignee {} --role reader'.format(
                self.user), None)