Skip to content

Commit

Permalink
Merge pull request #4176 from jestabro/vyconf-minimal
Browse files Browse the repository at this point in the history
T6718: use the vyconf daemon for validation of set commands
  • Loading branch information
jestabro authored Dec 13, 2024
2 parents 4221687 + 6999f85 commit 6a7766e
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ python/vyos/xml_ref/cache.py
python/vyos/xml_ref/pkg_cache/*_cache.py
python/vyos/xml_ref/op_cache.py
python/vyos/xml_ref/pkg_cache/*_op_cache.py
data/reftree.cache
# autogenerated vyos-configd JSON definition
data/configd-include.json

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface_definitions: $(config_xml_obj)

find $(BUILD_DIR)/interface-definitions -type f -name "*.xml" | xargs -I {} $(CURDIR)/scripts/build-command-templates {} $(CURDIR)/schema/interface_definition.rng $(TMPL_DIR) || exit 1

$(CURDIR)/python/vyos/xml_ref/generate_cache.py --xml-dir $(BUILD_DIR)/interface-definitions || exit 1
$(CURDIR)/python/vyos/xml_ref/generate_cache.py --xml-dir $(BUILD_DIR)/interface-definitions --internal-cache $(DATA_DIR)/reftree.cache || exit 1

# XXX: delete top level node.def's that now live in other packages
# IPSec VPN EAP-RADIUS does not support source-address
Expand Down
3 changes: 3 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ VYOS_CFG_TMPL_DIR := opt/vyatta/share/vyatta-cfg/templates
VYOS_OP_TMPL_DIR := opt/vyatta/share/vyatta-op/templates
VYOS_MIBS_DIR := usr/share/snmp/mibs
VYOS_LOCALUI_DIR := srv/localui
VYCONF_CONFIG_DIR := $(VYOS_LIBEXEC_DIR)/vyconf/config

MIGRATION_SCRIPTS_DIR := opt/vyatta/etc/config-migrate/migrate
ACTIVATION_SCRIPTS_DIR := usr/libexec/vyos/activate
Expand Down Expand Up @@ -89,6 +90,8 @@ override_dh_auto_install:
cp -r templates-op/* $(DIR)/$(VYOS_OP_TMPL_DIR)

# Install data files
mkdir -p $(DIR)/$(VYCONF_CONFIG_DIR)
cp -r data/reftree.cache $(DIR)/$(VYCONF_CONFIG_DIR)
mkdir -p $(DIR)/$(VYOS_DATA_DIR)
cp -r data/* $(DIR)/$(VYOS_DATA_DIR)

Expand Down
1 change: 1 addition & 0 deletions debian/vyos-1x.install
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ usr/libexec/vyos/op_mode
usr/libexec/vyos/services
usr/libexec/vyos/system
usr/libexec/vyos/validators
usr/libexec/vyos/vyconf
usr/libexec/vyos/*.py
usr/libexec/vyos/*.sh
usr/share
4 changes: 2 additions & 2 deletions python/vyos/configsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from vyos.utils.dict import dict_to_paths

CLI_SHELL_API = '/bin/cli-shell-api'
SET = '/opt/vyatta/sbin/my_set'
DELETE = '/opt/vyatta/sbin/my_delete'
SET = '/usr/libexec/vyos/vyconf/vy_set'
DELETE = '/usr/libexec/vyos/vyconf/vy_delete'
COMMENT = '/opt/vyatta/sbin/my_comment'
COMMIT = '/opt/vyatta/sbin/my_commit'
DISCARD = '/opt/vyatta/sbin/my_discard'
Expand Down
2 changes: 1 addition & 1 deletion python/vyos/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def install_into_config(conf, config_paths, override_prompt=True):
continue

try:
cmd(f'/opt/vyatta/sbin/my_set {path}')
cmd(f'/usr/libexec/vyos/vyconf/vy_set {path}')
count += 1
except:
failed.append(path)
Expand Down
6 changes: 5 additions & 1 deletion python/vyos/xml_ref/generate_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def main():
parser = ArgumentParser(description='generate and save dict from xml defintions')
parser.add_argument('--xml-dir', type=str, required=True,
help='transcluded xml interface-definition directory')
parser.add_argument('--internal-cache', type=str, required=True,
help='cache as unrendered json data for loading by vyconfd')
parser.add_argument('--package-name', type=non_trivial, default='vyos-1x',
help='name of current package')
parser.add_argument('--output-path', help='path to generated cache')
Expand All @@ -66,9 +68,11 @@ def main():
out_path = args['output_path']
path = out_path if out_path is not None else pkg_cache
xml_cache = abspath(join(path, cache_name))
internal_cache = args['internal_cache']

try:
reference_tree_to_json(xml_dir, xml_tmp)
reference_tree_to_json(xml_dir, xml_tmp,
internal_cache=internal_cache)
except ConfigTreeError as e:
print(e)
sys.exit(1)
Expand Down
14 changes: 14 additions & 0 deletions src/init/vyos-router
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ declare action=$1; shift
declare -x BOOTFILE=$vyatta_sysconfdir/config/config.boot
declare -x DEFAULT_BOOTFILE=$vyatta_sysconfdir/config.boot.default

declare -x VYCONF_CONFIG_DIR=/usr/libexec/vyos/vyconf/config

# If vyos-config= boot option is present, use that file instead
for x in $(cat /proc/cmdline); do
[[ $x = vyos-config=* ]] || continue
Expand Down Expand Up @@ -146,6 +148,10 @@ init_bootfile () {
chgrp ${GROUP} $BOOTFILE
chmod 660 $BOOTFILE
fi
if [ -d $VYCONF_CONFIG_DIR ] ; then
cp -f $BOOTFILE $VYCONF_CONFIG_DIR/config.boot
cp -f $DEFAULT_BOOTFILE $VYCONF_CONFIG_DIR/config.failsafe
fi
}

# if necessary, migrate initial config
Expand All @@ -154,6 +160,10 @@ migrate_bootfile ()
if [ -x $vyos_libexec_dir/run-config-migration.py ]; then
log_progress_msg migrate
sg ${GROUP} -c "$vyos_libexec_dir/run-config-migration.py $BOOTFILE"
# update vyconf copy after migration
if [ -d $VYCONF_CONFIG_DIR ] ; then
cp -f $BOOTFILE $VYCONF_CONFIG_DIR/config.boot
fi
fi
}

Expand Down Expand Up @@ -518,6 +528,8 @@ start ()

disabled system_config || system_config

systemctl start vyconfd.service

for s in ${subinit[@]} ; do
if ! disabled $s; then
log_progress_msg $s
Expand Down Expand Up @@ -560,6 +572,8 @@ stop()
umount ${vyatta_configdir}
log_action_end_msg $?

systemctl stop vyconfd.service

systemctl stop frr.service

unmount_encrypted_config
Expand Down
21 changes: 21 additions & 0 deletions src/systemd/vyconfd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Unit]
Description=VyOS vyconf daemon

# Without this option, lots of default dependencies are added,
# among them network.target, which creates a dependency cycle
DefaultDependencies=no

After=systemd-remount-fs.service

[Service]
ExecStart=/usr/libexec/vyos/vyconf/vyconfd --log-file /var/run/log/vyconfd.log
Type=exec
SyslogIdentifier=vyconfd
SyslogFacility=daemon
Restart=on-failure

User=root
Group=vyattacfg

[Install]
WantedBy=vyos.target

0 comments on commit 6a7766e

Please sign in to comment.