Example #1
0
    def test_delete_bucket(self):
        tmp_bucket = 'tmpbucket'

        cmdline = 'obs mb %s' % join_bucket_key(tmp_bucket)
        self.run_cmd(cmdline, expected_rc=0)

        cmdline = 'obs ls'
        stdout = self.run_cmd(cmdline, expected_rc=0)[0]
        self.assertIn(tmp_bucket, stdout)

        cmdline = '%s %s' % (self.cmd, join_bucket_key(tmp_bucket))
        self.run_cmd(cmdline, expected_rc=0)

        cmdline = 'obs ls'
        stdout = self.run_cmd(cmdline, expected_rc=0)[0]
        self.assertNotIn(tmp_bucket, stdout)
Example #2
0
    def test_make_acl_from_acl_control(self):

        cmdline = '%s %s --acl-control public-read-write' % (
            self.cmd, join_bucket_key(self.bucket))
        stdout = self.run_cmd(cmdline, expected_rc=0)[0]

        self.assertIn('complete', stdout)
 def setUpClass(cls):
     cls.client = create_client_with_default_config()
     cls.bucket = TEST_BUCKET
     if not ObsCmdUtil(cls.client).head_bucket(TEST_BUCKET):
         # cls.bucket = ObsCmdUtil(cls.client).create_bucket(TEST_BUCKET, location='cn-east-2')
         cls.bucket = ObsCmdUtil(cls.client).create_bucket(TEST_BUCKET)
         time.sleep(20)
     cls.fullbucket = join_bucket_key(cls.bucket)
Example #4
0
    def test_set_log(self):
        bucket = self.bucket
        log_str = '{"targetBucket":"' + bucket + '","targetPrefix":""}'
        cmdline = '%s %s --log %s' % (self.cmd, join_bucket_key(
            self.bucket), log_str)
        stdout = self.run_cmd(cmdline, expected_rc=0)[0]

        self.assertIn('complete', stdout)
Example #5
0
    def _list_all_objects(self, bucket, prefix, limit,  outfile=None):
        items = ObsCmdUtil(self.client).get_objects_info(bucket, prefix, ('lastModified', 'size', 'key'), limit)

        for item in items:
            self._outprint("%19s\t%8s\t%s\n" % (item[0], bytes_to_unitstr(item[1]), join_bucket_key(bucket, item[2])), outfile)

        self._outprint('\ndisplay total: %d objects' % len(items), outfile)
        if outfile:
            self._outprint('ls to file %s complete.' % outfile)
Example #6
0
    def test_delete_policy_from_json(self):
        policy = '{"Version":"2008-10-17","Id":"Policy2","Statement":[{"Sid":"Stmt1375240018061",' \
                 '"Effect":"Allow","Principal":{"AWS":["arn:aws:iam::userid:root"]},' \
                 '"Action":["s3:GetBucketPolicy"],"Resource":["arn:aws:s3:::%s"]}]}' % self.bucket

        cmdline = 'obs mbp %s %s' % (join_bucket_key(self.bucket), policy)
        self.run_cmd(cmdline, expected_rc=0)

        cmdline = 'obs infob %s --policy' % join_bucket_key(self.bucket)
        stdout = self.run_cmd(cmdline, expected_rc=0)[0]
        self.assertIn('Policy2', stdout)

        cmdline = '%s %s' % (self.cmd, join_bucket_key(self.bucket))
        self.run_cmd(cmdline, expected_rc=0)

        cmdline = 'obs infob %s --policy' % join_bucket_key(self.bucket)
        stdout = self.run_cmd(cmdline, expected_rc=0)[0]
        self.assertNotIn('Policy2', stdout)
    def test_set_website(self):

        cmdline = '%s %s %s' % (self.cmd, join_bucket_key(
            self.bucket
        ), '{"indexDocument":{"suffix":"index.html"},"errorDocument":{"key":"error.html"},"routingRules":[{"condition":{"httpErrorCodeReturnedEquals":404},"redirect":{"protocol":"http","replaceKeyWith":"NotFound.html"}}]}'
                                )
        stdout = self.run_cmd(cmdline, expected_rc=0)[0]

        self.assertIn('complete', stdout)
