예제 #1
0
    def test_quota_destroy_by_project(self):
        # Create limits, reservations and usage for project
        project = 'project1'
        self._quota_reserve(self.context, project)
        expected_usage = {
            'project_id': project,
            'volumes': {
                'reserved': 1,
                'in_use': 0
            },
            'gigabytes': {
                'reserved': 2,
                'in_use': 0
            }
        }
        expected = {'project_id': project, 'gigabytes': 2, 'volumes': 1}

        # Check that quotas are there
        self.assertEqual(expected,
                         api.quota_get_all_by_project(self.context, project))
        self.assertEqual(
            expected_usage,
            api.quota_usage_get_all_by_project(self.context, project))

        # Destroy only the limits
        api.quota_destroy_by_project(self.context, project)

        # Confirm that limits have been removed
        self.assertEqual({'project_id': project},
                         api.quota_get_all_by_project(self.context, project))

        # But that usage and reservations are the same
        self.assertEqual(
            expected_usage,
            api.quota_usage_get_all_by_project(self.context, project))
예제 #2
0
 def test_reservation_rollback(self):
     reservations = self._quota_reserve(self.context, 'project1')
     expected = {
         'project_id': 'project1',
         'volumes': {
             'reserved': 1,
             'in_use': 0
         },
         'gigabytes': {
             'reserved': 2,
             'in_use': 0
         },
     }
     self.assertEqual(
         expected,
         api.quota_usage_get_all_by_project(self.context, 'project1'))
     api.reservation_rollback(self.context, reservations, 'project1')
     expected = {
         'project_id': 'project1',
         'volumes': {
             'reserved': 0,
             'in_use': 0
         },
         'gigabytes': {
             'reserved': 0,
             'in_use': 0
         },
     }
     self.assertEqual(
         expected,
         api.quota_usage_get_all_by_project(self.context, 'project1'))
예제 #3
0
 def test_quota_usage_get_all_by_project(self):
     self._quota_reserve(self.context, 'p1')
     expected = {
         'project_id': 'p1',
         'volumes': {
             'in_use': 0,
             'reserved': 1
         },
         'gigabytes': {
             'in_use': 0,
             'reserved': 2
         }
     }
     self.assertEqual(
         expected, api.quota_usage_get_all_by_project(self.context, 'p1'))
예제 #4
0
    def test_quota_destroy_sqlalchemy_all_by_project_(self):
        # Create limits, reservations and usage for project
        project = 'project1'
        self._quota_reserve(self.context, project)
        expected_usage = {
            'project_id': project,
            'volumes': {
                'reserved': 1,
                'in_use': 0
            },
            'gigabytes': {
                'reserved': 2,
                'in_use': 0
            }
        }
        expected = {'project_id': project, 'gigabytes': 2, 'volumes': 1}
        expected_result = {'project_id': project}

        # Check that quotas are there
        self.assertEqual(expected,
                         api.quota_get_all_by_project(self.context, project))
        self.assertEqual(
            expected_usage,
            api.quota_usage_get_all_by_project(self.context, project))

        # Destroy all quotas using SQLAlchemy Implementation
        api.quota_destroy_all_by_project(self.context,
                                         project,
                                         only_quotas=False)

        # Check that all quotas have been deleted
        self.assertEqual(expected_result,
                         api.quota_get_all_by_project(self.context, project))
        self.assertEqual(
            expected_result,
            api.quota_usage_get_all_by_project(self.context, project))
예제 #5
0
 def test_quota_reserve(self):
     reservations = self._quota_reserve(self.context, 'project1')
     self.assertEqual(2, len(reservations))
     quota_usage = api.quota_usage_get_all_by_project(
         self.context, 'project1')
     self.assertEqual(
         {
             'project_id': 'project1',
             'gigabytes': {
                 'reserved': 2,
                 'in_use': 0
             },
             'volumes': {
                 'reserved': 1,
                 'in_use': 0
             }
         }, quota_usage)
예제 #6
0
    def test_reservation_expire(self):
        self.values['expire'] = datetime.datetime.utcnow() + \
            datetime.timedelta(days=1)
        self._quota_reserve(self.context, 'project1')
        api.reservation_expire(self.context)

        expected = {
            'project_id': 'project1',
            'gigabytes': {
                'reserved': 0,
                'in_use': 0
            },
            'volumes': {
                'reserved': 0,
                'in_use': 0
            }
        }
        self.assertEqual(
            expected,
            api.quota_usage_get_all_by_project(self.context, 'project1'))