Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions systemvm/patches/debian/buildsystemvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ vpn_config() {
cp -r ${scriptdir}/vpn/* ./
}

#
# IMPORTANT REMARK
# Package intallation is no longer done via this script. We are not removing the code yet, but we want to
# make sure that everybody willing to install/update packages should refer to the file:
# ==> cloud-tools/appliance/definitions/systemvmtemplate/install_systemvm_packages.sh
#
packages() {
DEBIAN_FRONTEND=noninteractive
DEBIAN_PRIORITY=critical
Expand Down Expand Up @@ -375,8 +381,10 @@ packages() {
chroot . apt-get --no-install-recommends -q -y --force-yes install open-vm-tools
#xenstore utils
chroot . apt-get --no-install-recommends -q -y --force-yes install xenstore-utils libxenstore3.0
#keepalived and conntrackd
chroot . apt-get --no-install-recommends -q -y --force-yes install keepalived conntrackd ipvsadm libnetfilter-conntrack3 libnl1
#keepalived - install version 1.2.13 from wheezy backports
chroot . apt-get --no-install-recommends -q -y --force-yes -t wheezy-backports install keepalived

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any package related change needs to go into: tools/appliance/definitions/systemvmtemplate/install_systemvm_packages.sh
AFAIK, this buildsystemvm script is not used or maintained by anyone

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, @bhaisaab . I blindly trusted the script and did not check the version before. I just created a rVPC and checked the router to confirm that the version was not updated. I will fix that one, test and push to the PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed with @wilderrodrigues : will add a note in this PR that this file is being phased out

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the following not to the file and will push it to the PR:

IMPORTANT REMARK
Package intallation is no longer done via this script. We are not removing the code yet, but we want to
make sure that everybody willing to install/update packages should refer to the file:
==> cloud-tools/appliance/definitions/systemvmtemplate/install_systemvm_packages.sh

Is it good enough?

Cheers,
Wilder

#conntrackd
chroot . apt-get --no-install-recommends -q -y --force-yes install conntrackd ipvsadm libnetfilter-conntrack3 libnl1
#ipcalc
chroot . apt-get --no-install-recommends -q -y --force-yes install ipcalc
#irqbalance from wheezy-backports
Expand Down
9 changes: 0 additions & 9 deletions systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ def get_gateway(self):
return self.get_attr("gateway")
else:
return self.config.cmdline().get_guest_gw()
# if self.config.cmdline().is_redundant():
# return self.config.cmdline().get_guest_gw()
# else:
# return self.get_ip()

def ip_in_subnet(self, ip):
ipo = IPAddress(ip)
Expand Down Expand Up @@ -410,10 +406,6 @@ def fw_vpcrouter(self):
])

if self.get_type() in ["public"]:
# self.fw.append(["nat", "front",
# "-A POSTROUTING -o %s -j SNAT --to-source %s" %
# (self.dev, self.address['public_ip'])
# ])
self.fw.append(["", "front",
"-A FORWARD -o %s -d %s -j ACL_INBOUND_%s" % (self.dev, self.address['network'], self.dev)
])
Expand Down Expand Up @@ -457,7 +449,6 @@ def post_config_change(self, method):
vpccidr = self.config.cmdline().get_vpccidr()
self.fw.append(["filter", "", "-A FORWARD -s %s ! -d %s -j ACCEPT" % (vpccidr, vpccidr)])
self.fw.append(["nat", "", "-A POSTROUTING -j SNAT -o %s --to-source %s" % (self.dev, self.address['public_ip'])])
# route.flush()

def list(self):
self.iplist = {}
Expand Down
8 changes: 0 additions & 8 deletions systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ def idata(self):
self.dbag['config'] = {}
return self.dbag['config']

def get_priority(self):
if "router_pr" in self.idata():
return self.idata()['router_pr']
return 99

def set_guest_gw(self, val):
self.idata()['guestgw'] = val

Expand All @@ -70,9 +65,6 @@ def get_guest_gw(self):
return self.idata()['guestgw']
return False

def set_priority(self, val):
self.idata()['router_pr'] = val

def is_redundant(self):
if "redundant_router" in self.idata():
return self.idata()['redundant_router'] == "true"
Expand Down
4 changes: 2 additions & 2 deletions systemvm/patches/debian/config/opt/cloud/bin/cs/CsFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ def load(self):
self.new_config.append(line)
except IOError:
logging.debug("File %s does not exist" % self.filename)
return
else:
logging.debug("Reading file %s" % self.filename)
self.config = copy.deepcopy(self.new_config)
self.config = list(self.new_config)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy.deepcopy may be a necessary evil, if the list new_config contains objects. I wrote an example to test this: https://gist.github.com/bhaisaab/fe85fb02e1a7fda2fd2d

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the way you put it, accessing the indexes, it changes both probably due to some reference. However, if one adds some other cases - mainly the uso of append(), as we have - you will see that it works. Check below:

a = 1
b = [1,2,3]
c = "some random string :)"
z = [a,b,c]
x = list(z)
x[1][1] = 100
print x
[1, [1, 100, 3], 'some random string :)']
print z
[1, [1, 100, 3], 'some random string :)']
z = []
print z
[]
print x
[1, [1, 100, 3], 'some random string :)']
z.append(1)
print x
[1, [1, 100, 3], 'some random string :)']
print z
[1]

Now, to show our complete use-case here:

for l in file:
new_config.append(l)

config = list(new_config)

Laters, for every new config item, we do:

new_config.append(x)
or
new_config.insert(index, item)

By using those operations we won't change the "config" variable.

Another example:

x = [1,2,3]
z = list(x)
z.insert(1,5)
z
[1, 5, 2, 3]
x
[1, 2, 3]
z.append(10)
z
[1, 5, 2, 3, 10]
x
[1, 2, 3]

What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, as I mentioned in my comment if the list contains (references to) other objects then only copy.deepcopy should be used. I was not clear about the usage, after reading the code I think it would work since we're working with list of strings (read from file), followed by append/insert operations; list() would be indeed faster than copy.deepcopy in this case as well.


def is_changed(self):
if set(self.config) != set(self.new_config):
Expand All @@ -58,6 +57,7 @@ def repopulate(self):

def commit(self):
if not self.is_changed():
logging.info("Nothing to commit. The %s file did not change" % self.filename)
return
handle = open(self.filename, "w+")
for line in self.new_config:
Expand Down
76 changes: 36 additions & 40 deletions systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,19 @@ def _redundant_on(self):

CsHelper.execute('sed -i "s/--exec\ \$DAEMON;/--exec\ \$DAEMON\ --\ --vrrp;/g" /etc/init.d/keepalived')
# checkrouter.sh configuration
file = CsFile("/opt/cloud/bin/checkrouter.sh")
file.greplace("[RROUTER_LOG]", self.RROUTER_LOG)
file.commit()
check_router = CsFile("/opt/cloud/bin/checkrouter.sh")
check_router.greplace("[RROUTER_LOG]", self.RROUTER_LOG)
check_router.commit()

# keepalived configuration
file = CsFile(self.KEEPALIVED_CONF)
ads = [o for o in self.address.get_ips() if o.is_public()]
# Add a comment for each public IP. If any change this will cause keepalived to restart
# As things stand keepalived will be configured before the IP is added or deleted
i = 0
for o in ads:
file.addeq("! %s=%s" % (i, o.get_cidr()))
i = i + 1
file.search(" router_id ", " router_id %s" % self.cl.get_name())
file.search(" priority ", " priority %s" % self.cl.get_priority())
file.search(" interface ", " interface %s" % guest.get_device())
file.search(" state ", " state %s" % "EQUAL")
file.search(" virtual_router_id ", " virtual_router_id %s" % self.cl.get_router_id())
file.greplace("[RROUTER_BIN_PATH]", self.CS_ROUTER_DIR)
file.section("authentication {", "}", [" auth_type AH \n", " auth_pass %s\n" % self.cl.get_router_password()])
file.section("virtual_ipaddress {", "}", self._collect_ips())
file.commit()
keepalived_conf = CsFile(self.KEEPALIVED_CONF)
keepalived_conf.search(" router_id ", " router_id %s" % self.cl.get_name())
keepalived_conf.search(" interface ", " interface %s" % guest.get_device())
keepalived_conf.search(" virtual_router_id ", " virtual_router_id %s" % self.cl.get_router_id())
keepalived_conf.greplace("[RROUTER_BIN_PATH]", self.CS_ROUTER_DIR)
keepalived_conf.section("authentication {", "}", [" auth_type AH \n", " auth_pass %s\n" % self.cl.get_router_password()])
keepalived_conf.section("virtual_ipaddress {", "}", self._collect_ips())
keepalived_conf.commit()

# conntrackd configuration
connt = CsFile(self.CONNTRACKD_CONF)
Expand All @@ -141,18 +132,30 @@ def _redundant_on(self):
if connt.is_changed():
CsHelper.service("conntrackd", "restart")

if file.is_changed():
CsHelper.service("keepalived", "reload")
# Configure heartbeat cron job - runs every 30 seconds
heartbeat_cron = CsFile("/etc/cron.d/heartbeat")
heartbeat_cron.add("SHELL=/bin/bash", 0)
heartbeat_cron.add("PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin", 1)
heartbeat_cron.add("* * * * * root $SHELL %s/check_heartbeat.sh 2>&1 > /dev/null" % self.CS_ROUTER_DIR, -1)
heartbeat_cron.add("* * * * * root sleep 30; $SHELL %s/check_heartbeat.sh 2>&1 > /dev/null" % self.CS_ROUTER_DIR, -1)
heartbeat_cron.commit()

# Configure KeepaliveD cron job - runs at every reboot
keepalived_cron = CsFile("/etc/cron.d/keepalived")
keepalived_cron.add("SHELL=/bin/bash", 0)
keepalived_cron.add("PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin", 1)
keepalived_cron.add("@reboot root service keepalived start", -1)
keepalived_cron.commit()

# Configure heartbeat cron job
cron = CsFile("/etc/cron.d/heartbeat")
cron.add("SHELL=/bin/bash", 0)
cron.add("PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin", 1)
cron.add("*/1 * * * * root $SHELL %s/check_heartbeat.sh 2>&1 > /dev/null" % self.CS_ROUTER_DIR, -1)
cron.commit()
# Configure ConntrackD cron job - runs at every reboot
conntrackd_cron = CsFile("/etc/cron.d/conntrackd")
conntrackd_cron.add("SHELL=/bin/bash", 0)
conntrackd_cron.add("PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin", 1)
conntrackd_cron.add("@reboot root service conntrackd start", -1)
conntrackd_cron.commit()

proc = CsProcess(['/usr/sbin/keepalived', '--vrrp'])
if not proc.find():
if not proc.find() or keepalived_conf.is_changed():
CsHelper.service("keepalived", "restart")

def release_lock(self):
Expand Down Expand Up @@ -185,6 +188,7 @@ def set_fault(self):
if not self.cl.is_redundant():
logging.error("Set fault called on non-redundant router")
return

self.set_lock()
logging.info("Router switched to fault mode")
ads = [o for o in self.address.get_ips() if o.is_public()]
Expand All @@ -208,11 +212,7 @@ def set_backup(self):
if not self.cl.is_redundant():
logging.error("Set backup called on non-redundant router")
return
"""
if not self.cl.is_master():
logging.error("Set backup called on node that is already backup")
return
"""

self.set_lock()
logging.debug("Setting router to backup")
ads = [o for o in self.address.get_ips() if o.is_public()]
Expand All @@ -232,7 +232,7 @@ def set_backup(self):
for o in ads:
CsPasswdSvc(o.get_gateway()).stop()
CsHelper.service("dnsmasq", "stop")
# self._set_priority(self.CS_PRIO_DOWN)

self.cl.set_master_state(False)
self.cl.save()
self.release_lock()
Expand All @@ -243,11 +243,7 @@ def set_master(self):
if not self.cl.is_redundant():
logging.error("Set master called on non-redundant router")
return
"""
if self.cl.is_master():
logging.error("Set master called on master node")
return
"""

self.set_lock()
logging.debug("Setting router to master")
ads = [o for o in self.address.get_ips() if o.is_public()]
Expand Down
3 changes: 3 additions & 0 deletions systemvm/patches/debian/config/opt/cloud/bin/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@

if options.backup:
red.set_backup()

if options.fault:
red.set_fault()
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ STRIKE_FILE="$ROUTER_BIN_PATH/keepalived.strikes"

if [ -e $ROUTER_BIN_PATH/keepalived.ts2 ]
then
lasttime=$(cat $ROUTER_BIN_PATH/keepalived.ts2)
thistime=$(cat $ROUTER_BIN_PATH/keepalived.ts)
diff=$(($thistime - $lasttime))
lasttime=$(cat $ROUTER_BIN_PATH/keepalived.ts2)
diff=$(($lasttime - $thistime))
s=0
if [ $diff -lt 30 ]

@jayakarteek jayakarteek Feb 14, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wilderrodrigues @rhtyd why there is a change in time comparison logic.
if condition will never be true with the changes last-time will be less then this-time and diff will be negative.
So this will end up filling the logs in else condition

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jayakarteek please refer master/4.11 for latest code, why are you commenting on this very old PR?

if [ $diff -ge 10 ]
then
if [ -e $STRIKE_FILE ]
then
Expand All @@ -47,13 +47,14 @@ then
if [ $s -gt 2 ]
then
echo Keepalived process is dead! >> $ROUTER_LOG
$ROUTER_BIN_PATH/services.sh stop >> $ROUTER_LOG 2>&1
$ROUTER_BIN_PATH/disable_pubip.sh >> $ROUTER_LOG 2>&1
$ROUTER_BIN_PATH/primary-backup.sh fault >> $ROUTER_LOG 2>&1
service keepalived stop >> $ROUTER_LOG 2>&1
service conntrackd stop >> $ROUTER_LOG 2>&1
pkill -9 keepalived >> $ROUTER_LOG 2>&1
pkill -9 conntrackd >> $ROUTER_LOG 2>&1

#Set fault so we have the same effect as a KeepaliveD fault.
python /opt/cloud/bin/master.py --fault

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will running the script here block this shell script until it exists, or will it launch as a daemon? If it's blocking then it's alright.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep... it will block.


pkill -9 keepalived >> $ROUTER_LOG 2>&1
pkill -9 conntrackd >> $ROUTER_LOG 2>&1
echo Status: FAULT \(keepalived process is dead\) >> $ROUTER_LOG
exit
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ global_defs {

vrrp_script heartbeat {
script "[RROUTER_BIN_PATH]/heartbeat.sh"
interval 10
interval 5
}

vrrp_instance inside_network {
state BACKUP
state EQUAL
interface eth0
virtual_router_id 51
priority [PRIORITY]
nopreempt
nopreempt

advert_int 1
authentication {
Expand All @@ -46,7 +45,7 @@ vrrp_instance inside_network {
}

!That's the correct path of the master.py file.
notify_master "/opt/cloud/bin/master.py --master"
notify_backup "/opt/cloud/bin/master.py --backup"
notify_master "/opt/cloud/bin/master.py --master"
notify_fault "/opt/cloud/bin/master.py --fault"
}
}
7 changes: 0 additions & 7 deletions systemvm/test/python/TestCsCmdLine.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ def test_ini(self):
def test_idata(self):
self.assertTrue(self.cscmdline.idata() == {})

def test_get_priority(self):
self.assertTrue(self.cscmdline.get_priority() == 99)

def test_set_priority(self):
self.cscmdline.set_priority(100)
self.assertTrue(self.cscmdline.get_priority() == 100)

def test_is_redundant(self):
self.assertTrue(self.cscmdline.is_redundant() is False)
self.cscmdline.set_redundant()
Expand Down
6 changes: 4 additions & 2 deletions test/integration/component/test_vpc_redundant.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ def check_master_status(self, count=2, showall=False):
cnts = [0, 0, 0]
self.query_routers(count, showall)
for router in self.routers:
cnts[vals.index(router.redundantstate)] += 1
if router.state == "Running":
cnts[vals.index(router.redundantstate)] += 1
if cnts[vals.index('MASTER')] != 1:
self.fail("No Master or too many master routers found %s" % cnts[vals.index('MASTER')])
# if cnts[vals.index('UNKNOWN')] > 0:
Expand Down Expand Up @@ -431,6 +432,7 @@ def test_01a_create_redundant_VPC(self):
self.do_vpc_test(False)

self.stop_router("MASTER")
# wait for the backup router to transit to master state
time.sleep(30)
self.check_master_status(1)
self.do_vpc_test(False)
Expand All @@ -441,7 +443,6 @@ def test_01a_create_redundant_VPC(self):

self.start_router()
self.add_nat_rules()
time.sleep(60)
self.check_master_status(2)
self.do_vpc_test(False)

Expand All @@ -459,6 +460,7 @@ def add_nat_rules(self):
vm.set_ip(self.acquire_publicip(o.get_net()))
if vm.get_nat() is None:
vm.set_nat(self.create_natrule(vm.get_vm(), vm.get_ip(), o.get_net()))
time.sleep(5)

def do_vpc_test(self, expectFail):
retries = 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function install_packages() {
xl2tpd bcrelay ppp ipsec-tools tdb-tools \
openswan=1:2.6.37-3 \
xenstore-utils libxenstore3.0 \
keepalived conntrackd ipvsadm libnetfilter-conntrack3 libnl1 \
conntrackd ipvsadm libnetfilter-conntrack3 libnl1 \
ipcalc \
openjdk-7-jre-headless \
iptables-persistent \
Expand All @@ -75,7 +75,7 @@ function install_packages() {
radvd \
sharutils

${apt_get} -t wheezy-backports install irqbalance open-vm-tools
${apt_get} -t wheezy-backports install keepalived irqbalance open-vm-tools

# hold on installed openswan version, upgrade rest of the packages (if any)
apt-mark hold openswan
Expand Down