Skip to content

Commit 5a1a215

Browse files
author
Naman Munet
committed
mgr/dashboard: unable to edit pipe config for bucket level policy of a bucket
Fixes: https://tracker.ceph.com/issues/68387 Fixes Includes: 1) Passing additional parameter for 'user' and 'mode' as the user can be either system/dashboard or other values while creating pipe. 2) Previously while removing the src/dest bucket field, we were getting same old values on editing pipe, but now it will become '*' if empty value passed from frontend. Signed-off-by: Naman Munet <[email protected]>
1 parent d7c144c commit 5a1a215

File tree

7 files changed

+87
-25
lines changed

7 files changed

+87
-25
lines changed

src/pybind/mgr/dashboard/controllers/rgw.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,24 @@ def create_sync_pipe(self, group_id: str, pipe_id: str,
244244
source_zones: Dict[str, Any],
245245
destination_zones: Dict[str, Any],
246246
source_bucket: str = '',
247-
destination_bucket: str = '', bucket_name: str = ''):
247+
destination_bucket: str = '', bucket_name: str = '',
248+
user: str = '', mode: str = ''):
248249
multisite_instance = RgwMultisite()
249250
return multisite_instance.create_sync_pipe(group_id, pipe_id, source_zones,
250251
destination_zones, source_bucket,
251-
destination_bucket, bucket_name, True)
252+
destination_bucket, bucket_name, True,
253+
user, mode)
252254

253255
@Endpoint(method='DELETE', path='/sync-pipe')
254256
@EndpointDoc("Remove the sync pipe")
255257
@DeletePermission
256258
def remove_sync_pipe(self, group_id: str, pipe_id: str,
257259
source_zones: Optional[List[str]] = None,
258260
destination_zones: Optional[List[str]] = None,
259-
destination_bucket: str = '',
260261
bucket_name: str = ''):
261262
multisite_instance = RgwMultisite()
262263
return multisite_instance.remove_sync_pipe(group_id, pipe_id, source_zones,
263-
destination_zones, destination_bucket,
264-
bucket_name, True)
264+
destination_zones, bucket_name, True)
265265

266266

267267
@APIRouter('/rgw/daemon', Scope.RGW)

src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-sync-pipe-modal/rgw-multisite-sync-pipe-modal.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
i18n-placeholder
6565
placeholder="Source Bucket Name..."
6666
formControlName="source_bucket"/>
67+
<cd-help-text>
68+
<span i18n>{{ allBucketSelectedHelpText }}</span>
69+
</cd-help-text>
6770
</div>
6871
</div>
6972
<div class="form-group row">
@@ -78,6 +81,9 @@
7881
i18n-placeholder
7982
placeholder="Destination Bucket Name..."
8083
formControlName="destination_bucket"/>
84+
<cd-help-text>
85+
<span i18n>{{ allBucketSelectedHelpText }}</span>
86+
</cd-help-text>
8187
</div>
8288
</div>
8389
</div>

