~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to pyopenchange/tests/provision.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-12 20:07:57 UTC
  • mfrom: (11 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20120412200757-k933d9trljmxj1l4
Tags: 1:1.0-4
* openchangeserver: Add dependency on openchangeproxy.
* Rebuild against newer version of Samba 4.
* Use dpkg-buildflags.
* Migrate to Git, update Vcs-Git header.
* Switch to debhelper 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# -*- coding: utf-8 -*-
3
 
 
4
 
import sys
5
 
 
6
 
import os
7
 
import openchange
8
 
import openchange.mapistoredb as mapistoredb
9
 
import openchange.mapistore as mapistore
10
 
from openchange import mapi
11
 
import string
12
 
 
13
 
username = "jkerihuel"
14
 
indent = 1
15
 
title_nb = 1
16
 
provisioning_root_dir = "/tmp/test_mapistore"
17
 
os.mkdir(provisioning_root_dir)
18
 
 
19
 
def newTitle(title, separator):
20
 
    global title_nb
21
 
    ftitle = "[Step %d]. %s" % (title_nb, title)
22
 
    print ""
23
 
    print ftitle
24
 
    print separator * len(ftitle)
25
 
    title_nb += 1
26
 
 
27
 
def TreeRoot(name):
28
 
    print ""
29
 
    str = "[+] %s" % name
30
 
    print str
31
 
    print "=" * len(str)
32
 
 
33
 
def TreeLeafStatus(name, retval, errstr):
34
 
    tree = " " * (indent * 8)
35
 
    if (retval):
36
 
        print tree + "[+] %s: %s (%s)" % (string.ljust(name, 60 - indent * 8), "[KO]", errstr)
37
 
        exit
38
 
    else:
39
 
        print tree + "[+] %s: %s" % (string.ljust(name, 60 - indent * 8), "[OK]")
40
 
 
41
 
def TreeIndent():
42
 
    global indent
43
 
    indent += 1
44
 
 
45
 
def TreeDeIndent():
46
 
    global indent
47
 
    indent -= 1
48
 
 
49
 
def start():
50
 
    newTitle("Initializing mapistore database", '=')
51
 
    MAPIStoreDB = mapistoredb.mapistoredb()
52
 
    MAPIStoreDB.initialize(provisioning_root_dir)
53
 
 
54
 
    newTitle("Provisioning mapistore database", '=')
55
 
    retval = MAPIStoreDB.provision(netbiosname = "server",
56
 
                                   firstorg = "OpenChange Project",
57
 
                                   firstou = "OpenChange Development Unit")
58
 
    if (retval == 0):
59
 
        print "\t* Provisioning: SUCCESS"
60
 
    else:
61
 
        print "\t* Provisioning: FAILURE (ret = %d)" % MAPIStoreDB.errstr(retval)
62
 
 
63
 
    newTitle("Create mapistore named properties database", '=')
64
 
    retval = MAPIStoreDB.provision_named_properties()
65
 
    if (retval == 0):
66
 
        print "\t* Provisioning: SUCCESS"
67
 
        (retval,npid) = MAPIStoreDB.namedprops_get_default_id(mapistoredb.MAPISTORE_NAMEDPROPS_EXTERNAL)
68
 
        print "\t\t* Last External Index: 0x%.4x" % (npid)
69
 
        (retval,npid) = MAPIStoreDB.namedprops_get_default_id(mapistoredb.MAPISTORE_NAMEDPROPS_INTERNAL)
70
 
        print "\t\t* Last Internal Index: 0x%.4x" % (npid)
71
 
    else:
72
 
        print "\t* Provisioning: FAILURE (ret = %s)" % MAPIStoreDB.errstr(retval)
73
 
 
74
 
    newTitle("Provision named properties namespace for backends", "=")
75
 
    retval = MAPIStoreDB.namedprops_provision_backends()
76
 
 
77
 
    newTitle("Provision named properties namespace for user", "=")
78
 
    retval = MAPIStoreDB.namedprops_provision_user(username)
79
 
    "\t* Return status: %s" % MAPIStoreDB.errstr(retval)
80
 
 
81
 
    newTitle("Create a new mailbox", '=')
82
 
    mailbox_root = MAPIStoreDB.get_mapistore_uri(folder=mapistoredb.MDB_ROOT_FOLDER,
83
 
                                                 username=username, 
84
 
                                                 namespace="mstoredb://")
85
 
    retval = MAPIStoreDB.new_mailbox(username, mailbox_root)
86
 
    print "\t* Mailbox Root: %s" % mailbox_root
87
 
    
88
 
    newTitle("Get and Set a new allocation range to the mailbox", '=')
89
 
    (retval, rstart,rend) = MAPIStoreDB.get_new_allocation_range(username,
90
 
                                                                 0x1000)
91
 
    if retval == 0:
92
 
        print "\t* Allocation range received:"
93
 
        print "\t\t* [start]: 0x%.16x" % rstart
94
 
        print "\t\t* [end]:   0x%.16x\n\n" % rend
95
 
        retval = MAPIStoreDB.set_mailbox_allocation_range(username, 
96
 
                                                          rstart, rend)
97
 
        if retval == 0:
98
 
            print "\t * Allocation range successfully set to mailbox"
99
 
        else:
100
 
            print "\t * Error while setting allocation range to the mailbox"
101
 
            
102
 
    newTitle("Uninitializing mapistore database context", '=')
103
 
    MAPIStoreDB.release()
104
 
                
105
 
    newTitle("Initializing mapistore context", '=')
106
 
    mapistore.set_mapping_path(os.path.join(provisioning_root_dir, "mapistore"))
107
 
    MAPIStore = mapistore.mapistore()
108
 
    
109
 
    newTitle("Adding a context over Mailbox Root Folder", '=')
110
 
    (context_id, mailbox_fid) = MAPIStore.add_context(username, mailbox_root)
111
 
    print "\t* context_id  = %s" % context_id
112
 
    print "\t* mailbox FID = 0x%.16x" % mailbox_fid
113
 
 
114
 
    newTitle("Create the mailbox hierarchy", '=')
115
 
    
116
 
    TreeRoot("Mailbox Root Folder")
117
 
    
118
 
    # MDB_DEFERRED_ACTIONS
119
 
    retval = MAPIStore.root_mkdir(context_id=context_id,
120
 
                                  parent_index=mapistore.MDB_ROOT_FOLDER, 
121
 
                                  index=mapistore.MDB_DEFERRED_ACTIONS, 
122
 
                                  folder_name="")
123
 
    TreeLeafStatus("Deferred Actions", retval, MAPIStore.errstr(retval))
124
 
    
125
 
    # MDB_SPOOLER_QUEUE
126
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
127
 
                                  parent_index=mapistore.MDB_ROOT_FOLDER, 
128
 
                                  index=mapistore.MDB_SPOOLER_QUEUE, 
129
 
                                  folder_name="")
