Skip to content

mgr/cephadm: rgw update period after realm, zone creation#36496

Merged
sebastian-philipp merged 1 commit intoceph:masterfrom
Daniel-Pivonka:cephadm-44926
Aug 21, 2020
Merged

mgr/cephadm: rgw update period after realm, zone creation#36496
sebastian-philipp merged 1 commit intoceph:masterfrom
Daniel-Pivonka:cephadm-44926

Conversation

@Daniel-Pivonka
Copy link

Fixes: https://tracker.ceph.com/issues/44926
Signed-off-by: Daniel-Pivonka dpivonka@redhat.com

@Daniel-Pivonka Daniel-Pivonka requested a review from a team as a code owner August 6, 2020 14:06
@sebastian-philipp
Copy link
Contributor

@sebastian-philipp
Copy link
Contributor

@theanalyst or @cbodley can you have a quick look?

@sebastian-philipp sebastian-philipp removed the wip-swagner-testing My Teuthology tests label Aug 7, 2020
@sebastian-philipp
Copy link
Contributor

Hm. we have a 100loc monster already here. would it make sense to ease reviewing by refactoring this a bit?

@Daniel-Pivonka
Copy link
Author

I broke this up into 2 commits because I was doing two things.
First I rearranged the zonegroup code so its only called if we are creating a zone.
Second I update the period if we created a realm or zone.

Copy link
Contributor

@sebastian-philipp sebastian-philipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gm. I had to refactor this thing in order to review it:

    def create_realm_zonegroup_zone(self, spec: RGWSpec, rgw_id: str):
        if utils.get_cluster_health(self.mgr) != 'HEALTH_OK':
            raise OrchestratorError('Health not ok, will try agin when health ok')

        #get keyring needed to run rados commands and strip out just the keyring
        keyring = self.get_keyring(rgw_id).split('key = ',1)[1].rstrip()

        # We can call radosgw-admin within the container, cause cephadm gives the MGR the required keyring permissions

        def get_realms() -> List[str]:
            cmd = ['radosgw-admin',
                   '--key=%s'%keyring,
                   '--user', 'rgw.%s'%rgw_id,
                   'realm', 'list',
                   '--format=json']
            result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            out = result.stdout
            if not out:
                return []
            try:
                j = json.loads(realms)
                return j.get('realms', [])
            except Exception as e:
                raise OrchestratorError('failed to parse realm info')

        def create_realm():
            cmd = ['radosgw-admin',
                   '--key=%s'%keyring,
                   '--user', 'rgw.%s'%rgw_id,
                   'realm', 'create',
                   '--rgw-realm=%s'%spec.rgw_realm,
                   '--default']
            result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            self.mgr.log.info('created realm: %s'%spec.rgw_realm)

        def get_zonegroups() -> List[str]:
            # get zonegroup
            cmd = ['radosgw-admin',
                   '--key=%s'%keyring,
                   '--user', 'rgw.%s'%rgw_id,
                   'zonegroup', 'list',
                   '--format=json']
            result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            out = result.stdout
            if not out:
                return []
            try:
                j = json.loads(result.stdout)
                return j.get('zonegroups', [])
            except Exception as e:
                raise OrchestratorError('failed to parse zonegroup info')

        def create_zonegroup():
            cmd = ['radosgw-admin',
                   '--key=%s'%keyring,
                   '--user', 'rgw.%s'%rgw_id,
                   'zonegroup', 'create',
                   '--rgw-zonegroup=default',
                   '--master', '--default']
            result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            self.mgr.log.info('created zonegroup: default')


        # create default zonegroup (will be used below if zone needs to be created)
        def create_zonegroup_if_requuired():
            zonegroups = get_zonegroups()
            if 'default' not in zonegroups:
                create_zonegroup()

        def get_zones() -> List[str]:
            cmd = ['radosgw-admin',
                   '--key=%s'%keyring,
                   '--user', 'rgw.%s'%rgw_id,
                   'zone', 'list',
                   '--format=json']
            result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            out = result.stdout
            if not out:
                return []
            try:
                j = json.loads(result.stdout)
                return j.get('zones', [])
            except Exception as e:
                raise OrchestratorError('failed to parse zone info')

        def create_zone():
            cmd = ['radosgw-admin',
                   '--key=%s'%keyring,
                   '--user', 'rgw.%s'%rgw_id,
                   'zone', 'create',
                   '--rgw-zonegroup=default',
                   '--rgw-zone=%s'%spec.rgw_zone,
                   '--master', '--default']
            result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            self.mgr.log.info('created zone: %s'%spec.rgw_zone)

        changes = False
        realms = get_realms()
        if spec.rgw_realm not in realms:
            create_realm()
            changes = True

        zones = get_zones()

        if spec.rgw_zone not in zones:
            create_zonegroup_if_requuired()
            create_zone()
            changes = True


        # update period if changes were made
        if changes:
            cmd = ['radosgw-admin',
                   '--key=%s'%keyring,
                   '--user', 'rgw.%s'%rgw_id,
                   'period', 'update',
                   '--rgw-realm=%s'%spec.rgw_realm,
                   '--commit']
            result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

this might be more readable?

Signed-off-by: Daniel-Pivonka <dpivonka@redhat.com>
@sebastian-philipp sebastian-philipp merged commit cb529ac into ceph:master Aug 21, 2020
trociny added a commit to trociny/sesdev that referenced this pull request Mar 12, 2021
This command was added to the upstream doc in this PR [1],
and it fixes the issue with creating a rgw bucket via dashboard
(InvalidLocationConstraint error).

[1] ceph/ceph#36496

Signed-off-by: Mykola Golub <mgolub@suse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants