mirror of
https://github.com/projectatomic/atomic.git
synced 2026-02-05 18:45:01 +01:00
Add support for modifying /etc/sysconfig/docker-storage-setup
atomic modify can be used to add devices to the storage backend. It can also be used to switch the backend storage driver. Closes: #385 Approved by: rhatdan
This commit is contained in:
@@ -20,6 +20,9 @@ except ImportError:
|
||||
from atomic import Atomic
|
||||
|
||||
class Storage(Atomic):
|
||||
dss_conf = "/etc/sysconfig/docker-storage-setup"
|
||||
dss_conf_bak = dss_conf + ".bkp"
|
||||
|
||||
def reset(self):
|
||||
root = "/var/lib/docker"
|
||||
try:
|
||||
@@ -38,6 +41,33 @@ class Storage(Atomic):
|
||||
except:
|
||||
selinux.restorecon(root)
|
||||
|
||||
def modify(self):
|
||||
try:
|
||||
shutil.copyfile(self.dss_conf, self.dss_conf_bak)
|
||||
if len(self.args.devices) > 0:
|
||||
self._add_device(self.args.devices)
|
||||
if self.args.driver:
|
||||
self._driver(self.args.driver)
|
||||
if util.call(["docker-storage-setup"]) != 0:
|
||||
os.rename(self.dss_conf_bak, self.dss_conf)
|
||||
util.call(["docker-storage-setup"])
|
||||
raise ValueError("docker-storage-setup failed")
|
||||
except:
|
||||
if os.path.exists(self.dss_conf_bak):
|
||||
os.rename(self.dss_conf_bak, self.dss_conf)
|
||||
raise
|
||||
finally:
|
||||
if os.path.exists(self.dss_conf_bak):
|
||||
os.remove(self.dss_conf_bak)
|
||||
|
||||
def _add_device(self, devices):
|
||||
util.sh_modify_var_in_file(self.dss_conf, "DEVS",
|
||||
lambda old: util.sh_set_add(old, devices))
|
||||
|
||||
def _driver(self, driver):
|
||||
util.sh_modify_var_in_file(self.dss_conf, "STORAGE_DRIVER",
|
||||
lambda old: driver)
|
||||
|
||||
def Export(self):
|
||||
try:
|
||||
export_docker(self.args.graph, self.args.export_location, self.force)
|
||||
|
||||
9
atomic
9
atomic
@@ -494,6 +494,15 @@ def create_parser(atomic):
|
||||
importp.add_argument("--dir", dest="import_location",
|
||||
default="/var/lib/atomic/migrate",
|
||||
help=_("Path for importing container's content (Default: /var/lib/atomic/migrate)"))
|
||||
|
||||
# atomic storage modify
|
||||
modifyp = storage_subparser.add_parser("modify",help='modify default storage setup')
|
||||
modifyp.add_argument('--add-device', dest="devices", default=[], nargs='?',
|
||||
action='append',
|
||||
help=_("add block devices to storage pool"))
|
||||
modifyp.add_argument('--driver', dest="driver", default=None, help='The storage backend driver', choices=['devicemapper', 'overlay'])
|
||||
modifyp.set_defaults(_class=Storage, func='modify')
|
||||
|
||||
# atomic storage reset
|
||||
resetp = storage_subparser.add_parser("reset",
|
||||
help=_("delete all containers/images from your system. Reset storage to its initial configuration."))
|
||||
|
||||
80
bash/atomic
80
bash/atomic
@@ -29,6 +29,9 @@
|
||||
# This order should be applied to lists, alternatives and code blocks.
|
||||
|
||||
|
||||
__atomic_previous_extglob_setting=$(shopt -p extglob)
|
||||
shopt -s extglob
|
||||
|
||||
__docker_q() {
|
||||
docker=$(awk -F ": " '/^default_docker/ {print $2}' /etc/atomic.conf 2>/dev/null || echo docker)
|
||||
docker 2>/dev/null "$@"
|
||||
@@ -167,6 +170,36 @@ _atomic_info() {
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Subcommand processing.
|
||||
# Locates the first occurrence of any of the subcommands contained in the
|
||||
# first argument. In case of a match, calls the corresponding completion
|
||||
# function and returns 0.
|
||||
# If no match is found, 1 is returned. The calling function can then
|
||||
# continue processing its completion.
|
||||
#
|
||||
# TODO if the preceding command has options that accept arguments and an
|
||||
# argument is equal ot one of the subcommands, this is falsely detected as
|
||||
# a match.
|
||||
__atomic_subcommands() {
|
||||
local subcommands="$1"
|
||||
|
||||
local counter=$(($command_pos + 1))
|
||||
while [ $counter -lt $cword ]; do
|
||||
case "${words[$counter]}" in
|
||||
$(__atomic_to_extglob "$subcommands") )
|
||||
subcommand_pos=$counter
|
||||
local subcommand=${words[$counter]}
|
||||
local completions_func=_atomic_${command}_${subcommand}
|
||||
declare -F $completions_func >/dev/null && $completions_func
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
(( counter++ ))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
_atomic_scan() {
|
||||
local options_with_args="
|
||||
--fetch_cves
|
||||
@@ -601,18 +634,57 @@ _atomic_host() {
|
||||
}
|
||||
|
||||
_atomic_storage() {
|
||||
local commands=(
|
||||
local subcommands="
|
||||
export
|
||||
import
|
||||
reset
|
||||
)
|
||||
modify
|
||||
"
|
||||
|
||||
local completions_func=_atomic_storage_${prev}
|
||||
declare -F $completions_func >/dev/null && $completions_func
|
||||
__atomic_subcommands "$subcommands" && return
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
_atomic_storage_modify() {
|
||||
local options_with_args="
|
||||
--driver
|
||||
--add-device
|
||||
"
|
||||
local all_options="$options_with_args
|
||||
--help
|
||||
-h
|
||||
"
|
||||
|
||||
local options_with_args_glob=$(__atomic_to_extglob "$options_with_args")
|
||||
|
||||
case "$prev" in
|
||||
--add-device)
|
||||
COMPREPLY=( $( compgen -f "/dev/" ) )
|
||||
return 0
|
||||
;;
|
||||
|
||||
--driver)
|
||||
COMPREPLY=( $( compgen -W "devicemapper overlay" -- "$cur" ) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_atomic_storage_storage() {
|
||||
local boolean_options="
|
||||
--help -h
|
||||
|
||||
@@ -19,28 +19,31 @@ and then import all their old data to the new system.
|
||||
**export**
|
||||
|
||||
export command will export all the current images, volumes, and containers
|
||||
to the specified directory (/var/lib/atomic/migrate by default), in the /images,
|
||||
to the specified directory (/var/lib/atomic/migrate by default), in the /images,
|
||||
/volumes, /containers subdirectories.
|
||||
|
||||
**import**
|
||||
|
||||
import command will import images, volumes, and containers from the specified
|
||||
import command will import images, volumes, and containers from the specified
|
||||
directory (/var/lib/atomic/migrate by default) into the new atomic instance.
|
||||
|
||||
**reset**
|
||||
Remove all containers/images from your system
|
||||
|
||||
**modify**
|
||||
Modify the default storage setup
|
||||
|
||||
# export OPTIONS
|
||||
**-h** **--help**
|
||||
Print usage statement
|
||||
|
||||
**--graph**
|
||||
Root of the docker runtime. If you are running docker at the default
|
||||
location (/var/lib/docker), you don't need to pass this flag. However
|
||||
Root of the docker runtime. If you are running docker at the default
|
||||
location (/var/lib/docker), you don't need to pass this flag. However
|
||||
if you are running docker at a custom location. This flag must be set.
|
||||
|
||||
**--dir**
|
||||
Directory in which to temporarily store the files (can be an existing
|
||||
Directory in which to temporarily store the files (can be an existing
|
||||
directory, or the command will create one). If no directory is specified,
|
||||
/var/lib/atomic/migrate would be used as default.
|
||||
|
||||
@@ -57,10 +60,22 @@ location (/var/lib/docker), you don't need to pass this flag. However
|
||||
if you are running docker at a custom location. This flag must be set.
|
||||
|
||||
**--dir**
|
||||
Directory from which to import the files (images, containers and volumes).
|
||||
If this flag is not set atomic storage will assume the import location to
|
||||
be /var/lib/atomic/migrate. Whether you set this flag or use the default,
|
||||
Directory from which to import the files (images, containers and volumes).
|
||||
If this flag is not set atomic storage will assume the import location to
|
||||
be /var/lib/atomic/migrate. Whether you set this flag or use the default,
|
||||
the directory must be present for the import to happen successfully.
|
||||
|
||||
# modify OPTIONS
|
||||
**-h** **--help**
|
||||
Print usage statement
|
||||
|
||||
**--add-device**
|
||||
Add block devices to storage pool. This command will expand your devicemapper
|
||||
storage pool by adding the block device. Only works with devicemapper driver.
|
||||
|
||||
**--driver**
|
||||
Backend storage driver for containers. This options the storage driver.
|
||||
Drivers supported: devicemapper, overlay
|
||||
|
||||
# HISTORY
|
||||
October 2015, Originally compiled by Shishir Mahajan (shishir dot mahajan at redhat dot com)
|
||||
|
||||
@@ -6,7 +6,7 @@ atomic \- Atomic Management Tool
|
||||
|
||||
# SYNOPSIS
|
||||
**atomic** [OPTIONS] COMMAND [arg...]
|
||||
{diff,host,images,info,install,mount,run,scan,stop,uninstall,unmount,update,upload,verify,version}
|
||||
{diff,host,images,info,install,mount,run,scan,stop,storage,uninstall,unmount,update,upload,verify,version}
|
||||
[**-h**|**-help**]
|
||||
|
||||
# DESCRIPTION
|
||||
@@ -51,6 +51,9 @@ execute image run method (default)
|
||||
**atomic-scan(1)**
|
||||
scan an image or container for CVEs
|
||||
|
||||
**atomic-storage(1)**
|
||||
manage the container storage on the system
|
||||
|
||||
**atomic-stop(1)**
|
||||
execute container image stop method
|
||||
|
||||
|
||||
70
tests/integration/test_storage.sh
Executable file
70
tests/integration/test_storage.sh
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/bin/bash -x
|
||||
set -euo pipefail
|
||||
|
||||
# Test scripts run with PWD=tests/..
|
||||
|
||||
# The test harness exports some variables into the environment during
|
||||
# testing: PYTHONPATH (python module import path
|
||||
# WORK_DIR (a directory that is safe to modify)
|
||||
# DOCKER (the docker executable location)
|
||||
# ATOMIC (an invocation of 'atomic' which measures code coverage)
|
||||
# SECRET (a generated sha256 hash inserted into test containers)
|
||||
|
||||
# In addition, the test harness creates some images for use in testing.
|
||||
# See tests/test-images/
|
||||
|
||||
# This can copy non-existing files
|
||||
#
|
||||
smarter_copy() {
|
||||
if [ -f "$1" ]; then
|
||||
cp "$1" "$2"
|
||||
else
|
||||
rm -f "$2"
|
||||
fi
|
||||
}
|
||||
|
||||
setup () {
|
||||
# Perform setup routines here.
|
||||
smarter_copy /etc/sysconfig/docker-storage-setup /etc/sysconfig/docker-storage-setup.atomic-tests-backup
|
||||
dd if=/dev/zero of=${WORK_DIR}/img-1 bs=1M count=10
|
||||
TEST_DEV_1=$(losetup --show -f -P ${WORK_DIR}/img-1)
|
||||
TEST_DEV_1_pvs=${TEST_DEV_1}p1
|
||||
|
||||
ROOT_DEV=$( awk '$2 ~ /^\/$/ && $1 !~ /rootfs/ { print $1 }' /proc/mounts )
|
||||
VGROUP=$(lvs --noheadings -o vg_name ${ROOT_DEV} || true)
|
||||
}
|
||||
|
||||
teardown () {
|
||||
# Cleanup your test data.
|
||||
set -e
|
||||
[ -n "$VGROUP" ] && vgreduce $VGROUP "$TEST_DEV_1_pvs"
|
||||
losetup -d "$TEST_DEV_1"
|
||||
smarter_copy /etc/sysconfig/docker-storage-setup.atomic-tests-backup /etc/sysconfig/docker-storage-setup
|
||||
}
|
||||
|
||||
trap teardown EXIT
|
||||
setup
|
||||
|
||||
# Running without /e/s/d-s-s should fail.
|
||||
|
||||
set +e
|
||||
rm -f /etc/sysconfig/docker-storage-setup
|
||||
OUTPUT=$(${ATOMIC} storage modify --add-device $TEST_DEV_1 2>&1)
|
||||
if [[ $? -eq 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
set -e
|
||||
echo $OUTPUT | grep -q "No such file or directory"
|
||||
|
||||
# Adding a device should put it into the volume group and should add
|
||||
# it to /e/s/d-s-s.
|
||||
|
||||
if [ -n "$VGROUP" ]; then
|
||||
echo >/etc/sysconfig/docker-storage-setup <<EOF
|
||||
MIN_DATA_SIZE=0G
|
||||
DEVS=""
|
||||
EOF
|
||||
${ATOMIC} storage modify --add-device $TEST_DEV_1
|
||||
[ $(pvs --noheadings -o vg_name $TEST_DEV_1_pvs) == $VGROUP ]
|
||||
grep -q "^DEVS=\"$TEST_DEV_1\"$" /etc/sysconfig/docker-storage-setup
|
||||
fi
|
||||
Reference in New Issue
Block a user