Allow to specify auto_security_group in default templates

The aim of this patch is to provide ability to specify
auto_security_group and security groups in default templates.

Change-Id: I304f4965580a9737c826e2862a70970a53cd5db8
Closes-bug: 1470177
This commit is contained in:
Vitaly Gridnev 2015-07-03 17:31:51 +03:00
parent c6dc37c3fb
commit 87bd46651f
30 changed files with 134 additions and 52 deletions

View File

@ -55,7 +55,13 @@ node_group_template_opts = [
help='Flavor id field for a node group template.'), help='Flavor id field for a node group template.'),
cfg.StrOpt('floating_ip_pool', cfg.StrOpt('floating_ip_pool',
help='Floating ip pool field for a node group template.') help='Floating ip pool field for a node group template.'),
cfg.BoolOpt('auto_security_group',
default=False,
help='Auto security group field for node group template.'),
cfg.ListOpt('security_groups',
default=[],
help='Security group field for node group template.')
] ]
# Options that we allow to be replaced in a cluster template # Options that we allow to be replaced in a cluster template
@ -260,12 +266,7 @@ def substitute_config_values(configs, template, path):
for opt, value in six.iteritems(configs): for opt, value in six.iteritems(configs):
if opt in opt_names and opt in template: if opt in opt_names and opt in template:
if value is None: template[opt] = value
template[opt] = None
else:
# Use args to allow for keyword arguments to format
args = {opt: value}
template[opt] = template[opt].format(**args)
def get_configs(section): def get_configs(section):

View File

@ -7,5 +7,7 @@
], ],
"name": "cdh-5-default-datanode", "name": "cdh-5-default-datanode",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -10,5 +10,7 @@
], ],
"name": "cdh-5-default-namenode", "name": "cdh-5-default-namenode",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -8,5 +8,7 @@
], ],
"name": "cdh-5-default-secondary-namenode", "name": "cdh-5-default-secondary-namenode",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "cdh-530-default-datanode", "name": "cdh-530-default-datanode",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -10,5 +10,7 @@
], ],
"name": "cdh-530-default-namenode", "name": "cdh-530-default-namenode",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -8,5 +8,7 @@
], ],
"name": "cdh-530-default-secondary-namenode", "name": "cdh-530-default-secondary-namenode",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "cdh-540-default-datanode", "name": "cdh-540-default-datanode",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -10,5 +10,7 @@
], ],
"name": "cdh-540-default-namenode", "name": "cdh-540-default-namenode",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -8,5 +8,7 @@
], ],
"name": "cdh-540-default-secondary-namenode", "name": "cdh-540-default-secondary-namenode",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -10,5 +10,7 @@
], ],
"name": "hdp-206-default-master", "name": "hdp-206-default-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -8,5 +8,7 @@
], ],
"name": "hdp-206-default-secondary-master", "name": "hdp-206-default-secondary-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "hdp-206-default-worker", "name": "hdp-206-default-worker",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -11,5 +11,7 @@
], ],
"name": "mapr-311-default-master", "name": "mapr-311-default-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "mapr-311-default-worker", "name": "mapr-311-default-worker",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -11,5 +11,7 @@
], ],
"name": "mapr-401mr1-default-master", "name": "mapr-401mr1-default-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "mapr-401mr1-default-worker", "name": "mapr-401mr1-default-worker",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -12,5 +12,7 @@
], ],
"name": "mapr-401mr2-default-master", "name": "mapr-401mr2-default-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "mapr-401mr2-default-worker", "name": "mapr-401mr2-default-worker",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -12,5 +12,7 @@
], ],
"name": "mapr-402mr2-default-master", "name": "mapr-402mr2-default-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "mapr-402mr2-default-worker", "name": "mapr-402mr2-default-worker",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -11,5 +11,7 @@
], ],
"name": "mapr-spark-default-master", "name": "mapr-spark-default-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "mapr-spark-default-worker", "name": "mapr-spark-default-worker",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "spark-100-default-master", "name": "spark-100-default-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "spark-100-default-slave", "name": "spark-100-default-slave",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -8,6 +8,7 @@ flavor_id = 2
# of the master node to 4 which is m1.large in the # of the master node to 4 which is m1.large in the
# default flavor set # default flavor set
flavor_id = 4 flavor_id = 4
auto_security_group = true
[cdh-530-default-namenode] [cdh-530-default-namenode]
# For the CDH plugin, version 5.3.0, set the flavor_id # For the CDH plugin, version 5.3.0, set the flavor_id

View File

@ -8,5 +8,7 @@
], ],
"name": "vanilla-260-default-master", "name": "vanilla-260-default-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -8,5 +8,7 @@
], ],
"name": "vanilla-260-default-secondary-master", "name": "vanilla-260-default-secondary-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -7,5 +7,7 @@
], ],
"name": "vanilla-260-default-worker", "name": "vanilla-260-default-worker",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
"security_groups": "{security_groups}"
} }

View File

@ -57,7 +57,9 @@ master_json = {
], ],
"name": "vanilla-260-default-master", "name": "vanilla-260-default-master",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
'security_groups': "{security_groups}"
} }
worker_json = { worker_json = {
@ -69,7 +71,9 @@ worker_json = {
], ],
"name": "vanilla-260-default-worker", "name": "vanilla-260-default-worker",
"floating_ip_pool": "{floating_ip_pool}", "floating_ip_pool": "{floating_ip_pool}",
"flavor_id": "{flavor_id}" "flavor_id": "{flavor_id}",
"auto_security_group": "{auto_security_group}",
'security_groups': "{security_groups}"
} }
@ -241,7 +245,8 @@ class TemplateUpdateTestCase(base.ConductorManagerTestCase):
files = self._write_files( files = self._write_files(
tempdir, [cluster_json, master_json, worker_json, some_other_json]) tempdir, [cluster_json, master_json, worker_json, some_other_json])
get_configs.return_value = {"flavor_id": 2} get_configs.return_value = {"flavor_id": '2', 'security_groups': [],
'auto_security_group': False}
option_values = {"plugin_name": None, option_values = {"plugin_name": None,
"plugin_version": None} "plugin_version": None}
template_api.set_conf(Config(option_values)) template_api.set_conf(Config(option_values))
@ -286,7 +291,12 @@ class TemplateUpdateTestCase(base.ConductorManagerTestCase):
files = self._write_files( files = self._write_files(
tempdir, [cluster_json, master_json, worker_json]) tempdir, [cluster_json, master_json, worker_json])
get_configs.return_value = {"flavor_id": 2} get_configs.return_value = {
"flavor_id": '2',
'security_groups': [],
'auto_security_group': False
}
option_values = {"plugin_name": None, option_values = {"plugin_name": None,
"plugin_version": None} "plugin_version": None}
template_api.set_conf(Config(option_values)) template_api.set_conf(Config(option_values))
@ -312,7 +322,8 @@ class TemplateUpdateTestCase(base.ConductorManagerTestCase):
files = self._write_files( files = self._write_files(
tempdir, [cluster_json, master_json, worker_json]) tempdir, [cluster_json, master_json, worker_json])
get_configs.return_value = {"flavor_id": 2} get_configs.return_value = {"flavor_id": '2', 'security_groups': [],
'auto_security_group': False}
option_values = {"plugin_name": None, option_values = {"plugin_name": None,
"plugin_version": None} "plugin_version": None}
template_api.set_conf(Config(option_values)) template_api.set_conf(Config(option_values))
@ -603,7 +614,7 @@ class TemplateUpdateTestCase(base.ConductorManagerTestCase):
@mock.patch("sahara.db.templates.api.get_configs") @mock.patch("sahara.db.templates.api.get_configs")
@mock.patch("sahara.db.templates.api.add_config_section_for_template") @mock.patch("sahara.db.templates.api.add_config_section_for_template")
def test_do_update(self, add_config, get_configs): def test_do_update_trash(self, add_config, get_configs):
self.logger.clear_log() self.logger.clear_log()
ctx = context.ctx() ctx = context.ctx()
@ -611,15 +622,19 @@ class TemplateUpdateTestCase(base.ConductorManagerTestCase):
self._write_files(tempdir, [cluster_json, master_json, worker_json]) self._write_files(tempdir, [cluster_json, master_json, worker_json])
get_configs.return_value = {"flavor_id": 2, get_configs.return_value = {
"neutron_management_network": uuid.uuid4()} "flavor_id": '2',
"neutron_management_network": str(uuid.uuid4()),
'auto_security_group': True,
'security_groups': [],
}
option_values = {"tenant_id": ctx.tenant_id, option_values = {"tenant_id": ctx.tenant_id,
"directory": tempdir, "directory": tempdir,
"norecurse": None, "norecurse": None,
"plugin_name": None, "plugin_name": None,
"plugin_version": None} "plugin_version": None}
template_api.set_conf(Config(option_values)) template_api.set_conf(Config(option_values))
template_api.do_update() template_api.do_update()
ngs = self.api.node_group_template_get_all(ctx) ngs = self.api.node_group_template_get_all(ctx)
@ -644,8 +659,11 @@ class TemplateUpdateTestCase(base.ConductorManagerTestCase):
self._write_files(tempdir, [cluster_json, master_json, worker_json]) self._write_files(tempdir, [cluster_json, master_json, worker_json])
get_configs.return_value = {"flavor_id": 2, get_configs.return_value = {
"neutron_management_network": uuid.uuid4()} "flavor_id": '2',
"neutron_management_network": str(uuid.uuid4())
}
option_values = {"tenant_id": ctx.tenant_id, option_values = {"tenant_id": ctx.tenant_id,
"directory": tempdir, "directory": tempdir,
"norecurse": None, "norecurse": None,
@ -679,8 +697,10 @@ class TemplateUpdateTestCase(base.ConductorManagerTestCase):
self._write_files(tempdir, [cluster_json, master_json, worker_json]) self._write_files(tempdir, [cluster_json, master_json, worker_json])
get_configs.return_value = {"flavor_id": 2, get_configs.return_value = {
"neutron_management_network": uuid.uuid4()} "flavor_id": '2',
"neutron_management_network": str(uuid.uuid4())
}
option_values = {"tenant_id": ctx.tenant_id, option_values = {"tenant_id": ctx.tenant_id,
"directory": tempdir, "directory": tempdir,
"norecurse": None, "norecurse": None,
@ -714,8 +734,11 @@ class TemplateUpdateTestCase(base.ConductorManagerTestCase):
self._write_files(tempdir, [cluster_json, master_json, worker_json]) self._write_files(tempdir, [cluster_json, master_json, worker_json])
get_configs.return_value = {"flavor_id": 2, get_configs.return_value = {
"neutron_management_network": uuid.uuid4()} "flavor_id": '2',
"neutron_management_network": str(uuid.uuid4())
}
option_values = {"tenant_id": ctx.tenant_id, option_values = {"tenant_id": ctx.tenant_id,
"directory": tempdir, "directory": tempdir,
"norecurse": None, "norecurse": None,
@ -755,8 +778,11 @@ class TemplateUpdateTestCase(base.ConductorManagerTestCase):
self._write_files(tempdir, [cluster_json, master_json, worker_json]) self._write_files(tempdir, [cluster_json, master_json, worker_json])
get_configs.return_value = {"flavor_id": 2, get_configs.return_value = {
"neutron_management_network": uuid.uuid4()} "flavor_id": '2',
"neutron_management_network": str(uuid.uuid4())
}
option_values = {"tenant_id": ctx.tenant_id, option_values = {"tenant_id": ctx.tenant_id,
"directory": tempdir, "directory": tempdir,
"norecurse": None, "norecurse": None,