Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
flame-clmc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
flame
flame-clmc
Commits
de9f537e
Commit
de9f537e
authored
5 years ago
by
panos
Browse files
Options
Downloads
Patches
Plain Diff
improve script to exit early on failure
parent
20b571c1
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
scripts/test/fixture.sh
+27
-18
27 additions, 18 deletions
scripts/test/fixture.sh
with
27 additions
and
18 deletions
scripts/test/fixture.sh
+
27
−
18
View file @
de9f537e
...
@@ -28,6 +28,12 @@ repo_root="/vagrant"
...
@@ -28,6 +28,12 @@ repo_root="/vagrant"
target_root
=
"/opt/clmc"
target_root
=
"/opt/clmc"
config_file
=
"rspec.json"
config_file
=
"rspec.json"
# make sure UID is root
if
[
"
$EUID
"
-ne
0
]
;
then
echo
"please run as root (requires to change iptables)"
exit
fi
usage
()
{
usage
()
{
echo
"Usage:
$0
create|start|stop|destroy [-f config_file] [-r repo_root] [-c container_name|all]"
1>&2
echo
"Usage:
$0
create|start|stop|destroy [-f config_file] [-r repo_root] [-c container_name|all]"
1>&2
echo
" -f defaults to '
${
config_file
}
'"
1>&2
echo
" -f defaults to '
${
config_file
}
'"
1>&2
...
@@ -39,8 +45,8 @@ usage() {
...
@@ -39,8 +45,8 @@ usage() {
failed
()
{
failed
()
{
msg
=
$1
msg
=
$1
sn
=
$2
sn
=
$2
echo
"failed o
n
:
$msg
"
echo
"failed
t
o:
$msg
for service
$service_name
"
delete
_c
$sn
delete
$sn
exit
1
exit
1
}
}
...
@@ -55,26 +61,28 @@ create() {
...
@@ -55,26 +61,28 @@ create() {
echo
$SERVICE
echo
$SERVICE
ip
=
$(
echo
$SERVICE
| jq
-r
'.ip_address'
)
ip
=
$(
echo
$SERVICE
| jq
-r
'.ip_address'
)
lxc init ubuntu:16.04
${
service_name
}
||
return
lxc init ubuntu:16.04
${
service_name
}
||
failed
"crate lxc image"
${
service_name
}
echo
"Creating network:
${
service_name
}
"
echo
"Creating network:
${
service_name
}
"
lxc network attach lxcbr0
${
service_name
}
eth0
lxc network attach lxcbr0
${
service_name
}
eth0
||
failed
"attach lxcbr0"
${
service_name
}
lxc config device
set
${
service_name
}
eth0 ipv4.address
${
ip
}
lxc config device
set
${
service_name
}
eth0 ipv4.address
${
ip
}
||
failed
"config eth0"
${
service_name
}
lxc config
set
${
service_name
}
security.privileged
true
lxc config
set
${
service_name
}
security.privileged
true
||
failed
"config security"
${
service_name
}
# copy flame clmc files into the root container
# copy flame clmc files into the root container
echo
"Copying files to rootfs"
echo
"Copying files to rootfs"
container_dir
=
"/var/lib/lxd/containers/"
${
service_name
}
"/rootfs"
container_dir
=
"/var/lib/lxd/containers/"
${
service_name
}
"/rootfs"
container_repo_root
=
${
container_dir
}${
target_root
}
container_repo_root
=
${
container_dir
}${
target_root
}
mkdir
-p
${
container_repo_root
}
||
failed
"
to
create target directory"
${
service_name
}
mkdir
-p
${
container_repo_root
}
||
failed
"create target directory"
${
service_name
}
cp
-f
${
repo_root
}
/reporc
${
container_repo_root
}
||
failed
"
to
copy reporc"
${
service_name
}
cp
-f
${
repo_root
}
/reporc
${
container_repo_root
}
||
failed
"copy reporc"
${
service_name
}
cp
-rf
${
repo_root
}
/scripts
${
container_repo_root
}
||
failed
"
to
copy scripts"
${
service_name
}
cp
-rf
${
repo_root
}
/scripts
${
container_repo_root
}
||
failed
"copy scripts"
${
service_name
}
cp
-rf
${
repo_root
}
/src
${
container_repo_root
}
||
failed
"
to
copy src"
${
service_name
}
cp
-rf
${
repo_root
}
/src
${
container_repo_root
}
||
failed
"copy src"
${
service_name
}
chown
-R
100000:100000
${
container_repo_root
}
||
failed
"
to
change permissions"
${
service_name
}
chown
-R
100000:100000
${
container_repo_root
}
||
failed
"change permissions"
${
service_name
}
# start the container
# start the container
echo
"Starting:
${
service_name
}
"
echo
"Starting:
${
service_name
}
"
lxc start
${
service_name
}
lxc start
${
service_name
}
# add delay to avoid while-loop lxc command failing initially
sleep
1
while
:
;
do
while
:
;
do
echo
"Waiting for container to start:
${
service_name
}
"
echo
"Waiting for container to start:
${
service_name
}
"
lxc file pull
${
service_name
}
/etc/resolv.conf - |
grep
-q
nameserver
&&
break
lxc file pull
${
service_name
}
/etc/resolv.conf - |
grep
-q
nameserver
&&
break
...
@@ -123,7 +131,7 @@ create() {
...
@@ -123,7 +131,7 @@ create() {
lxc
exec
${
service_name
}
--env
REPO_ROOT
=
"
${
target_root
}
"
--
${
cmd
}
lxc
exec
${
service_name
}
--env
REPO_ROOT
=
"
${
target_root
}
"
--
${
cmd
}
# check that telegraf installed (it may not have if the reporc file was not present or Nexus server was down)
# check that telegraf installed (it may not have if the reporc file was not present or Nexus server was down)
#if lxc-attach -n ${service_name} -- ls /etc/telegraf |& grep 'ls: cannot access'; then
if
lxc
exec
${
service_name
}
--
ls
/etc/telegraf |&
grep
'ls: cannot access'
;
then
if
lxc
exec
${
service_name
}
--
ls
/etc/telegraf |&
grep
'ls: cannot access'
;
then
echo
"Telegraf agent failed to install for
${
service_name
}
(check reporc?)"
echo
"Telegraf agent failed to install for
${
service_name
}
(check reporc?)"
exit
1
exit
1
...
@@ -133,13 +141,14 @@ create() {
...
@@ -133,13 +141,14 @@ create() {
lxc
exec
${
service_name
}
--
service telegraf stop
lxc
exec
${
service_name
}
--
service telegraf stop
# copy telegraf configuration templates
# copy telegraf configuration templates
cp
-f
${
repo_root
}
/scripts/clmc-agent/telegraf.conf
${
container_dir
}
/etc/telegraf/
echo
"copy telegraf configuration templates"
cp
-f
${
repo_root
}
/scripts/clmc-agent/telegraf_output.conf
${
container_dir
}
/etc/telegraf/telegraf.d/
lxc file push
-r
scripts/clmc-agent/telegraf.conf
${
service_name
}
/etc/telegraf/
lxc file push
-r
scripts/clmc-agent/telegraf_output.conf
${
service_name
}
/etc/telegraf/telegraf.d/
# copy the 'host' config into all service containers
# copy the 'host' config into all service containers
cp
-f
${
repo_root
}
/
src/test/clmctest/services/host/telegraf
*
.conf
${
container_dir
}
/etc/telegraf/telegraf.d/
lxc file push
-r
src/test/clmctest/services/host/telegraf
*
.conf
${
service_name
}
/etc/telegraf/telegraf.d/
# copy the service-specific config
# copy the service-specific config
cp
-f
${
repo_root
}
/
src/test/clmctest/services/
${
sf_package_id
}
/telegraf
*
.conf
${
container_dir
}
/etc/telegraf/telegraf.d/
lxc file push
-r
src/test/clmctest/services/
${
sf_package_id
}
/telegraf
*
.conf
${
service_name
}
/etc/telegraf/telegraf.d/
chown
-R
100000:100000
${
container_dir
}
/etc/telegraf/
lxc
exec
${
service_name
}
--
chown
-R
100000:100000 /etc/telegraf/
# replace telegraf template with container parameters
# replace telegraf template with container parameters
cmd
=
"
${
target_root
}
/scripts/clmc-agent/configure.sh
${
location
}
${
sfc_id
}
${
sfc_instance_id
}
${
sf_package_id
}
${
sf_id
}
${
sf_endpoint_id
}
${
influxdb_url
}
"
cmd
=
"
${
target_root
}
/scripts/clmc-agent/configure.sh
${
location
}
${
sfc_id
}
${
sfc_instance_id
}
${
sf_package_id
}
${
sf_id
}
${
sf_endpoint_id
}
${
influxdb_url
}
"
...
@@ -180,7 +189,7 @@ stop() {
...
@@ -180,7 +189,7 @@ stop() {
fi
fi
}
}
delete
_c
()
{
delete
()
{
service_name
=
$1
service_name
=
$1
if
lxc list |
grep
-q
${
service_name
}
;
then
if
lxc list |
grep
-q
${
service_name
}
;
then
echo
"Deleting container:
${
service_name
}
"
echo
"Deleting container:
${
service_name
}
"
...
...
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