Skip to content

Commit 511c407

Browse files
committed
more fixes
1 parent b5a0ced commit 511c407

3 files changed

Lines changed: 92 additions & 37 deletions

File tree

extensions/network-namespace/network-namespace-wrapper.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,20 @@
7878

7979
set -e
8080

81-
LOG_FILE="/var/log/cloudstack/network-namespace.log"
82-
STATE_DIR="/var/lib/cloudstack/network-namespace"
81+
# ---------------------------------------------------------------------------
82+
# Derive log path from this wrapper's own directory name so that each
83+
# renamed deployment writes to its own log file.
84+
# /etc/cloudstack/extensions/<name>/<name>-wrapper.sh
85+
# → /var/log/cloudstack/extensions/<name>/<name>.log
86+
# ---------------------------------------------------------------------------
87+
_WRAPPER_SELF="$(readlink -f "$0" 2>/dev/null \
88+
|| realpath "$0" 2>/dev/null \
89+
|| echo "$0")"
90+
_WRAPPER_EXT_DIR="$(basename "$(dirname "${_WRAPPER_SELF}")")"
91+
LOG_FILE="/var/log/cloudstack/extensions/${_WRAPPER_EXT_DIR}/${_WRAPPER_EXT_DIR}.log"
92+
mkdir -p "$(dirname "${LOG_FILE}")" 2>/dev/null || true
93+
94+
STATE_DIR="/var/lib/cloudstack/${_WRAPPER_EXT_DIR}"
8395

8496
# ---------------------------------------------------------------------------
8597
# JSON helpers (no jq dependency)

extensions/network-namespace/network-namespace.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,33 @@ DEFAULT_SSH_PORT=22
7979
DEFAULT_SSH_USER=root
8080

8181
# ---------------------------------------------------------------------------
82-
# The KVM wrapper script is deployed to the **same path** as this entry-point
83-
# on the management server. Resolve $0 to an absolute path so that the
84-
# remote SSH call uses the correct location regardless of how this script was
85-
# invoked (relative path, symlink, etc.).
82+
# Resolve this entry-point's absolute path so we can derive both the KVM
83+
# wrapper path and the log file name from the extension directory name.
84+
#
85+
# Layout:
86+
# management server: /usr/share/cloudstack-management/extensions/<name>/<name>.sh
87+
# KVM host (wrapper): /etc/cloudstack/extensions/<name>/<name>-wrapper.sh
88+
#
89+
# _EXT_DIR_NAME is the basename of the directory containing this script,
90+
# which equals the extension name assigned by CloudStack (e.g.
91+
# "extnet-isolated-gk3yys"). Both the wrapper path and the log file are
92+
# derived from it so that renamed deployments work automatically.
8693
#
8794
# Callers may still override the remote path via CS_NET_SCRIPT_PATH:
8895
# CS_NET_SCRIPT_PATH=/custom/path/wrapper.sh network-namespace.sh <cmd> ...
8996
# ---------------------------------------------------------------------------
9097
_SELF="$(readlink -f "$0" 2>/dev/null \
9198
|| realpath "$0" 2>/dev/null \
9299
|| echo "$0")"
93-
DEFAULT_SCRIPT_PATH="${_SELF}"
94-
95-
# Derive the log file name from this script's own basename so that a renamed
96-
# deployment (e.g. "my-extension.sh") writes to its own log file instead of
97-
# a hardcoded "network-namespace.log".
98100
_SCRIPT_BASENAME="$(basename "${_SELF}" .sh)"
99-
LOG_FILE="/var/log/cloudstack/management/${_SCRIPT_BASENAME}.log"
101+
_EXT_DIR_NAME="$(basename "$(dirname "${_SELF}")")"
102+
103+
# Remote wrapper path on each KVM host.
104+
DEFAULT_SCRIPT_PATH="/etc/cloudstack/extensions/${_EXT_DIR_NAME}/${_SCRIPT_BASENAME}-wrapper.sh"
105+
106+
# Log file — under /var/log/cloudstack/extensions/ named after the extension.
107+
LOG_FILE="/var/log/cloudstack/extensions/${_EXT_DIR_NAME}.log"
108+
mkdir -p "$(dirname "${LOG_FILE}")" 2>/dev/null || true
100109
TMPDIR_BASE=/tmp
101110

102111
# ---------------------------------------------------------------------------

test/integration/smoke/test_network_extension_namespace.py

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@
7070

7171
_multiprocess_shared_ = True
7272

73-
# Directory on KVM agents where network-namespace scripts are installed
74-
EXTENSIONS_DIR = '/etc/cloudstack/extensions/network-namespace'
73+
# Base directory on KVM agents where wrapper scripts are installed.
74+
# The actual per-extension subdirectory is derived at runtime from the
75+
# extension name: /etc/cloudstack/extensions/<ext-name>/
76+
EXTENSIONS_BASE_DIR = '/etc/cloudstack/extensions'
7577
SCRIPT_FILENAME = 'network-namespace-wrapper.sh'
7678
ENTRY_POINT_FILENAME = 'network-namespace.sh'
7779

@@ -306,9 +308,10 @@ class KvmHostDeployer:
306308
"""Copies the KVM wrapper script to all KVM hosts via SSH.
307309
308310
*dest_path* is the absolute path on each KVM host where the wrapper
309-
script is installed. It must be identical to the management-server
310-
extension path so that both the entry-point and the wrapper share the
311-
same directory and filename on their respective machines.
311+
script is installed. This path differs from the management-server
312+
entry-point path:
313+
management server: /usr/share/cloudstack-management/extensions/<name>/<name>.sh
314+
KVM host (wrapper): /etc/cloudstack/extensions/<name>/<name>-wrapper.sh
312315
"""
313316

314317
def __init__(self, config_hosts=None, logger=None, dest_path=None):
@@ -459,6 +462,7 @@ def setUp(self):
459462
self.extension_path = None
460463
self.mgmt_deployer = None
461464
self._mgmt_script_path = None
465+
self._all_mgmt_deployers = []
462466
self.kvm_deployer = None
463467
self._ssh_private_key_file = None
464468

@@ -520,40 +524,70 @@ def _delete_provider(self, provider_id):
520524
# ------------------------------------------------------------------
521525

522526
def _deploy_scripts(self):
523-
"""Deploy scripts to management server and all KVM hosts.
524-
525-
Both the entry-point (network-namespace.sh) and the KVM wrapper
526-
(network-namespace-wrapper.sh) are deployed to the **same path**:
527-
``self.extension_path``. The management server receives the
528-
entry-point script; each KVM host receives the wrapper script — both
529-
under the same directory and filename so that the entry-point can call
530-
the wrapper via its own ``$0`` path without any hard-coded name.
527+
"""Deploy scripts to all management servers and all KVM hosts.
528+
529+
The entry-point (network-namespace.sh) is deployed to every management
530+
server at ``self.extension_path`` (the path CloudStack assigned to the
531+
extension, e.g.
532+
``/usr/share/cloudstack-management/extensions/<name>/<name>.sh``).
533+
534+
The KVM wrapper (network-namespace-wrapper.sh) is deployed to each KVM
535+
host at a *different* path derived from the extension name:
536+
``/etc/cloudstack/extensions/<name>/<name>-wrapper.sh``
537+
538+
The entry-point script uses the same derivation at runtime (see
539+
DEFAULT_SCRIPT_PATH in network-namespace.sh) so that it always calls
540+
the correct wrapper on the remote KVM host.
531541
"""
532542
wrapper_src, entry_point_src = _ensure_scripts_downloaded()
533543

534-
self.mgmt_deployer = MgmtServerDeployer(self.mgtSvrDetails,
535-
logger=self.logger)
536544
self._mgmt_script_path = (self.extension_path or "").strip().rstrip('/')
537-
self.mgmt_deployer.copy_file(entry_point_src, self._mgmt_script_path)
538-
self.logger.info("Entry-point script deployed to mgmt at %s",
539-
self._mgmt_script_path)
540545

541-
# Deploy the wrapper to KVM hosts at the SAME path as the management
542-
# server entry-point so that both scripts share the same directory and
543-
# filename on their respective hosts.
546+
# Deploy entry-point to ALL management servers
547+
all_mgt_svrs = self.config.__dict__.get("mgtSvr", [])
548+
self._all_mgmt_deployers = []
549+
for mgt in all_mgt_svrs:
550+
mgt_details = mgt.__dict__ if hasattr(mgt, '__dict__') else mgt
551+
deployer = MgmtServerDeployer(mgt_details, logger=self.logger)
552+
deployer.copy_file(entry_point_src, self._mgmt_script_path)
553+
self.logger.info("Entry-point deployed to mgmt %s at %s",
554+
mgt_details.get("mgtSvrIp", "?"),
555+
self._mgmt_script_path)
556+
self._all_mgmt_deployers.append(deployer)
557+
558+
# Keep mgmt_deployer pointing at the primary server for backward-compat
559+
self.mgmt_deployer = (self._all_mgmt_deployers[0]
560+
if self._all_mgmt_deployers
561+
else MgmtServerDeployer(self.mgtSvrDetails,
562+
logger=self.logger))
563+
564+
# Derive the wrapper destination path on KVM hosts from the extension path:
565+
# mgmt: .../extensions/<name>/<name>.sh
566+
# kvm: /etc/cloudstack/extensions/<name>/<name>-wrapper.sh
567+
ext_dir_name = os.path.basename(os.path.dirname(self._mgmt_script_path))
568+
script_basename = os.path.splitext(
569+
os.path.basename(self._mgmt_script_path))[0]
570+
kvm_wrapper_path = "/etc/cloudstack/extensions/%s/%s-wrapper.sh" % (
571+
ext_dir_name, script_basename)
572+
544573
self.kvm_deployer = KvmHostDeployer(
545574
config_hosts=self.kvm_host_configs,
546575
logger=self.logger,
547-
dest_path=self._mgmt_script_path,
576+
dest_path=kvm_wrapper_path,
548577
)
549578
deployed = self.kvm_deployer.deploy()
550579
self.logger.info(
551580
"KVM wrapper deployed to %d host(s) at %s: %s",
552-
len(deployed), self._mgmt_script_path, deployed)
581+
len(deployed), kvm_wrapper_path, deployed)
553582

554583
def _cleanup_mgmt_script(self):
555-
if self.mgmt_deployer and self._mgmt_script_path:
556-
self.mgmt_deployer.remove_file(self._mgmt_script_path)
584+
if self._mgmt_script_path:
585+
all_deployers = getattr(self, '_all_mgmt_deployers', None) or []
586+
if all_deployers:
587+
for deployer in all_deployers:
588+
deployer.remove_file(self._mgmt_script_path)
589+
elif self.mgmt_deployer:
590+
self.mgmt_deployer.remove_file(self._mgmt_script_path)
557591
self._mgmt_script_path = None
558592

559593
# ------------------------------------------------------------------

0 commit comments

Comments
 (0)