Merge "Add ability to select flavor by name or id" into feature/zuulv3

This commit is contained in:
Jenkins 2017-04-27 21:29:20 +00:00 committed by Gerrit Code Review
commit 4fa554a958
17 changed files with 114 additions and 48 deletions

View File

@ -245,27 +245,27 @@ providers:
- name: centos-7
diskimage: centos-7
min-ram: 1024
name-filter: 'nodepool'
flavor-name: 'nodepool'
- name: debian-jessie
diskimage: debian-jessie
min-ram: 512
name-filter: 'nodepool'
flavor-name: 'nodepool'
- name: fedora-25
diskimage: fedora-25
min-ram: 1024
name-filter: 'nodepool'
flavor-name: 'nodepool'
- name: ubuntu-precise
diskimage: ubuntu-precise
min-ram: 512
name-filter: 'nodepool'
flavor-name: 'nodepool'
- name: ubuntu-trusty
diskimage: ubuntu-trusty
min-ram: 512
name-filter: 'nodepool'
flavor-name: 'nodepool'
- name: ubuntu-xenial
diskimage: ubuntu-xenial
min-ram: 512
name-filter: 'nodepool'
flavor-name: 'nodepool'
diskimages:
- name: centos-7

View File

@ -442,7 +442,7 @@ Example configuration::
labels:
- name: precise
min-ram: 8192
name-filter: 'something to match'
flavor-name: 'something to match'
**required**
@ -453,16 +453,15 @@ Example configuration::
``diskimage``
Refers to provider's diskimages, see :ref:`provider_diskimages`.
**at least one of**
``flavor-name``
Name or id of the flavor to use. If ``min-ram`` is omitted, it
must be an exact match. If ``min-ram`` is given, ``flavor-name`` will
be used to find flavor names that meet ``min-ram`` and also contain
``flavor-name``.
``min-ram``
Determine the flavor to use (e.g. ``m1.medium``, ``m1.large``,
etc). The smallest flavor that meets the ``min-ram`` requirements
will be chosen. To further filter by flavor name, see optional
``name-filter`` below.
**optional**
``name-filter``
Additional filter complementing ``min-ram``, will be required to match on
the flavor-name (e.g. Rackspace offer a "Performance" flavour; setting
`name-filter` to ``Performance`` will ensure the chosen flavor also
contains this string as well as meeting `min-ram` requirements).
will be chosen.

View File

@ -28,7 +28,7 @@ class ConfigValidator:
v.Required('name'): str,
v.Required('diskimage'): str,
'min-ram': int,
'name-filter': str,
'flavor-name': str,
}
pool = {

View File

@ -89,7 +89,7 @@ class ProviderLabel(ConfigValue):
def __eq__(self, other):
if (other.diskimage != self.diskimage or
other.min_ram != self.min_ram or
other.name_filter != self.name_filter):
other.flavor_name != self.flavor_name):
return False
return True
@ -217,7 +217,7 @@ def loadConfig(config_path):
diskimage = newconfig.diskimages[i.name]
diskimage.image_types.add(p.image_type)
#i.min_ram = image['min-ram']
#i.name_filter = image.get('name-filter', None)
#i.flavor_name = image.get('flavor-name', None)
i.pause = bool(image.get('pause', False))
i.config_drive = image.get('config-drive', None)
@ -250,9 +250,8 @@ def loadConfig(config_path):
pl.pool = pp
pp.labels[pl.name] = pl
pl.diskimage = newconfig.diskimages[label['diskimage']]
pl.min_ram = label['min-ram']
pl.name_filter = label.get('name-filter', None)
pl.min_ram = label.get('min-ram', 0)
pl.flavor_name = label.get('flavor-name', None)
top_label = newconfig.labels[pl.name]
top_label.pools.append(pp)

View File

