Exemplo n.º 1
0
 def test_batchai_usages(self):
     # Just check if we can get a usage and it contains info about clusters.
     self.cmd(
         'batchai list-usages -l {0}'.format(LOCATION_FOR_SCENARIO_TESTS),
         checks=[StringContainCheck("Cluster")])
     self.cmd('batchai list-usages -l {0} -o table'.format(
         LOCATION_FOR_SCENARIO_TESTS),
              checks=[StringContainCheck("Cluster")])
    def _test_flexible_server_public_access_mgmt(self, database_engine,
                                                 resource_group):
        # flexible-server create
        if self.cli_ctx.local_context.is_on:
            self.cmd('local-context off')

        if database_engine == 'postgres':
            sku_name = 'Standard_D2s_v3'
            location = self.postgres_location
        elif database_engine == 'mysql':
            sku_name = 'Standard_B1ms'
            location = self.mysql_location

        # flexible-servers
        servers = [
            self.create_random_name('azuredbpaccess', SERVER_NAME_MAX_LENGTH),
            self.create_random_name('azuredbpaccess', SERVER_NAME_MAX_LENGTH)
        ]

        # Case 1 : Provision a server with public access all
        # create server
        self.cmd(
            '{} flexible-server create -g {} -n {} --public-access {} -l {}'.
            format(database_engine, resource_group, servers[0], 'all',
                   location),
            checks=[
                JMESPathCheck('resourceGroup', resource_group),
                JMESPathCheck('skuname', sku_name),
                StringContainCheck('AllowAll_'),
                StringContainCheck(servers[0])
            ])

        # Case 2 : Provision a server with public access allowing all azure services
        self.cmd(
            '{} flexible-server create -g {} -n {} --public-access {} -l {}'.
            format(database_engine, resource_group, servers[1], '0.0.0.0',
                   location),
            checks=[
                JMESPathCheck('resourceGroup', resource_group),
                JMESPathCheck('skuname', sku_name),
                StringContainCheck(
                    'AllowAllAzureServicesAndResourcesWithinAzureIps_'),
                StringContainCheck(servers[1])
            ])

        # delete all servers
        self.cmd('{} flexible-server delete -g {} -n {} --yes'.format(
            database_engine, resource_group, servers[0]),
                 checks=NoneCheck())

        self.cmd('{} flexible-server delete -g {} -n {} --yes'.format(
            database_engine, resource_group, servers[1]),
                 checks=NoneCheck())
    def test_storage_file_main_scenario(self, resource_group, storage_account):
        account_info = self.get_account_info(resource_group, storage_account)
        s1 = self.create_share(account_info)
        s2 = self.create_random_name('share', 24)
        self.storage_cmd(
            'storage share create -n {} --metadata foo=bar cat=hat',
            account_info, s2)
        self.storage_cmd('storage share exists -n {}', account_info, s1) \
            .assert_with_checks(JMESPathCheck('exists', True))
        self.storage_cmd('storage share metadata show --name {}', account_info, s2) \
            .assert_with_checks(JMESPathCheck('cat', 'hat'), JMESPathCheck('foo', 'bar'))

        share_list = self.storage_cmd('storage share list --query "[].name"',
                                      account_info).get_output_in_json()
        self.assertIn(s1, share_list)
        self.assertIn(s2, share_list)

        # verify metadata can be set, queried, and cleared
        self.storage_cmd(
            'storage share metadata update --name {} --metadata a=b c=d',
            account_info, s1)
        self.storage_cmd('storage share metadata show -n {}', account_info, s1) \
            .assert_with_checks(JMESPathCheck('a', 'b'), JMESPathCheck('c', 'd'))
        self.storage_cmd('storage share metadata update -n {}', account_info,
                         s1)
        self.storage_cmd('storage share metadata show -n {}', account_info, s1) \
            .assert_with_checks(NoneCheck())

        self.storage_cmd('storage share update --name {} --quota 3',
                         account_info, s1)
        self.storage_cmd('storage share show --name {}', account_info, s1) \
            .assert_with_checks(JMESPathCheck('properties.quota', 3))
        self.storage_cmd('storage share url --name {}', account_info, s1) \
            .assert_with_checks(StringContainCheck(s1), StringContainCheck('http'))
        unc = self.storage_cmd('storage share url --name {} --unc',
                               account_info, s1).output
        self.assertTrue('http' not in unc and s1 in unc)

        sas = self.storage_cmd(
            'storage share generate-sas -n {} --permissions r --expiry '
            '2046-08-23T10:30Z', account_info, s1).output
        self.assertIn('sig=', sas)

        self.validate_file_scenario(account_info, s1)
        self.validate_directory_scenario(account_info, s1)

        self.storage_cmd('storage share delete -n {}', account_info, s1) \
            .assert_with_checks(JMESPathCheck('deleted', True))
