Skip to content

Commit 012b26a

Browse files
CE-633 Couchbase Plugin: Dsource sizing not working due to filesystem permissions (#68)
* CE-633 Couchbase Plugin: Dsource sizing not working due to filesystem permissions PR URL: https://www.github.com/delphix/couchbase-plugin/pull/68 * CE-633 Couchbase Plugin: Dsource sizing not working due to filesystem permissions
1 parent 0349fd3 commit 012b26a

File tree

6 files changed

+93
-55
lines changed

6 files changed

+93
-55
lines changed

plugin_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
id: 18f4ff11-b758-4bf2-9a37-719a22f5a4b8
22
name: sc:couchbase
3-
externalVersion: "1.3.0"
4-
buildNumber: 1.3.0
3+
externalVersion: "1.3.1"
4+
buildNumber: 1.3.1
55
language: PYTHON38
66
hostTypes:
77
- UNIX

src/controller/couchbase_operation.py

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
2+
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
33
#
44

55
##############################################################################
@@ -195,6 +195,9 @@ def run_os_command(self, os_command, **kwargs):
195195
stdout, stderr, exit_code = utilities.execute_bash(
196196
self.connection, command
197197
)
198+
logger.debug(f"os_command stdout: {stdout}")
199+
logger.debug(f"os_command stderr: {stderr}")
200+
logger.debug(f"os_command exit_code: {exit_code}")
198201
return [stdout, stderr, exit_code]
199202

200203
def restart_couchbase(self, provision=False):
@@ -430,6 +433,53 @@ def make_directory(self, directory_path, force_env_user=False):
430433

431434
logger.debug("Changed the permission of directory")
432435

436+
def check_stale_mountpoint(self, path):
437+
438+
output, stderr, exit_code = self.run_os_command(
439+
os_command="df", path=path
440+
)
441+
if exit_code != 0:
442+
if "No such file or directory" in stderr:
443+
# this is actually OK
444+
return False
445+
else:
446+
logger.error(
447+
"df retured error - stale mount point or other error"
448+
)
449+
logger.error(
450+
"stdout: {} stderr: {} exit_code: {}".format(
451+
output, stderr, exit_code
452+
)
453+
)
454+
return True
455+
else:
456+
return False
457+
458+
def get_db_size(self, path: str) -> str:
459+
"""
460+
Get the size of the dataset.
461+
462+
:param connection: Staging connection.
463+
:param path: Mount location corresponding to dataset
464+
465+
:return: du command output.
466+
467+
"""
468+
logger.debug("Started db sizing")
469+
du_std, du_stderr, du_exit_code = self.run_os_command(
470+
os_command="du", mount_path=path
471+
)
472+
if du_exit_code != 0:
473+
logger.error("Unable to calculate the dataset size")
474+
logger.error(f"stderr: {du_stderr}")
475+
raise UserError(
476+
"Problem with measuring mounted file system",
477+
"Ask OS admin to check mount",
478+
du_stderr,
479+
)
480+
logger.debug(f"Completed db sizing {du_std}")
481+
return du_std
482+
433483
def create_config_dir(self):
434484
"""create and return the hidden folder directory with name 'delphix'"""
435485

@@ -494,8 +544,9 @@ def source_bucket_list(self):
494544

495545
def get_backup_date(self, x):
496546
w = x.replace(
497-
"{}/{}".format(
547+
"{}/{}/{}".format(
498548
self.parameters.couchbase_bak_loc,
549+
self.parameters.archive_name,
499550
self.parameters.couchbase_bak_repo,
500551
),
501552
"",
@@ -1018,11 +1069,11 @@ def delete_config_folder(self):
10181069
srcname=config_directory_path,
10191070
trgname=target_folder,
10201071
)
1021-
logger.debug(
1022-
f"mv directory >> command_output=={command_output}"
1023-
f" , command_stderr=={command_stderr} , "
1024-
f"command_exit_code=={command_exit_code}"
1025-
)
1072+
# logger.debug(
1073+
# f"mv directory >> command_output=={command_output}"
1074+
# f" , command_stderr=={command_stderr} , "
1075+
# f"command_exit_code=={command_exit_code}"
1076+
# )
10261077

10271078
def delete_xdcr_config(self):
10281079
if self.parameters.d_source_type == "XDCR":

src/controller/helper_lib.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
2+
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
33
#
44

55
##############################################################################
@@ -34,7 +34,6 @@
3434
from internal_exceptions.plugin_exceptions import SourceConfigDiscoveryError
3535
from internal_exceptions.plugin_exceptions import UnmountFileSystemError
3636
from utils import utilities
37-
from dlpx.virtualization.common import RemoteConnection
3837

3938
# Global logger object for this file
4039
logger = logging.getLogger(__name__)
@@ -522,29 +521,3 @@ def clean_stale_mountpoint(connection, path):
522521
"Ask OS admin to check mount points",
523522
umount_stderr,
524523
)
525-
526-
527-
def get_db_size(connection: RemoteConnection, path: str) -> str:
528-
"""
529-
Get the size of the dataset.
530-
531-
:param connection: Staging connection.
532-
:param path: Mount location corresponding to dataset
533-
534-
:return: du command output.
535-
536-
"""
537-
logger.debug("Started db sizing")
538-
du_std, du_stderr, du_exit_code = utilities.execute_bash(
539-
connection, CommandFactory.du(mount_path=path)
540-
)
541-
if du_exit_code != 0:
542-
logger.error("Unable to calculate the dataset size")
543-
logger.error(f"stderr: {du_stderr}")
544-
raise UserError(
545-
"Problem with measuring mounted file system",
546-
"Ask OS admin to check mount",
547-
du_stderr,
548-
)
549-
logger.debug(f"Completed db sizing {du_std}")
550-
return du_std

src/db_commands/commands.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
2+
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
33
#
44

55
##############################################################################
@@ -90,8 +90,13 @@ def check_file(file_path, sudo=False, uid=None, **kwargs):
9090
)
9191

