Statistics
| Branch: | Tag: | Revision:

root / docs / upgrade-0.13.rst @ 9521d937

History | View | Annotate | Download (20.7 kB)

1
Upgrade to Synnefo v0.13
2
^^^^^^^^^^^^^^^^^^^^^^^^
3

    
4
The bulk of the upgrade to v0.13 is about user and quota migrations.
5
In summary, the migration process has 3 steps:
6

    
7
1. Run some commands and scripts to diagnose and extract some migration data
8
   while the OLD code is running, and BEFORE any changes are made.
9

    
10
2. Bring down services, upgrade packages, configure services, and perform
11
   django database migrations. These migrations do not need any interaction
12
   between services.
13

    
14
3. Initialize the Astakos quota system and bring the Astakos service up, since
15
   it will be needed during a second-phase of UUID and quota migrations, that
16
   also uses data extracted from step 1.
17

    
18

    
19
.. warning::
20
 
21
    It is strongly suggested that you keep separate database backups
22
    for each service after the completion of each of step.
23

    
24
1. Bring web services down, backup databases
25
============================================
26

    
27
1. All web services must be brought down so that the database maintains a
28
   predictable and consistent state during the migration process::
29

    
30
    # service gunicorn stop
31
    # service snf-dispatcher stop
32
    # etc.
33

    
34
2. Backup databases for recovery to a pre-migration state.
35

    
36
3. Keep the database servers running during the migration process
37

    
38

    
39
2. Prepare astakos user migration to case insensitive emails
40
============================================================
41

    
42
It is possible that two or more users have been registered with emails that
43
differ only in the case of its letters.  There can only be one of those
44
accounts after the migration, so the rest must be deleted.
45

    
46
Note that even if the users are deleted in Astakos, there still are duplicate
47
entries in Cyclades and Pithos.  For each service we need to reduce those
48
multiple accounts into one, either merging them together, or deleting and
49
discarding data from all but one.
50

    
51
.. _find_duplicate_emails:
52

    
53
2.1 Find duplicate email entries in Astakos
54
-------------------------------------------
55
(script: ``find_astakos_users_with_conflicting_emails.py``)::
56

    
57
    astakos-host$ cat << EOF > find_astakos_users_with_conflicting_emails.py
58
    #!/usr/bin/env python
59
    import os
60
    import sys
61

    
62
    os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings'
63

    
64
    import astakos
65
    from astakos.im.models import AstakosUser as A
66

    
67

    
68
    def user_filter(user):
69
        return A.objects.filter(email__iexact=user.email).count() > 1
70

    
71
    all_users = list(A.objects.all())
72
    userlist = [(str(u.pk) + ': ' + str(u.email) + ' (' + str(u.is_active) + ', ' +
73
                 str(u.date_joined) + ')') for u in filter(user_filter, all_users)]
74

    
75
    sys.stderr.write("id email (is_active, creation date)\n")
76
    print "\n".join(userlist)
77
    EOF
78

    
79
    astakos-host$ python ./find_astakos_users_with_conflicting_emails.py
80

    
81
.. _remove_astakos_duplicate:
82

    
83
2.1 Remove duplicate users in Astakos by their id
84
-------------------------------------------------
85
(script: ``delete_astakos_users.py``)::
86

    
87
    astakos-host$ cat << EOF > delete_astakos_users.py
88
    #!/usr/bin/env python
89

    
90
    import os
91
    import sys
92
    from time import sleep
93

    
94
    os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings'
95

    
96
    import astakos
97
    from astakos.im.models import AstakosUser as A
98

    
99

    
100
    def user_filter(user):
101
        return A.objects.filter(email__iexact=user.email).count() > 1
102

    
103
    argv = sys.argv
104
    argc = len(sys.argv)
105

    
106
    if argc < 2:
107
        print "Usage: ./delete_astakos_users.py <id>..."
108
        raise SystemExit()
109

    
110
    id_list = [int(x) for x in argv[1:]]
111

    
112
    print ""
113
    print "This will permanently delete the following users:\n"
114
    print "id  email (is_active, creation date)"
115
    print "--  --------------------------------"
