Merge "Enable setting label and instance name separately"
This commit is contained in:
commit
8d3f3ae5ea
|
@ -1789,6 +1789,8 @@ section of the configuration.
|
|||
:required:
|
||||
|
||||
Identifier to refer this label.
|
||||
Nodepool will use this to set the name of the instance unless
|
||||
the name is specified as a tag.
|
||||
|
||||
.. attr:: cloud-image
|
||||
:type: str
|
||||
|
|
|
@ -162,6 +162,11 @@ class AwsProvider(Provider):
|
|||
|
||||
def createInstance(self, label):
|
||||
image_id = self.getImageId(label.cloud_image)
|
||||
tags = label.tags
|
||||
if not [tag for tag in label.tags if tag["Key"] == "Name"]:
|
||||
tags.append(
|
||||
{"Key": "Name", "Value": str(label.name)}
|
||||
)
|
||||
args = dict(
|
||||
ImageId=image_id,
|
||||
MinCount=1,
|
||||
|
@ -174,8 +179,7 @@ class AwsProvider(Provider):
|
|||
'DeviceIndex': 0}],
|
||||
TagSpecifications=[{
|
||||
'ResourceType': 'instance',
|
||||
'Tags': [{"Key": "Name",
|
||||
"Value": str(label.name)}] + label.tags
|
||||
'Tags': tags
|
||||
}]
|
||||
)
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ labels:
|
|||
- name: ubuntu1404-private-ip
|
||||
- name: ubuntu1404-userdata
|
||||
- name: ubuntu1404-with-tags
|
||||
- name: ubuntu1404-with-name-tag
|
||||
|
||||
providers:
|
||||
- name: ec2-us-west-2
|
||||
|
@ -117,3 +118,14 @@ providers:
|
|||
key-name: zuul
|
||||
tags:
|
||||
has-tags: true
|
||||
- name: name-tag
|
||||
max-servers: 1
|
||||
subnet-id: null
|
||||
security-group-id: null
|
||||
labels:
|
||||
- name: ubuntu1404-with-name-tag
|
||||
cloud-image: ubuntu1404
|
||||
instance-type: t3.medium
|
||||
key-name: zuul
|
||||
tags:
|
||||
Name: different-name
|
||||
|
|
|
@ -49,7 +49,7 @@ class TestDriverAws(tests.DBTestCase):
|
|||
host_key_checking=True,
|
||||
userdata=None,
|
||||
public_ip=True,
|
||||
tags=False):
|
||||
tags=[]):
|
||||
aws_id = 'AK000000000000000000'
|
||||
aws_key = '0123456789abcdef0123456789abcdef0123456789abcdef'
|
||||
self.useFixture(
|
||||
|
@ -90,6 +90,8 @@ class TestDriverAws(tests.DBTestCase):
|
|||
raw_config['providers'][0]['pools'][3]['security-group-id'] = sg_id
|
||||
raw_config['providers'][0]['pools'][4]['subnet-id'] = subnet_id
|
||||
raw_config['providers'][0]['pools'][4]['security-group-id'] = sg_id
|
||||
raw_config['providers'][0]['pools'][5]['subnet-id'] = subnet_id
|
||||
raw_config['providers'][0]['pools'][5]['security-group-id'] = sg_id
|
||||
|
||||
with tempfile.NamedTemporaryFile() as tf:
|
||||
tf.write(yaml.safe_dump(
|
||||
|
@ -160,13 +162,8 @@ class TestDriverAws(tests.DBTestCase):
|
|||
if tags:
|
||||
instance = ec2_resource.Instance(node.external_id)
|
||||
tag_list = instance.tags
|
||||
|
||||
self.assertIn({"Key": "has-tags", "Value": "true"},
|
||||
tag_list)
|
||||
self.assertIn({
|
||||
"Key": "Name",
|
||||
"Value": "ubuntu1404-with-tags"
|
||||
}, tag_list)
|
||||
for tag in tags:
|
||||
self.assertIn(tag, tag_list)
|
||||
|
||||
# A new request will be paused and for lack of quota
|
||||
# until this one is deleted
|
||||
|
@ -228,4 +225,14 @@ class TestDriverAws(tests.DBTestCase):
|
|||
|
||||
def test_ec2_machine_tags(self):
|
||||
self._test_ec2_machine('ubuntu1404-with-tags',
|
||||
tags=True)
|
||||
tags=[
|
||||
{"Key": "has-tags", "Value": "true"},
|
||||
{"Key": "Name",
|
||||
"Value": "ubuntu1404-with-tags"}
|
||||
])
|
||||
|
||||
def test_ec2_machine_name_tag(self):
|
||||
self._test_ec2_machine('ubuntu1404-with-name-tag',
|
||||
tags=[
|
||||
{"Key": "Name", "Value": "different-name"}
|
||||
])
|
||||
|
|
Loading…
Reference in New Issue