Debian Codegraph @

dirsrvtests/tests/stress/cos/cos_scale_template_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2017 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9
10 import pytest
11
12 from test389.topologies import topology_st
13
14 from lib389.plugins import ClassOfServicePlugin
15 from lib389.cos import CosIndirectDefinitions, CosTemplates, CosTemplate
16 from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES
17 from lib389.idm.organizationalunit import OrganizationalUnits
18
19 from lib389._constants import DEFAULT_SUFFIX
20
21 import time
22
23 pytestmark = pytest.mark.tier3
24
25 # Given this should complete is about 0.005, this is generous.
26 # For the final test with 20 templates, about 0.02 is an acceptable time.
27 THRESHOLD = 0.05
28
29 class OUCosTemplate(CosTemplate):
30 def __init__(self, instance, dn=None):
31 """Create a OU specific cos template to replicate a specific user setup.
32 This template provides ou attrs onto the target entry.
33
34 :param instance: A dirsrv instance
35 :type instance: DirSrv
36 :param dn: The dn of the template
37 :type dn: str
38 """
39 super(OUCosTemplate, self).__init__(instance, dn)
40 self._rdn_attribute = 'ou'
41 self._must_attributes = ['ou']
42 self._create_objectclasses = [
43 'top',
44 'cosTemplate',
45 'organizationalUnit',
46 ]
47
48 class OUCosTemplates(CosTemplates):
49 def __init__(self, instance, basedn, rdn=None):
50 """Create an OU specific cos templates to replicate a specific use setup.
51 This costemplates object allows access to the OUCosTemplate types.
52
53 :param instance: A dirsrv instance
54 :type instance: DirSrv
55 :param basedn: The basedn of the templates
56 :type basedn: str
57 :param rdn: The rdn of the templates
58 :type rdn: str
59 """
60 super(OUCosTemplates, self).__init__(instance, basedn, rdn)
61 self._objectclasses = [
62 'cosTemplate',
63 'organizationalUnit',
64 ]
65 self._filterattrs = ['ou']
66 self._childobject = OUCosTemplate
67
68 def test_indirect_template_scale(topology_st):
69 """Test that cos templates can be added at a reasonable scale
70
71 :id: 7cbcdf22-1f9c-4222-9e76-685fe374fc20
72 :steps:
73 1. Enable COS plugin
74 2. Create the test user
75 3. Add an indirect cos template
76 4. Add a cos template
77 5. Add the user to the cos template and assert it works.
78 6. Add 25,000 templates to the database
79 7. Search the user. It should not exceed THRESHOLD.
80 :expectedresults:
81 1. It is enabled.
82 2. It is created.
83 3. Is is created.
84 4. It is created.
85 5. It is valid.
86 6. They are created.
87 7. It is fast.
88 """
89
90 cos_plugin = ClassOfServicePlugin(topology_st.standalone)
91 cos_plugin.enable()
92
93 topology_st.standalone.restart()
94
95 # Now create, the indirect specifier, and a user to template onto.
96 users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX)
97 user = users.create(properties=TEST_USER_PROPERTIES)
98
99 cos_inds = CosIndirectDefinitions(topology_st.standalone, DEFAULT_SUFFIX)
100 cos_ind = cos_inds.create(properties={
101 'cn' : 'cosIndirectDef',
102 'cosIndirectSpecifier': 'seeAlso',
103 'cosAttribute': [
104 'ou merge-schemes',
105 'description merge-schemes',
106 'postalCode merge-schemes',
107 ],
108 })
109
110 ous = OrganizationalUnits(topology_st.standalone, DEFAULT_SUFFIX)
111 ou_temp = ous.create(properties={'ou': 'templates'})
112 cos_temps = OUCosTemplates(topology_st.standalone, ou_temp.dn)
113
114 cos_temp_u = cos_temps.create(properties={
115 'ou' : 'ou_temp_u',
116 'description' : 'desc_temp_u',
117 'postalCode': '0'
118 })
119 # Edit the user to add the seeAlso ...
120 user.set('seeAlso', cos_temp_u.dn)
121
122 # Now create 25,0000 templates, they *don't* need to apply to the user though!
123 for i in range(1, 25001):
124 cos_temp_u = cos_temps.create(properties={
125 'ou' : 'ou_temp_%s' % i,
126 'description' : 'desc_temp_%s' % i,
127 'postalCode': '%s' % i
128 })
129
130 if i % 500 == 0:
131 start_time = time.monotonic()
132 u_search = users.get('testuser')
133 attrs = u_search.get_attr_vals_utf8('postalCode')
134 end_time = time.monotonic()
135 diff_time = end_time - start_time
136 assert diff_time < THRESHOLD
137
138 if i == 10000:
139 # Now add our user to this template also.
140 user.add('seeAlso', cos_temp_u.dn)
141
142 start_time = time.monotonic()
143 attrs_after = u_search.get_attr_vals_utf8('postalCode')
144 end_time = time.monotonic()
145 diff_time = end_time - start_time
146 assert(set(attrs) < set(attrs_after))
147 assert diff_time < THRESHOLD
148
149
150