예제 #1
0
 def test_create_delete_network_marks_dirty(self):
     self._test_init('network')
     net = self._make_network('json', 'meh', True)['network']
     self._verify_dirty_bit('network')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'network', self._tenant_id, dirty=False)
     self._delete('networks', net['id'])
     self._verify_dirty_bit('network')
예제 #2
0
 def test_create_delete_network_marks_dirty(self):
     self._test_init('network')
     net = self._make_network('json', 'meh', True)['network']
     self._verify_dirty_bit('network')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'network', self._tenant_id, dirty=False)
     self._delete('networks', net['id'])
     self._verify_dirty_bit('network')
예제 #3
0
 def test_create_delete_securitygroup_marks_dirty(self):
     self._test_init('security_group')
     sec_group = self._make_security_group(
         'json', 'meh', 'meh', tenant_id=self._tenant_id)['security_group']
     self._verify_dirty_bit('security_group')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'security_group', self._tenant_id, dirty=False)
     self._delete('security-groups', sec_group['id'])
     self._verify_dirty_bit('security_group')
예제 #4
0
 def test_create_delete_securitygroup_marks_dirty(self):
     self._test_init('security_group')
     sec_group = self._make_security_group(
         'json', 'meh', 'meh', tenant_id=self._tenant_id)['security_group']
     self._verify_dirty_bit('security_group')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'security_group', self._tenant_id, dirty=False)
     self._delete('security-groups', sec_group['id'])
     self._verify_dirty_bit('security_group')
예제 #5
0
 def test_create_delete_port_marks_dirty(self):
     self._test_init('port')
     net = self._make_network('json', 'meh', True)['network']
     port = self._make_port('json', net['id'])['port']
     self._verify_dirty_bit('port')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'port', self._project_id, dirty=False)
     self._delete('ports', port['id'])
     self._verify_dirty_bit('port')
예제 #6
0
 def test_create_delete_subnetpool_marks_dirty(self):
     self._test_init('subnetpool')
     pool = self._make_subnetpool('json', ['10.0.0.0/8'],
                                  name='meh',
                                  tenant_id=self._tenant_id)['subnetpool']
     self._verify_dirty_bit('subnetpool')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'subnetpool', self._tenant_id, dirty=False)
     self._delete('subnetpools', pool['id'])
     self._verify_dirty_bit('subnetpool')
예제 #7
0
 def test_create_delete_subnet_marks_dirty(self):
     self._test_init('subnet')
     net = self._make_network('json', 'meh', True)
     subnet = self._make_subnet('json', net, '10.0.0.1',
                                '10.0.0.0/24')['subnet']
     self._verify_dirty_bit('subnet')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'subnet', self._tenant_id, dirty=False)
     self._delete('subnets', subnet['id'])
     self._verify_dirty_bit('subnet')
예제 #8
0
 def test_count_with_dirty_true_no_usage_info_calls_set_quota_usage(self):
     res = self._create_resource()
     self._add_data()
     set_quota_usage = 'neutron.db.quota.api.set_quota_usage'
     with mock.patch(set_quota_usage) as mock_set_quota_usage:
         quota_api.set_quota_usage_dirty(self.context,
                                         self.resource,
                                         self.tenant_id)
         res.count(self.context, None, self.tenant_id, resync_usage=True)
         mock_set_quota_usage.assert_called_once_with(
             self.context, self.resource, self.tenant_id, in_use=2)
예제 #9
0
 def mark_dirty(self, context, nested=False):
     if not self._dirty_tenants:
         return
     with context.session.begin(nested=nested, subtransactions=True):
         for tenant_id in self._dirty_tenants:
             quota_api.set_quota_usage_dirty(context, self.name, tenant_id)
             LOG.debug(("Persisted dirty status for tenant:%(tenant_id)s "
                        "on resource:%(resource)s"),
                       {'tenant_id': tenant_id, 'resource': self.name})
     self._out_of_sync_tenants |= self._dirty_tenants
     self._dirty_tenants.clear()
예제 #10
0
 def test_create_delete_subnet_marks_dirty(self):
     self._test_init('subnet')
     net = self._make_network('json', 'meh', True)
     subnet = self._make_subnet('json', net, '10.0.0.1',
                                '10.0.0.0/24')['subnet']
     self._verify_dirty_bit('subnet')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'subnet', self._tenant_id, dirty=False)
     self._delete('subnets', subnet['id'])
     self._verify_dirty_bit('subnet')
