コード例 #1
0
ファイル: rebase_test.py プロジェクト: ws-tools/nimbus
class TestUser(unittest.TestCase):

    def setUp(self):
#        os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql"
        con = pynimbusauthz.db.make_test_database()
        self.db = DB(con=con)
        self.user = User(self.db)

    def tearDown(self):
        self.user.destroy_brutally()
        self.db.close()

    def test_get_no_quota(self):
        q = self.user.get_quota()
        self.assertEqual(q, User.UNLIMITED)

    def test_set_quota(self):
        q = 100
        self.user.set_quota(q)
        qrc = self.user.get_quota()
        self.assertEqual(q, qrc)

    def test_get_no_usage(self):
        u = self.user.get_quota_usage()
        self.assertEqual(u, 0)

    def test_add_file_usage_one_file(self):
        size1 = 100
        name = "/file/name"
        data = "/etc/group"

        file1 = File.create_file(self.db, name, self.user, data, pynimbusauthz.object_type_s3, size=size1)
        self.db.commit()

        u = self.user.get_quota_usage()
        self.assertEqual(u, size1)

    def test_add_file_usage_many_files(self):
        size1 = 100
        name = "/file/name"
        data = "/etc/group"

        total = 0
        for i in range(0, 10):
            file1 = File.create_file(self.db, name+str(i), self.user, data, pynimbusauthz.object_type_s3, size=size1)
            total = total + size1
        self.db.commit()

        u = self.user.get_quota_usage()
        self.assertEqual(u, total)
コード例 #2
0
ファイル: quota.py プロジェクト: ketancmaheshwari/nimbus
def main(argv=sys.argv[1:]):

    try:
        con_str = pynimbusauthz.get_db_connection_string()
        db_obj = DB(con_str=con_str)

        (opts, args) = setup_options(argv)

        user = User(db_obj, args[0], create=False)

        if opts.quota != None:
            q = opts.quota
            if opts.quota == "UNLIMITED":
                q = User.UNLIMITED

            user.set_quota(q, object_type=opts.type)
        if opts.report:
            q = user.get_quota(object_type=opts.type)
            u = user.get_quota_usage(object_type=opts.type)

            if q != User.UNLIMITED:
                r = q - u

                rstr = pynimbusauthz.pretty_number(r)
                qstr = pynimbusauthz.pretty_number(q)
                ustr = pynimbusauthz.pretty_number(u)

                pynimbusauthz.print_msg(opts, 0, "%-10s %s" % ("Quota", qstr))
                pynimbusauthz.print_msg(opts, 0, "%-10s %s" % ("Usage", ustr))
                pynimbusauthz.print_msg(opts, 0, "%-10s %s" % ("Remaining", rstr))
                if r < 0:
                    pynimbusauthz.print_msg(opts, 0, "OVER LIMIT!")
                elif r == 0:
                    pynimbusauthz.print_msg(opts, 0, "At Limit")
                else:
                    p = (float(r) / float(q)) * 100.0
                    pynimbusauthz.print_msg(opts, 0, "%-10s %5.1f%%" % ("Available", p))
            else:
                pynimbusauthz.print_msg(opts, 0, "Quota UNLIMITED")

        db_obj.commit()
    except AuthzException, ae:
        print ae
        return ae.get_rc()