Skip to content

Commit c0ed0b7

Browse files
author
Sheng Yang
committed
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.
1 parent e5304d5 commit c0ed0b7

6 files changed

Lines changed: 35 additions & 19 deletions

File tree

core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ private List<ConfigItem> generateConfig(LoadBalancerConfigCommand cmd) {
480480
}
481481

482482
String tmpCfgFilePath = "/etc/haproxy/";
483-
String tmpCfgFileName = "haproxy.cfg.new";
483+
String tmpCfgFileName = "haproxy.cfg.new." + String.valueOf(System.currentTimeMillis());
484484
cfg.add(new ConfigItem(tmpCfgFilePath, tmpCfgFileName, tmpCfgFileContents));
485485

486486
String[][] rules = cfgtr.generateFwRules(cmd);
@@ -489,7 +489,7 @@ private List<ConfigItem> generateConfig(LoadBalancerConfigCommand cmd) {
489489
String[] removeRules = rules[LoadBalancerConfigurator.REMOVE];
490490
String[] statRules = rules[LoadBalancerConfigurator.STATS];
491491

492-
String args = "";
492+
String args = " -f " + tmpCfgFilePath + tmpCfgFileName;
493493
StringBuilder sb = new StringBuilder();
494494
if (addRules.length > 0) {
495495
for (int i = 0; i < addRules.length; i++) {

core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer {
8080
VirtualRoutingResource _resource;
8181
NetworkElementCommand _currentCmd;
8282
int _count;
83+
String _file;
8384

8485
String ROUTERIP = "10.2.3.4";
8586

@@ -703,6 +704,7 @@ private void verifyArgs(DnsMasqConfigCommand cmd, String script, String args) {
703704
@Test
704705
public void testLoadBalancerConfigCommand() {
705706
_count = 0;
707+
_file = "";
706708

707709
List<LoadBalancerTO> lbs = new ArrayList<>();
708710
List<LbDestination> dests = new ArrayList<>();
@@ -713,9 +715,11 @@ public void testLoadBalancerConfigCommand() {
713715
lbs.toArray(arrayLbs);
714716
NicTO nic = new NicTO();
715717
LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(arrayLbs, "64.10.2.10", "10.1.10.2", "192.168.1.2", nic, null, "1000", false);
718+
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, "10.1.10.2");
716719
Answer answer = _resource.executeRequest(cmd);
717720
assertTrue(answer.getResult());
718721

722+
nic.setIp("10.1.10.2");
719723
cmd = new LoadBalancerConfigCommand(arrayLbs, "64.10.2.10", "10.1.10.2", "192.168.1.2", nic, Long.valueOf(1), "1000", false);
720724
answer = _resource.executeRequest(cmd);
721725
assertTrue(answer.getResult());
@@ -729,8 +733,9 @@ private void verifyFile(NetworkElementCommand cmd, String path, String filename,
729733
switch (_count) {
730734
case 1:
731735
case 3:
736+
_file = path + filename;
732737
assertEquals(path, "/etc/haproxy/");
733-
assertEquals(filename, "haproxy.cfg.new");
738+
assertTrue(filename.startsWith("haproxy.cfg.new"));
734739
assertEquals(content, "global\n" +
735740
"\tlog 127.0.0.1:3914 local0 warning\n" +
736741
"\tmaxconn 1000\n" +
@@ -779,11 +784,11 @@ private void verifyArgs(LoadBalancerConfigCommand cmd, String script, String arg
779784
switch (_count) {
780785
case 2:
781786
assertEquals(script, VRScripts.LB);
782-
assertEquals(args, " -i null -a 64.10.1.10:80:, -s 10.1.10.2:8081:0/0:,,");
787+
assertEquals(args, " -i 10.1.10.2 -f " + _file + " -a 64.10.1.10:80:, -s 10.1.10.2:8081:0/0:,,");
783788
break;
784789
case 4:
785790
assertEquals(script, VRScripts.VPC_LB);
786-
assertEquals(args, " -i null -a 64.10.1.10:80:, -s 10.1.10.2:8081:0/0:,,");
791+
assertEquals(args, " -i 10.1.10.2 -f " + _file + " -a 64.10.1.10:80:, -s 10.1.10.2:8081:0/0:,,");
787792
break;
788793
default:
789794
fail();

systemvm/patches/debian/config/opt/cloud/bin/ilb.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ fw_entry() {
113113

114114
#Hot reconfigure HA Proxy in the routing domain
115115
reconfig_lb() {
116-
/root/reconfigLB.sh
116+
logger -t cloud "Reconfiguring ilb using $1"
117+
/root/reconfigLB.sh $1
117118
return $?
118119
}
119120

@@ -126,7 +127,7 @@ restore_lb() {
126127
if [ $? -eq 0 ]
127128
then
128129
# Run reconfigLB.sh again
129-
/root/reconfigLB.sh
130+
/root/reconfigLB.sh /etc/haproxy/haproxy.cfg.new
130131
fi
131132
}
132133

@@ -136,9 +137,10 @@ logger -t cloud "$(basename $0): Entering $(dirname $0)/$(basename $0)"
136137
iflag=
137138
aflag=
138139
dflag=
140+
fflag=
139141
sflag=
140142

141-
while getopts 'i:a:d:s:' OPTION
143+
while getopts 'i:a:d:f:s:' OPTION
142144
do
143145
case $OPTION in
144146
i) iflag=1
@@ -150,7 +152,9 @@ do
150152
d) dflag=1
151153
removedIps="$OPTARG"
152154
;;
153-
155+
f) fflag=1
156+
cfgfile="$OPTARG"
157+
;;
154158
s) sflag=1
155159
statsIp="$OPTARG"
156160
;;

systemvm/patches/debian/config/opt/cloud/bin/loadbalancer.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ fw_entry() {
177177

178178
#Hot reconfigure HA Proxy in the routing domain
179179
reconfig_lb() {
180-
/root/reconfigLB.sh
180+
logger -t cloud "Reconfiguring loadbalancer using $1"
181+
/root/reconfigLB.sh $1
181182
return $?
182183
}
183184

@@ -190,7 +191,7 @@ restore_lb() {
190191
if [ $? -eq 0 ]
191192
then
192193
# Run reconfigLB.sh again
193-
/root/reconfigLB.sh
194+
/root/reconfigLB.sh /etc/haproxy/haproxy.cfg.new
194195
fi
195196
}
196197

@@ -234,7 +235,6 @@ do
234235
f) fflag=1
235236
cfgfile="$OPTARG"
236237
;;
237-
238238
s) sflag=1
239239
statsIp="$OPTARG"
240240
;;
@@ -297,7 +297,6 @@ then
297297
# Restore the LB
298298
restore_lb
299299

300-
301300
logger -t cloud "Reverting firewall config"
302301
# Revert iptables rules on DomR
303302
fw_restore

systemvm/patches/debian/config/opt/cloud/bin/vpc_loadbalancer.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ fw_entry() {
146146

147147
#Hot reconfigure HA Proxy in the routing domain
148148
reconfig_lb() {
149-
/root/reconfigLB.sh
149+
logger -t cloud "Reconfiguring loadbalancer using $1"
150+
/root/reconfigLB.sh $1
150151
return $?
151152
}
152153

@@ -159,16 +160,17 @@ restore_lb() {
159160
if [ $? -eq 0 ]
160161
then
161162
# Run reconfigLB.sh again
162-
/root/reconfigLB.sh
163+
/root/reconfigLB.sh /etc/haproxy/haproxy.cfg.new
163164
fi
164165
}
165166

166167
iflag=
167168
aflag=
168169
dflag=
170+
fflag=
169171
sflag=
170172

171-
while getopts 'i:a:d:s:' OPTION
173+
while getopts 'i:a:d:f:s:' OPTION
172174
do
173175
case $OPTION in
174176
i) iflag=1
@@ -183,6 +185,9 @@ do
183185
s) sflag=1
184186
statsIp="$OPTARG"
185187
;;
188+
f) fflag=1
189+
cfgfile="$OPTARG"
190+
;;
186191
?) usage
187192
unlock_exit 2 $lock $locked
188193
;;
@@ -203,7 +208,7 @@ then
203208
fi
204209

205210
# hot reconfigure haproxy
206-
reconfig_lb
211+
reconfig_lb $cfgfile
207212

208213
if [ $? -gt 0 ]
209214
then

systemvm/patches/debian/config/root/reconfigLB.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818

1919

2020
ret=0
21+
22+
new_config=$1
23+
2124
# save previous state
2225
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.old
2326
mv /var/run/haproxy.pid /var/run/haproxy.pid.old
2427

25-
mv /etc/haproxy/haproxy.cfg.new /etc/haproxy/haproxy.cfg
28+
mv $new_config /etc/haproxy/haproxy.cfg
2629
kill -TTOU $(cat /var/run/haproxy.pid.old)
2730
sleep 2
2831
if haproxy -D -p /var/run/haproxy.pid -f /etc/haproxy/haproxy.cfg; then
@@ -35,7 +38,7 @@ ret=0
3538
kill -TTIN $(cat /var/run/haproxy.pid.old)
3639
rm -f /var/run/haproxy.pid
3740
mv /var/run/haproxy.pid.old /var/run/haproxy.pid
38-
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.new
41+
mv /etc/haproxy/haproxy.cfg $new_config
3942
mv /etc/haproxy/haproxy.cfg.old /etc/haproxy/haproxy.cfg
4043
ret=1
4144
fi

0 commit comments

Comments
 (0)