示例#1
0
    def setUp(self):

        users = [
            {
                "auth_user": "******",
                "auth_key": "password",
                "tenant": "4000",
                "requirements": {
                    "is_admin": False,
                    "services": ["trove"]
                }
            },
            {
                "auth_user": "******",
                "auth_key": "password",
                "tenant": "4050",
                "requirements": {
                    "is_admin": False,
                    "services": ["trove"]
                }
            }]

        self._users = Users(users)

        rate_user = self._get_user('rate_limit')
        self.rd_client = create_dbaas_client(rate_user)
示例#2
0
class TestUsers(unittest.TestCase):

    NUMBER_OF_USER_TESTS = 12

    def setUp(self):
        self.users = Users(USER_LIST)

    def test_should_find_five_users(self):
        self.assertEqual(5, len(self.users.users))

    def test_initially_test_counts_are_zero(self):
        for user in self.users.users:
            self.assertEqual(0, user.test_count)

    def test_all_admin_users_are_found(self):
        admins = set()
        for x in range(self.NUMBER_OF_USER_TESTS):
            user = self.users.find_user(Requirements(is_admin=True))
            if user not in admins:
                admins.add(user)
        self.assertEqual(NUMBER_OF_ADMINS, len(admins))
        admin_names = list(user.auth_user for user in admins)
        self.assertTrue("admin" in admin_names)
        self.assertTrue("anne" in admin_names)
        self.assertTrue("dan" in admin_names)
        expected_test_count = self.NUMBER_OF_USER_TESTS / NUMBER_OF_ADMINS
        for user in admins:
            self.assertTrue(user.requirements.is_admin)
            self.assertEqual(expected_test_count, user.test_count)

    def test_all_non_admin_users_are_found(self):
        normals = set()
        for x in range(self.NUMBER_OF_USER_TESTS):
            user = self.users.find_user(Requirements(is_admin=False))
            if user not in normals:
                normals.add(user)
        self.assertEqual(NUMBER_OF_NORMALS, len(normals))
        normal_names = list(user.auth_user for user in normals)
        self.assertTrue("mike" in normal_names)
        self.assertTrue("tim" in normal_names)
        expected_test_count = self.NUMBER_OF_USER_TESTS / NUMBER_OF_NORMALS
        for user in normals:
            self.assertFalse(user.requirements.is_admin)
            self.assertEqual(expected_test_count, user.test_count)
示例#3
0
 def users(self):
     if self._users is None:
         from trove.tests.util.users import Users
         self._users = Users(self.values['users'])
     return self._users
示例#4
0
class Limits(object):

    @before_class
    def setUp(self):

        users = [
            {
                "auth_user": "******",
                "auth_key": "password",
                "tenant": "4000",
                "requirements": {
                    "is_admin": False,
                    "services": ["trove"]
                }
            },
            {
                "auth_user": "******",
                "auth_key": "password",
                "tenant": "4050",
                "requirements": {
                    "is_admin": False,
                    "services": ["trove"]
                }
            }]

        self._users = Users(users)

        rate_user = self._get_user('rate_limit')
        self.rd_client = create_dbaas_client(rate_user)

    def _get_user(self, name):
        return self._users.find_user_by_name(name)

    def __is_available(self, next_available):
        dt_next = timeutils.parse_isotime(next_available)
        dt_now = datetime.now()
        return dt_next.time() < dt_now.time()

    def _get_limits_as_dict(self, limits):
        d = {}
        for l in limits:
            d[l.verb] = l
        return d

    @test
    @ensure_limits_are_not_faked
    def test_limits_index(self):
        """Test_limits_index."""

        limits = self.rd_client.limits.list()
        d = self._get_limits_as_dict(limits)

        # remove the abs_limits from the rate limits
        abs_limits = d.pop("ABSOLUTE", None)
        assert_equal(abs_limits.verb, "ABSOLUTE")
        assert_equal(int(abs_limits.max_instances), DEFAULT_MAX_INSTANCES)
        assert_equal(int(abs_limits.max_backups), DEFAULT_MAX_BACKUPS)
        assert_equal(int(abs_limits.max_volumes), DEFAULT_MAX_VOLUMES)

        for k in d:
            assert_equal(d[k].verb, k)
            assert_equal(d[k].unit, "MINUTE")
            assert_true(int(d[k].remaining) <= DEFAULT_RATE)
            assert_true(d[k].nextAvailable is not None)

    @test
    @ensure_limits_are_not_faked
    def test_limits_get_remaining(self):
        """Test_limits_get_remaining."""

        limits = ()
        for i in xrange(5):
            limits = self.rd_client.limits.list()

        d = self._get_limits_as_dict(limits)
        abs_limits = d["ABSOLUTE"]
        get = d["GET"]

        assert_equal(int(abs_limits.max_instances), DEFAULT_MAX_INSTANCES)
        assert_equal(int(abs_limits.max_backups), DEFAULT_MAX_BACKUPS)
        assert_equal(int(abs_limits.max_volumes), DEFAULT_MAX_VOLUMES)
        assert_equal(get.verb, "GET")
        assert_equal(get.unit, "MINUTE")
        assert_true(int(get.remaining) <= DEFAULT_RATE - 5)
        assert_true(get.nextAvailable is not None)

    @test
    @ensure_limits_are_not_faked
    def test_limits_exception(self):
        """Test_limits_exception."""

        # use a different user to avoid throttling tests run out of order
        rate_user_exceeded = self._get_user('rate_limit_exceeded')
        rd_client = create_dbaas_client(rate_user_exceeded)

        get = None
        encountered = False
        for i in xrange(DEFAULT_RATE + 50):
            try:
                limits = rd_client.limits.list()
                d = self._get_limits_as_dict(limits)
                get = d["GET"]
                abs_limits = d["ABSOLUTE"]

                assert_equal(get.verb, "GET")
                assert_equal(get.unit, "MINUTE")
                assert_equal(int(abs_limits.max_instances),
                             DEFAULT_MAX_INSTANCES)
                assert_equal(int(abs_limits.max_backups),
                             DEFAULT_MAX_BACKUPS)
                assert_equal(int(abs_limits.max_volumes),
                             DEFAULT_MAX_VOLUMES)

            except exceptions.OverLimit:
                encountered = True

        assert_true(encountered)
        assert_true(int(get.remaining) <= 50)
示例#5
0
 def setUp(self):
     self.users = Users(USER_LIST)