You are here

Linux Container with LXD for focmm unit testing

Currently we are in the testing phase of the next release of our Ops Center (focmm). This testing is quite complex because it includes testing the interaction of various different components like a MariaDB Galera Cluster, a Galera Load Balancer, a virtual IP, etc.

Recently I was in the Linuxhotel for a Galera Cluster Training and there one of the other trainers was romanticising about Linux Containers and LXD. So I had a short look, if LXD could be useful to simplify our unit testing. Some old knowledge from a previous Docker PoC was quite helpful to start with...

Prepare a LXC container for Galera Load Balancer

This did NOT work as expected because the Debian image was lacking IPv4 addresses and I did not find on the quick how to change that. So I used the Ubuntu 22.04 image.

shell> lxc remote list
shell> lxc image list images: ubuntu/22.04 amd64

shell> INSTANCE='qa-glb'

shell> lxc launch images:ubuntu/jammy ${INSTANCE}
shell> lxc list *glb*
|  NAME  |  STATE  |         IPV4          |                     IPV6                     |    TYPE    | SNAPSHOTS |
| qa-glb | RUNNING | (eth0) | fd42:1730:178f:78c:216:3eff:fe3f:2948 (eth0) | PERSISTENT | 0         |

Now we should remember the IPv4 address for later use. I am sure this can be done more elegant but for now this is fine...

Install Galera Load Balancer in the LXC container

shell> lxc exec ${INSTANCE} -- /bin/bash

container> apt-get update
container> apt-get install wget
container> wget
container> apt-get install ./glb_1.0.1-Ubuntu12.04-x86_64.deb
container> rm -f glb_1.0.1-Ubuntu12.04-x86_64.deb

Then we have to add the unit file:

# /etc/systemd/system/glb.service

Description=Galera Load Balancer Service


ExecStart=/usr/local/sbin/glbd --daemon --threads $THREADS --max_conn $MAX_CONN $OTHER_OPTIONS --control $CONTROL_ADDR $LISTEN_ADDR $DEFAULT_TARGETS


enable the unit file, configure the Galera Load Balancer and start it:

container> systemctl enable glb

# Galera Load Balancer Configuration
# Redhat: /etc/sysconfig/glbd
# Debian: /etc/default/glbd

container> systemctl start glb
container> apt-get remove wget

Container testing

To be sure everything works fine we should do some basic tests:

shell> lxc stop ${INSTANCE}
shell> lxc start ${INSTANCE}
shell> echo getinfo | nc -q 1 8011

Unit testing focmm against Galera Load Balancer in the LXC container

And finally we did the unit testing of focmm against the Galera Local Balancer which is in the LXC container:

shell> ./tst/run_all_tests.php --instance=qamariadb106 --module=LoadBalancer  shell>/dev/null
Environment is: qamariadb106
Logfile is: /tmp/focmm_tst_qamariadb106.log
Tests are: module=LoadBalancer and function=all
OK  stopLoadBalancerRemote
OK  startLoadBalancerRemote
OK  restartLoadBalancerRemote
OK  readLoadBalancerTypes
OK  createLoadBalancer
OK  updateLoadBalancer
OK  readLoadBalancers
OK  parseGlbConfiguration
OK  openSocket
OK  writeReadSocket
OK  parseGlbGetInfo
OK  parseGlbGetStats
OK  changeLoadBalancerBackendWeightRemote
OK  deleteLoadBalancer