9292
@staticmethod
93-
def write_file(filename, data, **kwargs):
94-
return "echo {data} > {filename}".format(filename=filename, data=data)
93+
def write_file(filename, data, sudo=False, uid=None, **kwargs):
94+
if sudo:
95+
return f"sudo -u \#{uid} echo {data} > {filename}"
96+
else:
97+
return "echo {data} > {filename}".format(
98+
filename=filename, data=data
99+
)
95100

96101
@staticmethod
97102
def get_ip_of_hostname(**kwargs):
@@ -196,11 +201,14 @@ def cat(path, sudo=False, uid=None, **kwargs):
196201
return "cat {path}".format(path=path)
197202

198203
@staticmethod
199-
def df(mount_path, **kwargs):
200-
return "df -h {mount_path}".format(mount_path=mount_path)
204+
def df(path, sudo=False, uid=None, **kwargs):
205+
if sudo:
206+
return f"sudo -u \#{uid} df -h {path}"
207+
else:
208+
return f"df -h {path}"
201209

202210
@staticmethod
203-
def mount(**kwargs):
211+
def mount(sudo=False, uid=None, **kwargs):
204212
return "mount"
205213

206214
@staticmethod
@@ -211,15 +219,21 @@ def resolve_name(hostname, **kwargs):
211219
)
212220

213221
@staticmethod
214-
def du(mount_path: str, **kwargs) -> str:
222+
def du(mount_path: str, sudo=False, uid=None, **kwargs) -> str:
215223
"""
216224
Returns command string to get size of dataset.
217225
218226
:param mount_path: The path whose size is to be calculated
219227
220228
:return: The du command string
221229
"""
222-
return f"du -s --block-size=1 --apparent-size {mount_path}"
230+
if sudo:
231+
return (
232+
f"sudo -u \#{uid} du -s --block-size=1 --apparent-size "
233+
f"{mount_path}"
234+
)
235+
else:
236+
return f"du -s --block-size=1 --apparent-size {mount_path}"
223237

224238

225239
class DatabaseCommand(object):

src/operations/linked.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
2+
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
33
#
44
#############################################################################
55
# In this module, all dSource related operations are implemented
@@ -229,7 +229,7 @@ def _cleanup_in_exception_case(rx_connection, is_sync, is_snap_sync):
229229
raise
230230

231231

232-
def source_size(source_obj: StagedSource):
232+
def source_size(source_obj: StagedSource, repository, source_config):
233233
"""
234234
Returns space occupied by the dataset on the mount point in bytes.
235235
@@ -244,13 +244,18 @@ def source_size(source_obj: StagedSource):
244244
"Begin operation: Calculation of source"
245245
f" sizing for dSource {cluster_name}."
246246
)
247+
srcsize_obj = CouchbaseOperation(
248+
Resource.ObjectBuilder.set_staged_source(source_obj)
249+
.set_repository(repository)
250+
.build()
251+
)
247252
try:
248253
if not helper_lib.check_stale_mountpoint(
249254
connection=connection, path=mount_path
250255
) and helper_lib.check_server_is_used(
251256
connection=connection, path=mount_path
252257
):
253-
db_size_output = helper_lib.get_db_size(connection, mount_path)
258+
db_size_output = srcsize_obj.get_db_size(path=mount_path)
254259
if db_size_output:
255260
db_size = int(db_size_output.split()[0])
256261
logger.debug(
@@ -267,8 +272,3 @@ def source_size(source_obj: StagedSource):
267272
except Exception as error:
268273
logger.debug("Exception: {}".format(str(error)))
269274
raise
270-
finally:
271-
logger.info(
272-
"End operation: Calculation of source"
273-
f" sizing for dSource {cluster_name} couldn't be completed."
274-
)

src/plugin_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2020-2023 by Delphix. All rights reserved.
2+
# Copyright (c) 2020-2024 by Delphix. All rights reserved.
33
#
44
#
55

@@ -298,4 +298,4 @@ def add_node_to_virtual1(old_virtual_source):
298298

299299
@plugin.linked.source_size()
300300
def linked_source_size(staged_source, repository, source_config):
301-
return linked.source_size(staged_source)
301+
return linked.source_size(staged_source, repository, source_config)

0 commit comments

Comments
 (0)