From 882f7186143c337e0f30f4ed2c0415f238ed5c83 Mon Sep 17 00:00:00 2001 From: Kiril Vladimiroff Date: Fri, 30 May 2014 14:17:57 +0300 Subject: Add timeouts for reading/writing from/to to the serial console --- cloudinit/cs_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cloudinit') diff --git a/cloudinit/cs_utils.py b/cloudinit/cs_utils.py index 4e53c31a..1db3f110 100644 --- a/cloudinit/cs_utils.py +++ b/cloudinit/cs_utils.py @@ -35,6 +35,8 @@ import platform import serial +READ_TIMEOUT = 60 +WRITE_TIMEOUT = 10 SERIAL_PORT = '/dev/ttyS1' if platform.system() == 'Windows': SERIAL_PORT = 'COM2' @@ -76,7 +78,9 @@ class CepkoResult(object): self.result = self._marshal(self.raw_result) def _execute(self): - connection = serial.Serial(SERIAL_PORT) + connection = serial.Serial(port=SERIAL_PORT, + timeout=READ_TIMEOUT, + writeTimeout=WRITE_TIMEOUT) connection.write(self.request) return connection.readline().strip('\x04\n') -- cgit v1.2.3 From 71d817c427f06e9e1f5d547d5db191e541963d31 Mon Sep 17 00:00:00 2001 From: Kiril Vladimiroff Date: Fri, 30 May 2014 14:19:10 +0300 Subject: Use dmidecode to detect if cloud-init runs in CloudSigma's infrastructure --- cloudinit/sources/DataSourceCloudSigma.py | 22 ++++++++++++++++++++++ tests/unittests/test_datasource/test_cloudsigma.py | 1 + 2 files changed, 23 insertions(+) (limited to 'cloudinit') diff --git a/cloudinit/sources/DataSourceCloudSigma.py b/cloudinit/sources/DataSourceCloudSigma.py index e1c7e566..fffff91e 100644 --- a/cloudinit/sources/DataSourceCloudSigma.py +++ b/cloudinit/sources/DataSourceCloudSigma.py @@ -20,6 +20,7 @@ import re from cloudinit import log as logging from cloudinit import sources +from cloudinit import util from cloudinit.cs_utils import Cepko LOG = logging.getLogger(__name__) @@ -40,12 +41,33 @@ class DataSourceCloudSigma(sources.DataSource): self.ssh_public_key = '' sources.DataSource.__init__(self, sys_cfg, distro, paths) + def is_running_in_cloudsigma(self): + """ + Uses dmidecode to detect if this instance of cloud-init is running + in the CloudSigma's infrastructure. + """ + dmidecode_path = util.which('dmidecode') + if not dmidecode_path: + return False + + LOG.debug("Determining hypervisor product name via dmidecode") + try: + system_product_name, _ = util.subp([dmidecode_path, "-s", "system-product-name"]) + return 'cloudsigma' in system_product_name.lower() + except: + LOG.exception("Failed to get hypervisor product name") + + return False + def get_data(self): """ Metadata is the whole server context and /meta/cloud-config is used as userdata. """ dsmode = None + if not self.is_running_in_cloudsigma(): + return False + try: server_context = self.cepko.all().result server_meta = server_context['meta'] diff --git a/tests/unittests/test_datasource/test_cloudsigma.py b/tests/unittests/test_datasource/test_cloudsigma.py index adbb4afb..25dc12f3 100644 --- a/tests/unittests/test_datasource/test_cloudsigma.py +++ b/tests/unittests/test_datasource/test_cloudsigma.py @@ -35,6 +35,7 @@ class CepkoMock(Cepko): class DataSourceCloudSigmaTest(TestCase): def setUp(self): self.datasource = DataSourceCloudSigma.DataSourceCloudSigma("", "", "") + self.datasource.is_running_in_cloudsigma = lambda: True self.datasource.cepko = CepkoMock(SERVER_CONTEXT) self.datasource.get_data() -- cgit v1.2.3 From 2d36a7ce4a0ccec3bd2881dd99d6d5012a85fe3c Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 30 May 2014 14:46:53 -0400 Subject: minor cleanups. * do not run dmidecode on arm. * line length * comment that 60 second time out is expected --- cloudinit/cs_utils.py | 2 ++ cloudinit/sources/DataSourceCloudSigma.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/cs_utils.py b/cloudinit/cs_utils.py index 1db3f110..dcf56431 100644 --- a/cloudinit/cs_utils.py +++ b/cloudinit/cs_utils.py @@ -35,8 +35,10 @@ import platform import serial +# these high timeouts are necessary as read may read a lot of data. READ_TIMEOUT = 60 WRITE_TIMEOUT = 10 + SERIAL_PORT = '/dev/ttyS1' if platform.system() == 'Windows': SERIAL_PORT = 'COM2' diff --git a/cloudinit/sources/DataSourceCloudSigma.py b/cloudinit/sources/DataSourceCloudSigma.py index fffff91e..a8c04d19 100644 --- a/cloudinit/sources/DataSourceCloudSigma.py +++ b/cloudinit/sources/DataSourceCloudSigma.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . from base64 import b64decode +import os import re from cloudinit import log as logging @@ -46,16 +47,23 @@ class DataSourceCloudSigma(sources.DataSource): Uses dmidecode to detect if this instance of cloud-init is running in the CloudSigma's infrastructure. """ + uname_arch = os.uname()[4] + if uname_arch.startswith("arm") or uname_arch == "aarch64": + # Disabling because dmidecode in CMD_DMI_SYSTEM crashes kvm process + LOG.debug("Disabling CloudSigma datasource on arm (LP: #1243287)") + return False + dmidecode_path = util.which('dmidecode') if not dmidecode_path: return False LOG.debug("Determining hypervisor product name via dmidecode") try: - system_product_name, _ = util.subp([dmidecode_path, "-s", "system-product-name"]) + cmd = [dmidecode_path, "--string", "system-product-name"] + system_product_name, _ = util.subp(cmd) return 'cloudsigma' in system_product_name.lower() except: - LOG.exception("Failed to get hypervisor product name") + LOG.warn("Failed to get hypervisor product name via dmidecode") return False -- cgit v1.2.3