Skip to content

Commit 3824ae2

Browse files
authored
Merge pull request #1088 from nplanel/run-func-tests-in-vagrant
CI : run functional tests in vagrant
2 parents d07bfb1 + 01d25c0 commit 3824ae2

File tree

17 files changed

+271
-92
lines changed

17 files changed

+271
-92
lines changed

contrib/ansible/roles/skydive_agent/tasks/docker.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,34 @@
1010
state: started
1111
enabled: yes
1212

13+
- name: Run docker registry
14+
shell: "docker run -d -p 5000:5000 --restart=always --name registry registry:2"
15+
when: '"file://" in skydive_binary_remote_location'
16+
17+
- name: Set facts
18+
set_fact: "skydive_docker_registry=localhost:5000"
19+
when: '"file://" in skydive_binary_remote_location'
20+
21+
- name: Copy docker image
22+
copy:
23+
src: "{{ skydive_binary_remote_location | replace('file://', '') }}"
24+
dest: /tmp
25+
force: true
26+
mode: 0755
27+
when: '"file://" in skydive_binary_remote_location'
28+
29+
- name: Import skydive image
30+
shell: "docker load -i /tmp/{{ skydive_binary_remote_location | replace('file://', '') | basename }}"
31+
when: '"file://" in skydive_binary_remote_location'
32+
33+
- name: Tag skydive image
34+
shell: "docker tag skydive/skydive:devel {{ skydive_docker_registry }}/{{ skydive_agent_docker_image }}:{{ skydive_docker_image_tag }}"
35+
when: '"file://" in skydive_binary_remote_location'
36+
37+
- name: Push skydive image to registry
38+
shell: "docker push {{ skydive_docker_registry }}/{{ skydive_agent_docker_image }}:{{ skydive_docker_image_tag }}"
39+
when: '"file://" in skydive_binary_remote_location'
40+
1341
- name: Create systemd unit file
1442
include_role:
1543
name: skydive_common
@@ -22,7 +50,7 @@
2250
--privileged --net=host --pid=host \
2351
-v /var/run/openvswitch/db.sock:/var/run/openvswitch/db.sock \
2452
-v /var/run/docker.sock:/var/run/docker.sock \
25-
-v /var/run/netns:/host/run \
53+
-v /var/run/netns:/host/run:ro,shared \
2654
-v /etc/skydive/skydive.yml:/etc/skydive.yml \
2755
-e SKYDIVE_NETNS_RUN_PATH=/host/run {{ skydive_agent_docker_extra_env }} \
2856
-p {{ skydive_agent_port }}:{{ skydive_agent_port }} \

contrib/ansible/roles/skydive_common/tasks/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
force: no
1313
ignore_errors: yes
1414

15-
- name: Create empty config file is needed
15+
- name: Create empty config file if needed
1616
copy:
1717
content: ""
1818
dest: "{{ skydive_config_file }}"

contrib/vagrant/Vagrantfile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ systemctl start openvswitch
2222
systemctl start docker
2323
systemctl enable openvswitch
2424
systemctl enable docker
25+
yum -y install libpcap libselinux-python bridge-utils net-tools yum-plugin-copr.noarch
26+
#curl -o /etc/yum.repos.d/_copr_ganto-lxc3.repo https://copr.fedorainfracloud.org/coprs/ganto/lxc3/repo/epel-7/ganto-lxc3-epel-7.repo
27+
#yum repolist
28+
#yum -y install lxd
29+
#grep -q 'root:1000000:65536' /etc/subuid || echo 'root:1000000:65536' >> /etc/subuid
30+
#grep -q 'root:1000000:65536' /etc/subgid || echo 'root:1000000:65536' >> /etc/subgid
31+
#systemctl start lxd
32+
#ln -s /var/run/lxd.socket /var/lib/lxd/unix.socket
33+
#systemctl enable lxd
34+
#lxd init --auto
2535
SCRIPT
2636