Exemplo n.º 4
0
    def _test_flexible_server_local_context(self, database_engine, resource_group):
        self.cmd('config param-persist on')
        if database_engine == 'mysql':
            location = self.mysql_location
        else:
            location = self.postgres_location

        server_name = self.create_random_name(SERVER_NAME_PREFIX, SERVER_NAME_MAX_LENGTH)

        self.cli_ctx.local_context.set(['all'], 'resource_group_name', resource_group)
        self.cli_ctx.local_context.set(['all'], 'location', location)

        self.cmd('{} flexible-server create -n {} --public-access none'.format(database_engine, server_name))

        local_context_info = self.cmd('config param-persist show').get_output_in_json()

        self.cmd('{} flexible-server show'.format(database_engine),
                 checks=[JMESPathCheck('resourceGroup', local_context_info['all']['resource_group_name']),
                         JMESPathCheck('location', 'East US 2 EUAP'),
                         JMESPathCheck('name', local_context_info[database_engine + ' flexible-server']['server_name']),
                         JMESPathCheck('administratorLogin', local_context_info[database_engine + ' flexible-server']['administrator_login'])])

        self.cmd('{} flexible-server show-connection-string'.format(database_engine),
                 checks=[StringContainCheck(local_context_info[database_engine + ' flexible-server']['administrator_login'])]).get_output_in_json()

        self.cmd('{} flexible-server list-skus'.format(database_engine))

        self.cmd('{} flexible-server delete --yes'.format(database_engine))

        delete_local_context_info = self.cmd('config param-persist show').get_output_in_json()
        self.assertNotIn(database_engine + ' flexible-server', delete_local_context_info)
        self.assertNotIn(local_context_info[database_engine + ' flexible-server']['server_name'], delete_local_context_info)
        self.assertNotIn(local_context_info[database_engine + ' flexible-server']['administrator_login'], delete_local_context_info)
    def validate_file_scenario(self, account_info, share):
        source_file = self.create_temp_file(128, full_random=False)
        dest_file = self.create_temp_file(1)
        filename = "sample_file.bin"

        self.storage_cmd('storage file upload --share-name {} --source "{}" -p {}', account_info,
                         share, source_file, filename)
        self.storage_cmd('storage file exists -s {} -p {}', account_info, share, filename) \
            .assert_with_checks(JMESPathCheck('exists', True))

        if os.path.isfile(dest_file):
            os.remove(dest_file)

        self.storage_cmd('storage file download --share-name {} -p "{}" --dest "{}"', account_info,
                         share, filename, dest_file)

        self.assertTrue(os.path.isfile(dest_file))
        self.assertEqual(os.stat(dest_file).st_size, 128 * 1024)

        self.storage_cmd('storage file download --share-name {} -p "{}" --dest "{}" --start-range 0 --end-range 511', account_info,
                         share, filename, dest_file)

        self.assertTrue(os.path.isfile(dest_file))
        self.assertEqual(os.stat(dest_file).st_size, 512)

        # test resize command
        self.storage_cmd('storage file resize --share-name {} -p "{}" --size 1234', account_info,
                         share, filename)
        self.storage_cmd('storage file show -s {} -p "{}"', account_info, share, filename) \
            .assert_with_checks(JMESPathCheck('properties.contentLength', 1234))

        # test ability to set and reset metadata
        self.storage_cmd('storage file metadata update --share-name {} -p "{}" --metadata a=b c=d',
                         account_info, share, filename)
        self.storage_cmd('storage file metadata show -s {} -p "{}"', account_info, share,
                         filename) \
            .assert_with_checks(JMESPathCheck('a', 'b'), JMESPathCheck('c', 'd'))
        self.storage_cmd('storage file metadata update --share-name {} -p "{}"', account_info,
                         share, filename)
        self.storage_cmd('storage file metadata show -s {} -p "{}"', account_info, share,
                         filename) \
            .assert_with_checks(NoneCheck())

        file_url = 'https://{}.file.core.windows.net/{}/{}'.format(account_info[0], share, filename)
        self.storage_cmd('storage file url -s {} -p "{}"', account_info, share, filename) \
            .assert_with_checks(StringCheck(file_url))

        self.assertIn(filename,
                      self.storage_cmd('storage file list -s {} --query "[].name"',
                                       account_info, share).get_output_in_json())

        from datetime import datetime, timedelta
        expiry = (datetime.utcnow() + timedelta(hours=1)).strftime('%Y-%m-%dT%H:%MZ')
        self.storage_cmd('storage file generate-sas -s {} -p {} --permissions r --expiry {}', account_info, share,
                         filename, expiry).assert_with_checks(StringContainCheck('sig='))

        self.storage_cmd('storage file update -s {} -p {} --content-type "test/type"', account_info,
                         share, filename)
        self.storage_cmd('storage file show -s {} -p {}', account_info, share,
                         filename) \
            .assert_with_checks(JMESPathCheck('properties.contentSettings.contentType',
                                              'test/type'))

        self.storage_cmd('storage file delete --share-name {} -p "{}"',
                         account_info, share, filename)
        self.storage_cmd('storage file exists --share-name {} -p "{}"',
                         account_info, share, filename) \
            .assert_with_checks(JMESPathCheck('exists', False))