This is an automated email from the ASF dual-hosted git repository.

bhaisaab pushed a commit to branch debian9-systemvmtemplate
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/debian9-systemvmtemplate by 
this push:
     new 2273055  Fix systemvm python codebase, add tests and pylint/pep8 to 
Travis
2273055 is described below

commit 2273055e8b92a4388feb2fc2cd991b5695dfe200
Author: Rohit Yadav <[email protected]>
AuthorDate: Mon Dec 4 12:40:38 2017 +0530

    Fix systemvm python codebase, add tests and pylint/pep8 to Travis
    
    Signed-off-by: Rohit Yadav <[email protected]>
---
 systemvm/patches/debian/opt/cloud/bin/configure.py | 180 ++++++++++-----------
 .../patches/debian/opt/cloud/bin/cs/CsAddress.py   |   4 +-
 .../patches/debian/opt/cloud/bin/cs/CsDatabag.py   |   4 +-
 systemvm/patches/debian/opt/cloud/bin/cs/CsDhcp.py |   5 +-
 systemvm/patches/debian/opt/cloud/bin/cs/CsFile.py |   6 +-
 .../debian/opt/cloud/bin/cs/CsGuestNetwork.py      |   2 +-
 .../patches/debian/opt/cloud/bin/cs/CsHelper.py    |  12 +-
 .../patches/debian/opt/cloud/bin/cs/CsNetfilter.py |  12 +-
 .../patches/debian/opt/cloud/bin/cs/CsRedundant.py |  16 +-
 .../patches/debian/opt/cloud/bin/cs/CsRoute.py     |   9 +-
 systemvm/patches/debian/opt/cloud/bin/cs/CsRule.py |   2 +-
 systemvm/patches/debian/opt/cloud/bin/cs_ip.py     |   5 +-
 systemvm/patches/debian/opt/cloud/bin/cs_vmp.py    |   1 +
 .../patches/debian/opt/cloud/bin/cs_vpnusers.py    |   4 +-
 systemvm/patches/debian/opt/cloud/bin/master.py    |   2 +-
 systemvm/patches/debian/opt/cloud/bin/merge.py     |  13 +-
 .../patches/debian/opt/cloud/bin/set_redundant.py  |  10 +-
 systemvm/patches/debian/opt/cloud/bin/vmdata.py    |   2 +-
 systemvm/{patches => }/test/TestCsAddress.py       |   0
 systemvm/{patches => }/test/TestCsApp.py           |   0
 systemvm/{patches => }/test/TestCsCmdLine.py       |   0
 systemvm/{patches => }/test/TestCsConfig.py        |   0
 systemvm/{patches => }/test/TestCsDatabag.py       |   0
 systemvm/{patches => }/test/TestCsDhcp.py          |   0
 systemvm/{patches => }/test/TestCsFile.py          |   0
 systemvm/{patches => }/test/TestCsGuestNetwork.py  |   3 +-
 systemvm/{patches => }/test/TestCsHelper.py        |   0
 systemvm/{patches => }/test/TestCsInterface.py     |   0
 systemvm/{patches => }/test/TestCsNetfilter.py     |   0
 systemvm/{patches => }/test/TestCsProcess.py       |   0
 systemvm/{patches => }/test/TestCsRedundant.py     |   0
 systemvm/{patches => }/test/TestCsRoute.py         |   5 +-
 systemvm/{patches => }/test/TestCsRule.py          |   0
 systemvm/{patches => }/test/runtests.sh            |  21 ++-
 tools/travis/before_install.sh                     |   2 +-
 tools/travis/install.sh                            |   4 +
 36 files changed, 171 insertions(+), 153 deletions(-)

diff --git a/systemvm/patches/debian/opt/cloud/bin/configure.py 
b/systemvm/patches/debian/opt/cloud/bin/configure.py
index ed67ec6..7e8db9b 100755
--- a/systemvm/patches/debian/opt/cloud/bin/configure.py
+++ b/systemvm/patches/debian/opt/cloud/bin/configure.py
@@ -16,16 +16,14 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-import sys
-import os
 import base64
-import time
-
-from collections import OrderedDict
-
 import logging
+import os
 import re
+import sys
+import time
 
+from collections import OrderedDict
 from fcntl import flock, LOCK_EX, LOCK_UN
 
 from cs.CsDatabag import CsDataBag
@@ -42,7 +40,7 @@ from cs.CsStaticRoutes import CsStaticRoutes
 
 class CsPassword(CsDataBag):
 
-    TOKEN_FILE="/tmp/passwdsrvrtoken"
+    TOKEN_FILE = "/tmp/passwdsrvrtoken"
 
     def process(self):
         for item in self.dbag:
@@ -65,7 +63,7 @@ class CsPassword(CsDataBag):
             proc = CsProcess(['/opt/cloud/bin/passwd_server_ip.py', server_ip])
             if proc.find():
                 update_command = 'curl --header "DomU_Request: save_password" 
"http://{SERVER_IP}:8080/"; -F "ip={VM_IP}" -F "password={PASSWORD}" ' \
-                '-F "token={TOKEN}" >/dev/null 2>/dev/null 
&'.format(SERVER_IP=server_ip, VM_IP=vm_ip, PASSWORD=password, TOKEN=token)
+                                 '-F "token={TOKEN}" >/dev/null 2>/dev/null 
&'.format(SERVER_IP=server_ip, VM_IP=vm_ip, PASSWORD=password, TOKEN=token)
                 result = CsHelper.execute(update_command)
                 logging.debug("Update password server result ==> %s" % result)
 
@@ -95,7 +93,7 @@ class CsAcl(CsDataBag):
             self.rule['allowed'] = True
             self.rule['action'] = "ACCEPT"
 
-            if self.rule['type'] == 'all' and  obj['source_cidr_list']:
+            if self.rule['type'] == 'all' and obj['source_cidr_list']:
                 self.rule['cidr'] = []
             else:
                 self.rule['cidr'] = obj['source_cidr_list']
@@ -126,7 +124,7 @@ class CsAcl(CsDataBag):
             rnge = ''
             if "first_port" in self.rule.keys() and \
                self.rule['first_port'] == self.rule['last_port']:
-                    rnge = " --dport %s " %self.rule['first_port']
+                    rnge = " --dport %s " % self.rule['first_port']
             if "first_port" in self.rule.keys() and \
                self.rule['first_port'] != self.rule['last_port']:
                     rnge = " --dport %s:%s" % (rule['first_port'], 
rule['last_port'])
@@ -148,21 +146,21 @@ class CsAcl(CsDataBag):
                                         " -p %s " % rule['protocol'] +
                                         "  %s -j %s" % (rnge, 
self.rule['action'])])
 
-            sflag=False
-            dflag=False
+            sflag = False
+            dflag = False
             if self.direction == 'egress':
                 ruleId = self.rule['id']
-                sourceIpsetName = 'sourceCidrIpset-%d' %ruleId
-                destIpsetName = 'destCidrIpset-%d' %ruleId
+                sourceIpsetName = 'sourceCidrIpset-%d' % ruleId
+                destIpsetName = 'destCidrIpset-%d' % ruleId
 
