Skip to content

Commit a2a4d9b

Browse files
authored
Merge pull request ceph#60147 from rhcs-dashboard/sync-policy-pipe-edit-fixes
mgr/dashboard: unable to edit pipe config for bucket level policy of bucket Reviewed-by: Afreen Misbah <[email protected]>
2 parents a7d098c + 5a1a215 commit a2a4d9b

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
@@ -129,8 +129,15 @@ export class RgwMultisiteService {
129129
);
130130
}
131131

132-
createEditSyncPipe(payload: any) {
133-
return this.http.put(`${this.url}/sync-pipe`, payload);
132+
createEditSyncPipe(payload: any, user?: string, mode?: string) {
133+
let params = new HttpParams();
134+
if (user) {
135+
params = params.append('user', user);
136+
}
137+
if (mode) {
138+
params = params.append('mode', mode);
139+
}
140+
return this.http.put(`${this.url}/sync-pipe`, payload, { params });
134141
}
135142

136143
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
@@ -11453,13 +11453,19 @@ paths:
1145311453
type: string
1145411454
group_id:
1145511455
type: string
11456+
mode:
11457+
default: ''
11458+
type: string
1145611459
pipe_id:
1145711460
type: string
1145811461
source_bucket:
1145911462
default: ''
1146011463
type: string
1146111464
source_zones:
1146211465
type: string
11466+
user:
11467+
default: ''
11468+
type: string
1146311469
required:
1146411470
- group_id
1146511471
- pipe_id
@@ -11514,11 +11520,6 @@ paths:
1151411520
name: destination_zones
1151511521
schema:
1151611522
type: string
11517-
- default: ''
11518-
in: query
11519-
name: destination_bucket
11520-
schema:
11521-
type: string
1152211523
- default: ''
1152311524
in: query
1152411525
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
@@ -2245,7 +2245,8 @@ def create_sync_pipe(self, group_id: str, pipe_id: str,
22452245
source_bucket: str = '',
22462246
destination_bucket: str = '',
22472247
bucket_name: str = '',
2248-
update_period=False):
2248+
update_period=False,
2249+
user: str = '', mode: str = ''):
22492250

22502251
if source_zones['added'] or destination_zones['added']:
22512252
rgw_sync_policy_cmd = ['sync', 'group', 'pipe', 'create',
@@ -2254,18 +2255,22 @@ def create_sync_pipe(self, group_id: str, pipe_id: str,
22542255
if bucket_name:
22552256
rgw_sync_policy_cmd += ['--bucket', bucket_name]
22562257

2257-
if source_bucket:
2258-
rgw_sync_policy_cmd += ['--source-bucket', source_bucket]
2258+
rgw_sync_policy_cmd += ['--source-bucket', source_bucket]
22592259

2260-
if destination_bucket:
2261-
rgw_sync_policy_cmd += ['--dest-bucket', destination_bucket]
2260+
rgw_sync_policy_cmd += ['--dest-bucket', destination_bucket]
22622261

22632262
if source_zones['added']:
22642263
rgw_sync_policy_cmd += ['--source-zones', ','.join(source_zones['added'])]
22652264

22662265
if destination_zones['added']:
22672266
rgw_sync_policy_cmd += ['--dest-zones', ','.join(destination_zones['added'])]
22682267

2268+
if user:
2269+
rgw_sync_policy_cmd += ['--uid', user]
2270+
2271+
if mode:
2272+
rgw_sync_policy_cmd += ['--mode', mode]
2273+
22692274
logger.info("Creating sync pipe!")
22702275
try:
22712276
exit_code, _, err = mgr.send_rgwadmin_command(rgw_sync_policy_cmd)
@@ -2280,13 +2285,13 @@ def create_sync_pipe(self, group_id: str, pipe_id: str,
22802285
if ((source_zones['removed'] and '*' not in source_zones['added'])
22812286
or (destination_zones['removed'] and '*' not in destination_zones['added'])):
22822287
self.remove_sync_pipe(group_id, pipe_id, source_zones['removed'],
2283-
destination_zones['removed'], destination_bucket,
2284-
bucket_name)
2288+
destination_zones['removed'],
2289+
bucket_name, True)
22852290

22862291
def remove_sync_pipe(self, group_id: str, pipe_id: str,
22872292
source_zones: Optional[List[str]] = None,
22882293
destination_zones: Optional[List[str]] = None,
2289-
destination_bucket: str = '', bucket_name: str = '',
2294+
bucket_name: str = '',
22902295
update_period=False):
22912296
rgw_sync_policy_cmd = ['sync', 'group', 'pipe', 'remove',
22922297
'--group-id', group_id, '--pipe-id', pipe_id]
@@ -2300,9 +2305,6 @@ def remove_sync_pipe(self, group_id: str, pipe_id: str,
23002305
if destination_zones:
23012306
rgw_sync_policy_cmd += ['--dest-zones', ','.join(destination_zones)]
23022307

2303-
if destination_bucket:
2304-
rgw_sync_policy_cmd += ['--dest-bucket', destination_bucket]
2305-
23062308
logger.info("Removing sync pipe! %s", rgw_sync_policy_cmd)
23072309
try:
23082310
exit_code, _, err = mgr.send_rgwadmin_command(rgw_sync_policy_cmd)

0 commit comments

Comments
 (0)