116

    
117
    users = A.objects.filter(id__in=id_list)
118
    for user in users:
119
        print "%s: %s (%s, %s)" % (user.id, user.email, user.is_active,
120
                                   user.date_joined)
121

    
122
    print "\nExecute? (yes/no): ",
123
    line = raw_input().rstrip()
124
    if line != 'yes':
125
        print "\nCancelled"
126
        raise SystemExit()
127

    
128
    print "\nConfirmed."
129
    sleep(2)
130
    for user in users:
131
        print "deleting %s: %s" % (user.id, user.email)
132
        user.delete()
133

    
134
    EOF
135

    
136
    astakos-host$ python ./delete_astakos_users.py 30 40
137

    
138
.. warning::
139

    
140
    After deleting users with the ``delete_astakos_users.py`` script,
141
    check again with ``find_astakos_users_with_conflicting_emails.py``
142
    (as in :ref:`find_duplicate_emails`)
143
    to make sure that no duplicate email conflicts remain.
144

    
145

    
146
3. Upgrade Synnefo and configure settings
147
=========================================
148

    
149
3.1 Install the new versions of packages
150
----------------------------------------
151

    
152
::
153

    
154
    astakos.host$ apt-get install \
155
                            kamaki \
156
                            snf-common \
157
                            snf-webproject \
158
                            snf-quotaholder-app \
159
                            snf-astakos-app \
160

    
161

    
162
    cyclades.host$ apt-get install \
163
                            kamaki \
164
                            snf-common \
165
                            snf-webproject
166
                            snf-pithos-backend \
167
                            snf-cyclades-app \
168

    
169
                           
170
    pithos.host$ apt-get install \
171
                            kamaki \
172
                            snf-common \
173
                            snf-webproject
174
                            snf-pithos-backend \
175
                            snf-pithos-app \
176
                            snf-pithos-webclient \
177

    
178

    
179
    ganeti.node$ apt-get install \
180
                            kamaki \
181
                            snf-common \
182
                            snf-cyclades-gtools \
183
                            snf-pithos-backend \
184

    
185
.. note::
186

    
187
    Installing the packages will cause services to start. Make sure you bring
188
    them down again (at least ``gunicorn``, ``snf-dispatcher``)
189

    
190
3.2 Sync and migrate Django DB
191
------------------------------
192

    
193
.. note::
194

    
195
   If you are asked about stale content types during the migration process,
196
   answer 'no' and let the migration finish.
197

    
198
::
199

    
200
    astakos-host$ snf-manage syncdb
201
    astakos-host$ snf-manage migrate
202

    
203
    cyclades-host$ snf-manage syncdb
204
    cyclades-host$ snf-manage migrate
205

    
206
.. note::
207

    
208
    After the migration, Astakos has created uuids for all users,
209
    and has set the uuid as the public identifier of a user.
210
    This uuid is to be used both at other services (Cyclades, Pithos)
211
    and at the clientside (kamaki client settings).
212

    
213
    Duplicate-email users have been deleted earlier in
214
    :ref:`remove_astakos_duplicate`
215

    
216
3.3 Setup quota settings for all services
217
-----------------------------------------
218

    
219
Generally:
220

    
221
::
222

    
223
    # Service       Setting                       Value
224
    # quotaholder:  QUOTAHOLDER_TOKEN          = <random string>
225

    
226
    # astakos:      ASTAKOS_QUOTAHOLDER_TOKEN  = <the same random string>
227
    # astakos:      ASTAKOS_QUOTAHOLDER_URL    = https://quotaholder.host/quotaholder/v
228

    
229
    # cyclades:     CYCLADES_QUOTAHOLDER_TOKEN = <the same random string>
230
    # cyclades:     CYCLADES_QUOTAHOLDER_URL   = https://quotaholder.host/quotaholder/v
231
    # cyclades:     CYCLADES_USE_QUOTAHOLDER   = True
232

    
233

    
234
    # pithos:       PITHOS_QUOTAHOLDER_TOKEN   = <the same random string>
235
    # pithos:       PITHOS_QUOTAHOLDER_URL     = https://quotaholder.host/quotaholder/v
