IPS_PER_SIMULATION = 5
+
def indent(lines, amount, fillchar=' '):
"""Indent the string by amount of fill chars.
padding = amount * fillchar
return padding + ('\n'+padding).join(lines.split('\n'))
+
def print_to_stderr(msg, end='\n'):
"""Writes any text to stderr.
except ValueError:
pass
+
def get_assigned_interfaces(args, network="flat"):
"""Retrieve assigned interfaces in openstack network.
"Status other than 200 HTTP OK:\n{}"
.format(req.content))
+
def get_assigned_interfaces_count(args, network="flat"):
"""Count assigned interfaces in openstack network.
"""
return len(get_assigned_interfaces(args, network=network))
+
def check_ip_addresses(args):
"""Check IP address availability.
:raises RuntimeError: If not enough free addresses available.
"""
for i in range(args.wait_count):
- if (args.quota - \
- get_assigned_interfaces_count(args) >= IPS_PER_SIMULATION):
+ if (args.quota -
+ get_assigned_interfaces_count(args) >= IPS_PER_SIMULATION):
break
if args.verbosity >= 2:
print_to_stderr("DEBUG: - Attempt {} out of {}, waiting for free "
else:
raise RuntimeError("ERROR: Not enough IP addresses to run simulation")
+
def check_virl_resources(args):
"""Check virl resources availability.
# function executed in sequence. This should be broken down into multiple
# functions.
#
+
+
def main():
""" Main function."""
#
parser.add_argument("-q", "--quota",
help="VIRL quota for max number of allowed IPs",
type=int, default=74)
+ parser.add_argument("-si", "--skip-install", help="Skip VPP installation",
+ action='store_true')
args = parser.parse_args()
#
# Check if VPP package exists
#
- for package in args.packages:
- if args.verbosity >= 2:
- print_to_stderr("DEBUG: Checking if file {} exists"
- .format(package))
- if not os.path.isfile(package):
- print_to_stderr("ERROR: Debian package {} does not exist"
- .format(package))
- sys.exit(1)
+ if not args.skip_install:
+ for package in args.packages:
+ if args.verbosity >= 2:
+ print_to_stderr("DEBUG: Checking if file {} exists"
+ .format(package))
+ if not os.path.isfile(package):
+ print_to_stderr("ERROR: Required package {} does not exist"
+ .format(package))
+ sys.exit(1)
#
# Start VIRL topology
auth=(args.username, args.password))
try:
shutil.rmtree(scratch_directory)
- except shutil.Error:
+ except:
print_to_stderr("ERROR: Removing scratch directory")
print "{}".format(session_id)
sys.exit(1)
auth=(args.username, args.password))
try:
shutil.rmtree(scratch_directory)
- except shutil.Error:
+ except:
print_to_stderr("ERROR: Removing scratch directory")
print "{}".format(session_id)
sys.exit(1)
auth=(args.username, args.password))
try:
shutil.rmtree(scratch_directory)
- except shutil.Error:
+ except:
print_to_stderr("ERROR: Removing scratch directory")
print "{}".format(session_id)
sys.exit(1)
#
# Upgrade VPP
#
- if args.verbosity >= 1:
- print_to_stderr("DEBUG: Uprading VPP")
-
- for key1 in nodeaddrs:
- if not key1 == 'tg':
- for key2 in nodeaddrs[key1]:
- ipaddr = nodeaddrs[key1][key2]
- if args.verbosity >= 2:
- print_to_stderr("DEBUG: Upgrading VPP on node {}"
- .format(ipaddr))
- paramiko.util.log_to_file(os.path.join(scratch_directory,
- "ssh.log"))
- client = paramiko.SSHClient()
- client.load_system_host_keys()
- client.load_host_keys("/dev/null")
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(ipaddr, username=args.ssh_user,
- key_filename=args.ssh_privkey)
- if 'centos' in args.topology:
- if args.verbosity >= 1:
- print_to_stderr("DEBUG: Installing RPM packages")
- vpp_install_command = 'sudo rpm -ivh /scratch/vpp/*.rpm'
- elif 'trusty' in args.topology or 'xenial' in args.topology:
- if args.verbosity >= 1:
- print_to_stderr("DEBUG: Installing DEB packages")
- vpp_install_command = 'sudo dpkg -i --force-all ' \
- '/scratch/vpp/*.deb'
- else:
- print_to_stderr("ERROR: Unsupported OS requested: {}"
- .format(args.topology))
- vpp_install_command = ''
- _, stdout, stderr = \
- client.exec_command(vpp_install_command)
- c_stdout = stdout.read()
- c_stderr = stderr.read()
- if args.verbosity >= 2:
- print_to_stderr("DEBUG: Command output was:")
- print_to_stderr(c_stdout)
- print_to_stderr("DEBUG: Command stderr was:")
- print_to_stderr(c_stderr)
+ if not args.skip_install:
+ if args.verbosity >= 1:
+ print_to_stderr("DEBUG: Uprading VPP")
+
+ for key1 in nodeaddrs:
+ if not key1 == 'tg':
+ for key2 in nodeaddrs[key1]:
+ ipaddr = nodeaddrs[key1][key2]
+ if args.verbosity >= 2:
+ print_to_stderr("DEBUG: Upgrading VPP on node {}"
+ .format(ipaddr))
+ paramiko.util.log_to_file(os.path.join(scratch_directory,
+ "ssh.log"))
+ client = paramiko.SSHClient()
+ client.load_system_host_keys()
+ client.load_host_keys("/dev/null")
+ client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ client.connect(ipaddr, username=args.ssh_user,
+ key_filename=args.ssh_privkey)
+ if 'centos' in args.topology:
+ if args.verbosity >= 1:
+ print_to_stderr("DEBUG: Installing RPM packages")
+ vpp_install_command = 'sudo rpm -ivh /scratch/vpp/*.rpm'
+ elif 'trusty' in args.topology or 'xenial' in args.topology:
+ if args.verbosity >= 1:
+ print_to_stderr("DEBUG: Installing DEB packages")
+ vpp_install_command = 'sudo dpkg -i --force-all ' \
+ '/scratch/vpp/*.deb'
+ else:
+ print_to_stderr("ERROR: Unsupported OS requested: {}"
+ .format(args.topology))
+ vpp_install_command = ''
+ _, stdout, stderr = \
+ client.exec_command(vpp_install_command)
+ c_stdout = stdout.read()
+ c_stderr = stderr.read()
+ if args.verbosity >= 2:
+ print_to_stderr("DEBUG: Command output was:")
+ print_to_stderr(c_stdout)
+ print_to_stderr("DEBUG: Command stderr was:")
+ print_to_stderr(c_stderr)
#
# Write a file with timestamp to scratch directory. We can use this to track