summaryrefslogtreecommitdiffstats
path: root/qa/tasks/rgw_cloudtier.py
blob: 88f7d0dc285a81824321b9590571754401ec80f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""
rgw_cloudtier configuration routines
"""
import argparse
import logging

from teuthology import misc as teuthology
from teuthology.exceptions import ConfigError
from tasks.util.rgw import rgwadmin, wait_for_radosgw
from teuthology.task import Task

log = logging.getLogger(__name__)

class RGWCloudTier(Task):
    """
    Configure CloudTier storage class.

    To configure cloudtiering on any client::

        tasks:
        - ceph:
        - rgw:
        - rgw-cloudtier:
            client.0:
              cloud_storage_class:
              cloud_client:
              cloud_regular_storage_class:
              cloud_target_storage_class:
              cloud_retain_head_object:
              cloud_target_path:
              cloudtier_user:
                cloud_secret:
                cloud_access_key:

    """
    def __init__(self, ctx, config):
        super(RGWCloudTier, self).__init__(ctx, config)

    def setup(self):
        super(RGWCloudTier, self).setup()

        overrides = self.ctx.config.get('overrides', {})
        teuthology.deep_merge(self.config, overrides.get('rgw-cloudtier', {}))

        if not self.ctx.rgw:
            raise ConfigError('rgw-cloudtier must run after the rgw task')

        self.ctx.rgw_cloudtier = argparse.Namespace()
        self.ctx.rgw_cloudtier.config = self.config

        log.info('Configuring rgw cloudtier ...')
        clients = self.config.keys() # http://tracker.ceph.com/issues/20417
        for client in clients:
            client_config = self.config.get(client)
            if client_config is None:
                client_config = {}

            if client_config is not None:
                log.info('client %s - cloudtier config is -----------------%s ', client, client_config)
                # configuring cloudtier

                cloud_client = client_config.get('cloud_client')
                cloud_storage_class = client_config.get('cloud_storage_class')
                cloud_target_path = client_config.get('cloud_target_path')
                cloud_target_storage_class = client_config.get('cloud_target_storage_class')
                cloud_retain_head_object = client_config.get('cloud_retain_head_object')

                cloudtier_user = client_config.get('cloudtier_user')
                cloud_access_key = cloudtier_user.get('cloud_access_key')
                cloud_secret = cloudtier_user.get('cloud_secret')

                # XXX: the 'default' zone and zonegroup aren't created until we run RGWRados::init_complete().
                # issue a 'radosgw-admin user list' command to trigger this
                rgwadmin(self.ctx, client, cmd=['user', 'list'], check_status=True)

                endpoint = self.ctx.rgw.role_endpoints[cloud_client]

                # create cloudtier storage class
                tier_config_params = "endpoint=" + endpoint.url() + \
                           ",access_key=" + cloud_access_key + \
                            ",secret=" + cloud_secret + \
                            ",retain_head_object=" + cloud_retain_head_object

                if (cloud_target_path != None):
                    tier_config_params += ",target_path=" + cloud_target_path
                if (cloud_target_storage_class != None):
                    tier_config_params += ",target_storage_class=" + cloud_target_storage_class

                log.info('Configuring cloud-s3 tier storage class type = %s', cloud_storage_class)

                rgwadmin(self.ctx, client,
                      cmd=['zonegroup', 'placement', 'add',
                            '--rgw-zone', 'default',
                            '--placement-id', 'default-placement',
                            '--storage-class', cloud_storage_class,
                            '--tier-type', 'cloud-s3',
                            '--tier-config', tier_config_params],
                      check_status=True)

                ## create cloudtier user with the access keys given on the cloud client
                cloud_tier_user_id = "cloud-tier-user-" + cloud_client
                cloud_tier_user_name = "CLOUD TIER USER - " + cloud_client
                rgwadmin(self.ctx, cloud_client,
                     cmd=['user', 'create', '--uid', cloud_tier_user_id,
                        '--display-name', cloud_tier_user_name,
                        '--access-key', cloud_access_key,
                        '--secret', cloud_secret,
                        '--caps', 'user-policy=*'],
                        check_status=True)

                log.info('Finished Configuring rgw cloudtier ...')
                
                cluster_name, daemon_type, client_id = teuthology.split_role(client)
                client_with_id = daemon_type + '.' + client_id
                self.ctx.daemons.get_daemon('rgw', client_with_id, cluster_name).restart()
                log.info('restarted rgw daemon ...')

                (remote,) = self.ctx.cluster.only(client).remotes.keys()
                wait_for_radosgw(endpoint.url(), remote)
                

task = RGWCloudTier