-                #create source cidr ipset
+                # Create source cidr ipset
                 srcIpset = 'ipset create '+sourceIpsetName + ' hash:net '
                 dstIpset = 'ipset create '+destIpsetName + ' hash:net '
 
                 CsHelper.execute(srcIpset)
                 CsHelper.execute(dstIpset)
                 for cidr in self.rule['cidr']:
-                    ipsetAddCmd = 'ipset add '+ sourceIpsetName + ' '+cidr
+                    ipsetAddCmd = 'ipset add ' + sourceIpsetName + ' ' + cidr
                     CsHelper.execute(ipsetAddCmd)
                     sflag = True
 
@@ -170,7 +168,7 @@ class CsAcl(CsDataBag):
                 for cidr in self.rule['dcidr']:
                     if cidr == CIDR_ALL:
                         continue
-                    ipsetAddCmd = 'ipset add '+ destIpsetName + ' '+cidr
+                    ipsetAddCmd = 'ipset add ' + destIpsetName + ' ' + cidr
                     CsHelper.execute(ipsetAddCmd)
                     dflag = True
 
@@ -195,8 +193,8 @@ class CsAcl(CsDataBag):
                     else:
                         self.rule['action'] = "ACCEPT"
 
-                egressIpsetStr=''
-                if sflag and dflag :
+                egressIpsetStr = ''
+                if sflag and dflag:
                     egressIpsetStr = " -m set --match-set %s src " % 
sourceIpsetName + \
                                 " -m set --match-set %s dst " % destIpsetName
                 elif sflag:
@@ -358,7 +356,7 @@ class CsVmMetadata(CsDataBag):
             if data is not None:
                 # need to pad data if it is not valid base 64
                 if len(data) % 4 != 0:
-                    data  += (4-(len(data) % 4)) * "="
+                    data += (4 - (len(data) % 4)) * "="
                 data = base64.b64decode(data)
 
         fh = open(dest, "w")
@@ -465,7 +463,7 @@ class CsVmMetadata(CsDataBag):
     def __unflock(self, file):
         try:
             flock(file, LOCK_UN)
-        except IOError:
+        except IOError as e:
             print "failed to unlock file" + file.name + " due to : " + 
e.strerror
             sys.exit(1)  # FIXME
         return True
@@ -538,8 +536,8 @@ class CsSite2SiteVpn(CsDataBag):
         peerlist = obj['peer_guest_cidr_list'].replace(' ', '')
         vpnconffile = "%s/ipsec.vpn-%s.conf" % (self.VPNCONFDIR, rightpeer)
         vpnsecretsfile = "%s/ipsec.vpn-%s.secrets" % (self.VPNCONFDIR, 
rightpeer)
-        ikepolicy=obj['ike_policy'].replace(';','-')
-        esppolicy=obj['esp_policy'].replace(';','-')
+        ikepolicy = obj['ike_policy'].replace(';', '-')
+        esppolicy = obj['esp_policy'].replace(';', '-')
 
         if rightpeer in self.confips:
             self.confips.remove(rightpeer)
@@ -560,7 +558,7 @@ class CsSite2SiteVpn(CsDataBag):
         file.addeq(" keyingtries=2")
         file.addeq(" auto=route")
         if 'encap' not in obj:
-            obj['encap']=False
+            obj['encap'] = False
         file.addeq(" forceencaps=%s" % CsHelper.bool_to_yn(obj['encap']))
         if obj['dpd']:
             file.addeq(" dpddelay=30")
@@ -594,14 +592,14 @@ class CsSite2SiteVpn(CsDataBag):
 
 
 class CsVpnUser(CsDataBag):
-    PPP_CHAP='/etc/ppp/chap-secrets'
+    PPP_CHAP = '/etc/ppp/chap-secrets'
 
     def process(self):
         for user in self.dbag:
             if user == 'id':
                 continue
 
-            userconfig=self.dbag[user]
+            userconfig = self.dbag[user]
             if userconfig['add']:
                 self.add_l2tp_ipsec_user(user, userconfig)
             else:
@@ -611,7 +609,7 @@ class CsVpnUser(CsDataBag):
         userfound = False
         password = obj['password']
 
-        userAddEntry = "%s * %s *" %(user,password)
+        userAddEntry = "%s * %s *" % (user, password)
         logging.debug("Adding vpn user '%s'" % user)
 
         file = CsFile(self.PPP_CHAP)
@@ -625,7 +623,7 @@ class CsVpnUser(CsDataBag):
     def del_l2tp_ipsec_user(self, user, obj):
         userfound = False
         password = obj['password']
-        userentry = "%s * %s *" % (user,password)
+        userentry = "%s * %s *" % (user, password)
 
         logging.debug("Deleting the user '%s'" % user)
         file = CsFile(self.PPP_CHAP)
@@ -646,7 +644,7 @@ class CsVpnUser(CsDataBag):
                     if pppd == 'PPPD_PID':
                         pid = str.split('=')[1]
                         if pid:
-                            logging.debug("killing process %s" %pid)
+                            logging.debug("killing process %s" % pid)
                             CsHelper.execute('kill -9 %s' % pid)
 
 
@@ -661,11 +659,11 @@ class CsRemoteAccessVpn(CsDataBag):
         for public_ip in self.dbag:
             if public_ip == "id":
                 continue
-            vpnconfig=self.dbag[public_ip]
+            vpnconfig = self.dbag[public_ip]
 
             # Enable remote access vpn
             if vpnconfig['create']:
-                logging.debug("Enabling remote access vpn  on "+ public_ip)
+                logging.debug("Enabling remote access vpn on " + public_ip)
 
                 CsHelper.start_if_stopped("ipsec")
                 self.configure_l2tpIpsec(public_ip, self.dbag[public_ip])
@@ -680,20 +678,19 @@ class CsRemoteAccessVpn(CsDataBag):
                 CsHelper.execute("ipsec down L2TP-PSK")
                 CsHelper.execute("systemctl stop xl2tpd")
 
+    def configure_l2tpIpsec(self, left, obj):
+        l2tpconffile = "%s/l2tp.conf" % (self.VPNCONFDIR)
+        vpnsecretfilte = "%s/ipsec.any.secrets" % (self.VPNCONFDIR)
+        xl2tpdconffile = "/etc/xl2tpd/xl2tpd.conf"
+        xl2tpoptionsfile = "/etc/ppp/options.xl2tpd"
 
-    def configure_l2tpIpsec(self, left,  obj):
-        l2tpconffile="%s/l2tp.conf" % (self.VPNCONFDIR)
-        vpnsecretfilte="%s/ipsec.any.secrets" % (self.VPNCONFDIR)
-        xl2tpdconffile="/etc/xl2tpd/xl2tpd.conf"
-        xl2tpoptionsfile='/etc/ppp/options.xl2tpd'
+        localip = obj['local_ip']
+        localcidr = obj['local_cidr']
+        publicIface = obj['public_interface']
+        iprange = obj['ip_range']
+        psk = obj['preshared_key']
 