130
 
    TreeLeafStatus("Spooler Queue", retval, MAPIStore.errstr(retval))
131
 
    
132
 
    # MDB_IPM_SUBTREE
133
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
134
 
                                  parent_index=mapistore.MDB_ROOT_FOLDER, 
135
 
                                  index=mapistore.MDB_IPM_SUBTREE, 
136
 
                                  folder_name="")
137
 
    TreeLeafStatus("IPM Subtree", retval, MAPIStore.errstr(retval))
138
 
    
139
 
    # MDB_IPM_SUBTREE > MDB_INBOX
140
 
    TreeIndent()
141
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
142
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
143
 
                                  index=mapistore.MDB_INBOX, 
144
 
                                  folder_name="")
145
 
    TreeLeafStatus("Inbox", retval, MAPIStore.errstr(retval))
146
 
    
147
 
    # MDB_IPM_SUBTREE > MDB_OUTBOX
148
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
149
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
150
 
                                  index=mapistore.MDB_OUTBOX, 
151
 
                                  folder_name="")
152
 
    TreeLeafStatus("Outbox", retval, MAPIStore.errstr(retval))
153
 
    
154
 
    # MDB_IPM_SUBTREE > MDB_SENT_ITEMS
155
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
156
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
157
 
                                  index=mapistore.MDB_SENT_ITEMS, 
158
 
                                  folder_name="")
159
 
    TreeLeafStatus("Sent Items", retval, MAPIStore.errstr(retval))
160
 
    
161
 
    # MDB_IPM_SUBTREE > MDB_DELETED_ITEMS
162
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
163
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
164
 
                                  index=mapistore.MDB_DELETED_ITEMS, 
165
 
                                  folder_name="")
166
 
    TreeLeafStatus("Deleted Items", retval, MAPIStore.errstr(retval))
167
 
    
168
 
#### SPECIAL FOLDERS #####
169
 
        
170
 
    # MDB_IPM_SUBTREE > MDB_CALENDAR
171
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
172
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
173
 
                                  index=mapistore.MDB_CALENDAR, 
174
 
                                  folder_name="")
175
 
    TreeLeafStatus("Calendar", retval, MAPIStore.errstr(retval))
176
 
        
177
 
    # MDB_IPM_SUBTREE > MDB_CONTACTS
178
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
179
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
180
 
                                  index=mapistore.MDB_CONTACTS, 
181
 
                                  folder_name="")
182
 
    TreeLeafStatus("Contacts", retval, MAPIStore.errstr(retval))
183
 
        
184
 
    # MDB_IPM_SUBTREE > MDB_JOURNAL
185
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
186
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
187
 
                                  index=mapistore.MDB_JOURNAL, 
188
 
                                  folder_name="")
189
 
    TreeLeafStatus("Journal", retval, MAPIStore.errstr(retval))
190
 
        
191
 
    # MDB_IPM_SUBTREE > MDB_NOTES
192
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
193
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
194
 
                                  index=mapistore.MDB_NOTES, 
195
 
                                  folder_name="")
196
 
    TreeLeafStatus("Notes", retval, MAPIStore.errstr(retval))
197
 
 
198
 
    # MDB_IPM_SUBTREE > MDB_TASKS
199
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
200
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
201
 
                                  index=mapistore.MDB_TASKS, 
202
 
                                  folder_name="")