예제 #11
0
 def test_create_delete_subnetpool_marks_dirty(self):
     self._test_init('subnetpool')
     pool = self._make_subnetpool('json', ['10.0.0.0/8'],
                                  name='meh',
                                  tenant_id=self._tenant_id)['subnetpool']
     self._verify_dirty_bit('subnetpool')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'subnetpool', self._tenant_id, dirty=False)
     self._delete('subnetpools', pool['id'])
     self._verify_dirty_bit('subnetpool')
예제 #12
0
 def test_count_with_dirty_true_no_usage_info_calls_set_quota_usage(self):
     res = self._create_resource()
     self._add_data()
     set_quota_usage = 'neutron.db.quota.api.set_quota_usage'
     with mock.patch(set_quota_usage) as mock_set_quota_usage:
         quota_api.set_quota_usage_dirty(self.context,
                                         self.resource,
                                         self.tenant_id)
         res.count(self.context, None, self.tenant_id, resync_usage=True)
         mock_set_quota_usage.assert_called_once_with(
             self.context, self.resource, self.tenant_id, in_use=2)
예제 #13
0
 def test_count_used_with_dirty_true_resync_calls_set_quota_usage(self):
     res = self._test_count()
     set_quota_usage = 'neutron.db.quota.api.set_quota_usage'
     with mock.patch(set_quota_usage) as mock_set_quota_usage:
         quota_api.set_quota_usage_dirty(self.context, self.resource,
                                         self.project_id)
         res.count_used(self.context, self.project_id, resync_usage=True)
         mock_set_quota_usage.assert_called_once_with(self.context,
                                                      self.resource,
                                                      self.project_id,
                                                      in_use=2)
예제 #14
0
 def mark_dirty(self, context, nested=False):
     if not self._dirty_tenants:
         return
     with context.session.begin(nested=nested, subtransactions=True):
         for tenant_id in self._dirty_tenants:
             quota_api.set_quota_usage_dirty(context, self.name, tenant_id)
             LOG.debug(("Persisted dirty status for tenant:%(tenant_id)s "
                        "on resource:%(resource)s"), {
                            'tenant_id': tenant_id,
                            'resource': self.name
                        })
     self._out_of_sync_tenants |= self._dirty_tenants
     self._dirty_tenants.clear()
예제 #15
0
 def test_create_delete_securitygrouprule_marks_dirty(self):
     self._test_init('security_group_rule')
     sec_group = self._make_security_group(
         'json', 'meh', 'meh', tenant_id=self._tenant_id)['security_group']
     rule_req = self._build_security_group_rule(
         sec_group['id'], 'ingress', 'TCP', tenant_id=self._tenant_id)
     sec_group_rule = self._make_security_group_rule(
         'json', rule_req)['security_group_rule']
     self._verify_dirty_bit('security_group_rule')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'security_group_rule', self._tenant_id, dirty=False)
     self._delete('security-group-rules', sec_group_rule['id'])
     self._verify_dirty_bit('security_group_rule')
예제 #16
0
 def test_create_delete_securitygrouprule_marks_dirty(self):
     self._test_init('security_group_rule')
     sec_group = self._make_security_group(
         'json', 'meh', 'meh', tenant_id=self._tenant_id)['security_group']
     rule_req = self._build_security_group_rule(
         sec_group['id'], 'ingress', 'TCP', tenant_id=self._tenant_id)
     sec_group_rule = self._make_security_group_rule(
         'json', rule_req)['security_group_rule']
     self._verify_dirty_bit('security_group_rule')
     # Clear the dirty bit
     quota_db_api.set_quota_usage_dirty(
         self.ctx, 'security_group_rule', self._tenant_id, dirty=False)
     self._delete('security-group-rules', sec_group_rule['id'])
     self._verify_dirty_bit('security_group_rule')