-        localip=obj['local_ip']
-        localcidr=obj['local_cidr']
-        publicIface=obj['public_interface']
-        iprange=obj['ip_range']
-        psk=obj['preshared_key']
-
-        #left
+        # Left
         l2tpfile = CsFile(l2tpconffile)
         l2tpfile.addeq(" left=%s" % left)
         l2tpfile.commit()
@@ -704,19 +701,18 @@ class CsRemoteAccessVpn(CsDataBag):
         secret.commit()
 
         xl2tpdconf = CsFile(xl2tpdconffile)
-        xl2tpdconf.addeq("ip range = %s" %iprange)
-        xl2tpdconf.addeq("local ip = %s" %localip)
+        xl2tpdconf.addeq("ip range = %s" % iprange)
+        xl2tpdconf.addeq("local ip = %s" % localip)
         xl2tpdconf.commit()
 
-        xl2tpoptions=CsFile(xl2tpoptionsfile)
-        xl2tpoptions.search("ms-dns ", "ms-dns %s" %localip)
+        xl2tpoptions = CsFile(xl2tpoptionsfile)
+        xl2tpoptions.search("ms-dns ", "ms-dns %s" % localip)
         xl2tpoptions.commit()
 
     def remoteaccessvpn_iptables(self, publicip, obj):