203
 
    TreeLeafStatus("Tasks", retval, MAPIStore.errstr(retval))
204
 
 
205
 
    # MDB_IPM_SUBTREE > MDB_DRAFTS
206
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
207
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE, 
208
 
                                  index=mapistore.MDB_DRAFTS, 
209
 
                                  folder_name="")
210
 
    TreeLeafStatus("Drafts", retval, MAPIStore.errstr(retval))
211
 
 
212
 
    # MDB_SYNC_ISSUES
213
 
    retval = MAPIStore.root_mkdir(context_id=context_id,
214
 
                                  parent_index=mapistore.MDB_IPM_SUBTREE,
215
 
                                  index=mapistore.MDB_SYNC_ISSUES,
216
 
                                  folder_name="")
217
 
    TreeLeafStatus("Sync Issues", retval, MAPIStore.errstr(retval))
218
 
 
219
 
    TreeIndent()
220
 
 
221
 
    # MDB_SYNC_ISSUES > MDB_CONFLICTS
222
 
    ipm_subtree = MAPIStore.get_folder_identifier(context_id=context_id,
223
 
                                                  index=mapistore.MDB_IPM_SUBTREE,
224
 
                                                  uri=None)
225
 
    sync_fid = MAPIStore.get_folder_identifier(context_id=context_id,
226
 
                                               index=mapistore.MDB_SYNC_ISSUES,
227
 
                                               uri=None)
228
 
    print "IPM Subtree           FID: 0x%.16x" % ipm_subtree
229
 
    print "Synchronization Issue FID: 0x%.16x" % sync_fid
230
 
    MAPIStore.opendir(context_id=context_id, parent_fid=ipm_subtree, fid=sync_fid)
231
 
    conflicts_fid = MAPIStore.mkdir(context_id, sync_fid, "Conflicts", None, mapistore.FOLDER_GENERIC)
232
 
    print "Conflicts             FID: 0x%.16x" % conflicts_fid
233
 
 
234
 
    TreeDeIndent()
235
 
    
236
 
    # MDB_COMMON_VIEWS
237
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
238
 
                                  parent_index=mapistore.MDB_ROOT_FOLDER, 
239
 
                                  index=mapistore.MDB_COMMON_VIEWS, 
240
 
                                  folder_name="")
241
 
    TreeLeafStatus("Common Views", retval, MAPIStore.errstr(retval))
242
 
 
243
 
    # MDB_SCHEDULE
244
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
245
 
                                  parent_index=mapistore.MDB_ROOT_FOLDER, 
246
 
                                  index=mapistore.MDB_SCHEDULE, 
247
 
                                  folder_name="")
248
 
    TreeLeafStatus("Schedule", retval, MAPIStore.errstr(retval))
249
 
 
250
 
    # MDB_SEARCH
251
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
252
 
                                  parent_index=mapistore.MDB_ROOT_FOLDER, 
253
 
                                  index=mapistore.MDB_SEARCH, 
254
 
                                  folder_name="")
255
 
    TreeLeafStatus("Search", retval, MAPIStore.errstr(retval))
256
 
 
257
 
    # MDB_VIEWS
258
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
259
 
                                  parent_index=mapistore.MDB_ROOT_FOLDER, 
260
 
                                  index=mapistore.MDB_VIEWS, 
261
 
                                  folder_name="")
262
 
    TreeLeafStatus("Views", retval, MAPIStore.errstr(retval))
263
 
 
264
 
    # MDB_SHORTCUTS
265
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
266
 
                                  parent_index=mapistore.MDB_ROOT_FOLDER, 
267
 
                                  index=mapistore.MDB_SHORTCUTS, 
268
 
                                  folder_name="")
269
 
    TreeLeafStatus("Shortcuts", retval, MAPIStore.errstr(retval))
270
 
 
271
 
    # MDB_REMINDERS
272
 
    retval = MAPIStore.root_mkdir(context_id=context_id, 
273
 
                                  parent_index=mapistore.MDB_ROOT_FOLDER, 
274
 
                                  index=mapistore.MDB_REMINDERS, 
275
 
                                  folder_name="")
276
 
    TreeLeafStatus("Reminders", retval, MAPIStore.errstr(retval))
277
 
 
278
 
 
279
 
    newTitle("Setting mailbox folders to fsocpf", '=')
280
 
    inbox_uri = MAPIStore.get_mapistore_uri(mapistore.MDB_INBOX, username, "fsocpf://")
281
 
    retval = MAPIStore.set_mapistore_uri(context_id, mapistore.MDB_INBOX, inbox_uri)
282
 
    if retval == 0:
283
 
        print "\t* Inbox [fsocpf]: [OK] - " + inbox_uri
284
 
    else:
285
 
        print "\t* Inbox [fsocpf]: [KO] (%s)" % MAPIStore.errstr(retval)
286
 
 
287
 
 
288
 
    newTitle("Creating mailbox folder", "=")
289
 
    (inbox_context_id, inbox_fid) = MAPIStore.add_context(username, inbox_uri)
290
 
 
291
 
    print "\t* Inbox FID: 0x%x" % inbox_fid
292
 
 
293
 
start()