From a0d0c8dfc306ef9b7249cb606a2b211a5fd2fb56 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Tue, 31 May 2016 10:21:11 +0200 Subject: [PATCH] CLOUDSTACK-9568: slow operations on system VM --- .../config/opt/cloud/bin/cs/CsAddress.py | 4 +- .../config/opt/cloud/bin/cs/CsHelper.py | 40 +++++++++++++++++-- .../debian/config/opt/cloud/bin/merge.py | 7 +--- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py index 64ddb2681b72..cff0aaac4318 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py @@ -593,9 +593,11 @@ def hasIP(self, ip): return ip in self.address.values() def arpPing(self): + if not self.address['gateway'] or self.address['gateway'] == 'None': + return cmd = "arping -c 1 -I %s -A -U -s %s %s" % ( self.dev, self.address['public_ip'], self.address['gateway']) - CsHelper.execute(cmd) + CsHelper.execute_background(cmd) # Delete any ips that are configured but not in the bag def compare(self, bag): diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsHelper.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsHelper.py index 1d6baff99e33..c57d68014e3a 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsHelper.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsHelper.py @@ -24,9 +24,17 @@ import os.path import re import shutil + +try: + from subprocess import DEVNULL # py3k +except ImportError: + import os + DEVNULL = open(os.devnull, 'wb') + from netaddr import * from pprint import pprint + 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'", @@ -180,11 +188,35 @@ def get_hostname(): def execute(command): - """ Execute command """ + """Execute a command in a new process and return stdout + + The command is executed in a shell (which allow use of pipes and such), + wait for the command to terminate, and return stdout. + + :param command: command with arguments to be executed, + see :py:class:`subprocess.Popen` + :type command: str or list or tuple + :return: command stdout + :rtype: list + """ logging.debug("Executing: %s" % command) - p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) - result = p.communicate()[0] - return result.splitlines() + p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=DEVNULL, shell=True) + return p.communicate()[0].splitlines() + + +def execute_background(command): + """Execute a command in a new process + + The command is executed in a shell (which allow use of pipes and such). + The function does not wait command completion to return. + + :param command: command with arguments to be executed, + see :py:class:`subprocess.Popen` + :type command: str or list or tuple + :return: None + """ + logging.debug("Executing: %s" % command) + subprocess.Popen(command, stdout=DEVNULL, stderr=DEVNULL, shell=True) def save_iptables(command, iptables_file): diff --git a/systemvm/patches/debian/config/opt/cloud/bin/merge.py b/systemvm/patches/debian/config/opt/cloud/bin/merge.py index 50d9ee9aae8c..7e8aa4f1eac0 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/merge.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/merge.py @@ -230,12 +230,9 @@ def processCLItem(self, num, nw_type): dp['add'] = True dp['one_to_one_nat'] = False if nw_type == "public": - dp['gateway'] = self.qFile.data['cmd_line']['gateway'] + dp['gateway'] = self.qFile.data['cmd_line'].get('gateway', 'None') else: - if('localgw' in self.qFile.data['cmd_line']): - dp['gateway'] = self.qFile.data['cmd_line']['localgw'] - else: - dp['gateway'] = 'None' + dp['gateway'] = self.qFile.data['cmd_line'].get('localgw', 'None') dp['nic_dev_id'] = num dp['nw_type'] = nw_type qf = QueueFile()