diff --git a/.kitchen.yml b/.kitchen.yml index 348c378..201c280 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -22,8 +22,9 @@ provisioner: platforms: - name: ubuntu-16.04 - - name: ubuntu-14.04 - - name: ubuntu-12.04 +## FIXME! test frozing/stalling on '-----> Running bats test suite' for trusty and precise??? +# - name: ubuntu-14.04 +# - name: ubuntu-12.04 - name: centos-7 # - name: centos-6 ## FIXME! 'Installing Chef Omnibus to install busser to run tests' not supported = can disable diff --git a/.travis.yml b/.travis.yml index 1270cb4..055fd4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,8 +39,7 @@ before_install: - env - pwd - find -ls - - ln -s ansible-fprobe ../juju4.fprobe - - ./get-dependencies.sh + - "[ -f get-dependencies.sh ] && sh -x get-dependencies.sh" - cp test/travis/initctl_faker test/ # Customize container - 'sudo docker build --rm=true --file=test/travis/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible test' diff --git a/.travis.yml.docker b/.travis.yml.docker index 1270cb4..055fd4d 100644 --- a/.travis.yml.docker +++ b/.travis.yml.docker @@ -39,8 +39,7 @@ before_install: - env - pwd - find -ls - - ln -s ansible-fprobe ../juju4.fprobe - - ./get-dependencies.sh + - "[ -f get-dependencies.sh ] && sh -x get-dependencies.sh" - cp test/travis/initctl_faker test/ # Customize container - 'sudo docker build --rm=true --file=test/travis/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible test' diff --git a/.travis.yml.lxd b/.travis.yml.lxd index ff1592a..42eab8e 100644 --- a/.travis.yml.lxd +++ b/.travis.yml.lxd @@ -24,8 +24,7 @@ before_install: - pwd - find -ls ## use appropriate role path and not github name - - ln -s ansible-fprobe ../juju4.fprobe - - ./get-dependencies.sh + - "[ -f get-dependencies.sh ] && sh -x get-dependencies.sh" ## No Xenial, https://github.com/travis-ci/travis-ci/issues/5821 # - sudo apt install lxd - echo "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/trusty-backports.list @@ -38,7 +37,7 @@ before_install: - sudo -E su $USER -c "lxc remote list" - sudo -E su $USER -c "lxc image list" ## pre-download base images - - 'sudo -E su $USER -c "[ ${distribution} == ubuntu ] || lxc image copy images:/${distribution}/${version}/amd64 local: --alias=${distribution}-${version}"' + - 'sudo -E su $USER -c "[ ${distribution} == ubuntu ] || lxc image copy images:${distribution}/${version}/amd64 local: --alias=${distribution}-${version}"' - 'sudo -E su $USER -c "[ ${distribution} == ubuntu ] && lxc image copy ubuntu:${version} local: --alias=${distribution}-${version}" || true' ## configure lxd-bridge - sudo perl -pi -e 's@^LXD_IPV4_ADDR=""@LXD_IPV4_ADDR="10.252.116.1"@;s@^LXD_IPV4_NETMASK=""@LXD_IPV4_NETMASK="255.255.255.0"@;s@^LXD_IPV4_NETWORK=""@LXD_IPV4_NETWORK="10.252.116.1/24"@;s@^LXD_IPV4_DHCP_RANGE=""@LXD_IPV4_DHCP_RANGE="10.252.116.2,10.252.116.254"@;s@^LXD_IPV4_DHCP_MAX=""@LXD_IPV4_DHCP_MAX="252"@;s@LXD_IPV6_PROXY="true"@LXD_IPV6_PROXY="false"@' /etc/default/lxd-bridge diff --git a/.travis.yml.lxd-kitchen b/.travis.yml.lxd-kitchen index f9117c3..b5c9d43 100644 --- a/.travis.yml.lxd-kitchen +++ b/.travis.yml.lxd-kitchen @@ -24,8 +24,7 @@ before_install: - pwd - find -ls ## use appropriate role path and not github name - - ln -s ansible-fprobe ../juju4.fprobe - - ./get-dependencies.sh + - "[ -f get-dependencies.sh ] && sh -x get-dependencies.sh" ## No Xenial, https://github.com/travis-ci/travis-ci/issues/5821 # - sudo apt install lxd - echo "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/trusty-backports.list diff --git a/.travis.yml.simple b/.travis.yml.simple index 4ad2497..e4cc721 100644 --- a/.travis.yml.simple +++ b/.travis.yml.simple @@ -5,8 +5,7 @@ python: "2.7" before_install: - sudo apt-get update -qq - sudo apt-get install -qq python-apt python-pycurl - - ln -s ansible-fprobe ../juju4.fprobe - - ./get-dependencies.sh + - "[ -f get-dependencies.sh ] && sh -x get-dependencies.sh" ## for local travis execution as we use same default.yml than kitchen - mkdir /tmp/kitchen - ln -s /home/travis/build/juju4/ansible-fprobe/test/integration/default/tmp /tmp/kitchen/tmp diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..7e6bc81 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,59 @@ +// Work in progress + +node { + + try{ + currentBuild.result = "SUCCESS" + def workspace = pwd() + def directory = "juju4.fprobe" + + stage 'Clean Workspace' + deleteDir() + + stage("Download source and capture commit ID") { + sh "mkdir $directory" + dir("$directory") { + checkout scm + // Get the commit ID + sh 'git rev-parse --verify HEAD > GIT_COMMIT' + git_commit = readFile('GIT_COMMIT').take(7) + echo "Current commit ID: ${git_commit}" + } + } + + dir("$directory") { + + stage("Get dependencies"){ + sh "sh -x get-dependencies.sh" + } + stage("Build and verify 1"){ + defaultplatform = sh ( + script: '''#!/bin/bash +kitchen list | awk "!/Instance/ {print \\$1; exit}" + ''', + returnStdout: true + ).trim() + echo "default platform: ${defaultplatform}" + + sh "kitchen test ${defaultplatform}" + // must keep instance for security testing after + //sh "kitchen verify ${defaultplatform}" + } + + stage("Build and verify all platforms"){ + sh "kitchen test" + } + + stage("Cleanup if no errors"){ + sh "kitchen destroy" + } + + } + + } + + catch(err) { + currentBuild.result = "FAILURE" + throw err + } +} diff --git a/get-dependencies.sh b/get-dependencies.sh index 0aa628f..826d1d1 100755 --- a/get-dependencies.sh +++ b/get-dependencies.sh @@ -10,4 +10,10 @@ rolesdir=$(dirname $0)/.. fi [ ! -d $rolesdir/juju4.redhat-epel ] && git clone https://github.com/juju4/ansible-redhat-epel $rolesdir/juju4.redhat-epel +## galaxy naming: kitchen fails to transfer symlink folder +#[ ! -e $rolesdir/juju4.fprobe ] && ln -s ansible-fprobe $rolesdir/juju4.fprobe +[ ! -e $rolesdir/juju4.fprobe ] && cp -R $rolesdir/ansible-fprobe $rolesdir/juju4.fprobe + +## don't stop build on this script return code +true diff --git a/meta/main.yml b/meta/main.yml index e940450..7a2f5f0 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,7 +1,7 @@ --- galaxy_info: author: juju4 - description: TEMPLATE + description: setup fprobe as netflow exporter license: BSD min_ansible_version: 2.0 # diff --git a/tasks/fprobe.yml b/tasks/fprobe.yml index 3aef04e..03ecf34 100644 --- a/tasks/fprobe.yml +++ b/tasks/fprobe.yml @@ -32,7 +32,10 @@ - name: add init.d script template: src=init.d-fprobe.j2 dest=/etc/rc.d/init.d/fprobe-ulog mode=0755 - when: ansible_os_family == 'RedHat' + when: ansible_os_family == 'RedHat' and ansible_service_mgr != 'systemd' +- name: add systemd script + template: "src=systemd-fprobe-ulog.service.j2 dest=/lib/systemd/system/{{ fprobe_svc }}.service mode=0644" + when: ansible_service_mgr == 'systemd' - name: ensure service is enabled and started service: name={{ fprobe_svc }} state=started enabled=yes diff --git a/templates/init.d-fprobe.j2 b/templates/init.d-fprobe.j2 index 7d927b3..5eef434 100644 --- a/templates/init.d-fprobe.j2 +++ b/templates/init.d-fprobe.j2 @@ -14,18 +14,19 @@ start() { - echo -n "Starting fprobe-ulog: " + echo -n "Starting fprobe-ulog" fprobe-ulog -c /var/tmp $FLOW_COLLECTOR touch /var/lock/subsys/fprobe-ulog - echo. + echo . + ps axu | egrep '[f]probe-ulog' return 0 } stop() { - echo -n "Shutting down fprobe-ulog: " + echo -n "Shutting down fprobe-ulog" pkill fprobe-ulog rm -f /var/lock/subsys/fprobe-ulog - echo. + echo . return 0 } diff --git a/templates/systemd-fprobe-ulog.service.j2 b/templates/systemd-fprobe-ulog.service.j2 new file mode 100644 index 0000000..10612d4 --- /dev/null +++ b/templates/systemd-fprobe-ulog.service.j2 @@ -0,0 +1,17 @@ +[Unit] +Description=fprobe netflow collector +Requires=network.target + +[Service] +Type=simple +{% if ansible_os_family == 'RedHat' %} +ExecStart=/usr/bin/fprobe-ulog -c /var/tmp {{ fprobe_flow_collector }} -l 3 +{% else %} +ExecStart=/usr/sbin/fprobe -i{{ fprobe_if }} {{ fprobe_args }} {{ fprobe_flow_collector }} -l 3 +{% endif %} +TimeoutSec=30 +RestartSec=15s +Restart=always + +[Install] +WantedBy=multi-user.target