-        publicdev=obj['public_interface']
-        localcidr=obj['local_cidr']
-        local_ip=obj['local_ip']
-
+        publicdev = obj['public_interface']
+        localcidr = obj['local_cidr']
+        local_ip = obj['local_ip']
 
         self.fw.append(["", "", "-A INPUT -i %s --dst %s -p udp -m udp --dport 
500 -j ACCEPT" % (publicdev, publicip)])
         self.fw.append(["", "", "-A INPUT -i %s --dst %s -p udp -m udp --dport 
4500 -j ACCEPT" % (publicdev, publicip)])
@@ -727,31 +723,30 @@ class CsRemoteAccessVpn(CsDataBag):
         self.fw.append(["", "", "-A OUTPUT -p esp -j ACCEPT"])
 
         if self.config.is_vpc():
-            self.fw.append(["", ""," -N VPN_FORWARD"])
-            self.fw.append(["", "","-I FORWARD -i ppp+ -j VPN_FORWARD"])
-            self.fw.append(["", "","-I FORWARD -o ppp+ -j VPN_FORWARD"])
-            self.fw.append(["", "","-I FORWARD -o ppp+ -j VPN_FORWARD"])
-            self.fw.append(["", "","-A VPN_FORWARD -s  %s -j RETURN" 
%localcidr])
-            self.fw.append(["", "","-A VPN_FORWARD -i ppp+ -d %s -j RETURN" 
%localcidr])
-            self.fw.append(["", "","-A VPN_FORWARD -i ppp+  -o ppp+ -j 
RETURN"])
+            self.fw.append(["", "", " -N VPN_FORWARD"])
+            self.fw.append(["", "", "-I FORWARD -i ppp+ -j VPN_FORWARD"])
+            self.fw.append(["", "", "-I FORWARD -o ppp+ -j VPN_FORWARD"])
+            self.fw.append(["", "", "-I FORWARD -o ppp+ -j VPN_FORWARD"])
+            self.fw.append(["", "", "-A VPN_FORWARD -s  %s -j RETURN" % 
localcidr])
+            self.fw.append(["", "", "-A VPN_FORWARD -i ppp+ -d %s -j RETURN" % 
localcidr])
+            self.fw.append(["", "", "-A VPN_FORWARD -i ppp+  -o ppp+ -j 
RETURN"])
         else:
-            self.fw.append(["", "","-A FORWARD -i ppp+ -o  ppp+ -j ACCEPT"])
-            self.fw.append(["", "","-A FORWARD -s %s -o  ppp+ -j ACCEPT" % 
localcidr])
-            self.fw.append(["", "","-A FORWARD -i ppp+ -d %s  -j ACCEPT" % 
localcidr])
+            self.fw.append(["", "", "-A FORWARD -i ppp+ -o  ppp+ -j ACCEPT"])
+            self.fw.append(["", "", "-A FORWARD -s %s -o  ppp+ -j ACCEPT" % 
localcidr])
+            self.fw.append(["", "", "-A FORWARD -i ppp+ -d %s  -j ACCEPT" % 
localcidr])
 
-
-        self.fw.append(["", "","-A INPUT -i ppp+ -m udp -p udp --dport 53 -j 
ACCEPT"])
-        self.fw.append(["", "","-A INPUT -i ppp+ -m tcp -p tcp --dport 53 -j 
ACCEPT"])
-        self.fw.append(["nat", "","-I PREROUTING -i ppp+ -m tcp --dport 53 -j 
DNAT --to-destination %s" % local_ip])
+        self.fw.append(["", "", "-A INPUT -i ppp+ -m udp -p udp --dport 53 -j 
ACCEPT"])
+        self.fw.append(["", "", "-A INPUT -i ppp+ -m tcp -p tcp --dport 53 -j 
ACCEPT"])
+        self.fw.append(["nat", "", "-I PREROUTING -i ppp+ -m tcp --dport 53 -j 
DNAT --to-destination %s" % local_ip])
 
         if self.config.is_vpc():
             return
 
-        self.fw.append(["mangle", "","-N  VPN_%s " %publicip])
-        self.fw.append(["mangle", "","-A VPN_%s -j RETURN " % publicip])
-        self.fw.append(["mangle", "","-I VPN_%s -p ah  -j ACCEPT " % publicip])
-        self.fw.append(["mangle", "","-I VPN_%s -p esp  -j ACCEPT " % 
publicip])
-        self.fw.append(["mangle", "","-I PREROUTING  -d %s -j VPN_%s " % 
(publicip, publicip)])
+        self.fw.append(["mangle", "", "-N  VPN_%s " % publicip])
+        self.fw.append(["mangle", "", "-A VPN_%s -j RETURN " % publicip])
+        self.fw.append(["mangle", "", "-I VPN_%s -p ah  -j ACCEPT " % 
publicip])
+        self.fw.append(["mangle", "", "-I VPN_%s -p esp  -j ACCEPT " % 
publicip])
+        self.fw.append(["mangle", "", "-I PREROUTING  -d %s -j VPN_%s " % 
(publicip, publicip)])
 
 
 class CsForwardingRules(CsDataBag):
@@ -766,7 +761,7 @@ class CsForwardingRules(CsDataBag):
                 elif rule["type"] == "staticnat":
                     self.processStaticNatRule(rule)
 
-    #return the VR guest interface ip
+    # Return the VR guest interface ip
     def getGuestIp(self):
         interfaces = []
         ipAddr = None
@@ -812,7 +807,7 @@ class CsForwardingRules(CsDataBag):
             self.forward_vr(rule)
 
     def forward_vr(self, rule):
-        #prefetch iptables variables
+        # Prefetch iptables variables
         public_fwinterface = self.getDeviceByIp(rule['public_ip'])
         internal_fwinterface = self.getDeviceByIp(rule['internal_ip'])
         public_fwports = self.portsToString(rule['public_ports'], ':')
@@ -928,10 +923,10 @@ class CsForwardingRules(CsDataBag):
             raise Exception("Ip address %s has no device in the ips databag" % 
rule["public_ip"])
 
         self.fw.append(["mangle", "",
-                        "-I PREROUTING -s %s/32 -m state --state NEW -j 
CONNMARK --save-mark --nfmask 0xffffffff --ctmask 0xffffffff" % \
+                        "-I PREROUTING -s %s/32 -m state --state NEW -j 
CONNMARK --save-mark --nfmask 0xffffffff --ctmask 0xffffffff" %
                         rule["internal_ip"]])
         self.fw.append(["mangle", "",
-                        "-I PREROUTING -s %s/32 -m state --state NEW -j MARK 
--set-xmark 0x%s/0xffffffff" % \
+                        "-I PREROUTING -s %s/32 -m state --state NEW -j MARK 
--set-xmark 0x%s/0xffffffff" %
                         (rule["internal_ip"], device[len("eth"):])])
         self.fw.append(["nat", "front",
                         "-A PREROUTING -d %s/32 -j DNAT --to-destination %s" % 
(rule["public_ip"], rule["internal_ip"])])
@@ -942,11 +937,12 @@ class CsForwardingRules(CsDataBag):
         self.fw.append(["filter", "",
                         "-A FORWARD -i %s -o eth0  -d %s  -m state  --state 
NEW -j ACCEPT " % (device, rule["internal_ip"])])
 
-        #configure the hairpin nat
+        # Configure the hairpin nat
         self.fw.append(["nat", "front",
                         "-A PREROUTING -d %s -i eth0 -j DNAT --to-destination 
%s" % (rule["public_ip"], rule["internal_ip"])])
 
-        self.fw.append(["nat", "front", "-A POSTROUTING -s %s -d %s -j SNAT -o 
eth0 --to-source %s" % 
(self.getNetworkByIp(rule['internal_ip']),rule["internal_ip"], 
self.getGuestIp())])
+        self.fw.append(["nat", "front", "-A POSTROUTING -s %s -d %s -j SNAT -o 
eth0 --to-source %s" %
+                        (self.getNetworkByIp(rule['internal_ip']), 
rule["internal_ip"], self.getGuestIp())])
 
 
 class IpTablesExecutor:
@@ -985,6 +981,7 @@ class IpTablesExecutor:
         CsHelper.save_iptables("iptables-save", 
"/etc/iptables/router_rules.v4")
         CsHelper.save_iptables("ip6tables-save", 
"/etc/iptables/router_rules.v6")
 
+
 def main(argv):
     # The file we are currently processing, if it is "cmd_line.json" 
everything will be processed.
     process_file = argv[1]
@@ -1008,21 +1005,21 @@ def main(argv):
     config.address().compare()
     config.address().process()
 
-    databag_map = OrderedDict([("guest_network",     {"process_iptables" : 
True,  "executor" : []}),
-                               ("vm_password",       {"process_iptables" : 
False, "executor" : [CsPassword("vmpassword", config)]}),
-                               ("vm_metadata",       {"process_iptables" : 
False, "executor" : [CsVmMetadata('vmdata', config)]}),
-                               ("network_acl",       {"process_iptables" : 
True,  "executor" : []}),
-                               ("firewall_rules",    {"process_iptables" : 
True,  "executor" : []}),
-                               ("forwarding_rules",  {"process_iptables" : 
True,  "executor" : []}),
-                               ("staticnat_rules",   {"process_iptables" : 
True,  "executor" : []}),
-                               ("site_2_site_vpn",   {"process_iptables" : 
True,  "executor" : []}),
-                               ("remote_access_vpn", {"process_iptables" : 
True,  "executor" : []}),
-                               ("vpn_user_list",     {"process_iptables" : 
False, "executor" : [CsVpnUser("vpnuserlist", config)]}),
-                               ("vm_dhcp_entry",     {"process_iptables" : 
False, "executor" : [CsDhcp("dhcpentry", config)]}),
-                               ("dhcp",              {"process_iptables" : 
False, "executor" : [CsDhcp("dhcpentry", config)]}),
-                               ("load_balancer",     {"process_iptables" : 
True,  "executor" : []}),
-                               ("monitor_service",   {"process_iptables" : 
False, "executor" : [CsMonitor("monitorservice", config)]}),
-                               ("static_routes",     {"process_iptables" : 
False, "executor" : [CsStaticRoutes("staticroutes", config)]})
+    databag_map = OrderedDict([("guest_network",     {"process_iptables": 
True,  "executor": []}),
+                               ("vm_password",       {"process_iptables": 
False, "executor": [CsPassword("vmpassword", config)]}),
+                               ("vm_metadata",       {"process_iptables": 
False, "executor": [CsVmMetadata('vmdata', config)]}),
+                               ("network_acl",       {"process_iptables": 
True,  "executor": []}),
+                               ("firewall_rules",    {"process_iptables": 
True,  "executor": []}),
+                               ("forwarding_rules",  {"process_iptables": 
True,  "executor": []}),
+                               ("staticnat_rules",   {"process_iptables": 
True,  "executor": []}),
+                               ("site_2_site_vpn",   {"process_iptables": 
True,  "executor": []}),
+                               ("remote_access_vpn", {"process_iptables": 
True,  "executor": []}),
+                               ("vpn_user_list",     {"process_iptables": 
False, "executor": [CsVpnUser("vpnuserlist", config)]}),
+                               ("vm_dhcp_entry",     {"process_iptables": 
False, "executor": [CsDhcp("dhcpentry", config)]}),
+                               ("dhcp",              {"process_iptables": 
False, "executor": [CsDhcp("dhcpentry", config)]}),
+                               ("load_balancer",     {"process_iptables": 
True,  "executor": []}),
+                               ("monitor_service",   {"process_iptables": 
False, "executor": [CsMonitor("monitorservice", config)]}),
+                               ("static_routes",     {"process_iptables": 
False, "executor": [CsStaticRoutes("staticroutes", config)]})
                                ])
 
     def execDatabag(key, db):
@@ -1052,6 +1049,7 @@ def main(argv):
 
     red = CsRedundant(config)
     red.set()
+    return 0
 
 if __name__ == "__main__":
     main(sys.argv)
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsAddress.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsAddress.py
index 3980b18..376e8ea 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsAddress.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsAddress.py
@@ -27,6 +27,7 @@ from CsRule import CsRule
 
 VRRP_TYPES = ['guest']
 
+
 class CsAddress(CsDataBag):
 
     def compare(self):
@@ -359,7 +360,6 @@ class CsIP:
         self.fw.append(["filter", "", "-P INPUT DROP"])
         self.fw.append(["filter", "", "-P FORWARD DROP"])
 
-
     def fw_router(self):
         if self.config.is_vpc():
             return
@@ -439,7 +439,7 @@ class CsIP:
 
         if self.get_type() in ["guest"]:
             self.fw.append(["mangle", "front", "-A PREROUTING " +
-                            " -i %s -m state --state RELATED,ESTABLISHED "  % 
self.dev +
+                            " -i %s -m state --state RELATED,ESTABLISHED " % 
self.dev +
                             "-j CONNMARK --restore-mark --nfmask 0xffffffff 
--ctmask 0xffffffff"])
             guestNetworkCidr = self.address['network']
             self.fw.append(["filter", "", "-A FORWARD -d %s -o %s -j 
ACL_INBOUND_%s" %
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsDatabag.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsDatabag.py
index 9ccb768..adb9a1a 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsDatabag.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsDatabag.py
@@ -136,8 +136,8 @@ class CsCmdLine(CsDataBag):
         This is slightly difficult to happen, but if it does, destroy the 
router with the password generated with the
         code below and restart the VPC with out the clean up option.
         '''
-        if(self.get_type()=='router'):
-            passwd="%s-%s" % (self.get_eth2_ip(), self.get_router_id())
+        if self.get_type() == 'router':
+            passwd = "%s-%s" % (self.get_eth2_ip(), self.get_router_id())
         else:
             passwd = "%s-%s" % (self.get_vpccidr(), self.get_router_id())
         md5 = hashlib.md5()
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsDhcp.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsDhcp.py
index b645679..6680b94 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsDhcp.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsDhcp.py
@@ -135,13 +135,13 @@ class CsDhcp(CsDataBag):
         # with a splay of 60 hours to prevent storms
         lease = randint(700, 760)
 
-        if entry['default_entry'] == True:
+        if entry['default_entry']:
             self.cloud.add("%s,%s,%s,%sh" % (entry['mac_address'],
                                              entry['ipv4_adress'],
                                              entry['host_name'],
                                              lease))
         else:
-            tag = entry['ipv4_adress'].replace(".","_")
+            tag = entry['ipv4_adress'].replace(".", "_")
             self.cloud.add("%s,set:%s,%s,%s,%sh" % (entry['mac_address'],
                                                     tag,
                                                     entry['ipv4_adress'],
@@ -159,6 +159,5 @@ class CsDhcp(CsDataBag):
                 # Virtual Router
                 v['gateway'] = entry['default_gateway']
 
-
     def add_host(self, ip, hosts):
         self.hosts[ip] = hosts
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsFile.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsFile.py
index 334e631..b0a2591 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsFile.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsFile.py
@@ -67,7 +67,6 @@ class CsFile:
         self.config = list(self.new_config)
         logging.info("Updated file in-cache configuration")
 
-
     def dump(self):
         for line in self.new_config:
             print line
@@ -134,13 +133,12 @@ class CsFile:
             return True
         return False
 
-
     def searchString(self, search, ignoreLinesStartWith):
         found = False
         logging.debug("Searching for %s string " % search)
 
         for index, line in enumerate(self.new_config):
-            print ' line = ' +line
+            print ' line = ' + line
             if line.lstrip().startswith(ignoreLinesStartWith):
                 continue
             if search in line:
@@ -149,7 +147,6 @@ class CsFile:
 
         return found
 
-
     def deleteLine(self, search):
         found = False
         logging.debug("Searching for %s to remove the line " % search)
@@ -162,7 +159,6 @@ class CsFile:
 
         self.new_config = list(temp_config)
 
-
     def compare(self, o):
         result = (isinstance(o, self.__class__) and set(self.config) == 
set(o.config))
         logging.debug("Comparison of CsFiles content is ==> %s" % result)
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsGuestNetwork.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsGuestNetwork.py
index d23a870..9a94dc6 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsGuestNetwork.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsGuestNetwork.py
@@ -40,7 +40,7 @@ class CsGuestNetwork:
             return self.config.get_dns()
 
         dns = []
-        if not self.config.use_extdns() and 'router_guest_gateway' in 
self.data:
+        if 'router_guest_gateway' in self.data and not 
self.config.use_extdns():
             dns.append(self.data['router_guest_gateway'])
 
         if 'dns' in self.data:
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsHelper.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsHelper.py
index 7ff32ee..ad8480d 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsHelper.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsHelper.py
@@ -21,16 +21,18 @@ for use in the configuration process
 """
 import subprocess
 import logging
+import sys
 import os.path
 import re
 import shutil
 from netaddr import *
 from pprint import pprint
 
-PUBLIC_INTERFACES = {"router" : "eth2", "vpcrouter" : "eth1"}
+PUBLIC_INTERFACES = {"router": "eth2", "vpcrouter": "eth1"}
+
+STATE_COMMANDS = {"router": "ip addr | grep eth0 | grep inet | wc -l | xargs 
bash -c  'if [ $0 == 2 ]; then echo \"MASTER\"; else echo \"BACKUP\"; fi'",
+                  "vpcrouter": "ip addr | grep eth1 | grep state | awk '{print 
$9;}' | xargs bash -c 'if [ $0 == \"UP\" ]; then echo \"MASTER\"; else echo 
\"BACKUP\"; fi'"}
 
-STATE_COMMANDS = {"router" : "ip addr | grep eth0 | grep inet | wc -l | xargs 
bash -c  'if [ $0 == 2 ]; then echo \"MASTER\"; else echo \"BACKUP\"; fi'",
-                  "vpcrouter" : "ip addr | grep eth1 | grep state | awk 
'{print $9;}' | xargs bash -c 'if [ $0 == \"UP\" ]; then echo \"MASTER\"; else 
echo \"BACKUP\"; fi'"}
 
 def reconfigure_interfaces(router_config, interfaces):
     for interface in interfaces:
@@ -52,6 +54,7 @@ def reconfigure_interfaces(router_config, interfaces):
                 else:
                     execute(cmd)
 
+
 def is_mounted(name):
     for i in execute("mount"):
         vals = i.lstrip().split()
@@ -242,6 +245,7 @@ def copy_if_needed(src, dest):
         return
     copy(src, dest)
 
+
 def copy(src, dest):
     """
     copy source to destination.
@@ -249,6 +253,6 @@ def copy(src, dest):
     try:
         shutil.copy2(src, dest)
     except IOError:
-        logging.Error("Could not copy %s to %s" % (src, dest))
+        logging.error("Could not copy %s to %s" % (src, dest))
     else:
         logging.info("Copied %s to %s" % (src, dest))
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsNetfilter.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsNetfilter.py
index 035125e..c3c7962 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsNetfilter.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsNetfilter.py
@@ -143,7 +143,7 @@ class CsNetfilters(object):
         # PASS 2: Create rules
         for fw in list:
             tupledFw = tuple(fw)
-            if tupledFw in ruleSet :
+            if tupledFw in ruleSet:
                 logging.debug("Already processed : %s", tupledFw)
                 continue
 
@@ -173,12 +173,12 @@ class CsNetfilters(object):
                     else:
                         cpy = cpy.replace("-A %s" % new_rule.get_chain(), '-I 
%s %s' % (new_rule.get_chain(), fw[1]))
                 ret = CsHelper.execute2("iptables -t %s %s" % 
(new_rule.get_table(), cpy))
-                #There are some issues in this framework causing failures  .. 
like adding a chain without checking it is present causing
+                # There are some issues in this framework causing failures  .. 
like adding a chain without checking it is present causing
                 # the failures. Also some of the rule like 
removeFromLoadBalancerRule is deleting rule and deleteLoadBalancerRule
-                #trying to delete which causes the failure.
-                #For now raising the log.
-                #TODO: Need to fix in the framework.
-                if ret.returncode != 0 :
+                # trying to delete which causes the failure.
+                # For now raising the log.
+                # TODO: Need to fix in the framework.
+                if ret.returncode != 0:
                     error = ret.communicate()[0]
                     logging.debug("iptables command got failed ... continuing")
                 ruleSet.add(tupledFw)
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsRedundant.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsRedundant.py
index 71c4eba..d3acb44 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsRedundant.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsRedundant.py
@@ -42,6 +42,7 @@ from CsStaticRoutes import CsStaticRoutes
 import socket
 from time import sleep
 
+
 class CsRedundant(object):
 
     CS_RAMDISK_DIR = "/ramdisk"
@@ -74,10 +75,6 @@ class CsRedundant(object):
     def _redundant_off(self):
         CsHelper.service("conntrackd", "stop")
         CsHelper.service("keepalived", "stop")
-        #CsHelper.umount_tmpfs(self.CS_RAMDISK_DIR)
-        #CsHelper.rmdir(self.CS_RAMDISK_DIR)
-        #CsHelper.rm(self.CONNTRACKD_CONF)
-        #CsHelper.rm(self.KEEPALIVED_CONF)
 
     def _redundant_on(self):
         return
@@ -111,9 +108,10 @@ class CsRedundant(object):
             CsHelper.service("keepalived", "stop")
             return
 
-        #CsHelper.mkdir(self.CS_RAMDISK_DIR, 0755, False)
-        #CsHelper.mount_tmpfs(self.CS_RAMDISK_DIR)
-        #CsHelper.mkdir(self.CS_ROUTER_DIR, 0755, False)
+        # setup_router should execute this already:
+        # CsHelper.mkdir(self.CS_RAMDISK_DIR, 0755, False)
+        # CsHelper.mount_tmpfs(self.CS_RAMDISK_DIR)
+        # CsHelper.mkdir(self.CS_ROUTER_DIR, 0755, False)
         for s in self.CS_TEMPLATES:
             d = s
             if s.endswith(".templ"):
@@ -372,10 +370,10 @@ class CsRedundant(object):
         lines = []
         for interface in self.address.get_interfaces():
             if interface.needs_vrrp():
-                cmdline=self.config.get_cmdline_instance()
+                cmdline = self.config.get_cmdline_instance()
                 if not interface.is_added():
                     continue
-                if(cmdline.get_type()=='router'):
+                if cmdline.get_type() == 'router':
                     str = "        %s brd %s dev %s\n" % 
(cmdline.get_guest_gw(), interface.get_broadcast(), interface.get_device())
                 else:
                     str = "        %s brd %s dev %s\n" % 
(interface.get_gateway_cidr(), interface.get_broadcast(), 
interface.get_device())
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsRoute.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsRoute.py
index 56096c8..02cc881 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsRoute.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsRoute.py
@@ -34,14 +34,13 @@ class CsRoute:
         tablename = self.get_tablename(devicename)
         str = "%s %s" % (tablenumber, tablename)
         filename = "/etc/iproute2/rt_tables"
-        logging.info(
-            "Adding route table: " + str + " to " + filename + " if not 
present ")
+        logging.info("Adding route table: " + str + " to " + filename + " if 
not present ")
         if not CsHelper.definedinfile(filename, str):
-             CsHelper.execute("sudo echo " + str + " >> 
/etc/iproute2/rt_tables")
+            CsHelper.execute("sudo echo " + str + " >> 
/etc/iproute2/rt_tables")
         # remove "from all table tablename" if exists, else it will interfer 
with
         # routing of unintended traffic
         if self.findRule("from all lookup " + tablename):
-             CsHelper.execute("sudo ip rule delete from all table " + 
tablename)
+            CsHelper.execute("sudo ip rule delete from all table " + tablename)
 
     def flush_table(self, tablename):
         CsHelper.execute("ip route flush table %s" % (tablename))
@@ -115,4 +114,4 @@ class CsRoute:
         for i in CsHelper.execute("ip rule show"):
             if rule in i.strip():
                 return True
-        return False
\ No newline at end of file
+        return False
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs/CsRule.py 
b/systemvm/patches/debian/opt/cloud/bin/cs/CsRule.py
index 9c48768..85953fe 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs/CsRule.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs/CsRule.py
@@ -49,7 +49,7 @@ class CsRule:
             logging.info("Added fwmark rule for %s" % (self.table))
 
     def delMark(self):
-        if  self.findMark():
+        if self.findMark():
             cmd = "ip rule delete fwmark %s table %s" % (self.tableNo, 
self.table)
             CsHelper.execute(cmd)
             logging.info("Deleting fwmark rule for %s" % (self.table))
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs_ip.py 
b/systemvm/patches/debian/opt/cloud/bin/cs_ip.py
index f83bf29..1e7b326 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs_ip.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs_ip.py
@@ -18,6 +18,7 @@
 
 from netaddr import *
 
+
 def merge(dbag, ip):
     nic_dev_id = None
     for dev in dbag:
@@ -31,7 +32,7 @@ def merge(dbag, ip):
 
     ipo = IPNetwork(ip['public_ip'] + '/' + ip['netmask'])
     if 'nic_dev_id' in ip:
-         nic_dev_id = ip['nic_dev_id']
+        nic_dev_id = ip['nic_dev_id']
     ip['device'] = 'eth' + str(nic_dev_id)
     ip['broadcast'] = str(ipo.broadcast)
     ip['cidr'] = str(ipo.ip) + '/' + str(ipo.prefixlen)
@@ -45,7 +46,7 @@ def merge(dbag, ip):
         dbag[ip['device']] = [ip]
     else:
         if 'source_nat' in ip and ip['source_nat'] and ip['device'] in dbag 
and len(dbag[ip['device']]) > 0:
-            dbag[ip['device']].insert(0, ip) # make sure the source_nat ip is 
first (primary) on the device
+            dbag[ip['device']].insert(0, ip)  # Make sure the source_nat ip is 
first (primary) on the device
         else:
             dbag.setdefault(ip['device'], []).append(ip)
 
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs_vmp.py 
b/systemvm/patches/debian/opt/cloud/bin/cs_vmp.py
index 7873fe8..d0169f7 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs_vmp.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs_vmp.py
@@ -18,6 +18,7 @@
 from pprint import pprint
 from netaddr import *
 
+
 def merge(dbag, data):
     """
     create a dictionary of values new in data ignoring those in dbag and 
return it
diff --git a/systemvm/patches/debian/opt/cloud/bin/cs_vpnusers.py 
b/systemvm/patches/debian/opt/cloud/bin/cs_vpnusers.py
index 316fabc..8dc4548 100755
--- a/systemvm/patches/debian/opt/cloud/bin/cs_vpnusers.py
+++ b/systemvm/patches/debian/opt/cloud/bin/cs_vpnusers.py
@@ -38,8 +38,8 @@ def merge(dbag, data):
             del(dbagc[user])
 
     for user in data['vpn_users']:
-        username=user['user']
-        add=user['add']
+        username = user['user']
+        add = user['add']
         if username not in dbagc.keys():
             dbagc[username] = user
         elif username in dbagc.keys() and not add:
diff --git a/systemvm/patches/debian/opt/cloud/bin/master.py 
b/systemvm/patches/debian/opt/cloud/bin/master.py
index 3d1dcd7..26de8b9 100755
--- a/systemvm/patches/debian/opt/cloud/bin/master.py
+++ b/systemvm/patches/debian/opt/cloud/bin/master.py
@@ -42,7 +42,7 @@ logging.basicConfig(filename=config.get_logger(),
                     format=config.get_format())
 config.cmdline()
 cl = CsCmdLine("cmdline", config)
-#Update the configuration to set state as backup and let keepalived decide who 
the real Master is!
+# Update the configuration to set state as backup and let keepalived decide 
who the real Master is!
 cl.set_master_state(False)
 cl.save()
 
diff --git a/systemvm/patches/debian/opt/cloud/bin/merge.py 
b/systemvm/patches/debian/opt/cloud/bin/merge.py
index ef20d0b..0aaa340 100755
--- a/systemvm/patches/debian/opt/cloud/bin/merge.py
+++ b/systemvm/patches/debian/opt/cloud/bin/merge.py
@@ -271,6 +271,7 @@ class updateDataBag:
             dbag = cs_ip.merge(dbag, ip)
         return dbag
 
+
 class QueueFile:
 
     fileName = ''
@@ -284,15 +285,15 @@ class QueueFile:
             self.type = self.data["type"]
             updateDataBag(self)
             return
-        filename = '{cache_location}/{json_file}'.format(cache_location = 
self.configCache, json_file = self.fileName)
+        filename = 
'{cache_location}/{json_file}'.format(cache_location=self.configCache, 
json_file=self.fileName)
         try:
             handle = open(filename)
         except IOError as exception:
-            error_message = ("Exception occurred with the following exception 
error '{error}'. Could not open '{file}'. "
-                             "It seems that the file has already been 
moved.".format(error = exception, file = filename))
+            error_message = ("Exception occurred with the following exception 
error '{error}'. Could not open '{filename}'. "
+                             "It seems that the file has already been 
moved.".format(error=exception, filename=filename))
             logging.error(error_message)
         else:
-            logging.info("Continuing with the processing of file 
'{file}'".format(file = filename))
+            logging.info("Continuing with the processing of file 
'{filename}'".format(filename=filename))
 
             self.data = json.load(handle)
             self.type = self.data["type"]
@@ -331,7 +332,6 @@ class QueueFile:
 
 class PrivateGatewayHack:
 
-
     @classmethod
     def update_network_type_for_privategateway(cls, dbag, data):
         ip = data['router_guest_ip'] if 'router_guest_ip' in data.keys() else 
data['public_ip']
@@ -347,12 +347,10 @@ class PrivateGatewayHack:
             logging.debug("Not updating nw_type for ip %s because 
has_private_gw_ip = %s and private_gw_matches = %s " % (ip, has_private_gw_ip, 
private_gw_matches))
         return data
 
-
     @classmethod
     def if_config_has_privategateway(cls, dbag):
         return 'privategateway' in dbag['config'].keys() and 
dbag['config']['privategateway'] != "None"
 
-
     @classmethod
     def ip_matches_private_gateway_ip(cls, ip, private_gateway_ip):
         new_ip_matches_private_gateway_ip = False
@@ -360,7 +358,6 @@ class PrivateGatewayHack:
             new_ip_matches_private_gateway_ip = True
         return new_ip_matches_private_gateway_ip
 
-
     @classmethod
     def load_inital_data(cls):
         initial_data_bag = DataBag()
diff --git a/systemvm/patches/debian/opt/cloud/bin/set_redundant.py 
b/systemvm/patches/debian/opt/cloud/bin/set_redundant.py
index 7a8dad0..c0431c5 100755
--- a/systemvm/patches/debian/opt/cloud/bin/set_redundant.py
+++ b/systemvm/patches/debian/opt/cloud/bin/set_redundant.py
@@ -37,11 +37,13 @@ config = CsConfig()
 logging.basicConfig(filename=config.get_logger(),
                     level=config.get_level(),
                     format=config.get_format())
-config.set_cl()
+
+# Commented following as set_cl() is not defined
+# config.set_cl()
 
 if options.enable:
-    config.get_cmdline().set_redundant("true")
+    config.cmdline().set_redundant("true")
 if options.disable:
-    config.get_cmdline().set_redundant("false")
+    config.cmdline().set_redundant("false")
 
-config.get_cmdline().save()
+config.cmdline().save()
diff --git a/systemvm/patches/debian/opt/cloud/bin/vmdata.py 
b/systemvm/patches/debian/opt/cloud/bin/vmdata.py
index b9127a1..65f5278 100755
--- a/systemvm/patches/debian/opt/cloud/bin/vmdata.py
+++ b/systemvm/patches/debian/opt/cloud/bin/vmdata.py
@@ -159,7 +159,7 @@ def exflock(file):
 def unflock(file):
     try:
         flock(file, LOCK_UN)
-    except IOError:
+    except IOError as e:
         print "failed to unlock file" + file.name + " due to : " + e.strerror
         sys.exit(1)
     return True
diff --git a/systemvm/patches/test/TestCsAddress.py 
b/systemvm/test/TestCsAddress.py
similarity index 100%
rename from systemvm/patches/test/TestCsAddress.py
rename to systemvm/test/TestCsAddress.py
diff --git a/systemvm/patches/test/TestCsApp.py b/systemvm/test/TestCsApp.py
similarity index 100%
rename from systemvm/patches/test/TestCsApp.py
rename to systemvm/test/TestCsApp.py
diff --git a/systemvm/patches/test/TestCsCmdLine.py 
b/systemvm/test/TestCsCmdLine.py
similarity index 100%
rename from systemvm/patches/test/TestCsCmdLine.py
rename to systemvm/test/TestCsCmdLine.py
diff --git a/systemvm/patches/test/TestCsConfig.py 
b/systemvm/test/TestCsConfig.py
similarity index 100%
rename from systemvm/patches/test/TestCsConfig.py
rename to systemvm/test/TestCsConfig.py
diff --git a/systemvm/patches/test/TestCsDatabag.py 
b/systemvm/test/TestCsDatabag.py
similarity index 100%
rename from systemvm/patches/test/TestCsDatabag.py
rename to systemvm/test/TestCsDatabag.py
diff --git a/systemvm/patches/test/TestCsDhcp.py b/systemvm/test/TestCsDhcp.py
similarity index 100%
rename from systemvm/patches/test/TestCsDhcp.py
rename to systemvm/test/TestCsDhcp.py
diff --git a/systemvm/patches/test/TestCsFile.py b/systemvm/test/TestCsFile.py
similarity index 100%
rename from systemvm/patches/test/TestCsFile.py
rename to systemvm/test/TestCsFile.py
diff --git a/systemvm/patches/test/TestCsGuestNetwork.py 
b/systemvm/test/TestCsGuestNetwork.py
similarity index 94%
rename from systemvm/patches/test/TestCsGuestNetwork.py
rename to systemvm/test/TestCsGuestNetwork.py
index 08a6b37..06e2d16 100644
--- a/systemvm/patches/test/TestCsGuestNetwork.py
+++ b/systemvm/test/TestCsGuestNetwork.py
@@ -17,6 +17,7 @@
 
 import unittest
 from cs.CsGuestNetwork import CsGuestNetwork
+from cs.CsConfig import CsConfig
 import merge
 
 
@@ -30,7 +31,7 @@ class TestCsGuestNetwork(unittest.TestCase):
         self.assertTrue(csguestnetwork is not None)
 
     def test_get_dns(self):
-        csguestnetwork = CsGuestNetwork({}, {})
+        csguestnetwork = CsGuestNetwork({}, CsConfig())
         csguestnetwork.guest = True
         csguestnetwork.set_dns("1.1.1.1,2.2.2.2")
         csguestnetwork.set_router("3.3.3.3")
diff --git a/systemvm/patches/test/TestCsHelper.py 
b/systemvm/test/TestCsHelper.py
similarity index 100%
rename from systemvm/patches/test/TestCsHelper.py
rename to systemvm/test/TestCsHelper.py
diff --git a/systemvm/patches/test/TestCsInterface.py 
b/systemvm/test/TestCsInterface.py
similarity index 100%
rename from systemvm/patches/test/TestCsInterface.py
rename to systemvm/test/TestCsInterface.py
diff --git a/systemvm/patches/test/TestCsNetfilter.py 
b/systemvm/test/TestCsNetfilter.py
similarity index 100%
rename from systemvm/patches/test/TestCsNetfilter.py
rename to systemvm/test/TestCsNetfilter.py
diff --git a/systemvm/patches/test/TestCsProcess.py 
b/systemvm/test/TestCsProcess.py
similarity index 100%
rename from systemvm/patches/test/TestCsProcess.py
rename to systemvm/test/TestCsProcess.py
diff --git a/systemvm/patches/test/TestCsRedundant.py 
b/systemvm/test/TestCsRedundant.py
similarity index 100%
rename from systemvm/patches/test/TestCsRedundant.py
rename to systemvm/test/TestCsRedundant.py
diff --git a/systemvm/patches/test/TestCsRoute.py b/systemvm/test/TestCsRoute.py
similarity index 87%
rename from systemvm/patches/test/TestCsRoute.py
rename to systemvm/test/TestCsRoute.py
index 6035258..f9982fe 100644
--- a/systemvm/patches/test/TestCsRoute.py
+++ b/systemvm/test/TestCsRoute.py
@@ -31,11 +31,12 @@ class TestCsRoute(unittest.TestCase):
 
     def test_defaultroute_exists(self):
         csroute = CsRoute()
-        self.assertFalse(csroute.defaultroute_exists())
+        self.assertTrue(csroute.defaultroute_exists())
 
     def test_add_defaultroute(self):
         csroute = CsRoute()
-        self.assertTrue(csroute.add_defaultroute("192.168.1.1"))
+        # Default route would exist on any test environment with network
+        self.assertFalse(csroute.add_defaultroute("192.168.1.1"))
 
     def test_get_tablename(self):
         csroute = CsRoute()
diff --git a/systemvm/patches/test/TestCsRule.py b/systemvm/test/TestCsRule.py
similarity index 100%
rename from systemvm/patches/test/TestCsRule.py
rename to systemvm/test/TestCsRule.py
diff --git a/systemvm/patches/test/runtests.sh b/systemvm/test/runtests.sh
similarity index 64%
rename from systemvm/patches/test/runtests.sh
rename to systemvm/test/runtests.sh
index e64f867..3b62eee 100644
--- a/systemvm/patches/test/runtests.sh
+++ b/systemvm/test/runtests.sh
@@ -18,10 +18,27 @@
 
 # requires netaddr
 
-export PYTHONPATH="../debian/opt/cloud/bin/"
+export PYTHONPATH="../patches/debian/opt/cloud/bin/"
 export PYTHONDONTWRITEBYTECODE=False
 
-pep8 --max-line-length=179 
--exclude=monitorServices.py,baremetal-vr.py,passwd_server_ip.py `find 
../../patches -name \*.py`
+echo "Running pep8 to check systemvm/python code for errors"
 pep8 --max-line-length=179 *py
+pep8 --max-line-length=179 
--exclude=monitorServices.py,baremetal-vr.py,passwd_server_ip.py `find 
../patches -name \*.py`
+if [ $? -gt 0 ]
+then
+    echo "Pylint failed, please check your code"
+    exit 1
+fi
 
+echo "Running pylint to check systemvm/python code for errors"
+pylint --disable=R,C,W *.py
+pylint --disable=R,C,W `find ../patches -name \*.py`
+if [ $? -gt 0 ]
+then
+    echo "Pylint failed, please check your code"
+    exit 1
+fi
+
+echo "Running systemvm/python unit tests"
 nosetests .
+exit $?
diff --git a/tools/travis/before_install.sh b/tools/travis/before_install.sh
index 409bf8a..2333ad9 100755
--- a/tools/travis/before_install.sh
+++ b/tools/travis/before_install.sh
@@ -100,7 +100,7 @@ pip install --user --upgrade pip
 
 for ((i=0;i<$RETRY_COUNT;i++))
 do
-  pip install --user --upgrade lxml paramiko nose texttable ipmisim pyopenssl 
> /tmp/piplog
+  pip install --user --upgrade lxml paramiko nose texttable ipmisim pyopenssl 
flask netaddr pylint pep8 > /tmp/piplog
   if [[ $? -eq 0 ]]; then
     echo -e "\npython packages installed successfully"
     break;
diff --git a/tools/travis/install.sh b/tools/travis/install.sh
index d759528..f1ef4f1 100755
--- a/tools/travis/install.sh
+++ b/tools/travis/install.sh
@@ -25,9 +25,13 @@ export MAVEN_OPTS="-Xmx4096m -XX:MaxPermSize=800m 
-Djava.security.egd=file:/dev/
 set -e
 
 if [ $TEST_SEQUENCE_NUMBER -eq 1 ]; then
+   # Pylint/pep8 systemvm python codebase
+   cd systemvm/test && bash -x runtests.sh && cd ..
+   # Build noredist
    git clone https://github.com/rhtyd/cloudstack-nonoss.git nonoss
    cd nonoss && bash -x install-non-oss.sh && cd ..
    git clean -fdx .
+   # Perform rat checks
    mvn -P developer,systemvm -Dsimulator -Dnoredist 
--projects='org.apache.cloudstack:cloudstack' 
org.apache.rat:apache-rat-plugin:0.12:check
    mvn -q -B -P developer,systemvm -Dsimulator -Dnoredist clean install
 else

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to