Merge ~ruansx/cloud-init:add-zstack-datasource into cloud-init:master

Proposed by Steve Ruan
Status: Merged
Approved by: Scott Moser
Approved revision: faac76e6adbfbab9e1e3ea59089611e7f95a1532
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~ruansx/cloud-init:add-zstack-datasource
Merge into: cloud-init:master
Diff against target: 198 lines (+94/-2)
7 files modified
cloudinit/apport.py (+1/-0)
cloudinit/sources/DataSourceEc2.py (+15/-1)
doc/rtd/topics/datasources.rst (+1/-0)
doc/rtd/topics/datasources/zstack.rst (+36/-0)
tests/unittests/test_datasource/test_ec2.py (+28/-0)
tests/unittests/test_ds_identify.py (+8/-1)
tools/ds-identify (+5/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Scott Moser Approve
Review via email: mp+372445@code.launchpad.net

Commit message

Add datasource for ZStack platform.

Zstack platform provides a AWS Ec2 metadata service, and
identifies their platform to the guest by setting the 'chassis asset tag'
to a string that ends with '.zstack.io'.

LP: #1841181

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

Quick review things:
 * make a better commit message (the 'Commit message` above will be be used when this is ultimately squashed and merged)
 * add 'LP: #1841181' to your commit message. See git log for examples. Thats how MPs get associated with bugs.
 * Tests needed.
    * tests/unittests/test_ds_identify.py should be fairly to understand and update for Zstack
    * Probably add a tests/unittests/test_datasource/test_zstack.py
 * Add doc/rtd/topics/datasources/zstack.rst and update doc/rtd/topics/datasources.rst to reference it. See Exoscale for a recently added datasource example.

  * Did you check to see if simply adding Zstack in the same way as BrightBox is added would work? That could be even less code.

Revision history for this message
Steve Ruan (ruansx) wrote :

Thanks.
It's more clean to add ZStack in same way as BrightBox,and I changed it.

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

Some comments inline. I also updated your commit message a bit.

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

Also, this request is still relevant.

 * Add doc/rtd/topics/datasources/zstack.rst and update doc/rtd/topics/datasources.rst to reference it. See Exoscale for a recently added datasource example.

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

Thanks, Scott.
All comments are fixed.

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

This looks good to me now, thanks.

Steve, one style comment in-line though.

I'll get someone to point the c-i bot at this too.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:c8d47870a851f3a5b7a96fabb1442ab0224b9388
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1138/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1138//rebuild

review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

@Steve,

Just for your ease, I put together a change that updates the Zstack/ZSTACK and adds a test case also.

http://paste.ubuntu.com/p/KZWYKZCmcd/

Please grab that and update.

Revision history for this message
Ryan Harper (raharper) wrote :

Suggest a different word in the documentation, see inline comment.

Revision history for this message
Steve Ruan (ruansx) wrote :

Sorry for the late response because there is a short vacation.

Thanks for the comment. @Scott and @Ryan.

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

I'm +1 now. But you do have to fix a merge issue (look for <<<<).

Revision history for this message
Steve Ruan (ruansx) wrote :

doc/rtd/topics/datasources.rst is changed in master branch. Someone move the section "datasource/xx" from the buttom to the middle, and my commit also changed this part.

The conflict is fixed now.

Revision history for this message
Scott Moser (smoser) :
review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

Autolanding: FAILED
More details in the following jenkins job:
https://jenkins.ubuntu.com/server/job/cloud-init-autoland-test/333/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

Autolanding: FAILED
More details in the following jenkins job:
https://jenkins.ubuntu.com/server/job/cloud-init-autoland-test/334/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

Autolanding: FAILED
More details in the following jenkins job:
https://jenkins.ubuntu.com/server/job/cloud-init-autoland-test/335/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

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

Steve,
I'm sorry for not having run pycodestyle on my suggested changes..
the Lander rejected this due to some code formatting.
Fix at http://paste.ubuntu.com/p/9st9YCstxf/

you can run those tests locally with:
 tox
or specifically the pycodestyle with
  tox -e pycodestyle

Fix that and we can land. Sorry for the loss of another day.

Revision history for this message
Steve Ruan (ruansx) wrote :

Thanks Scott. It's my fault, I should run tox before pushing to the branch.

Revision history for this message
Server Team CI bot (server-team-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/apport.py b/cloudinit/apport.py
index 003ff1f..fde1f75 100644
--- a/cloudinit/apport.py
+++ b/cloudinit/apport.py
@@ -37,6 +37,7 @@ KNOWN_CLOUD_NAMES = [
37 'Scaleway',37 'Scaleway',
38 'SmartOS',38 'SmartOS',
39 'VMware',39 'VMware',
40 'ZStack',
40 'Other']41 'Other']
4142
42# Potentially clear text collected logs43# Potentially clear text collected logs
diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
index 1010745..6c72ace 100644
--- a/cloudinit/sources/DataSourceEc2.py
+++ b/cloudinit/sources/DataSourceEc2.py
@@ -33,6 +33,7 @@ class CloudNames(object):
33 ALIYUN = "aliyun"33 ALIYUN = "aliyun"
34 AWS = "aws"34 AWS = "aws"
35 BRIGHTBOX = "brightbox"35 BRIGHTBOX = "brightbox"
36 ZSTACK = "zstack"
36 # UNKNOWN indicates no positive id. If strict_id is 'warn' or 'false',37 # UNKNOWN indicates no positive id. If strict_id is 'warn' or 'false',
37 # then an attempt at the Ec2 Metadata service will be made.38 # then an attempt at the Ec2 Metadata service will be made.
38 UNKNOWN = "unknown"39 UNKNOWN = "unknown"
@@ -477,10 +478,16 @@ def identify_brightbox(data):
477 return CloudNames.BRIGHTBOX478 return CloudNames.BRIGHTBOX
478479
479480
481def identify_zstack(data):
482 if data['asset_tag'].endswith('.zstack.io'):
483 return CloudNames.ZSTACK
484
485
480def identify_platform():486def identify_platform():
481 # identify the platform and return an entry in CloudNames.487 # identify the platform and return an entry in CloudNames.
482 data = _collect_platform_data()488 data = _collect_platform_data()
483 checks = (identify_aws, identify_brightbox, lambda x: CloudNames.UNKNOWN)489 checks = (identify_aws, identify_brightbox, identify_zstack,
490 lambda x: CloudNames.UNKNOWN)
484 for checker in checks:491 for checker in checks:
485 try:492 try:
486 result = checker(data)493 result = checker(data)
@@ -498,6 +505,7 @@ def _collect_platform_data():
498 uuid: system-uuid from dmi or /sys/hypervisor505 uuid: system-uuid from dmi or /sys/hypervisor
499 uuid_source: 'hypervisor' (/sys/hypervisor/uuid) or 'dmi'506 uuid_source: 'hypervisor' (/sys/hypervisor/uuid) or 'dmi'
500 serial: dmi 'system-serial-number' (/sys/.../product_serial)507 serial: dmi 'system-serial-number' (/sys/.../product_serial)
508 asset_tag: 'dmidecode -s chassis-asset-tag'
501509
502 On Ec2 instances experimentation is that product_serial is upper case,510 On Ec2 instances experimentation is that product_serial is upper case,
503 and product_uuid is lower case. This returns lower case values for both.511 and product_uuid is lower case. This returns lower case values for both.
@@ -520,6 +528,12 @@ def _collect_platform_data():
520528
521 data['serial'] = serial.lower()529 data['serial'] = serial.lower()
522530
531 asset_tag = util.read_dmi_data('chassis-asset-tag')
532 if asset_tag is None:
533 asset_tag = ''
534
535 data['asset_tag'] = asset_tag.lower()
536
523 return data537 return data
524538
525539
diff --git a/doc/rtd/topics/datasources.rst b/doc/rtd/topics/datasources.rst
index 8e58be9..a337c08 100644
--- a/doc/rtd/topics/datasources.rst
+++ b/doc/rtd/topics/datasources.rst
@@ -45,6 +45,7 @@ The following is a list of documents for each supported datasource:
45 datasources/oracle.rst45 datasources/oracle.rst
46 datasources/ovf.rst46 datasources/ovf.rst
47 datasources/smartos.rst47 datasources/smartos.rst
48 datasources/zstack.rst
4849
4950
50Creation51Creation
diff --git a/doc/rtd/topics/datasources/zstack.rst b/doc/rtd/topics/datasources/zstack.rst
51new file mode 10064452new file mode 100644
index 0000000..36e60ff
--- /dev/null
+++ b/doc/rtd/topics/datasources/zstack.rst
@@ -0,0 +1,36 @@
1.. _datasource_zstack:
2
3ZStack
4======
5ZStack platform provides a AWS Ec2 metadata service, but with different datasource identity.
6More information about ZStack can be found at `ZStack <https://www.zstack.io>`__.
7
8Discovery
9---------
10To determine whether a vm running on ZStack platform, cloud-init checks DMI information
11by 'dmidecode -s chassis-asset-tag', if the output ends with '.zstack.io', it's running
12on ZStack platform:
13
14
15Metadata
16^^^^^^^^
17Same as EC2, instance metadata can be queried at
18
19::
20
21 GET http://169.254.169.254/2009-04-04/meta-data/
22 instance-id
23 local-hostname
24
25Userdata
26^^^^^^^^
27Same as EC2, instance userdata can be queried at
28
29::
30
31 GET http://169.254.169.254/2009-04-04/user-data/
32 meta_data.json
33 user_data
34 password
35
36.. vi: textwidth=78
diff --git a/tests/unittests/test_datasource/test_ec2.py b/tests/unittests/test_datasource/test_ec2.py
index 1ec8e00..6fabf25 100644
--- a/tests/unittests/test_datasource/test_ec2.py
+++ b/tests/unittests/test_datasource/test_ec2.py
@@ -662,4 +662,32 @@ class TestConvertEc2MetadataNetworkConfig(test_helpers.CiTestCase):
662 expected,662 expected,
663 ec2.convert_ec2_metadata_network_config(self.network_metadata))663 ec2.convert_ec2_metadata_network_config(self.network_metadata))
664664
665
666class TesIdentifyPlatform(test_helpers.CiTestCase):
667
668 def collmock(self, **kwargs):
669 """return non-special _collect_platform_data updated with changes."""
670 unspecial = {
671 'asset_tag': '3857-0037-2746-7462-1818-3997-77',
672 'serial': 'H23-C4J3JV-R6',
673 'uuid': '81c7e555-6471-4833-9551-1ab366c4cfd2',
674 'uuid_source': 'dmi',
675 }
676 unspecial.update(**kwargs)
677 return unspecial
678
679 @mock.patch('cloudinit.sources.DataSourceEc2._collect_platform_data')
680 def test_identify_zstack(self, m_collect):
681 """zstack should be identified if cassis-asset-tag ends in .zstack.io
682 """
683 m_collect.return_value = self.collmock(asset_tag='123456.zstack.io')
684 self.assertEqual(ec2.CloudNames.ZSTACK, ec2.identify_platform())
685
686 @mock.patch('cloudinit.sources.DataSourceEc2._collect_platform_data')
687 def test_identify_zstack_full_domain_only(self, m_collect):
688 """zstack asset-tag matching should match only on full domain boundary.
689 """
690 m_collect.return_value = self.collmock(asset_tag='123456.buzzstack.io')
691 self.assertEqual(ec2.CloudNames.UNKNOWN, ec2.identify_platform())
692
665# vi: ts=4 expandtab693# vi: ts=4 expandtab
diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py
index de87be2..7aeeb91 100644
--- a/tests/unittests/test_ds_identify.py
+++ b/tests/unittests/test_ds_identify.py
@@ -609,6 +609,10 @@ class TestDsIdentify(DsIdentifyBase):
609 self.assertEqual(expected, [p for p in expected if p in toks],609 self.assertEqual(expected, [p for p in expected if p in toks],
610 "path did not have expected tokens")610 "path did not have expected tokens")
611611
612 def test_zstack_is_ec2(self):
613 """EC2: chassis asset tag ends with 'zstack.io'"""
614 self._test_ds_found('Ec2-ZStack')
615
612616
613class TestIsIBMProvisioning(DsIdentifyBase):617class TestIsIBMProvisioning(DsIdentifyBase):
614 """Test the is_ibm_provisioning method in ds-identify."""618 """Test the is_ibm_provisioning method in ds-identify."""
@@ -971,8 +975,11 @@ VALID_CFG = {
971 {'name': 'blkid', 'ret': 2, 'out': ''},975 {'name': 'blkid', 'ret': 2, 'out': ''},
972 ],976 ],
973 'files': {ds_smartos.METADATA_SOCKFILE: 'would be a socket\n'},977 'files': {ds_smartos.METADATA_SOCKFILE: 'would be a socket\n'},
978 },
979 'Ec2-ZStack': {
980 'ds': 'Ec2',
981 'files': {P_CHASSIS_ASSET_TAG: '123456.zstack.io\n'},
974 }982 }
975
976}983}
977984
978# vi: ts=4 expandtab985# vi: ts=4 expandtab
diff --git a/tools/ds-identify b/tools/ds-identify
index 2447d14..f76f2a6 100755
--- a/tools/ds-identify
+++ b/tools/ds-identify
@@ -895,6 +895,11 @@ ec2_identify_platform() {
895 *.brightbox.com) _RET="Brightbox"; return 0;;895 *.brightbox.com) _RET="Brightbox"; return 0;;
896 esac896 esac
897897
898 local asset_tag="${DI_DMI_CHASSIS_ASSET_TAG}"
899 case "$asset_tag" in
900 *.zstack.io) _RET="ZStack"; return 0;;
901 esac
902
898 # AWS http://docs.aws.amazon.com/AWSEC2/903 # AWS http://docs.aws.amazon.com/AWSEC2/
899 # latest/UserGuide/identify_ec2_instances.html904 # latest/UserGuide/identify_ec2_instances.html
900 local uuid="" hvuuid="${PATH_SYS_HYPERVISOR}/uuid"905 local uuid="" hvuuid="${PATH_SYS_HYPERVISOR}/uuid"

Subscribers

People subscribed via source and target branches