Skip to content

Commit

Permalink
Fixes to enable test to succeed. Small change to Marvin to be able to…
Browse files Browse the repository at this point in the history
… override retries

Signed-off-by: wilderrodrigues <[email protected]>
  • Loading branch information
Ian Southam authored and wilderrodrigues committed Jul 8, 2015
1 parent 1a93d70 commit b7b54f1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
1 change: 1 addition & 0 deletions systemvm/patches/debian/config/opt/cloud/bin/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from cs.CsApp import CsApache, CsDnsmasq
from cs.CsMonitor import CsMonitor
from cs.CsLoadBalancer import CsLoadBalancer
from cs.CsConfig import CsConfig


class CsPassword(CsDataBag):
Expand Down
15 changes: 9 additions & 6 deletions systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ def get_ips(self):

def get_guest_if(self):
"""
Return CsInterface object for the first guest interface
Return CsInterface object for the lowest guest interface
"""
ipr = []
for ip in self.get_ips():
if ip.is_guest():
return ip
ipr.append(ip)
if len(ipr) > 0:
return sorted(ipr)[-1]
return None

def get_guest_ip(self):
Expand Down Expand Up @@ -407,10 +410,10 @@ 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(["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
62 changes: 39 additions & 23 deletions systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@
# eth1 public ip
# eth2+ Guest networks
# -------------------------------------------------------------------- #
import sys
import os
from pprint import pprint
from CsDatabag import CsDataBag, CsCmdLine
import logging
import CsHelper
from CsFile import CsFile
from CsConfig import CsConfig
from CsProcess import CsProcess
from CsApp import CsPasswdSvc
from CsAddress import CsDevice
import socket
from time import sleep

Expand All @@ -64,6 +61,7 @@ class CsRedundant(object):
def __init__(self, config):
self.cl = config.cmdline()
self.address = config.address()
self.config = config

def set(self):
logging.debug("Router redundancy status is %s", self.cl.is_redundant())
Expand All @@ -83,13 +81,11 @@ def _redundant_off(self):
def _redundant_on(self):
guest = self.address.get_guest_if()
# No redundancy if there is no guest network
if self.cl.is_master() or guest is None:
for obj in [o for o in self.address.get_ips() if o.is_public()]:
self.check_is_up(obj.get_device())
if guest is None:
self._redundant_off()
# Bring up the public Interface(s)
if self.cl.is_master():
for obj in [o for o in self.address.get_ips() if o.is_public()]:
print obj.get_device()
self.check_is_up(obj.get_device())
return
CsHelper.mkdir(self.CS_RAMDISK_DIR, 0755, False)
CsHelper.mount_tmpfs(self.CS_RAMDISK_DIR)
Expand Down Expand Up @@ -159,6 +155,12 @@ def _redundant_on(self):
if not proc.find():
CsHelper.service("keepalived", "restart")

def release_lock(self):
try:
os.remove("/tmp/master_lock")
except OSError:
pass

def set_lock(self):
"""
Make sure that master state changes happen sequentially
Expand All @@ -169,21 +171,21 @@ def set_lock(self):
for iter in range(0, iterations):
try:
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.bind('\0master_lock')
s.bind('/tmp/master_lock')
return s
except socket.error, e:
error_code = e.args[0]
error_string = e.args[1]
print "Process already running (%d:%s). Exiting" % (error_code, error_string)
logging.info("Master is already running, waiting")
sleep(1)
sleep(time_between)

def set_fault(self):
""" Set fault mode on this router """
if not self.cl.is_redundant():
logging.error("Set fault called on non-redundant router")
return
s = self.set_lock()
self.set_lock()
logging.info("Router switched to fault mode")
ads = [o for o in self.address.get_ips() if o.is_public()]
for o in ads:
Expand All @@ -195,9 +197,10 @@ def set_fault(self):
CsHelper.service("dnsmasq", "stop")
ads = [o for o in self.address.get_ips() if o.needs_vrrp()]
for o in ads:
pwdsvc = CsPasswdSvc(o.get_gateway()).stop()
CsPasswdSvc(o.get_gateway()).stop()
self.cl.set_fault_state()
self.cl.save()
self.release_lock()
logging.info("Router switched to fault mode")

def set_backup(self):
Expand All @@ -210,22 +213,29 @@ def set_backup(self):
logging.error("Set backup called on node that is already backup")
return
"""
s = self.set_lock()
self.set_lock()
logging.debug("Setting router to backup")
ads = [o for o in self.address.get_ips() if o.is_public()]
dev = ''
for o in ads:
CsHelper.execute("ifconfig %s down" % o.get_device())
if dev == o.get_device():
continue
logging.info("Bringing public interface %s down" % o.get_device())
cmd2 = "ip link set %s up" % o.get_device()
CsHelper.execute(cmd2)
dev = o.get_device()
cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONF)
CsHelper.execute("%s -d" % cmd)
CsHelper.service("ipsec", "stop")
CsHelper.service("xl2tpd", "stop")
ads = [o for o in self.address.get_ips() if o.needs_vrrp()]
for o in ads:
pwdsvc = CsPasswdSvc(o.get_gateway()).stop()
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()
logging.info("Router switched to backup mode")

def set_master(self):
Expand All @@ -238,15 +248,20 @@ def set_master(self):
logging.error("Set master called on master node")
return
"""
s = self.set_lock()
self.set_lock()
logging.debug("Setting router to master")
ads = [o for o in self.address.get_ips() if o.is_public()]
dev = ''
for o in ads:
# cmd2 = "ip link set %s up" % self.getDevice()
CsHelper.execute("ifconfig %s down" % o.get_device())
CsHelper.execute("ifconfig %s up" % o.get_device())
CsHelper.execute("arping -I %s -A %s -c 1" % (o.get_device(), o.get_ip()))
# FIXME Need to add in the default routes but I am unsure what the gateway is
if dev == o.get_device():
continue
cmd2 = "ip link set %s up" % o.get_device()
if CsDevice(o.get_device(), self.config).waitfordevice():
CsHelper.execute(cmd2)
dev = o.get_device()
logging.info("Bringing public interface %s up" % o.get_device())
else:
logging.error("Device %s was not ready could not bring it up" % o.get_device())
# ip route add default via $gw table Table_$dev proto static
cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONF)
CsHelper.execute("%s -c" % cmd)
Expand All @@ -257,10 +272,11 @@ def set_master(self):
CsHelper.service("xl2tpd", "restart")
ads = [o for o in self.address.get_ips() if o.needs_vrrp()]
for o in ads:
pwdsvc = CsPasswdSvc(o.get_gateway()).restart()
CsPasswdSvc(o.get_gateway()).restart()
CsHelper.service("dnsmasq", "restart")
self.cl.set_master_state(True)
self.cl.save()
self.release_lock()
logging.info("Router switched to master mode")

def _collect_ignore_ips(self):
Expand Down
4 changes: 3 additions & 1 deletion tools/marvin/marvin/lib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def restore(self, apiclient, templateid=None):

def get_ssh_client(
self, ipaddress=None, reconnect=False, port=None,
keyPairFileLocation=None):
keyPairFileLocation=None, retries=20):
"""Get SSH object of VM"""

# If NAT Rules are not created while VM deployment in Advanced mode
Expand All @@ -570,13 +570,15 @@ def get_ssh_client(
self.ssh_port,
self.username,
self.password,
retries=retries,
keyPairFileLocation=keyPairFileLocation
)
self.ssh_client = self.ssh_client or is_server_ssh_ready(
self.ssh_ip,
self.ssh_port,
self.username,
self.password,
retries=retries,
keyPairFileLocation=keyPairFileLocation
)
return self.ssh_client
Expand Down

0 comments on commit b7b54f1

Please sign in to comment.