@ -277,9 +277,9 @@ class NodeLauncher(threading.Thread, StatsReporter):
server = self._manager.createServer(
hostname,
self._label.min_ram,
cloud_image.external_id,
name_filter=self._label.name_filter,
image_id=cloud_image.external_id,
min_ram=self._label.min_ram,
flavor_name=self._label.flavor_name,
az=self._node.az,
config_drive=self._diskimage.config_drive,
nodepool_node_id=self._node.id,

View File

@ -131,15 +131,32 @@ class ProviderManager(object):
flavors.sort(lambda a, b: cmp(a['ram'], b['ram']))
return flavors
def findFlavor(self, min_ram, name_filter=None):
# TODO(mordred): These next three methods duplicate logic that is in
# shade, but we can't defer to shade until we're happy
# with using shade's resource caching facility. We have
# not yet proven that to our satisfaction, but if/when
# we do, these should be able to go away.
def _findFlavorByName(self, flavor_name):
for f in self._flavors:
if flavor_name in (f['name'], f['id']):
return f
raise Exception("Unable to find flavor: %s" % flavor_name)
def _findFlavorByRam(self, min_ram, flavor_name):
for f in self._flavors:
if (f['ram'] >= min_ram
and (not flavor_name or flavor_name in f['name'])):
return f
raise Exception("Unable to find flavor with min ram: %s" % min_ram)
def findFlavor(self, flavor_name, min_ram):
# Note: this will throw an error if the provider is offline
# but all the callers are in threads (they call in via CreateServer) so
# the mainloop won't be affected.
for f in self._flavors:
if (f['ram'] >= min_ram
and (not name_filter or name_filter in f['name'])):
return f
raise Exception("Unable to find flavor with min ram: %s" % min_ram)
if min_ram:
return self._findFlavorByRam(min_ram, flavor_name)
else:
return self._findFlavorByName(flavor_name)
def findImage(self, name):
if name in self._images:
@ -166,17 +183,18 @@ class ProviderManager(object):
with shade_inner_exceptions():
return self._client.delete_image(name)
def createServer(self, name, min_ram, image_id=None, image_name=None,
az=None, key_name=None, name_filter=None,
config_drive=True, nodepool_node_id=None,
nodepool_image_name=None, networks=None):
def createServer(self, name, image_id=None, image_name=None,
flavor_name=None, min_ram=None,
az=None, key_name=None, config_drive=True,
nodepool_node_id=None, nodepool_image_name=None,
networks=None):
if not networks:
networks = []
if image_name:
image = self.findImage(image_name)
else:
image = {'id': image_id}
flavor = self.findFlavor(min_ram, name_filter)
flavor = self.findFlavor(flavor_name=flavor_name, min_ram=min_ram)
create_args = dict(name=name,
image=image,
flavor=flavor,

View File

@ -23,7 +23,7 @@ providers:
- name: real-label
diskimage: fake-image
min-ram: 8192
name-filter: 'Real'
flavor-name: 'Real'
diskimages:
- name: fake-image

View File

@ -23,7 +23,7 @@ providers:
- name: fake-label
diskimage: fake-image
min-ram: 8192
name-filter: 'Real'
flavor-name: 'Real'
diskimages:
- name: fake-image

View File

@ -31,7 +31,7 @@ providers:
- name: fake-label1
diskimage: fake-image
min-ram: 8192
name-filter: 'Fake'
flavor-name: 'Fake'
- name: pool2
max-servers: 1
@ -41,7 +41,7 @@ providers:
- name: fake-label2
diskimage: fake-image
min-ram: 8192
name-filter: 'Fake'
flavor-name: 'Fake'
diskimages:
- name: fake-image

View File

@ -31,7 +31,7 @@ providers:
- name: fake-label
diskimage: fake-image
min-ram: 8192
name-filter: 'Fake'
flavor-name: 'Fake'
diskimages:
- name: fake-image

View File

@ -29,7 +29,7 @@ providers:
- name: fake-label
diskimage: fake-image
min-ram: 8192
name-filter: 'Fake'
flavor-name: 'Fake'
diskimages:
- name: fake-image

View File

@ -27,7 +27,7 @@ providers:
- name: fake-label1
diskimage: fake-image1
min-ram: 8192
name-filter: 'fake'
flavor-name: 'fake'
- name: fake-provider2
cloud: fake
@ -44,7 +44,7 @@ providers:
- name: fake-label2
diskimage: fake-image2
min-ram: 8192
name-filter: 'fake'
flavor-name: 'fake'
diskimages:
- name: fake-image1

View File

@ -27,7 +27,7 @@ providers:
- name: fake-label
diskimage: fake-image
min-ram: 8192
name-filter: 'fake'
flavor-name: 'fake'
diskimages:
- name: fake-image

View File

@ -27,7 +27,7 @@ providers:
- name: fake-label
diskimage: fake-image
min-ram: 8192
name-filter: 'fake'
flavor-name: 'fake'
diskimages:
- name: fake-image

View File

@ -0,0 +1,38 @@
elements-dir: .
images-dir: '{images_dir}'
zookeeper-servers:
- host: {zookeeper_host}
port: {zookeeper_port}
chroot: {zookeeper_chroot}
labels:
- name: fake-label
min-ready: 1
providers:
- name: fake-provider
cloud: fake
region-name: fake-region
rate: 0.0001
diskimages:
- name: fake-image
pools:
- name: main
max-servers: 96
labels:
- name: fake-label
diskimage: fake-image
flavor-name: Fake Flavor
diskimages:
- name: fake-image
elements:
- fedora
- vm
release: 21
env-vars:
TMPDIR: /opt/dib_tmp
DIB_IMAGE_CACHE: /opt/dib_cache
DIB_CLOUD_IMAGES: http://download.fedoraproject.org/pub/fedora/linux/releases/test/21-Beta/Cloud/Images/x86_64/
BASE_IMAGE_FILE: Fedora-Cloud-Base-20141029-21_Beta.x86_64.qcow2

View File

@ -247,6 +247,18 @@ class TestNodepool(tests.DBTestCase):
self.assertEqual(nodes[0].provider, 'fake-provider')
self.assertEqual(nodes[0].type, 'fake-label')
def test_node_flavor_name(self):
"""Test that a node is created with a flavor name"""
configfile = self.setup_config('node_flavor_name.yaml')
pool = self.useNodepool(configfile, watermark_sleep=1)
self._useBuilder(configfile)
pool.start()
self.waitForImage('fake-provider', 'fake-image')
nodes = self.waitForNodes('fake-label')
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0].provider, 'fake-provider')
self.assertEqual(nodes[0].type, 'fake-label')
def test_node_vhd_image(self):
"""Test that a image and node are created vhd image"""
configfile = self.setup_config('node_vhd.yaml')

View File

@ -33,4 +33,4 @@ providers:
- name: big-fake
diskimage: fake-nodepool
min-ram: 8192
name-filter: 'Fake'
flavor-name: 'Fake'