Skip to content

Commit da8a356

Browse files
committed
CLOUDSTACK-9848: Added exit status checking for the iptables commands
1 parent ed2f573 commit da8a356

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

systemvm/patches/debian/config/opt/cloud/bin/configure.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,10 @@ def add_rule(self, cidr):
168168
if rule['protocol'] == "icmp":
169169
fwr += " -s %s " % cidr + \
170170
" -p %s " % rule['protocol'] + \
171-
" -m %s " % rule['protocol'] + \
172171
" --icmp-type %s" % icmp_type
173172
elif rule['protocol'] != "all":
174173
fwr += " -s %s " % cidr + \
175174
" -p %s " % rule['protocol'] + \
176-
" -m %s " % rule['protocol'] + \
177175
" %s" % rnge
178176
elif rule['protocol'] == "all":
179177
fwr += " -s %s " % cidr
@@ -1022,6 +1020,7 @@ def main(argv):
10221020
static_routes.process()
10231021
except Exception:
10241022
logging.exception("Exception while configuring router")
1023+
return 1
10251024

10261025
if __name__ == "__main__":
10271026
main(sys.argv)

systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def fw_router(self):
382382
"-A FIREWALL_%s " % self.address['public_ip'] +
383383
"-m state --state RELATED,ESTABLISHED -j ACCEPT"])
384384
self.fw.append(["mangle", "",
385-
"-A FIREWALL_%s DROP" % self.address['public_ip']])
385+
"-A FIREWALL_%s -j DROP" % self.address['public_ip']])
386386
self.fw.append(["mangle", "",
387387
"-A VPN_%s -m state --state RELATED,ESTABLISHED -j ACCEPT" % self.address['public_ip']])
388388
self.fw.append(["mangle", "",
@@ -392,8 +392,6 @@ def fw_router(self):
392392
self.fw.append(["mangle", "",
393393
"-A PREROUTING -i %s -m state --state NEW " % self.dev +
394394
"-j CONNMARK --set-xmark %s/0xffffffff" % self.dnum])
395-
self.fw.append(
396-
["mangle", "", "-A FIREWALL_%s -j DROP" % self.address['public_ip']])
397395
self.fw.append(["filter", "",
398396
"-A FORWARD -i %s -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT" % self.dev])
399397
self.fw.append(["filter", "",
@@ -484,10 +482,6 @@ def fw_vpcrouter(self):
484482
(guestNetworkCidr, self.dev, self.address['public_ip'])])
485483

486484
if self.get_type() in ["public"]:
487-
self.fw.append(["", "front",
488-
"-A FORWARD -o %s -d %s -j ACL_INBOUND_%s" % (
489-
self.dev, self.address['network'], self.dev)
490-
])
491485
self.fw.append(
492486
["mangle", "", "-A FORWARD -j VPN_STATS_%s" % self.dev])
493487
self.fw.append(

systemvm/patches/debian/config/opt/cloud/bin/cs/CsHelper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ def get_hostname():
181181

182182
def execute(command):
183183
""" Execute command """
184-
logging.debug("Executing: %s" % command)
185184
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
185+
p.wait()
186+
rc = p.returncode
187+
188+
logging.debug("Executed: %s - exitstatus=%s " % (command, rc))
186189
result = p.communicate()[0]
187190
return result.splitlines()
188191

systemvm/patches/debian/config/opt/cloud/bin/cs/CsNetfilter.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818
import CsHelper
19-
from pprint import pprint
20-
from CsDatabag import CsDataBag, CsCmdLine
19+
from CsDatabag import CsCmdLine
2120
import logging
2221

2322

@@ -173,7 +172,15 @@ def compare(self, list):
173172
cpy = cpy.replace("-A %s" % new_rule.get_chain(), '-I %s %s' % (new_rule.get_chain(), rule_count))
174173
else:
175174
cpy = cpy.replace("-A %s" % new_rule.get_chain(), '-I %s %s' % (new_rule.get_chain(), fw[1]))
176-
CsHelper.execute("iptables -t %s %s" % (new_rule.get_table(), cpy))
175+
ret = CsHelper.execute2("iptables -t %s %s" % (new_rule.get_table(), cpy))
176+
#There are some issues in this framework causing failures .. like adding a chain without checking it is present causing
177+
# the failures. Also some of the rule like removeFromLoadBalancerRule is deleting rule and deleteLoadBalancerRule
178+
#trying to delete which causes the failure.
179+
#For now raising the log.
180+
#TODO: Need to fix in the framework.
181+
if ret.returncode != 0 :
182+
error = ret.communicate()[0]
183+
logging.debug("iptables command got failed ... continuing")
177184
ruleSet.add(tupledFw)
178185
self.chain.add_rule(rule_chain)
179186
self.del_standard()

0 commit comments

Comments
 (0)