src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-sync-pipe-modal/rgw-multisite-sync-pipe-modal.component.spec.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,47 @@ describe('RgwMultisiteSyncPipeModalComponent', () => {
8989
component.submit();
9090
expect(spy).toHaveBeenCalled();
9191
expect(putDataSpy).toHaveBeenCalled();
92-
expect(putDataSpy).toHaveBeenCalledWith(component.pipeForm.getRawValue());
92+
expect(putDataSpy).toHaveBeenCalledWith({
93+
...component.pipeForm.getRawValue(),
94+
mode: '',
95+
user: ''
96+
});
97+
});
98+
99+
it('should pass "user" and "mode" while creating/editing pipe', () => {
100+
component.editing = true;
101+
component.pipeForm.patchValue({
102+
pipe_id: 'pipe1',
103+
group_id: 's3-bucket-replication:enabled',
104+
source_bucket: '',
105+
source_zones: { added: ['zone1-zg1-realm1'], removed: [] },
106+
destination_bucket: '',
107+
destination_zones: { added: ['zone2-zg1-realm1'], removed: [] }
108+
});
109+
component.pipeSelectedRow = {
110+
dest: { bucket: '*', zones: ['zone2-zg1-realm1'] },
111+
id: 'pipi1',
112+
params: {
113+
dest: {},
114+
mode: 'user',
115+
priority: 0,
116+
source: { filter: { tags: [] } },
117+
user: 'dashboard'
118+
},
119+
source: { bucket: '*', zones: ['zone1-zg1-realm1'] }
120+
};
121+
122+
component.sourceZones.data.selected = ['zone1-zg1-realm1'];
123+
component.destZones.data.selected = ['zone2-zg1-realm1'];
124+
const spy = jest.spyOn(component, 'submit');
125+
const putDataSpy = jest.spyOn(multisiteServiceMock, 'createEditSyncPipe');
126+
component.submit();
127+
expect(spy).toHaveBeenCalled();
128+
expect(putDataSpy).toHaveBeenCalled();
129+
expect(putDataSpy).toHaveBeenCalledWith({
130+
...component.pipeForm.getRawValue(),
131+
mode: 'user',
132+
user: 'dashboard'
133+
});
93134
});
94135
});

src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-sync-pipe-modal/rgw-multisite-sync-pipe-modal.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { ZoneData } from '../models/rgw-multisite-zone-selector';
1818
import { SucceededActionLabelsI18n } from '~/app/shared/constants/app.constants';
1919

2020
const ALL_ZONES = $localize`All zones (*)`;
21+
const ALL_BUCKET_SELECTED_HELP_TEXT =
22+
'If no value is provided, all the buckets in the zone group will be selected.';
2123