예제 #17
0
파일: test_api.py 프로젝트: thh/neutron
    def test_set_resources_quota_usage_dirty_with_empty_list(self):
        self._create_quota_usage('goals', 26)
        self._create_quota_usage('assists', 11)
        self._create_quota_usage('bookings', 3)
        # Expect all the resources for the project to be set dirty
        self.assertEqual(
            3,
            quota_api.set_resources_quota_usage_dirty(self.context, [],
                                                      self.project_id))
        usage_info_goals = quota_api.get_quota_usage_by_resource_and_project(
            self.context, 'goals', self.project_id)
        usage_info_assists = quota_api.get_quota_usage_by_resource_and_project(
            self.context, 'assists', self.project_id)
        usage_info_bookings = (
            quota_api.get_quota_usage_by_resource_and_project(
                self.context, 'bookings', self.project_id))
        self._verify_quota_usage(usage_info_goals, expected_dirty=True)
        self._verify_quota_usage(usage_info_assists, expected_dirty=True)
        self._verify_quota_usage(usage_info_bookings, expected_dirty=True)

        # Higuain is clean now
        self.assertEqual(
            1,
            quota_api.set_quota_usage_dirty(self.context,
                                            'goals',
                                            self.project_id,
                                            dirty=False))
        usage_info = quota_api.get_quota_usage_by_resource_and_project(
            self.context, 'goals', self.project_id)
        self._verify_quota_usage(usage_info, expected_dirty=False)
예제 #18
0
파일: test_api.py 프로젝트: cubeek/neutron
 def test_set_quota_usage_dirty(self):
     self._create_quota_usage('goals', 26)
     # Higuain needs a shower after the match
     self.assertEqual(1, quota_api.set_quota_usage_dirty(
         self.context, 'goals', self.tenant_id))
     usage_info = quota_api.get_quota_usage_by_resource_and_tenant(
         self.context, 'goals', self.tenant_id)
     self._verify_quota_usage(usage_info,
                              expected_dirty=True)
     # Higuain is clean now
     self.assertEqual(1, quota_api.set_quota_usage_dirty(
         self.context, 'goals', self.tenant_id, dirty=False))
     usage_info = quota_api.get_quota_usage_by_resource_and_tenant(
         self.context, 'goals', self.tenant_id)
     self._verify_quota_usage(usage_info,
                              expected_dirty=False)
예제 #19
0
 def test_set_quota_usage_dirty(self):
     self._create_quota_usage('goals', 26)
     # Higuain needs a shower after the match
     self.assertEqual(1, quota_api.set_quota_usage_dirty(
         self.context, 'goals', self.tenant_id))
     usage_info = quota_api.get_quota_usage_by_resource_and_tenant(
         self.context, 'goals', self.tenant_id)
     self._verify_quota_usage(usage_info,
                              expected_dirty=True)
     # Higuain is clean now
     self.assertEqual(1, quota_api.set_quota_usage_dirty(
         self.context, 'goals', self.tenant_id, dirty=False))
     usage_info = quota_api.get_quota_usage_by_resource_and_tenant(
         self.context, 'goals', self.tenant_id)
     self._verify_quota_usage(usage_info,
                              expected_dirty=False)
예제 #20
0
파일: resource.py 프로젝트: huntxu/neutron
 def mark_dirty(self, context):
     if not self._dirty_tenants:
         return
     with db_api.context_manager.writer.using(context):
         # It is not necessary to protect this operation with a lock.
         # Indeed when this method is called the request has been processed
         # and therefore all resources created or deleted.
         # dirty_tenants will contain all the tenants for which the
         # resource count is changed. The list might contain also tenants
         # for which resource count was altered in other requests, but this
         # won't be harmful.
         dirty_tenants_snap = self._dirty_tenants.copy()
         for tenant_id in dirty_tenants_snap:
             quota_api.set_quota_usage_dirty(context, self.name, tenant_id)
     self._out_of_sync_tenants |= dirty_tenants_snap
     self._dirty_tenants -= dirty_tenants_snap
예제 #21
0
파일: resource.py 프로젝트: zhhuabj/neutron
 def mark_dirty(self, context):
     if not self._dirty_tenants or not self._track_resource_events:
         return
     with db_api.CONTEXT_WRITER.using(context):
         # It is not necessary to protect this operation with a lock.
         # Indeed when this method is called the request has been processed
         # and therefore all resources created or deleted.
         # dirty_tenants will contain all the tenants for which the
         # resource count is changed. The list might contain also tenants
         # for which resource count was altered in other requests, but this
         # won't be harmful.
         dirty_tenants_snap = self._dirty_tenants.copy()
         for tenant_id in dirty_tenants_snap:
             quota_api.set_quota_usage_dirty(context, self.name, tenant_id)
     self._out_of_sync_tenants |= dirty_tenants_snap
     self._dirty_tenants -= dirty_tenants_snap