Example #8
0
    def test_upload_download_single_bigfile_on_ecs(self):
        """
        compare spending time for no flow width limit, the flow width must
        greater than 100M/s
        :return: 
        """
        obspath = join_bucket_key(self.bucket)

        with mock.patch(
                'obscmd.utils.get_flowwidth_from_flowpolicy') as flowwidth:
            flowwidth.return_value = 100 * 1024**3

            # upload
            file500M = self.files.create_size_file('file500M', '500M')
            cmdline = '%s %s %s --tasknum 4' % (self.cmd, file500M, obspath)
            delta_time1 = self.run_cmd_for_count_time(cmdline, expected_rc=0)
            self.print_run_time('500M', delta_time1, 4, cmdline)
            self.assertLess(delta_time1, 500 / 100.0)

            cmdline = '%s %s %s --tasknum 8' % (self.cmd, file500M, obspath)
            delta_time1 = self.run_cmd_for_count_time(cmdline, expected_rc=0)
            self.print_run_time('500M', delta_time1, 8, cmdline)
            self.assertLess(delta_time1, 500 / 100.0)

            file10G = self.files.create_size_file('file10G', '10G')

            cmdline = '%s %s %s --tasknum 4' % (self.cmd, file10G, obspath)
            delta_time1 = self.run_cmd_for_count_time(cmdline, expected_rc=0)
            self.print_run_time('10G', delta_time1, 4, cmdline)
            self.assertLess(delta_time1, 10 * 1024 / 100.0)

            cmdline = '%s %s %s --tasknum 8' % (self.cmd, file10G, obspath)
            delta_time1 = self.run_cmd_for_count_time(cmdline, expected_rc=0)
            self.print_run_time('10G', delta_time1, 8, cmdline)
            self.assertLess(delta_time1, 10 * 1024 / 100.0)

            # download
            fulltmpdir = self.files.create_dir('bigfiles')
            cmdline = '%s %s/file10G %s --tasknum 4' % (self.cmd, obspath,
                                                        fulltmpdir)
            delta_time1 = self.run_cmd_for_count_time(cmdline, expected_rc=0)
            self.print_run_time('10G', delta_time1, 4, cmdline)
            self.assertLess(delta_time1, 10 * 1024 / 100.0)

            cmdline = '%s %s/file10G %s --tasknum 8' % (self.cmd, obspath,
                                                        fulltmpdir)
            delta_time1 = self.run_cmd_for_count_time(cmdline, expected_rc=0)
            self.print_run_time('10G', delta_time1, 8, cmdline)
            self.assertLess(delta_time1, 10 * 1024 / 100.0)
Example #9
0
    def _list_dirs_objects(self, bucket, prefix, limit, outfile=None):

        dirs, objects = ObsCmdUtil(self.client).list_dirs_objects(bucket, prefix)
        cur = 0
        for item in dirs:
            if limit and cur >= limit:
                break
            self._outprint("%19s\t%8s\t%s\n" % ('--', '--', join_bucket_key(bucket, item)), outfile)
            cur += 1
        for item in objects:
            if limit and cur >= limit:
                break
            self._outprint("%19s\t%8s\t%s\n" % (item['lastModified'], bytes_to_unitstr(item['size']), (join_bucket_key(bucket, item['key']))), outfile)
            cur += 1

        self._outprint('\ntotal: %d dirs, %d objects' % (len(dirs), len(objects)), outfile)
Example #10
0
    def _list_all_buckets(self):
        resp = self.client.listBuckets()
        check_resp(resp)

        if not resp.body.buckets:
            self._outprint("no bucket found.")
        bucket_infos = []

        for bucket in resp.body.buckets:
            storage = ObsCmdUtil(self.client).get_bucket_storage(bucket.name)
            bucket_infos.append((bucket, storage))

        for bucket, storage in bucket_infos:
            self._outprint("%-19s\t%-8s\t%-8s\t%-8s\n" % (bucket.create_date, bucket.location, storage, join_bucket_key(bucket.name)))
Example #11
0
    def test_delete_all_lifecycle(self):

        cmdline = '%s %s' % (self.cmd, join_bucket_key(self.bucket))
        stdout = self.run_cmd(cmdline, expected_rc=0)[0]

        self.assertIn('complete', stdout)
Example #12
0
    def test_notset_log(self):
        cmdline = '%s %s' % (self.cmd, join_bucket_key(self.bucket))
        stdout = self.run_cmd(cmdline, expected_rc=0)[0]

        self.assertIn('complete', stdout)
Example #13
0
    def delete_object(self, bucket, key, version):
        self.obs_cmd_util.delete_object(bucket, key, version)
        self._outprint("delete object: %s" % join_bucket_key(bucket, key))

        if version:
            self._outprint("version: %s" % version)
Example #14
0
 def test_bucket_without_key(self):
     self.assertEqual(join_bucket_key('bucket'), 'obs://bucket')
Example #15
0
 def test_bucket_with_key(self):
     self.assertEqual(join_bucket_key('bucket', '/foo'), 'obs://bucket/foo')
     self.assertEqual(join_bucket_key('bucket/', '/doc/foo'),
                      'obs://bucket/doc/foo')
     self.assertEqual(join_bucket_key('bucket', '\\doc\\foo/'),
                      'obs://bucket/doc/foo/')