2737
$skydive_extra_config = {
@@ -30,6 +40,18 @@ $skydive_extra_config = {
3040
"agent.topology.netlink.metrics_update" => 5,
3141
}
3242

43+
if DEVMODE then
44+
# default config from tests/tests.go:testConfig
45+
$skydive_extra_config["flow.expire"] = "600"
46+
$skydive_extra_config["flow.update"] = "10"
47+
$skydive_extra_config["agent.topology.probes"] = "netlink netns ovsdb docker"
48+
$skydive_extra_config["agent.topology.metrics_update"] = "5"
49+
$skydive_extra_config["agent.metadata.mydict.value"] = "123"
50+
$skydive_extra_config["analyzer.startup.capture_gremlin"] = "g.V().Has('Name','startup-vm2')"
51+
$skydive_extra_config["ovs.oflow.enable"] = "true"
52+
$skydive_extra_config["logging.level"] = "DEBUG"
53+
end
54+
3355
def ifcfg_config(interface, network, netmask, ip)
3456
ifcfg_template = <<-IFCFG
3557
cat > /etc/sysconfig/network-scripts/ifcfg-#{interface} <<EOF
@@ -69,9 +91,8 @@ def provision_es(vm, hosts)
6991
ansible.playbook = "playbook-es.yml"
7092
ansible.groups = { "elasticsearch": hosts.map { |h| h["name"] } }
7193
ansible.limit = "all"
72-
ansible.verbose = "-vvv"
7394
ansible.galaxy_role_file = 'requirements.yml'
74-
ansible.sudo = true
95+
ansible.become = true
7596
end
7697

7798
$skydive_extra_config["analyzer.flow.backend"] = "elasticsearch"

contrib/vagrant/setup-common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

3-
sudo yum -y install python2 python-yaml
3+
sudo yum -y install python2 python-yaml libpcap ntpdate audit
44
sudo setenforce 0
5-
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
5+
sudo sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/sysconfig/selinux

gremlin/query.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package gremlin
2424

2525
import (
2626
"fmt"
27+
"strings"
2728
"time"
2829

2930
"github.com/skydive-project/skydive/common"
@@ -104,6 +105,16 @@ func (q QueryString) Context(list ...interface{}) QueryString {
104105
for _, v := range list {
105106
if !first {
106107
newQ = newQ.appends(", ")
108+
} else {
109+
switch t := v.(type) {
110+
case string:
111+
up := strings.ToUpper(t)
112+
if up == "NOW" || up == "FOREVER" {
113+
newQ = newQ.appends(up)
114+
first = false
115+
continue
116+
}
117+
}
107118
}
108119
first = false
109120
switch t := v.(type) {

scripts/ci/run-vagrant-tests.sh

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,116 @@ set -v
1212

1313
dir="$(dirname "$0")"
1414

15-
cd ${GOPATH}/src/github.com/skydive-project/skydive
15+
root=${GOPATH}/src/github.com/skydive-project/skydive
16+
cd $root
17+
18+
if [ "$DEVMODE" = "true" ]; then
19+
make
1620

17-
if [ "$DEVMODE" == "true" ]; then
18-
make static
1921
make srpm
2022
VERSION=$(make -s version | cut -d '-' -f 1)
2123
TAG=$(make -s version | cut -s -d '-' -f 2- | tr '-' '.')
2224
mock -r centos-7-x86_64 -D "fullver $(make -s version)" --resultdir . --rebuild rpmbuild/SRPMS/skydive-${VERSION}*${TAG}.src.rpm
2325
mkdir -p rpmbuild/RPMS/{x86_64,noarch}
2426
mv skydive*-${VERSION}-*${TAG}*.x86_64.rpm rpmbuild/RPMS/x86_64/
2527
mv skydive*-${VERSION}-*${TAG}*.noarch.rpm rpmbuild/RPMS/noarch/
28+
2629
make docker-image
2730
docker save skydive/skydive:devel -o skydive-docker-devel.tar
31+
32+
make test.functionals.compile
2833
fi
2934

3035
cd contrib/vagrant
3136

37+
export ANALYZER_COUNT=1
38+
export AGENT_COUNT=1
39+
export SKYDIVE_RELEASE=master
40+
3241
function vagrant_cleanup {
42+
set +e
43+
echo "===== journalctl agent1"
44+
vagrant ssh agent1 -c 'sudo journalctl -xe | grep skydive'
45+
echo "===== journalctl analyzer1"
46+
vagrant ssh analyzer1 -c 'sudo journalctl -xe | grep skydive'
3347
vagrant destroy --force
3448
}
3549
trap vagrant_cleanup EXIT
3650

37-
export ANALYZER_COUNT=2
38-
export AGENT_COUNT=1
39-
export SKYDIVE_RELEASE=master
51+
function run_functional_tests {
52+
vagrant ssh-config > vagrant-ssh-config
53+
scp -F vagrant-ssh-config $root/tests/functionals agent1:
54+
rsync -av -e 'ssh -F vagrant-ssh-config' $root/tests/pcaptraces agent1:
55+
AGENT1_IP=$(vagrant ssh-config agent1 | grep HostName | awk '{print $2}')
56+
ANALYZER1_IP=$(vagrant ssh-config analyzer1 | grep HostName | awk '{print $2}')
57+
58+
vagrant ssh agent1 -c 'for i in $(find /proc/sys/net/bridge/ -type f) ; do echo 0 | sudo tee $i ; done'
59+
vagrant ssh agent1 -c 'sudo iptables -F ; sudo iptables -P FORWARD ACCEPT'
60+
61+
if [ "$mode" = "container" ]; then
62+
OPT="-nooftests"
63+
fi
64+
vagrant ssh agent1 -c "AGENT1_IP=$AGENT1_IP SKYDIVE_ANALYZERS=\"$ANALYZER1_IP:8082\" sudo -E ./functionals -agenttestsonly -test.v $OPT"
65+
66+
if [ "$mode" = "package" ]; then
67+
for a in analyzer1 agent1; do
68+
echo "===== ausearch AVC on $a ======"
69+
vagrant ssh $a -c 'sudo ausearch -m avc -r' || true
70+
done
71+
fi
72+
rm -f vagrant-ssh-config
73+
}
74+
75+
function install_skydive_selinux_enforcing {
76+
cat <<'EOF' | vagrant ssh $1 -- bash -
77+
sudo setenforce 1
78+
sudo sed -i 's/SELINUX=permissive/SELINUX=enforcing/' /etc/sysconfig/selinux
79+
EOF
80+
}
81+
82+
function install_skydive_from_docker_image {
83+
cat <<'EOF' | vagrant ssh $1 -- bash -
84+
t=$(mktemp -d skydive.docker.XXX)
85+
pushd $t
86+
sudo docker image save skydive/skydive | tar xf - "*/layer.tar"
87+
find . -name "layer.tar" | xargs -n 1 --replace=XXX sudo tar -C / -xf XXX usr/bin/skydive &>/dev/null || true
88+
popd
89+
rm -rf $t
90+
EOF
91+
}
4092

4193
for mode in $MODES
4294
do
95+
echo "================== deploying mode $mode ==============================="
4396
DEPLOYMENT_MODE=$mode vagrant box update
4497
DEPLOYMENT_MODE=$mode vagrant up --provision-with common
4598
DEPLOYMENT_MODE=$mode vagrant provision
4699

100+
vagrant ssh analyzer1 -- sudo ntpdate fr.pool.ntp.org
101+
vagrant ssh agent1 -- sudo ntpdate fr.pool.ntp.org
102+
47103
vagrant ssh analyzer1 -- sudo cat /etc/skydive/skydive.yml
48-
vagrant ssh analyzer2 -- sudo cat /etc/skydive/skydive.yml
49104

50105
vagrant ssh analyzer1 -- sudo journalctl -n 100 -u skydive-analyzer
51-
vagrant ssh analyzer2 -- sudo journalctl -n 100 -u skydive-analyzer
52106
vagrant ssh agent1 -- sudo journalctl -n 100 -u skydive-agent
53107

54108
vagrant ssh analyzer1 -- curl http://localhost:8082
109+
110+
if [ "$mode" = "container" ]; then
111+
install_skydive_from_docker_image analyzer1
112+
install_skydive_from_docker_image agent1
113+
fi
114+
115+
if [ "$mode" = "package" ]; then
116+
install_skydive_selinux_enforcing analyzer1
117+
install_skydive_selinux_enforcing agent1
118+
fi
119+
120+
vagrant ssh analyzer1 -c 'set -e; skydive client query "g.V()"'
121+
55122
if [ "$mode" != "container" ]; then
56-
vagrant ssh analyzer1 -c 'set -e; skydive client query "g.V()"'
57-
else
58-
CONTAINER=$(vagrant ssh analyzer1 -- sudo docker ps | grep 'skydive/skydive:latest' | awk '{print $1}')
59-
vagrant ssh analyzer1 -- sudo docker exec -t $CONTAINER skydive client query "'g.V()'"
123+
sleep 10
124+
run_functional_tests
60125
fi
61126

62127
vagrant destroy --force

tests/alert_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ func TestAlertWebhook(t *testing.T) {
8686

8787
testPassed.Store(false)
8888

89+
agent1IP := os.Getenv("AGENT1_IP")
90+
if agent1IP == "" {
91+
agent1IP = "localhost"
92+
}
93+
8994
ListenAndServe := func(addr string, port int) {
9095
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, port))
9196
if err != nil {
@@ -123,14 +128,14 @@ func TestAlertWebhook(t *testing.T) {
123128

124129
setupFunction: func(c *TestContext) error {
125130
wg.Add(1)
126-
ListenAndServe("localhost", 8080)
131+
ListenAndServe(agent1IP, 8080)
127132

128133
alertLock.Lock()
129134
defer alertLock.Unlock()
130135

131136
al = types.NewAlert()
132137
al.Expression = "G.V().Has('Name', 'alert-ns-webhook', 'Type', 'netns')"
133-
al.Action = "http://localhost:8080/"
138+
al.Action = fmt.Sprintf("http://%s:8080/", agent1IP)
134139

135140
if err = c.client.Create("alert", al); err != nil {
136141
return fmt.Errorf("Failed to create alert: %s", err.Error())
@@ -165,6 +170,10 @@ func TestAlertWebhook(t *testing.T) {
165170
}
166171

167172
func TestAlertScript(t *testing.T) {
173+
if helper.AgentTestsOnly {
174+
t.Skip("this test works only when agent and analyzers are on the same host")
175+
}
176+
168177
var (
169178
err error
170179
al *types.Alert
@@ -260,7 +269,7 @@ func TestAlertWithTimer(t *testing.T) {
260269
},
261270

262271
setupFunction: func(c *TestContext) error {
263-
ws, err = helper.WSConnect(config.GetString("analyzer.listen"), 5, nil)
272+
ws, err = helper.WSConnect(config.GetStringSlice("analyzers")[0], 5, nil)
264273
if err != nil {
265274
return err
266275
}
@@ -334,7 +343,7 @@ func TestMultipleTriggering(t *testing.T) {
334343
},
335344

336345
setupFunction: func(c *TestContext) error {
337-
ws, err = helper.WSConnect(config.GetString("analyzer.listen"), 5, nil)
346+
ws, err = helper.WSConnect(config.GetStringSlice("analyzers")[0], 5, nil)
338347
if err != nil {
339348
return err
340349
}

0 commit comments

Comments
 (0)