예제 #22
0
 def mark_dirty(self, context):
     if not self._dirty_tenants:
         return
     with db_api.context_manager.writer.using(context):
         # It is not necessary to protect this operation with a lock.
         # Indeed when this method is called the request has been processed
         # and therefore all resources created or deleted.
         # dirty_tenants will contain all the tenants for which the
         # resource count is changed. The list might contain also tenants
         # for which resource count was altered in other requests, but this
         # won't be harmful.
         dirty_tenants_snap = self._dirty_tenants.copy()
         for tenant_id in dirty_tenants_snap:
             quota_api.set_quota_usage_dirty(context, self.name, tenant_id)
             LOG.debug(("Persisted dirty status for tenant:%(tenant_id)s "
                        "on resource:%(resource)s"),
                       {'tenant_id': tenant_id, 'resource': self.name})
     self._out_of_sync_tenants |= dirty_tenants_snap
     self._dirty_tenants -= dirty_tenants_snap
예제 #23
0
 def mark_dirty(self, context, nested=False):
     if not self._dirty_tenants:
         return
     with context.session.begin(nested=nested, subtransactions=True):
         # It is not necessary to protect this operation with a lock.
         # Indeed when this method is called the request has been processed
         # and therefore all resources created or deleted.
         # dirty_tenants will contain all the tenants for which the
         # resource count is changed. The list might contain also tenants
         # for which resource count was altered in other requests, but this
         # won't be harmful.
         dirty_tenants_snap = self._dirty_tenants.copy()
         for tenant_id in dirty_tenants_snap:
             quota_api.set_quota_usage_dirty(context, self.name, tenant_id)
             LOG.debug(("Persisted dirty status for tenant:%(tenant_id)s "
                        "on resource:%(resource)s"),
                       {'tenant_id': tenant_id, 'resource': self.name})
     self._out_of_sync_tenants |= dirty_tenants_snap
     self._dirty_tenants = self._dirty_tenants - dirty_tenants_snap
예제 #24
0
파일: test_api.py 프로젝트: cubeek/neutron
    def test_set_resources_quota_usage_dirty_with_empty_list(self):
        self._create_quota_usage('goals', 26)
        self._create_quota_usage('assists', 11)
        self._create_quota_usage('bookings', 3)
        # Expect all the resources for the tenant to be set dirty
        self.assertEqual(3, quota_api.set_resources_quota_usage_dirty(
            self.context, [], self.tenant_id))
        usage_info_goals = quota_api.get_quota_usage_by_resource_and_tenant(
            self.context, 'goals', self.tenant_id)
        usage_info_assists = quota_api.get_quota_usage_by_resource_and_tenant(
            self.context, 'assists', self.tenant_id)
        usage_info_bookings = quota_api.get_quota_usage_by_resource_and_tenant(
            self.context, 'bookings', self.tenant_id)
        self._verify_quota_usage(usage_info_goals, expected_dirty=True)
        self._verify_quota_usage(usage_info_assists, expected_dirty=True)
        self._verify_quota_usage(usage_info_bookings, expected_dirty=True)

        # Higuain is clean now
        self.assertEqual(1, quota_api.set_quota_usage_dirty(
            self.context, 'goals', self.tenant_id, dirty=False))
        usage_info = quota_api.get_quota_usage_by_resource_and_tenant(
            self.context, 'goals', self.tenant_id)
        self._verify_quota_usage(usage_info,
                                 expected_dirty=False)
예제 #25
0
파일: test_api.py 프로젝트: cubeek/neutron
 def test_set_dirty_non_existing_quota_usage(self):
     self.assertEqual(0, quota_api.set_quota_usage_dirty(
         self.context, 'meh', self.tenant_id))
예제 #26
0
 def test_set_dirty_non_existing_quota_usage(self):
     self.assertEqual(0, quota_api.set_quota_usage_dirty(
         self.context, 'meh', self.tenant_id))