CLOUDSTACK-6047: Make VR LB script accept a file name

Rather than default filename everytime since in aggregated commands the file
would be overrided if the filename is same.
This commit is contained in:
Sheng Yang 2014-02-21 16:46:08 -08:00
parent e5304d5e82
commit c0ed0b7819
6 changed files with 35 additions and 19 deletions

View File

@ -480,7 +480,7 @@ public class VirtualRoutingResource {
}
String tmpCfgFilePath = "/etc/haproxy/";
String tmpCfgFileName = "haproxy.cfg.new";
String tmpCfgFileName = "haproxy.cfg.new." + String.valueOf(System.currentTimeMillis());
cfg.add(new ConfigItem(tmpCfgFilePath, tmpCfgFileName, tmpCfgFileContents));
String[][] rules = cfgtr.generateFwRules(cmd);
@ -489,7 +489,7 @@ public class VirtualRoutingResource {
String[] removeRules = rules[LoadBalancerConfigurator.REMOVE];
String[] statRules = rules[LoadBalancerConfigurator.STATS];
String args = "";
String args = " -f " + tmpCfgFilePath + tmpCfgFileName;
StringBuilder sb = new StringBuilder();
if (addRules.length > 0) {
for (int i = 0; i < addRules.length; i++) {

View File

@ -80,6 +80,7 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer {
VirtualRoutingResource _resource;
NetworkElementCommand _currentCmd;
int _count;
String _file;
String ROUTERIP = "10.2.3.4";
@ -703,6 +704,7 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer {
@Test
public void testLoadBalancerConfigCommand() {
_count = 0;
_file = "";
List<LoadBalancerTO> lbs = new ArrayList<>();
List<LbDestination> dests = new ArrayList<>();
@ -713,9 +715,11 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer {
lbs.toArray(arrayLbs);
NicTO nic = new NicTO();
LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(arrayLbs, "64.10.2.10", "10.1.10.2", "192.168.1.2", nic, null, "1000", false);
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, "10.1.10.2");
Answer answer = _resource.executeRequest(cmd);
assertTrue(answer.getResult());
nic.setIp("10.1.10.2");
cmd = new LoadBalancerConfigCommand(arrayLbs, "64.10.2.10", "10.1.10.2", "192.168.1.2", nic, Long.valueOf(1), "1000", false);
answer = _resource.executeRequest(cmd);
assertTrue(answer.getResult());
@ -729,8 +733,9 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer {
switch (_count) {
case 1:
case 3:
_file = path + filename;
assertEquals(path, "/etc/haproxy/");
assertEquals(filename, "haproxy.cfg.new");
assertTrue(filename.startsWith("haproxy.cfg.new"));
assertEquals(content, "global\n" +
"\tlog 127.0.0.1:3914 local0 warning\n" +
"\tmaxconn 1000\n" +
@ -779,11 +784,11 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer {
switch (_count) {
case 2:
assertEquals(script, VRScripts.LB);
assertEquals(args, " -i null -a 64.10.1.10:80:, -s 10.1.10.2:8081:0/0:,,");
assertEquals(args, " -i 10.1.10.2 -f " + _file + " -a 64.10.1.10:80:, -s 10.1.10.2:8081:0/0:,,");
break;
case 4:
assertEquals(script, VRScripts.VPC_LB);
assertEquals(args, " -i null -a 64.10.1.10:80:, -s 10.1.10.2:8081:0/0:,,");
assertEquals(args, " -i 10.1.10.2 -f " + _file + " -a 64.10.1.10:80:, -s 10.1.10.2:8081:0/0:,,");
break;
default:
fail();

View File

@ -113,7 +113,8 @@ fw_entry() {
#Hot reconfigure HA Proxy in the routing domain
reconfig_lb() {
/root/reconfigLB.sh
logger -t cloud "Reconfiguring ilb using $1"
/root/reconfigLB.sh $1
return $?
}
@ -126,7 +127,7 @@ restore_lb() {
if [ $? -eq 0 ]
then
# Run reconfigLB.sh again
/root/reconfigLB.sh
/root/reconfigLB.sh /etc/haproxy/haproxy.cfg.new
fi
}
@ -136,9 +137,10 @@ logger -t cloud "$(basename $0): Entering $(dirname $0)/$(basename $0)"
iflag=
aflag=
dflag=
fflag=
sflag=
while getopts 'i:a:d:s:' OPTION
while getopts 'i:a:d:f:s:' OPTION
do
case $OPTION in
i) iflag=1
@ -150,7 +152,9 @@ do
d) dflag=1
removedIps="$OPTARG"
;;
f) fflag=1
cfgfile="$OPTARG"
;;
s) sflag=1
statsIp="$OPTARG"
;;

View File

@ -177,7 +177,8 @@ fw_entry() {
#Hot reconfigure HA Proxy in the routing domain
reconfig_lb() {
/root/reconfigLB.sh
logger -t cloud "Reconfiguring loadbalancer using $1"
/root/reconfigLB.sh $1
return $?
}
@ -190,7 +191,7 @@ restore_lb() {
if [ $? -eq 0 ]
then
# Run reconfigLB.sh again
/root/reconfigLB.sh
/root/reconfigLB.sh /etc/haproxy/haproxy.cfg.new
fi
}
@ -234,7 +235,6 @@ do
f) fflag=1
cfgfile="$OPTARG"
;;
s) sflag=1
statsIp="$OPTARG"
;;
@ -297,7 +297,6 @@ then
# Restore the LB
restore_lb
logger -t cloud "Reverting firewall config"
# Revert iptables rules on DomR
fw_restore

View File

@ -146,7 +146,8 @@ fw_entry() {
#Hot reconfigure HA Proxy in the routing domain
reconfig_lb() {
/root/reconfigLB.sh
logger -t cloud "Reconfiguring loadbalancer using $1"
/root/reconfigLB.sh $1
return $?
}
@ -159,16 +160,17 @@ restore_lb() {
if [ $? -eq 0 ]
then
# Run reconfigLB.sh again
/root/reconfigLB.sh
/root/reconfigLB.sh /etc/haproxy/haproxy.cfg.new
fi
}
iflag=
aflag=
dflag=
fflag=
sflag=
while getopts 'i:a:d:s:' OPTION
while getopts 'i:a:d:f:s:' OPTION
do
case $OPTION in
i) iflag=1
@ -183,6 +185,9 @@ do
s) sflag=1
statsIp="$OPTARG"
;;
f) fflag=1
cfgfile="$OPTARG"
;;
?) usage
unlock_exit 2 $lock $locked
;;
@ -203,7 +208,7 @@ then
fi
# hot reconfigure haproxy
reconfig_lb
reconfig_lb $cfgfile
if [ $? -gt 0 ]
then

View File

@ -18,11 +18,14 @@
ret=0
new_config=$1
# save previous state
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.old
mv /var/run/haproxy.pid /var/run/haproxy.pid.old
mv /etc/haproxy/haproxy.cfg.new /etc/haproxy/haproxy.cfg
mv $new_config /etc/haproxy/haproxy.cfg
kill -TTOU $(cat /var/run/haproxy.pid.old)
sleep 2
if haproxy -D -p /var/run/haproxy.pid -f /etc/haproxy/haproxy.cfg; then
@ -35,7 +38,7 @@ ret=0
kill -TTIN $(cat /var/run/haproxy.pid.old)
rm -f /var/run/haproxy.pid
mv /var/run/haproxy.pid.old /var/run/haproxy.pid
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.new
mv /etc/haproxy/haproxy.cfg $new_config
mv /etc/haproxy/haproxy.cfg.old /etc/haproxy/haproxy.cfg
ret=1
fi