← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check into lp:cloud-init

 

Kiril Vladimiroff has proposed merging lp:~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check/+merge/221524

Changes made to the CloudSigma DS:

- Add timeouts for reading/writting from/to the serial console
- Check if the cloud-init is running in CloudSigma's infrastructure before trying to fetch data from its serial console (Fixes #1316475)
-- 
https://code.launchpad.net/~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check/+merge/221524
Your team cloud init development team is requested to review the proposed merge of lp:~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check into lp:cloud-init.
=== modified file 'cloudinit/cs_utils.py'
--- cloudinit/cs_utils.py	2014-02-12 10:14:49 +0000
+++ cloudinit/cs_utils.py	2014-05-30 11:27:37 +0000
@@ -35,6 +35,8 @@
 
 import serial
 
+READ_TIMEOUT = 60
+WRITE_TIMEOUT = 10
 SERIAL_PORT = '/dev/ttyS1'
 if platform.system() == 'Windows':
     SERIAL_PORT = 'COM2'
@@ -76,7 +78,9 @@
         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')
 

=== modified file 'cloudinit/sources/DataSourceCloudSigma.py'
--- cloudinit/sources/DataSourceCloudSigma.py	2014-03-04 17:11:10 +0000
+++ cloudinit/sources/DataSourceCloudSigma.py	2014-05-30 11:27:37 +0000
@@ -20,6 +20,7 @@
 
 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 @@
         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']

=== modified file 'tests/unittests/test_datasource/test_cloudsigma.py'
--- tests/unittests/test_datasource/test_cloudsigma.py	2014-02-19 08:45:53 +0000
+++ tests/unittests/test_datasource/test_cloudsigma.py	2014-05-30 11:27:37 +0000
@@ -35,6 +35,7 @@
 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()