236
    # pithos:       PITHOS_USE_QUOTAHOLDER     = True
237
    # All services must match the quotaholder token and url configured for quotaholder.
238

    
239
Specifically:
240

    
241
On the Astakos host, edit ``/etc/synnefo/20-snf-astakos-app-settings.conf``:
242

    
243
::
244

    
245
    QUOTAHOLDER_TOKEN = 'aExampleTokenJbFm12w'
246
    ASTAKOS_QUOTAHOLDER_TOKEN = 'aExampleTokenJbFm12w'
247
    ASTAKOS_QUOTAHOLDER_URL = 'https://accounts.example.synnefo.org/quotaholder/v'
248

    
249
On the Cyclades host, edit ``/etc/synnefo/20-snf-cyclades-app-quotas.conf``:
250

    
251
::
252

    
253
    CYCLADES_USE_QUOTAHOLDER = True
254
    CYCLADES_QUOTAHOLDER_URL = 'https://accounts.example.synnefo.org/quotaholder/v'
255
    CYCLADES_QUOTAHOLDER_TOKEN = 'aExampleTokenJbFm12w'
256

    
257
On the Pithos host, edit ``/etc/synnefo/20-snf-pithos-app-settings.conf``:
258

    
259
::
260

    
261
    PITHOS_QUOTAHOLDER_URL = 'https://accounts.example.synnefo.org/quotaholder/v'
262
    PITHOS_QUOTAHOLDER_TOKEN = 'aExampleTokenJbFm12w'
263
    PITHOS_USE_QUOTAHOLDER = False # will set to True after migration
264

    
265
.. note::
266

    
267
    During the migration it must be set, ``PITHOS_USE_QUOTAHOLDER = False``.
268
    Set to ``True`` once the migration is over.
269

    
270
3.4 Setup astakos
271
-----------------
272

    
273
- **Remove** this redirection from astakos front-end web server ::
274

    
275
        RewriteRule ^/login(.*) /im/login/redirect$1 [PT,NE]
276

    
277
    (see `<http://docs.dev.grnet.gr/synnefo/latest/quick-install-admin-guide.html#apache2-setup>`_)
278

    
279
- Enable users to change their contact email. Edit
280
``/etc/synnefo/20-snf-astakos-app-settings.conf`` ::
281

    
282
    ASTAKOS_EMAILCHANGE_ENABLED = True
283

    
284
- Rename the following (Astakos-specific) setting::
285

    
286
    ASTAKOS_DEFAULT_FROM_EMAIL
287
  
288
  to this (Django-specific) name::
289

    
290
    SERVER_EMAIL
291

    
292
- Instead of using the following (Astakos-specific) setting::
293

    
294
    ASTAKOS_DEFAULT_ADMIN_EMAIL
295

    
296
  include one or more entries in this (Django-specific) setting::
297

    
298
    ADMINS = (
299
        ('Joe Doe', 'doe@example.net'),
300
        ('Mary Jean', 'mary@example.net'),
301
    ) 
302

    
303
.. note::
304

    
305
    The ``SERVER_EMAIL`` and ``ADMINS`` settings are Django-specific.
306
    As such they will be the shared for any two (or more) services that happen
307
    to be collocated within the same application server (e.g. astakos &
308
    cyclades within the same gunicorn)
309

    
310
3.5 Setup Cyclades
311
------------------
312

    
313
- Run on the Astakos host ::
314

    
315
    # snf-manage service-list
316

    
317
- Set the Cyclades service token in
318
  ``/etc/synnefo/20-snf-cyclades-app-api.conf`` ::
319

    
320
    CYCLADES_ASTAKOS_SERVICE_TOKEN = 'asfasdf_CycladesServiceToken_iknl'
321

    
322
- Since version 0.13, Synnefo uses **VMAPI** in order to prevent sensitive data
323
  needed by 'snf-image' to be stored in Ganeti configuration (e.g. VM
324
  password). This is achieved by storing all sensitive information to a CACHE
325
  backend and exporting it via VMAPI. The cache entries are invalidated after
326
  the first request. Synnefo uses **memcached** as a django cache backend.
327
  To install, run on the Cyclades host::
