diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 80633f2ce..e5890f99b 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -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 diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 181cdf7a9..5fb958b98 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -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. diff --git a/nodepool/cmd/config_validator.py b/nodepool/cmd/config_validator.py index cc1743baa..666824e2b 100644 --- a/nodepool/cmd/config_validator.py +++ b/nodepool/cmd/config_validator.py @@ -28,7 +28,7 @@ class ConfigValidator: v.Required('name'): str, v.Required('diskimage'): str, 'min-ram': int, - 'name-filter': str, + 'flavor-name': str, } pool = { diff --git a/nodepool/config.py b/nodepool/config.py index ce91850c3..c7370549c 100644 --- a/nodepool/config.py +++ b/nodepool/config.py @@ -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) diff --git a/nodepool/nodepool.py b/nodepool/nodepool.py index dc38e4f32..5354dbfd4 100644 --- a/nodepool/nodepool.py +++ b/nodepool/nodepool.py @@ -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, diff --git a/nodepool/provider_manager.py b/nodepool/provider_manager.py index 1c24eae13..b9ccef3e0 100644 --- a/nodepool/provider_manager.py +++ b/nodepool/provider_manager.py @@ -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, diff --git a/nodepool/tests/fixtures/integration_noocc.yaml b/nodepool/tests/fixtures/integration_noocc.yaml index ab4392d49..4cfcaad0c 100644 --- a/nodepool/tests/fixtures/integration_noocc.yaml +++ b/nodepool/tests/fixtures/integration_noocc.yaml @@ -23,7 +23,7 @@ providers: - name: real-label diskimage: fake-image min-ram: 8192 - name-filter: 'Real' + flavor-name: 'Real' diskimages: - name: fake-image diff --git a/nodepool/tests/fixtures/integration_occ.yaml b/nodepool/tests/fixtures/integration_occ.yaml index a4f711fe8..bc0733c9d 100644 --- a/nodepool/tests/fixtures/integration_occ.yaml +++ b/nodepool/tests/fixtures/integration_occ.yaml @@ -23,7 +23,7 @@ providers: - name: fake-label diskimage: fake-image min-ram: 8192 - name-filter: 'Real' + flavor-name: 'Real' diskimages: - name: fake-image diff --git a/nodepool/tests/fixtures/multiple_pools.yaml b/nodepool/tests/fixtures/multiple_pools.yaml index 50c23a188..49f667320 100644 --- a/nodepool/tests/fixtures/multiple_pools.yaml +++ b/nodepool/tests/fixtures/multiple_pools.yaml @@ -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 diff --git a/nodepool/tests/fixtures/node.yaml b/nodepool/tests/fixtures/node.yaml index 6691e9c92..eb2cb2b07 100644 --- a/nodepool/tests/fixtures/node.yaml +++ b/nodepool/tests/fixtures/node.yaml @@ -31,7 +31,7 @@ providers: - name: fake-label diskimage: fake-image min-ram: 8192 - name-filter: 'Fake' + flavor-name: 'Fake' diskimages: - name: fake-image diff --git a/nodepool/tests/fixtures/node_az.yaml b/nodepool/tests/fixtures/node_az.yaml index 7162e910e..f234cab1b 100644 --- a/nodepool/tests/fixtures/node_az.yaml +++ b/nodepool/tests/fixtures/node_az.yaml @@ -29,7 +29,7 @@ providers: - name: fake-label diskimage: fake-image min-ram: 8192 - name-filter: 'Fake' + flavor-name: 'Fake' diskimages: - name: fake-image diff --git a/nodepool/tests/fixtures/node_cmd.yaml b/nodepool/tests/fixtures/node_cmd.yaml index 8e48874f2..08e1120cd 100644 --- a/nodepool/tests/fixtures/node_cmd.yaml +++ b/nodepool/tests/fixtures/node_cmd.yaml @@ -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 diff --git a/nodepool/tests/fixtures/node_disabled_label.yaml b/nodepool/tests/fixtures/node_disabled_label.yaml index 93c2c4d07..e6e20dd3d 100644 --- a/nodepool/tests/fixtures/node_disabled_label.yaml +++ b/nodepool/tests/fixtures/node_disabled_label.yaml @@ -27,7 +27,7 @@ providers: - name: fake-label diskimage: fake-image min-ram: 8192 - name-filter: 'fake' + flavor-name: 'fake' diskimages: - name: fake-image diff --git a/nodepool/tests/fixtures/node_diskimage_fail.yaml b/nodepool/tests/fixtures/node_diskimage_fail.yaml index f0f5b86f3..f05be81b8 100644 --- a/nodepool/tests/fixtures/node_diskimage_fail.yaml +++ b/nodepool/tests/fixtures/node_diskimage_fail.yaml @@ -27,7 +27,7 @@ providers: - name: fake-label diskimage: fake-image min-ram: 8192 - name-filter: 'fake' + flavor-name: 'fake' diskimages: - name: fake-image diff --git a/nodepool/tests/fixtures/node_flavor_name.yaml b/nodepool/tests/fixtures/node_flavor_name.yaml new file mode 100644 index 000000000..10909dd5e --- /dev/null +++ b/nodepool/tests/fixtures/node_flavor_name.yaml @@ -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 diff --git a/nodepool/tests/test_nodepool.py b/nodepool/tests/test_nodepool.py index 32cd4ba32..bd4ce8b9d 100644 --- a/nodepool/tests/test_nodepool.py +++ b/nodepool/tests/test_nodepool.py @@ -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') diff --git a/tools/fake.yaml b/tools/fake.yaml index 52815f5f1..8a9a2786b 100644 --- a/tools/fake.yaml +++ b/tools/fake.yaml @@ -33,4 +33,4 @@ providers: - name: big-fake diskimage: fake-nodepool min-ram: 8192 - name-filter: 'Fake' + flavor-name: 'Fake'