2224
@Component({
2325
selector: 'cd-rgw-multisite-sync-pipe-modal',
@@ -33,6 +35,7 @@ export class RgwMultisiteSyncPipeModalComponent implements OnInit {
3335
sourceZones = new ZoneData(false, 'Filter Zones');
3436
destZones = new ZoneData(false, 'Filter Zones');
3537
icons = Icons;
38+
allBucketSelectedHelpText = ALL_BUCKET_SELECTED_HELP_TEXT;
3639

3740
constructor(
3841
public activeModal: NgbActiveModal,
@@ -187,7 +190,9 @@ export class RgwMultisiteSyncPipeModalComponent implements OnInit {
187190
.createEditSyncPipe({
188191
...this.pipeForm.getRawValue(),
189192
source_zones: sourceZones,
190-
destination_zones: destZones
193+
destination_zones: destZones,
194+
user: this.editing ? this.pipeSelectedRow?.params?.user : '',
195+
mode: this.editing ? this.pipeSelectedRow?.params?.mode : ''
191196
})
192197
.subscribe(
193198
() => {

src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-multisite.service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,15 @@ export class RgwMultisiteService {
123123
);
124124
}
125125

126-
createEditSyncPipe(payload: any) {
127-
return this.http.put(`${this.url}/sync-pipe`, payload);
126+
createEditSyncPipe(payload: any, user?: string, mode?: string) {
127+
let params = new HttpParams();
128+
if (user) {
129+
params = params.append('user', user);
130+
}
131+
if (mode) {
132+
params = params.append('mode', mode);
133+
}
134+
return this.http.put(`${this.url}/sync-pipe`, payload, { params });
128135
}
129136

130137
removeSyncPipe(pipe_id: string, group_id: string, bucket_name?: string) {

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11384,13 +11384,19 @@ paths:
1138411384
type: string
1138511385
group_id:
1138611386
type: string
11387+
mode:
11388+
default: ''
11389+
type: string
1138711390
pipe_id:
1138811391
type: string
1138911392
source_bucket:
1139011393
default: ''
1139111394
type: string
1139211395
source_zones:
1139311396
type: string
11397+
user:
11398+
default: ''
11399+
type: string
1139411400
required:
1139511401
- group_id
1139611402
- pipe_id
@@ -11445,11 +11451,6 @@ paths:
1144511451
name: destination_zones
1144611452
schema:
1144711453
type: string
11448-
- default: ''
11449-
in: query
11450-
name: destination_bucket
11451-
schema:
11452-
type: string
1145311454
- default: ''
1145411455
in: query
1145511456
name: bucket_name

src/pybind/mgr/dashboard/services/rgw_client.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,8 @@ def create_sync_pipe(self, group_id: str, pipe_id: str,
22362236
source_bucket: str = '',
22372237
destination_bucket: str = '',
22382238
bucket_name: str = '',
2239-
update_period=False):
2239+
update_period=False,
2240+
user: str = '', mode: str = ''):
22402241

22412242
if source_zones['added'] or destination_zones['added']:
22422243
rgw_sync_policy_cmd = ['sync', 'group', 'pipe', 'create',
@@ -2245,18 +2246,22 @@ def create_sync_pipe(self, group_id: str, pipe_id: str,
22452246
if bucket_name:
22462247
rgw_sync_policy_cmd += ['--bucket', bucket_name]
22472248

2248-
if source_bucket:
2249-
rgw_sync_policy_cmd += ['--source-bucket', source_bucket]
2249+
rgw_sync_policy_cmd += ['--source-bucket', source_bucket]
22502250

2251-
if destination_bucket:
2252-
rgw_sync_policy_cmd += ['--dest-bucket', destination_bucket]
2251+
rgw_sync_policy_cmd += ['--dest-bucket', destination_bucket]
22532252

22542253
if source_zones['added']:
22552254
rgw_sync_policy_cmd += ['--source-zones', ','.join(source_zones['added'])]
22562255

22572256
if destination_zones['added']:
22582257
rgw_sync_policy_cmd += ['--dest-zones', ','.join(destination_zones['added'])]
22592258

2259+
if user:
2260+
rgw_sync_policy_cmd += ['--uid', user]
2261+
2262+
if mode:
2263+
rgw_sync_policy_cmd += ['--mode', mode]
2264+
22602265
logger.info("Creating sync pipe!")
22612266
try:
22622267
exit_code, _, err = mgr.send_rgwadmin_command(rgw_sync_policy_cmd)
@@ -2271,13 +2276,13 @@ def create_sync_pipe(self, group_id: str, pipe_id: str,
22712276
if ((source_zones['removed'] and '*' not in source_zones['added'])
22722277
or (destination_zones['removed'] and '*' not in destination_zones['added'])):
22732278
self.remove_sync_pipe(group_id, pipe_id, source_zones['removed'],
2274-
destination_zones['removed'], destination_bucket,
2275-
bucket_name)
2279+
destination_zones['removed'],
2280+
bucket_name, True)
22762281

22772282
def remove_sync_pipe(self, group_id: str, pipe_id: str,
22782283
source_zones: Optional[List[str]] = None,
22792284
destination_zones: Optional[List[str]] = None,
2280-
destination_bucket: str = '', bucket_name: str = '',
2285+
bucket_name: str = '',
22812286
update_period=False):
22822287
rgw_sync_policy_cmd = ['sync', 'group', 'pipe', 'remove',
22832288
'--group-id', group_id, '--pipe-id', pipe_id]
@@ -2291,9 +2296,6 @@ def remove_sync_pipe(self, group_id: str, pipe_id: str,
22912296
if destination_zones:
22922297
rgw_sync_policy_cmd += ['--dest-zones', ','.join(destination_zones)]
22932298

2294-
if destination_bucket:
2295-
rgw_sync_policy_cmd += ['--dest-bucket', destination_bucket]
2296-
22972299
logger.info("Removing sync pipe! %s", rgw_sync_policy_cmd)
22982300
try:
22992301
exit_code, _, err = mgr.send_rgwadmin_command(rgw_sync_policy_cmd)

0 commit comments

Comments
 (0)