328

    
329
        apt-get install memcached
330
        apt-get install python-memcache
331

    
332
  You will also need to configure Cyclades to use the memcached cache backend.
333
  Namely, you need to set IP address and port of the memcached daemon, and the
334
  default timeout (seconds tha value is stored in the cache). Edit
335
  ``/etc/synnefo/20-snf-cyclades-app-vmapi.conf`` ::
336

    
337
    VMAPI_CACHE_BACKEND = "memcached://127.0.0.1:11211/?timeout=3600"
338

    
339

    
340
  Finally, set the BASE_URL for the VMAPI, which is actually the base URL of
341
  Cyclades, again in ``/etc/synnefo/20-snf-cyclades-app-vmapi.conf``. Make sure
342
  the domain is exaclty the same, so that no re-directs happen ::
343

    
344
    VMAPI_BASE_URL = "https://cyclades.example.synnefo.org"
345

    
346
  .. note::
347

    
348
    - These settings are needed in all Cyclades workers.
349

    
350
    - VMAPI_CACHE_BACKEND just overrides django's CACHE_BACKEND setting
351

    
352
    - memcached must be reachable from all Cyclades workers.
353

    
354
    - For more information about configuring django to use memcached:
355
      https://docs.djangoproject.com/en/1.2/topics/cache
356

    
357
3.6 Setup Pithos
358
----------------
359

    
360
- Pithos forwards user catalog services to Astakos so that web clients may
361
  access them for uuid-displayname translations. Edit on the Pithos host
362
  ``/etc/synnefo/20-snf-pithos-app-settings.conf`` ::
363

    
364
    PITHOS_USER_CATALOG_URL    = https://accounts.example.synnefo.org/user_catalogs/
365
    PITHOS_USER_FEEDBACK_URL   = https://accounts.example.synnefo.org/feedback/
366
    PITHOS_USER_LOGIN_URL      = https://accounts.example.synnefo.org/login/
367
    #PITHOS_PROXY_USER_SERVICES = True # Set False if astakos & pithos are on the same host
368

    
369

    
370
4. Start astakos and quota services
371
===================================
372
.. warning::
373

    
374
    To ensure consistency, prevent public access to astakos during migrations.
375
    This can be done via firewall or webserver access control.
376

    
377
Start (or restart, if running) the webserver and gunicorn on the Astakos host.
378
E.g.::
379

    
380
    # service apache2 start
381
    # service gunicorn start
382

    
383
.. _astakos-load-resources:
384

    
385
5. Load resource definitions into Astakos
386
=========================================
387

    
388
First, set the corresponding values on the following dict in
389
``/etc/synnefo/20-snf-astakos-app-settings.conf`` ::
390

    
391
    # Set the cloud service properties
392
    ASTAKOS_SERVICES = {
393
        'cyclades': {
394
    #        # Specifying the key 'url' will overwrite it.
395
    #        # Use this to (re)set service URL.
396
    #        'url': 'https://cyclades.example.synnefo.org/ui/',
397
    #        # order services in listings, cloudbar, etc.
398
    #        'order' : 1
399
            'resources': [{
400
                'name': 'disk',
401
                'group': 'compute',
402
                'uplimit': 30*1024*1024*1024,
403
                'unit': 'bytes',
404
                'desc': 'Virtual machine disk size'
405
                }, {
406
                'name': 'cpu',
407
                'group': 'compute',
408
                'uplimit': 6,
409
                'desc': 'Number of virtual machine processors'
410
                }, {
411
                'name': 'ram',
412
                'group': 'compute',
413
                'uplimit': 6*1024*1024*1024,
414
                'unit': 'bytes',
415
                'desc': 'Virtual machines'
416
                }, {
417
                'name': 'vm',
418
                'group': 'compute',
419
                'uplimit': 2,
420
                'desc': 'Number of virtual machines'
421
                }, {
422
                'name': 'network.private',
423
                'group': 'network',
424
                'uplimit': 1,
425
                'desc': 'Private networks'
426
                }
427
            ]
428
        },
429
        'pithos+': {
430
    #        # Use this to (re)set service URL.
431
    #        'url': 'https://pithos.example.synnefo.org/ui/',
432
    #        # order services in listings, cloudbar, etc.
433
    #        'order' : 2
434
            'resources':[{
435
                'name': 'diskspace',
436
                'group': 'storage',
437
                'uplimit': 5*1024*1024*1024,
438
                'unit': 'bytes',
439
                'desc': 'Pithos account diskspace'
440
                }]
441
        }
442
    }
