Skip to content

Instantly share code, notes, and snippets.

@larsks

larsks/cftest.py Secret

Last active March 12, 2019 15:15
Show Gist options
  • Save larsks/a559e121a818290b36872cbc4151e411 to your computer and use it in GitHub Desktop.
Save larsks/a559e121a818290b36872cbc4151e411 to your computer and use it in GitHub Desktop.
import os
import subprocess
import sys
from oslo_log import log
from oslo_config import cfg
LOG = log.getLogger(__name__)
CONF = cfg.CONF
options = [
cfg.BoolOpt('test-option', default=False)
]
def main():
CONF.register_cli_opts(options, group='test')
CONF(sys.argv[1:])
if CONF.test.test_option:
print('test-option was set')
else:
print('test-option was not set')
if __name__ == '__main__':
sys.exit(main())
#!/bin/sh
assert_equals() {
if [[ $1 != $2 ]]; then
echo "FAILED: \"$1\" != \"$2\""
exit 1
fi
}
cat > test.conf <<EOF
[test]
test_option = true
EOF
assert_equals "$(python cftest.py)" "test-option was not set"
assert_equals "$(python cftest.py --test-test-option)" "test-option was set"
assert_equals "$(python cftest.py --config-file test.conf)" "test-option was set"
assert_equals "$(python cftest.py --config-file test.conf --test-notest-option)" "test-option was not set"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment