Merge lp:~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Kiril Vladimiroff
Status: Merged
Merged at revision: 975
Proposed branch: lp:~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 80 lines (+28/-1)
3 files modified
cloudinit/cs_utils.py (+5/-1)
cloudinit/sources/DataSourceCloudSigma.py (+22/-0)
tests/unittests/test_datasource/test_cloudsigma.py (+1/-0)
To merge this branch: bzr merge lp:~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check
Reviewer Review Type Date Requested Status
Scott Moser Needs Fixing
Review via email: mp+221524@code.launchpad.net

Description of the change

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)

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

This looks reasonable. I only have a few minor comments:
 a.) READ_TIMEOUT and WRITE_TIMEOUT of 60 seconds and 10 seconds seem a bit high to me. Is there a need for that to be so high? I suspect if the other end of your datasource did not return in < 5 seconds to a query that you'd be looking to fix that very quickly.
 b.) did you want to allow configuration of the string 'cloudsigma' and/or the 'is_running_in_clouds' check?
    doc/examples/cloud-config-datasources.txt has examples of other configuration that datasources have. I might just suggest:
    datasource:
      CloudSigma:
        system_product_name: (null|cloudsigma)

    If null then do not bother checking. If set to some other value (such as 'cloudsigma') then check and disable if not present.

I'd like the timeouts lowered unless you have a good reason for them to be so high( as we've seen negative fallout of this already). I'm fine to take it without the configuration though. That part is up to you.

review: Needs Fixing
Revision history for this message
Scott Moser (smoser) wrote :

one other thing. due to the unavailability (and general failure) on arm, you'll need to modify your tests similar to I did in revision 960. Basically, even if dmi-decode is available, we don't want to run it on arm.

Revision history for this message
Kiril Vladimiroff (kiril-vladimiroff) wrote :

a) When a virtual machine from our marketplace is cloned all the
metadata for it gets cloned, too (arch, os, distribution, version and
most all: **install notes**). And install notes could be huge. When
this data is a lot, a lot of time is spent on receiving it. So, since
we have the SMBIOS check now, we're sure such serial read/writes will
be executed only in our cloud. In other words: especially the read
timeout is completely reasonable.

b) We're going to deploy the new version of our cloud soon and it's
useless to put this as configuration option. Will use custom builds
until then.

> Basically, even if dmi-decode is available, we don't want to run it on arm.

Could you please explain why? I don't see a reason to filter by arch,
since the SMBIOS check is pretty straightforward.
Kiril Vladimiroff

Software Developer

CloudSigma

E: <email address hidden>

T: www.twitter.com/CloudSigma

W: www.cloudsigma.com

The first exchange for trading IaaS cloud resources has arrived:

http://cld.sg/14RyTYG.

CloudSigma is a proud launch partner with Deutsche Börse:

http://cld.sg/17Xcbo7.

CloudSigma named Cool Vendor 2013 by Gartner Research: http://cld.sg/10G5az6

====================

This email is from CLOUDSIGMA AG. The contents of this email and any
attachments are confidential to the intended recipient. They may not
be disclosed to or used by or copied in any way by anyone other than
the intended recipient. If this email is received in error, please
contact CLOUDSIGMA AG on +41 (0)44 585 39 07 quoting the name of the
sender and the email address to which it has been sent and then delete
it. Please note that neither CLOUDSIGMA AG nor the sender accepts any
responsibility for viruses and it is your responsibility to scan or
otherwise check this email and any attachments. CLOUDSIGMA AG is a
public limited company registered in Canton Zürich, Switzerland
(registered number CH-020.3.034.422-0) with registered offices at
Sägereistrasse 35, 8152 Glattbrugg, Switzerland. For further
information, please refer to www.cloudsigma.com .

====================

On Fri, May 30, 2014 at 5:15 PM, Scott Moser <email address hidden> wrote:
> one other thing. due to the unavailability (and general failure) on arm, you'll need to modify your tests similar to I did in revision 960. Basically, even if dmi-decode is available, we don't want to run it on arm.
>
> --
> https://code.launchpad.net/~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check/+merge/221524
> You are the owner of lp:~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check.

Revision history for this message
Kiril Vladimiroff (kiril-vladimiroff) wrote :

a) When a virtual machine from our marketplace is cloned all the
metadata for it gets cloned, too (arch, os, distribution, version and
most all: **install notes**). And install notes could be huge. When
this data is a lot, a lot of time is spent on receiving it. So, since
we have the SMBIOS check now, we're sure such serial read/writes will
be executed only in our cloud. In other words: especially the read
timeout is completely reasonable.

b) We're going to deploy the new version of our cloud soon and it's
useless to put this as configuration option. Will use custom builds
until then.

> Basically, even if dmi-decode is available, we don't want to run it on arm.

Could you please explain why? I don't see a reason to filter by arch,
since the SMBIOS check is pretty straightforward.

P.S.: It seems that replies to the received email from this merge proposal don't show up here.

Revision history for this message
Scott Moser (smoser) wrote :

dmi-decode can actually crash arm guests or hosts. yes, thats completely silly, but true.
https://bugs.launchpad.net/qemu/+bug/1243287

kvm guests will simply die (killing kvm), and it is reported to me that bare metal hosts can crash similarly.

Revision history for this message
Kiril Vladimiroff (kiril-vladimiroff) wrote :

Oh, well... that's a reason. Will take a look at it tomorrow and see how to do the architecture checks, too.

Should I push these new arch checks to this merge proposal or open a new one?

Revision history for this message
Kiril Vladimiroff (kiril-vladimiroff) wrote :

I've pushed changes that disables the whole data source on arm to this very same branch. I however don't see it appended to the current merge proposal. What should I do in order to achieve that?

The revision is 974 (https://bazaar.launchpad.net/~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check/revision/974?start_revid=974) ?

Revision history for this message
Scott Moser (smoser) wrote :

Hey, I added some ifarch and merged branch yesterday. Please make sure trunk looks good now.

On May 31, 2014 4:20:08 AM EDT, Kiril Vladimiroff <email address hidden> wrote:
>I've pushed changes that disables the whole data source on arm to this
>very same branch. I however don't see it appended to the current merge
>proposal. What should I do in order to achieve that?
>
>The revision is 974
>(https://bazaar.launchpad.net/~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check/revision/974?start_revid=974)
>?
>--
>https://code.launchpad.net/~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check/+merge/221524
>You are reviewing the proposed merge of
>lp:~kiril-vladimiroff/cloud-init/cloudsigma-smbios-data-check into
>lp:cloud-init.

Revision history for this message
Kiril Vladimiroff (kiril-vladimiroff) wrote :

Well it's the same check I've pushed :)

Super. We can consider this one fixed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloudinit/cs_utils.py'
2--- cloudinit/cs_utils.py 2014-02-12 10:14:49 +0000
3+++ cloudinit/cs_utils.py 2014-05-30 11:27:37 +0000
4@@ -35,6 +35,8 @@
5
6 import serial
7
8+READ_TIMEOUT = 60
9+WRITE_TIMEOUT = 10
10 SERIAL_PORT = '/dev/ttyS1'
11 if platform.system() == 'Windows':
12 SERIAL_PORT = 'COM2'
13@@ -76,7 +78,9 @@
14 self.result = self._marshal(self.raw_result)
15
16 def _execute(self):
17- connection = serial.Serial(SERIAL_PORT)
18+ connection = serial.Serial(port=SERIAL_PORT,
19+ timeout=READ_TIMEOUT,
20+ writeTimeout=WRITE_TIMEOUT)
21 connection.write(self.request)
22 return connection.readline().strip('\x04\n')
23
24
25=== modified file 'cloudinit/sources/DataSourceCloudSigma.py'
26--- cloudinit/sources/DataSourceCloudSigma.py 2014-03-04 17:11:10 +0000
27+++ cloudinit/sources/DataSourceCloudSigma.py 2014-05-30 11:27:37 +0000
28@@ -20,6 +20,7 @@
29
30 from cloudinit import log as logging
31 from cloudinit import sources
32+from cloudinit import util
33 from cloudinit.cs_utils import Cepko
34
35 LOG = logging.getLogger(__name__)
36@@ -40,12 +41,33 @@
37 self.ssh_public_key = ''
38 sources.DataSource.__init__(self, sys_cfg, distro, paths)
39
40+ def is_running_in_cloudsigma(self):
41+ """
42+ Uses dmidecode to detect if this instance of cloud-init is running
43+ in the CloudSigma's infrastructure.
44+ """
45+ dmidecode_path = util.which('dmidecode')
46+ if not dmidecode_path:
47+ return False
48+
49+ LOG.debug("Determining hypervisor product name via dmidecode")
50+ try:
51+ system_product_name, _ = util.subp([dmidecode_path, "-s", "system-product-name"])
52+ return 'cloudsigma' in system_product_name.lower()
53+ except:
54+ LOG.exception("Failed to get hypervisor product name")
55+
56+ return False
57+
58 def get_data(self):
59 """
60 Metadata is the whole server context and /meta/cloud-config is used
61 as userdata.
62 """
63 dsmode = None
64+ if not self.is_running_in_cloudsigma():
65+ return False
66+
67 try:
68 server_context = self.cepko.all().result
69 server_meta = server_context['meta']
70
71=== modified file 'tests/unittests/test_datasource/test_cloudsigma.py'
72--- tests/unittests/test_datasource/test_cloudsigma.py 2014-02-19 08:45:53 +0000
73+++ tests/unittests/test_datasource/test_cloudsigma.py 2014-05-30 11:27:37 +0000
74@@ -35,6 +35,7 @@
75 class DataSourceCloudSigmaTest(TestCase):
76 def setUp(self):
77 self.datasource = DataSourceCloudSigma.DataSourceCloudSigma("", "", "")
78+ self.datasource.is_running_in_cloudsigma = lambda: True
79 self.datasource.cepko = CepkoMock(SERVER_CONTEXT)
80 self.datasource.get_data()
81