443

    
444
.. note::
445

    
446
    The name of the Pithos service is ``pithos+``.
447
    If you have named your pithos service ``pithos``, without ``+``,
448
    then you must rename it::
449

    
450
        $ snf-manage service-list | grep pithos # find service id
451
        $ snf-manage service-update --name='pithos+' <service id> 
452

    
453
Then, configure and load the available resources per service
454
and associated default limits into Astakos. On the Astakos host run ::
455

    
456
     # snf-manage astakos-init --load-service-resources
457

    
458

    
459
.. note::
460

    
461
    Before v0.13, only `cyclades.vm`, `cyclades.network.private`,
462
    and `pithos+.diskspace` existed (not with these names,
463
    there were per-service settings).
464
    However, limits to the new resources must also be set.
465

    
466
    If the intetion is to keep a resource unlimited, (counting on that VM
467
    creation will be limited by other resources' limit) it is best to calculate
468
    a value that is too large to be reached because of other limits (and
469
    available flavours), but not much larger than needed because this might
470
    confuse users who do not readily understand that multiple limits apply and
471
    flavors are limited.
472

    
473

    
474
6. Migrate Services user names to uuids
475
=======================================
476

    
477

    
478
6.1 Double-check cyclades before user case/uuid migration
479
---------------------------------------------------------
480

    
481
::
482

    
483
    cyclades.host$ snf-manage cyclades-astakos-migrate-013 --validate
484

    
485
Duplicate user found?
486

    
487
- either *merge* (merge will merge all resources to one user)::
488

    
489
    cyclades.host$ snf-manage cyclades-astakos-migrate-013 --merge-user=kpap@grnet.gr
490

    
491
- or *delete* ::
492

    
493
    cyclades.host$ snf-manage cyclades-astakos-migrate-013 --delete-user=KPap@grnet.gr
494
    # (only KPap will be deleted not kpap)
495

    
496
6.2 Double-check pithos before user case/uuid migration
497
---------------------------------------------------------
498

    
499
::
500

    
501
    pithos.host$ snf-manage pithos-manage-accounts --list-duplicate
502

    
503
Duplicate user found?
504

    
505
If you want to migrate files first:
506

    
507
- *merge* (merge will merge all resources to one user)::
508

    
509
    pithos.host$ snf-manage pithos-manage-accounts --merge-accounts --src-account=SPapagian@grnet.gr --dest-account=spapagian@grnet.gr
510
    # (SPapagian@grnet.gr's contents will be merged into spapagian@grnet.gr, but SPapagian@grnet.gr account will still exist)
511

    
512
- and then *delete* ::
513

    
514
    pithos.host$ snf-manage pithos-manage-accounts --delete-account=SPapagian@grnet.gr
515
    # (only SPapagian@grnet.gr will be deleted not spapagian@grnet.gr)
516

    
517
If you do *NOT* want to migrate files just run the second step and delete
518
the duplicate account.
519

    
520
6.3 Migrate Cyclades users (email case/uuid)
521
--------------------------------------------
522

    
523
::
524

    
525
    cyclades.host$ snf-manage cyclades-astakos-migrate-013 --migrate-users
526

    
527
- if invalid usernames are found, verify that they do not exist in astakos::
528

    
529
    astakos.host$ snf-manage user-list
530

    
531
- if no user exists::
532

    
533
    cyclades.host$ snf-manage cyclades-astakos-migrate-013 --delete-user=<userid>
534

    
535
Finally, if you have set manually quotas for specific users inside
536
``/etc/synnefo/20-snf-cyclades-app-api.conf`` (in ``VMS_USER_QUOTA``,
537
``NETWORKS_USER_QUOTA`` make sure to update them so that:
538

    
539
1. There are no double entries wrt case sensitivity
540
2. Replace all user email addresses with the corresponding UUIDs
541

    
542
To find the UUIDs for step 2 run on the Astakos host ::
543

    
544
     # snf-manage user-list
545

    
546
6.4 Migrate Pithos user names
547
-----------------------------
548

    
549
Check if alembic has not been initialized ::
550

    
551
    pithos.host$ pithos-migrate current
552

    
553
- If alembic current is None (e.g. okeanos.io) ::
554

    
555
    pithos.host$ pithos-migrate stamp 3dd56e750a3
556

    
557
Then, migrate pithos account name to uuid::
558

    
559
    pithos.host$ pithos-migrate upgrade head
560

    
561
Finally, set this setting to ``True``::
562

    
563
    PITHOS_USE_QUOTAHOLDER = True
564

    
565

    
566
7. Migrate old quota limits
567
===========================
568

    
569
7.1 Migrate Pithos quota limits to Astakos
570
------------------------------------------
571

    
572
Migrate from pithos native to astakos/quotaholder.
573
This requires a file to be transfered from Cyclades to Astakos::
574

    
575
    pithos.host$ snf-manage pithos-export-quota --location=pithos-quota.txt
576
    pithos.host$ scp pithos-quota.txt astakos.host:
577
    astakos.host$ snf-manage user-set-initial-quota pithos-quota.txt
578

    
579
.. _export-quota-note:
580

    
581
.. note::
582

    
583
    `pithos-export-quota` will only export quotas that are not equal to the
584
    defaults in Pithos. Therefore, it is possible to both change or maintain
585
    the default quotas across the migration. To maintain quotas the new default
586
    pithos+.diskpace limit in Astakos must be equal to the (old) default quota
587
    limit in Pithos. Change either one of them make them equal.
588

    
589
    see :ref:`astakos-load-resources` on how to set the (new) default quotas in Astakos.
590

    
591
7.2 Migrate Cyclades quota limits to Astakos
592
--------------------------------------------
593

    
594
::
595

    
596
    cyclades.host$ snf-manage cyclades-export-quota --location=cyclades-quota.txt
597
    cyclades.host$ scp cyclades-quota.txt astakos.host:
598
    astakos.host$ snf-manage user-set-initial-quota cyclades-quota.txt
599

    
600
`cyclades-export-quota` will only export quotas that are not equal to the defaults.
601
See :ref:`note above <export-quota-note>`.
602

    
603
8. Enforce the new quota limits migrated to Astakos
604
===================================================
605
The following should report all users not having quota limits set
606
because the effective quota database has not been initialized yet. ::
607

    
608
    astakos.host$ snf-manage astakos-quota --verify
609

    
610
Initialize the effective quota database::
611

    
612
    astakos.host$ snf-manage astakos-quota --sync
613

    
614
This procedure may be used to verify and re-synchronize the effective quota
615
database with the quota limits that are derived from policies in Astakos
616
(initial quotas, project memberships, etc.)
617

    
618
9. Initialize resource usage
619
============================
620

    
621
The effective quota database (quotaholder) has just been initialized and knows
622
nothing of the current resource usage. Therefore, each service must send it in.
623

    
624
9.1 Initialize Pithos resource usage
625
------------------------------------
626

    
627
::
628

    
629
    pithos.host$ snf-manage pithos-reset-usage
630

    
631
9.2 Initialize Cyclades resource usage
632
--------------------------------------
633

    
634
::
635

    
636
    cyclades.host$ snf-manage cyclades-reset-usage
637

    
638
10. Install periodic project maintainance checks
639
================================================
640
In order to detect and effect project expiration,
641
a management command has to be run periodically
642
(depending on the required granularity, e.g. once a day/hour)::
643

    
644
    astakos.host$ snf-manage project-control --terminate-expired
645

    
646
A list of expired projects can be extracted with::
647

    
648
    astakos.host$ snf-manage project-control --list-expired
649

    
650

    
651
11. Restart all services
652
========================
653

    
654
Start (or restart, if running) all Synnefo services on all hosts.
655

    
656
::
657

    
658
    # service gunicorn restart
659
    # service snf-dispatcher restart
660
    # etc.