Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kolla Ansible
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Very Demiurge Very Mindful
Kolla Ansible
Commits
a1e3daf5
Commit
a1e3daf5
authored
9 years ago
by
Martin André
Browse files
Options
Downloads
Patches
Plain Diff
Use c-style string interpolation for log messages
TrivialFix Change-Id: I7ddebc7b6f71e50254801324fa2bf093fdaa8ce0
parent
735deace
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docker/base/set_configs.py
+18
-21
18 additions, 21 deletions
docker/base/set_configs.py
with
18 additions
and
21 deletions
docker/base/set_configs.py
+
18
−
21
View file @
a1e3daf5
...
...
@@ -44,7 +44,7 @@ def validate_config(config):
# required. 'owner' and 'perm' should user system defaults if not
# specified
if
not
data
.
viewkeys
()
>=
required_keys
:
LOG
.
error
(
'
Config is missing required keys:
{}
'
.
format
(
data
)
)
LOG
.
error
(
"
Config is missing required keys:
%s
"
,
data
)
sys
.
exit
(
1
)
...
...
@@ -59,10 +59,10 @@ def validate_source(data):
if
not
exists
:
if
data
.
get
(
'
optional
'
):
LOG
.
warn
(
'
{}
does not exist, but is not required
'
.
format
(
source
)
)
LOG
.
warn
(
"
%s
does not exist, but is not required
"
,
source
)
return
False
else
:
LOG
.
error
(
'
The source to copy does not exist:
{}
'
.
format
(
source
)
)
LOG
.
error
(
"
The source to copy does not exist:
%s
"
,
source
)
sys
.
exit
(
1
)
return
True
...
...
@@ -107,11 +107,10 @@ def zk_copy_tree(zk, src, dest):
if
data
:
dest_path
=
os
.
path
.
dirname
(
dest
)
if
not
os
.
path
.
exists
(
dest_path
):
LOG
.
info
(
'
Creating dest parent directory: {}
'
.
format
(
dest_path
))
LOG
.
info
(
"
Creating dest parent directory: %s
"
,
dest_path
)
os
.
makedirs
(
dest_path
)
LOG
.
info
(
'
Copying
{}
to
{}
'
.
format
(
src
,
dest
)
)
LOG
.
info
(
"
Copying
%s
to
%s
"
,
src
,
dest
)
with
open
(
dest
,
'
w
'
)
as
df
:
df
.
write
(
data
.
decode
(
"
utf-8
"
))
...
...
@@ -129,7 +128,7 @@ def copy_files(data):
source
=
data
.
get
(
'
source
'
)
if
os
.
path
.
exists
(
dest
):
LOG
.
info
(
'
Removing existing destination:
{}
'
.
format
(
dest
)
)
LOG
.
info
(
"
Removing existing destination:
%s
"
,
dest
)
if
os
.
path
.
isdir
(
dest
):
shutil
.
rmtree
(
dest
)
else
:
...
...
@@ -148,18 +147,18 @@ def copy_files(data):
dest_path
=
os
.
path
.
dirname
(
dest
)
if
not
os
.
path
.
exists
(
dest_path
):
LOG
.
info
(
'
Creating dest parent directory:
{}
'
.
format
(
dest_path
)
)
LOG
.
info
(
"
Creating dest parent directory:
%s
"
,
dest_path
)
os
.
makedirs
(
dest_path
)
if
source
!=
source_path
:
# Source is file
LOG
.
info
(
'
Copying
{}
to
{}
'
.
format
(
source
,
dest
)
)
LOG
.
info
(
"
Copying
%s
to
%s
"
,
source
,
dest
)
shutil
.
copy
(
source
,
dest
)
else
:
# Source is a directory
for
src
in
os
.
listdir
(
source_path
):
LOG
.
info
(
'
Copying
{}
to
{}
'
.
format
(
os
.
path
.
join
(
source_path
,
src
),
dest_path
)
)
LOG
.
info
(
"
Copying
%s
to
%s
"
,
os
.
path
.
join
(
source_path
,
src
),
dest_path
)
if
os
.
path
.
isdir
(
src
):
shutil
.
copytree
(
os
.
path
.
join
(
source_path
,
src
),
dest_path
)
...
...
@@ -169,14 +168,13 @@ def copy_files(data):
def
set_permissions
(
data
):
def
set_perms
(
file_
,
uid
,
guid
,
perm
):
LOG
.
info
(
'
Setting permissions for
{}
'
.
format
(
file_
)
)
LOG
.
info
(
"
Setting permissions for
%s
"
,
file_
)
# Give config file proper perms.
try
:
os
.
chown
(
file_
,
uid
,
gid
)
os
.
chmod
(
file_
,
perm
)
except
OSError
as
e
:
LOG
.
error
(
'
Error while setting permissions for {}: {}
'
.
format
(
file_
,
e
))
LOG
.
error
(
"
Error while setting permissions for %s: %r
"
,
file_
,
e
)
sys
.
exit
(
1
)
dest
=
data
.
get
(
'
dest
'
)
...
...
@@ -187,7 +185,7 @@ def set_permissions(data):
try
:
user
=
getpwnam
(
owner
)
except
KeyError
:
LOG
.
error
(
'
The specified user does not exist:
{}
'
.
format
(
owner
)
)
LOG
.
error
(
"
The specified user does not exist:
%s
"
,
owner
)
sys
.
exit
(
1
)
uid
=
user
.
pw_uid
...
...
@@ -219,18 +217,17 @@ def load_config():
def
load_from_file
():
config_file
=
'
/var/lib/kolla/config_files/config.json
'
LOG
.
info
(
'
Loading config file at
{}
'
.
format
(
config_file
)
)
LOG
.
info
(
"
Loading config file at
%s
"
,
config_file
)
# Attempt to read config file
with
open
(
config_file
)
as
f
:
try
:
return
json
.
load
(
f
)
except
ValueError
:
LOG
.
error
(
'
Invalid json file found at
{}
'
.
format
(
config_file
)
)
LOG
.
error
(
"
Invalid json file found at
%s
"
,
config_file
)
sys
.
exit
(
1
)
except
IOError
as
e
:
LOG
.
error
(
'
Could not read file {}. Failed with error {}
'
.
format
(
config_file
,
e
))
LOG
.
error
(
"
Could not read file %s: %r
"
,
config_file
,
e
)
sys
.
exit
(
1
)
config
=
load_from_env
()
...
...
@@ -250,7 +247,7 @@ def load_config():
LOG
.
debug
(
'
No files to copy found in config
'
)
LOG
.
info
(
'
Writing out command to execute
'
)
LOG
.
debug
(
'
Command is:
{}
'
.
format
(
config
[
'
command
'
])
)
LOG
.
debug
(
"
Command is:
%s
"
,
config
[
'
command
'
])
# The value from the 'command' key will be written to '/run_command'
with
open
(
'
/run_command
'
,
'
w+
'
)
as
f
:
f
.
write
(
config
[
'
command
'
])
...
...
@@ -258,7 +255,7 @@ def load_config():
def
execute_config_strategy
():
config_strategy
=
os
.
environ
.
get
(
"
KOLLA_CONFIG_STRATEGY
"
)
LOG
.
info
(
'
Kolla config strategy set to:
{}
'
.
format
(
config_strategy
)
)
LOG
.
info
(
"
Kolla config strategy set to:
%s
"
,
config_strategy
)
if
config_strategy
==
"
COPY_ALWAYS
"
:
load_config
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment