Commit b3e4d794 authored by Senthil Kumaran S's avatar Senthil Kumaran S

LAVA-1232 - LAVA LXC Mocker

Set of scripts to mock LXC commands used within LAVA.

Change-Id: I40f300dcdd471cd63f811d739a8d1063f4226f19
parent 4d445841
......@@ -13,6 +13,7 @@ include .gitreview
include COPYING
include lava/dispatcher/lava-run
include lava/dispatcher/lava-slave
include lava/lxc-mocker/*
recursive-include lava_dispatcher/devices *.yaml
recursive-include lava_dispatcher/test *.yaml *.txt
include requirements.txt
......
#!/bin/bash
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Linaro Limited
#
# Author: Senthil Kumaran S <senthil.kumaran@linaro.org>
#
# This file is part of LAVA LXC mocker.
#
# Released under the MIT License:
# http://www.opensource.org/licenses/mit-license.php
#
# Mocks lxc-attach command which is used by LAVA.
CMD=$(awk -F'-- ' '{print $2}' <<< "$@")
while getopts "n:" opt; do
case $opt in
n)
LXC_NAME="$OPTARG"
;;
*)
;;
esac
done
if [ "$CMD" ]; then
# execute the given command
$CMD
else
# when no commands are requested, open up a shell
exec /bin/bash
fi
#!/bin/bash
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Linaro Limited
#
# Author: Senthil Kumaran S <senthil.kumaran@linaro.org>
#
# This file is part of LAVA LXC mocker.
#
# Released under the MIT License:
# http://www.opensource.org/licenses/mit-license.php
#
# Mocks lxc-create command which is used by LAVA.
# Get the list of requested packages.
PACKAGES=$(sed 's/,/ /g' <<< $(cut -d' ' -f1 <<< $(awk -F'--packages ' '{print $2}' <<< "$@")))
while getopts "qt:n:" opt; do
case $opt in
q)
QUIET=1
;;
n)
LXC_NAME="$OPTARG"
;;
*)
;;
esac
done
if [ "$PACKAGES" ] && [ "$QUIET" ]; then
DEBIAN_FRONTEND=noninteractive apt update > /dev/null 2>&1
DEBIAN_FRONTEND=noninteractive apt upgrade -y > /dev/null 2>&1
# install the requested packages.
DEBIAN_FRONTEND=noninteractive apt install -y $PACKAGES > /dev/null 2>&1
elif [ "$PACKAGES" ]; then
DEBIAN_FRONTEND=noninteractive apt update
DEBIAN_FRONTEND=noninteractive apt upgrade -y
# install the requested packages.
DEBIAN_FRONTEND=noninteractive apt install -y $PACKAGES
fi
if [ "$LXC_NAME" ]; then
# create dummy lxc rootfs.
mkdir -p /var/lib/lxc/${LXC_NAME}
ln -s / /var/lib/lxc/${LXC_NAME}/rootfs
fi
#!/bin/bash
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Linaro Limited
#
# Author: Senthil Kumaran S <senthil.kumaran@linaro.org>
#
# This file is part of LAVA LXC mocker.
#
# Released under the MIT License:
# http://www.opensource.org/licenses/mit-license.php
#
# Mocks lxc-destroy command which is used by LAVA.
while getopts "fn:" opt; do
case $opt in
n)
LXC_NAME="$OPTARG"
;;
*)
;;
esac
done
if [ "$LXC_NAME" ]; then
# Remove lxc rootfs directory if any
rm -rf /var/lib/lxc/${LXC_NAME}
# echo container destroyed message
echo "Destroyed container $LXC_NAME"
exit 0
fi
#!/bin/bash
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Linaro Limited
#
# Author: Senthil Kumaran S <senthil.kumaran@linaro.org>
#
# This file is part of LAVA LXC mocker.
#
# Released under the MIT License:
# http://www.opensource.org/licenses/mit-license.php
#
# Mocks lxc-device command which is used by LAVA.
echo "True"
exit 0
#!/bin/bash
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Linaro Limited
#
# Author: Senthil Kumaran S <senthil.kumaran@linaro.org>
#
# This file is part of LAVA LXC mocker.
#
# Released under the MIT License:
# http://www.opensource.org/licenses/mit-license.php
#
# Mocks lxc-info command which is used by LAVA.
while getopts "s:i:n:" opt; do
case $opt in
n)
LXC_NAME="$OPTARG"
;;
s)
STATUS=1
;;
i)
IP=1
;;
*)
;;
esac
done
if [ "$STATUS" ]; then
# echo running state.
echo "'$LXC_NAME' state is RUNNING"
exit 0
fi
if [ "$IP" ]; then
# echo a dummy ip.
echo "'$LXC_NAME' IP address is: '0.0.0.0'"
exit 0
fi
#!/bin/bash
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Linaro Limited
#
# Author: Senthil Kumaran S <senthil.kumaran@linaro.org>
#
# This file is part of LAVA LXC mocker.
#
# Released under the MIT License:
# http://www.opensource.org/licenses/mit-license.php
#
# Mocks lxc-start command which is used by LAVA.
exit 0
#!/bin/bash
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Linaro Limited
#
# Author: Senthil Kumaran S <senthil.kumaran@linaro.org>
#
# This file is part of LAVA LXC mocker.
#
# Released under the MIT License:
# http://www.opensource.org/licenses/mit-license.php
#
# Mocks lxc-stop command which is used by LAVA.
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment