swarm: Add docker_volume_type label

* add docker_volume_type for the cinder volumes which are
  used for docker storage.
* add default_docker_volume_type configuration option

Related-Bug: #1678153
Change-Id: Ie18096acf24873ef91a904df4f1a84694a2bb644
This commit is contained in:
Spyros Trigazis 2017-04-03 08:39:10 +02:00 committed by yatin
parent bd69b3fff6
commit 295ef945f6
8 changed files with 70 additions and 12 deletions

View File

@ -215,6 +215,11 @@ function create_magnum_conf {
iniset $MAGNUM_CONF docker_registry swift_region $REGION_NAME iniset $MAGNUM_CONF docker_registry swift_region $REGION_NAME
iniset $MAGNUM_CONF docker_registry swift_registry_container $MAGNUM_SWIFT_REGISTRY_CONTAINER iniset $MAGNUM_CONF docker_registry swift_registry_container $MAGNUM_SWIFT_REGISTRY_CONTAINER
fi fi
# Get the default volume type from cinder.conf and set the coresponding
# default in magnum.conf
default_volume_type=$(iniget /etc/cinder/cinder.conf DEFAULT default_volume_type)
iniset $MAGNUM_CONF cinder default_docker_volume_type $default_volume_type
} }
function create_api_paste_conf { function create_api_paste_conf {

View File

@ -14,8 +14,20 @@ from oslo_config import cfg
from magnum.i18n import _ from magnum.i18n import _
cinder_group = cfg.OptGroup(name='cinder_client', cinder_group = cfg.OptGroup(
title='Options for the Cinder client') name='cinder',
title='Options for the Cinder configuration')
cinder_client_group = cfg.OptGroup(
name='cinder_client',
title='Options for the Cinder client')
cinder_opts = [
cfg.StrOpt('default_docker_volume_type',
help=_('The default docker volume_type to use for volumes '
'used for docker storage. To use the cinder volumes '
'for docker storage, you need to select a default '
'value.'))]
cinder_client_opts = [ cinder_client_opts = [
cfg.StrOpt('region_name', cfg.StrOpt('region_name',
@ -25,10 +37,13 @@ cinder_client_opts = [
def register_opts(conf): def register_opts(conf):
conf.register_group(cinder_group) conf.register_group(cinder_group)
conf.register_opts(cinder_client_opts, group=cinder_group) conf.register_group(cinder_client_group)
conf.register_opts(cinder_opts, group=cinder_group)
conf.register_opts(cinder_client_opts, group=cinder_client_group)
def list_opts(): def list_opts():
return { return {
cinder_group: cinder_client_opts cinder_group: cinder_opts,
cinder_client_group: cinder_client_opts
} }

View File

@ -103,6 +103,12 @@ class SwarmFedoraTemplateDefinition(template_def.BaseTemplateDefinition):
extra_params['auth_url'] = context.auth_url extra_params['auth_url'] = context.auth_url
# set docker_volume_type
# use the configuration default if None provided
docker_volume_type = cluster_template.labels.get(
'docker_volume_type', CONF.cinder.default_docker_volume_type)
extra_params['docker_volume_type'] = docker_volume_type
for label in label_list: for label in label_list:
extra_params[label] = cluster_template.labels.get(label) extra_params[label] = cluster_template.labels.get(label)

View File

@ -130,6 +130,12 @@ parameters:
storage storage
default: 0 default: 0
docker_volume_type:
type: string
description: >
type of a cinder volume to allocate to docker for container/image
storage
docker_storage_driver: docker_storage_driver:
type: string type: string
description: docker storage driver name description: docker storage driver name
@ -351,6 +357,7 @@ resources:
server_image: {get_param: server_image} server_image: {get_param: server_image}
server_flavor: {get_param: master_flavor} server_flavor: {get_param: master_flavor}
docker_volume_size: {get_param: docker_volume_size} docker_volume_size: {get_param: docker_volume_size}
docker_volume_type: {get_param: docker_volume_type}
docker_storage_driver: {get_param: docker_storage_driver} docker_storage_driver: {get_param: docker_storage_driver}
fixed_network_id: {get_attr: [network, fixed_network]} fixed_network_id: {get_attr: [network, fixed_network]}
fixed_subnet_id: {get_attr: [network, fixed_subnet]} fixed_subnet_id: {get_attr: [network, fixed_subnet]}
@ -395,6 +402,7 @@ resources:
server_image: {get_param: server_image} server_image: {get_param: server_image}
server_flavor: {get_param: node_flavor} server_flavor: {get_param: node_flavor}
docker_volume_size: {get_param: docker_volume_size} docker_volume_size: {get_param: docker_volume_size}
docker_volume_type: {get_param: docker_volume_type}
docker_storage_driver: {get_param: docker_storage_driver} docker_storage_driver: {get_param: docker_storage_driver}
fixed_network_id: {get_attr: [network, fixed_network]} fixed_network_id: {get_attr: [network, fixed_network]}
fixed_subnet_id: {get_attr: [network, fixed_subnet]} fixed_subnet_id: {get_attr: [network, fixed_subnet]}

View File

@ -16,6 +16,12 @@ parameters:
size of a cinder volume to allocate to docker for container/image size of a cinder volume to allocate to docker for container/image
storage storage
docker_volume_type:
type: string
description: >
type of a cinder volume to allocate to docker for container/image
storage
docker_storage_driver: docker_storage_driver:
type: string type: string
description: docker storage driver name description: docker storage driver name
@ -452,6 +458,7 @@ resources:
type: Magnum::Optional::Cinder::Volume type: Magnum::Optional::Cinder::Volume
properties: properties:
size: {get_param: docker_volume_size} size: {get_param: docker_volume_size}
volume_type: {get_param: docker_volume_type}
docker_volume_attach: docker_volume_attach:
type: Magnum::Optional::Cinder::VolumeAttachment type: Magnum::Optional::Cinder::VolumeAttachment

View File

@ -25,6 +25,12 @@ parameters:
size of a cinder volume to allocate to docker for container/image size of a cinder volume to allocate to docker for container/image
storage storage
docker_volume_type:
type: string
description: >
type of a cinder volume to allocate to docker for container/image
storage
docker_storage_driver: docker_storage_driver:
type: string type: string
description: docker storage driver name description: docker storage driver name
@ -392,6 +398,7 @@ resources:
type: Magnum::Optional::Cinder::Volume type: Magnum::Optional::Cinder::Volume
properties: properties:
size: {get_param: docker_volume_size} size: {get_param: docker_volume_size}
volume_type: {get_param: docker_volume_type}
docker_volume_attach: docker_volume_attach:
type: Magnum::Optional::Cinder::VolumeAttachment type: Magnum::Optional::Cinder::VolumeAttachment

View File

@ -48,7 +48,8 @@ class TestClusterConductorWithSwarm(base.TestCase):
'registry_enabled': False, 'registry_enabled': False,
'server_type': 'vm', 'server_type': 'vm',
'network_driver': 'network_driver', 'network_driver': 'network_driver',
'labels': {'flannel_network_cidr': '10.101.0.0/16', 'labels': {'docker_volume_type': 'lvmdriver-1',
'flannel_network_cidr': '10.101.0.0/16',
'flannel_network_subnetlen': '26', 'flannel_network_subnetlen': '26',
'flannel_backend': 'vxlan', 'flannel_backend': 'vxlan',
'rexray_preempt': 'False', 'rexray_preempt': 'False',
@ -150,7 +151,8 @@ class TestClusterConductorWithSwarm(base.TestCase):
'swarm_version': 'fake-version', 'swarm_version': 'fake-version',
'swarm_strategy': u'spread', 'swarm_strategy': u'spread',
'volume_driver': 'rexray', 'volume_driver': 'rexray',
'rexray_preempt': 'False' 'rexray_preempt': 'False',
'docker_volume_type': 'lvmdriver-1'
} }
self.assertEqual(expected, definition) self.assertEqual(expected, definition)
self.assertEqual( self.assertEqual(
@ -225,7 +227,8 @@ class TestClusterConductorWithSwarm(base.TestCase):
'swarm_version': 'fake-version', 'swarm_version': 'fake-version',
'swarm_strategy': u'spread', 'swarm_strategy': u'spread',
'volume_driver': 'rexray', 'volume_driver': 'rexray',
'rexray_preempt': 'False' 'rexray_preempt': 'False',
'docker_volume_type': 'lvmdriver-1'
} }
self.assertEqual(expected, definition) self.assertEqual(expected, definition)
self.assertEqual( self.assertEqual(
@ -247,7 +250,8 @@ class TestClusterConductorWithSwarm(base.TestCase):
'docker_volume_size', 'fixed_network', 'http_proxy', 'docker_volume_size', 'fixed_network', 'http_proxy',
'https_proxy', 'no_proxy', 'network_driver', 'https_proxy', 'no_proxy', 'network_driver',
'master_flavor_id', 'docker_storage_driver', 'master_flavor_id', 'docker_storage_driver',
'volume_driver', 'rexray_preempt', 'fixed_subnet'] 'volume_driver', 'rexray_preempt', 'fixed_subnet',
'docker_volume_type']
for key in not_required: for key in not_required:
self.cluster_template_dict[key] = None self.cluster_template_dict[key] = None
self.cluster_dict['discovery_url'] = 'https://discovery.etcd.io/test' self.cluster_dict['discovery_url'] = 'https://discovery.etcd.io/test'
@ -290,7 +294,8 @@ class TestClusterConductorWithSwarm(base.TestCase):
'auth_url': 'http://192.168.10.10:5000/v3', 'auth_url': 'http://192.168.10.10:5000/v3',
'swarm_version': 'fake-version', 'swarm_version': 'fake-version',
'swarm_strategy': u'spread', 'swarm_strategy': u'spread',
'rexray_preempt': 'False' 'rexray_preempt': 'False',
'docker_volume_type': 'lvmdriver-1'
} }
self.assertEqual(expected, definition) self.assertEqual(expected, definition)
self.assertEqual( self.assertEqual(
@ -359,7 +364,8 @@ class TestClusterConductorWithSwarm(base.TestCase):
'swarm_version': 'fake-version', 'swarm_version': 'fake-version',
'swarm_strategy': u'spread', 'swarm_strategy': u'spread',
'volume_driver': 'rexray', 'volume_driver': 'rexray',
'rexray_preempt': 'False' 'rexray_preempt': 'False',
'docker_volume_type': 'lvmdriver-1'
} }
self.assertEqual(expected, definition) self.assertEqual(expected, definition)
self.assertEqual( self.assertEqual(
@ -429,7 +435,8 @@ class TestClusterConductorWithSwarm(base.TestCase):
'swarm_version': 'fake-version', 'swarm_version': 'fake-version',
'swarm_strategy': u'spread', 'swarm_strategy': u'spread',
'volume_driver': 'rexray', 'volume_driver': 'rexray',
'rexray_preempt': 'False' 'rexray_preempt': 'False',
'docker_volume_type': 'lvmdriver-1'
} }
self.assertEqual(expected, definition) self.assertEqual(expected, definition)
self.assertEqual( self.assertEqual(

View File

@ -749,6 +749,8 @@ class AtomicSwarmTemplateDefinitionTestCase(base.TestCase):
mock_context.user_name = 'fake_user' mock_context.user_name = 'fake_user'
mock_context.tenant = 'fake_tenant' mock_context.tenant = 'fake_tenant'
docker_volume_type = mock_cluster_template.labels.get(
'docker_volume_type')
flannel_cidr = mock_cluster_template.labels.get('flannel_network_cidr') flannel_cidr = mock_cluster_template.labels.get('flannel_network_cidr')
flannel_subnet = mock_cluster_template.labels.get( flannel_subnet = mock_cluster_template.labels.get(
'flannel_network_subnetlen') 'flannel_network_subnetlen')
@ -768,7 +770,8 @@ class AtomicSwarmTemplateDefinitionTestCase(base.TestCase):
'flannel_network_subnetlen': flannel_subnet, 'flannel_network_subnetlen': flannel_subnet,
'auth_url': 'http://192.168.10.10:5000/v3', 'auth_url': 'http://192.168.10.10:5000/v3',
'rexray_preempt': rexray_preempt, 'rexray_preempt': rexray_preempt,
'swarm_strategy': swarm_strategy}} 'swarm_strategy': swarm_strategy,
'docker_volume_type': docker_volume_type}}
mock_get_params.assert_called_once_with(mock_context, mock_get_params.assert_called_once_with(mock_context,
mock_cluster_template, mock_cluster_template,
mock_cluster, mock_cluster,