diff --git a/etc/rally/rally.conf.sample b/etc/rally/rally.conf.sample index ca726865..b2e5c4cd 100644 --- a/etc/rally/rally.conf.sample +++ b/etc/rally/rally.conf.sample @@ -240,15 +240,15 @@ # Time(in sec) to sleep after creating a resource before polling for # the status. (floating point value) -#magnum_bay_create_prepoll_delay = 5.0 +#magnum_cluster_create_prepoll_delay = 5.0 -# Time(in sec) to wait for magnum bay to be created. (floating point +# Time(in sec) to wait for magnum cluster to be created. (floating point # value) -#magnum_bay_create_timeout = 1200.0 +#magnum_cluster_create_timeout = 1200.0 -# Time interval(in sec) between checks when waiting for bay creation. +# Time interval(in sec) between checks when waiting for cluster creation. # (floating point value) -#magnum_bay_create_poll_interval = 1.0 +#magnum_cluster_create_poll_interval = 1.0 # Delay between creating Manila share and polling for its status. # (floating point value) diff --git a/rally-jobs/rally-magnum.yaml b/rally-jobs/rally-magnum.yaml index 096d4bc2..73efc57f 100644 --- a/rally-jobs/rally-magnum.yaml +++ b/rally-jobs/rally-magnum.yaml @@ -1,5 +1,5 @@ --- - MagnumBaymodels.list_baymodels: + MagnumClusterTemplates.list_cluster_templates: - runner: type: "constant" @@ -9,7 +9,7 @@ users: tenants: 1 users_per_tenant: 1 - baymodels: + cluster_templates: image_id: "fedora-atomic-latest" flavor_id: "m1.small" master_flavor_id: "m1.small" @@ -33,7 +33,7 @@ users: tenants: 1 users_per_tenant: 1 - baymodels: + cluster_templates: image_id: "fedora-atomic-latest" flavor_id: "m1.small" master_flavor_id: "m1.small" @@ -48,7 +48,7 @@ failure_rate: max: 0 - MagnumBays.create_and_list_bays: + MagnumClusters.create_and_list_clusters: - args: node_count: 1 @@ -60,7 +60,7 @@ users: tenants: 1 users_per_tenant: 1 - baymodels: + cluster_templates: image_id: "fedora-atomic-latest" flavor_id: "m1.small" master_flavor_id: "m1.small" diff --git a/rally/plugins/openstack/cleanup/resources.py b/rally/plugins/openstack/cleanup/resources.py index 7983ed3b..69437a39 100644 --- a/rally/plugins/openstack/cleanup/resources.py +++ b/rally/plugins/openstack/cleanup/resources.py @@ -90,16 +90,16 @@ class MagnumMixin(base.ResourceManager): return result -@base.resource("magnum", "bays", order=next(_magnum_order), +@base.resource("magnum", "clusters", order=next(_magnum_order), tenant_resource=True) -class MagnumBay(MagnumMixin): - """Resource class for Magnum bay.""" +class MagnumCluster(MagnumMixin): + """Resource class for Magnum cluster.""" -@base.resource("magnum", "baymodels", order=next(_magnum_order), +@base.resource("magnum", "cluster_templates", order=next(_magnum_order), tenant_resource=True) -class MagnumBaymodel(MagnumMixin): - """Resource class for Magnum baymodel.""" +class MagnumClusterTemplate(MagnumMixin): + """Resource class for Magnum cluster_template.""" # HEAT diff --git a/rally/plugins/openstack/context/magnum/cluster_templates.py b/rally/plugins/openstack/context/magnum/cluster_templates.py new file mode 100644 index 00000000..2e20da9f --- /dev/null +++ b/rally/plugins/openstack/context/magnum/cluster_templates.py @@ -0,0 +1,134 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from rally.common.i18n import _ +from rally.common import logging +from rally.common import utils as rutils +from rally import consts +from rally.plugins.openstack.cleanup import manager as resource_manager +from rally.plugins.openstack.scenarios.magnum import utils as magnum_utils +from rally.plugins.openstack.scenarios.nova import utils as nova_utils +from rally.task import context + + +LOG = logging.getLogger(__name__) + + +@context.configure(name="cluster_templates", order=470) +class ClusterTemplateGenerator(context.Context): + """Context class for generating temporary cluster model for benchmarks.""" + + CONFIG_SCHEMA = { + "type": "object", + "$schema": consts.JSON_SCHEMA, + "properties": { + "image_id": { + "type": "string" + }, + "flavor_id": { + "type": "string" + }, + "master_flavor_id": { + "type": "string" + }, + "external_network_id": { + "type": "string" + }, + "fixed_network": { + "type": "string" + }, + "fixed_subnet": { + "type": "string" + }, + "dns_nameserver": { + "type": "string" + }, + "docker_volume_size": { + "type": "integer" + }, + "labels": { + "type": ["string"] + }, + "coe": { + "type": "string" + }, + "http_proxy": { + "type": "string" + }, + "https_proxy": { + "type": "string" + }, + "no_proxy": { + "type": "string" + }, + "network_driver": { + "type": "string" + }, + "tls_disabled": { + "type": "boolean" + }, + "public": { + "type": "boolean" + }, + "registry_enabled": { + "type": "boolean" + }, + "volume_driver": { + "type": "string" + }, + "server_type": { + "type": "string" + }, + "docker_storage_driver": { + "type": "string" + }, + "master_lb_enabled": { + "type": "boolean" + } + }, + "required": ["image_id", "external_network_id", "coe"], + "additionalProperties": False + } + + @logging.log_task_wrapper(LOG.info, _("Enter context: `ClusterTemplate`")) + def setup(self): + for user, tenant_id in rutils.iterate_per_tenants( + self.context["users"]): + + nova_scenario = nova_utils.NovaScenario({ + "user": user, + "task": self.context["task"], + "config": {"api_versions": self.context["config"].get( + "api_versions", [])} + }) + keypair = nova_scenario._create_keypair() + + magnum_scenario = magnum_utils.MagnumScenario({ + "user": user, + "task": self.context["task"], + "config": {"api_versions": self.context["config"].get( + "api_versions", [])} + }) + + cluster_template = magnum_scenario._create_cluster_template( + keypair_id=keypair, **self.config) + + ct_uuid = cluster_template.uuid + self.context["tenants"][tenant_id]["cluster_template"] = ct_uuid + + @logging.log_task_wrapper(LOG.info, _("Exit context: `ClusterTemplate`")) + def cleanup(self): + resource_manager.cleanup( + names=["magnum.cluster_templates", "nova.keypairs"], + users=self.context.get("users", [])) diff --git a/rally/plugins/openstack/context/magnum/clusters.py b/rally/plugins/openstack/context/magnum/clusters.py new file mode 100644 index 00000000..b3461e1a --- /dev/null +++ b/rally/plugins/openstack/context/magnum/clusters.py @@ -0,0 +1,73 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from rally.common.i18n import _ +from rally.common import logging +from rally.common import utils as rutils +from rally import consts +from rally.plugins.openstack.cleanup import manager as resource_manager +from rally.plugins.openstack.scenarios.magnum import utils as magnum_utils +from rally.task import context + + +LOG = logging.getLogger(__name__) + + +@context.configure(name="clusters", order=480) +class ClusterGenerator(context.Context): + """Context class for generating temporary cluster for benchmarks.""" + + CONFIG_SCHEMA = { + "type": "object", + "$schema": consts.JSON_SCHEMA, + "properties": { + "cluster_template_uuid": { + "type": "string" + }, + "node_count": { + "type": "integer", + "minimum": 1, + "default": 1 + }, + }, + "additionalProperties": False + } + + @logging.log_task_wrapper(LOG.info, _("Enter context: `Cluster`")) + def setup(self): + for user, tenant_id in rutils.iterate_per_tenants( + self.context["users"]): + + magnum_scenario = magnum_utils.MagnumScenario({ + "user": user, + "task": self.context["task"], + "config": {"api_versions": self.context["config"].get( + "api_versions", [])} + }) + + # create a cluster + ct_uuid = self.config.get("cluster_template_uuid", None) + if ct_uuid is None: + ctx = self.context["tenants"][tenant_id] + ct_uuid = ctx.get("cluster_template") + cluster = magnum_scenario._create_cluster( + cluster_template=ct_uuid, + node_count=self.config.get("node_count")) + self.context["tenants"][tenant_id]["cluster"] = cluster.uuid + + @logging.log_task_wrapper(LOG.info, _("Exit context: `Cluster`")) + def cleanup(self): + resource_manager.cleanup( + names=["magnum.clusters"], + users=self.context.get("users", [])) diff --git a/rally/plugins/openstack/scenarios/magnum/cluster_templates.py b/rally/plugins/openstack/scenarios/magnum/cluster_templates.py new file mode 100644 index 00000000..46718c74 --- /dev/null +++ b/rally/plugins/openstack/scenarios/magnum/cluster_templates.py @@ -0,0 +1,45 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from rally import consts +from rally.plugins.openstack import scenario +from rally.plugins.openstack.scenarios.magnum import utils +from rally.task import validation + + +"""Scenarios for Magnum cluster_templates.""" + + +@validation.required_services(consts.Service.MAGNUM) +@validation.required_openstack(users=True) +@scenario.configure(context={"cleanup": ["magnum"]}, + name="MagnumClusterTemplates.list_cluster_templates") +class ListClusterTemplates(utils.MagnumScenario): + + def run(self, **kwargs): + """List all cluster_templates. + + Measure the "magnum cluster_template-list" command performance. + + :param limit: (Optional) The maximum number of results to return + per request, if: + + 1) limit > 0, the maximum number of cluster_templates to return. + 2) limit param is NOT specified (None), the number of items + returned respect the maximum imposed by the Magnum API + (see Magnum's api.max_limit option). + :param kwargs: optional additional arguments for cluster_templates + listing + """ + self._list_cluster_templates(**kwargs) diff --git a/rally/plugins/openstack/scenarios/magnum/clusters.py b/rally/plugins/openstack/scenarios/magnum/clusters.py new file mode 100644 index 00000000..f3f0fabf --- /dev/null +++ b/rally/plugins/openstack/scenarios/magnum/clusters.py @@ -0,0 +1,65 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from rally import consts +from rally.plugins.openstack import scenario +from rally.plugins.openstack.scenarios.magnum import utils +from rally.task import validation + +"""Scenarios for Magnum clusters.""" + + +@validation.required_services(consts.Service.MAGNUM) +@validation.required_openstack(users=True) +@scenario.configure(context={"cleanup": ["magnum.clusters"]}, + name="MagnumClusters.list_clusters") +class ListClusters(utils.MagnumScenario): + + def run(self, **kwargs): + """List all clusters. + + Measure the "magnum clusters-list" command performance. + :param limit: (Optional) The maximum number of results to return + per request, if: + + 1) limit > 0, the maximum number of clusters to return. + 2) limit param is NOT specified (None), the number of items + returned respect the maximum imposed by the Magnum API + (see Magnum's api.max_limit option). + + :param kwargs: optional additional arguments for clusters listing + """ + self._list_clusters(**kwargs) + + +@validation.required_services(consts.Service.MAGNUM) +@validation.required_openstack(users=True) +@validation.required_contexts("cluster_templates") +@scenario.configure(context={"cleanup": ["magnum.clusters"]}, + name="MagnumClusters.create_and_list_clusters") +class CreateAndListClusters(utils.MagnumScenario): + + def run(self, node_count, **kwargs): + """create cluster and then list all clusters. + + :param node_count: the cluster node count. + :param cluster_template_uuid: optional, if user want to use an existing + cluster_template + :param kwargs: optional additional arguments for cluster creation + """ + cluster_template_uuid = kwargs.get("cluster_template_uuid", None) + if cluster_template_uuid is None: + cluster_template_uuid = self.context["tenant"]["cluster_template"] + self._create_cluster(cluster_template_uuid, node_count, **kwargs) + self._list_clusters(**kwargs) diff --git a/rally/plugins/openstack/scenarios/magnum/utils.py b/rally/plugins/openstack/scenarios/magnum/utils.py index 511cbfb9..44fc4f2e 100644 --- a/rally/plugins/openstack/scenarios/magnum/utils.py +++ b/rally/plugins/openstack/scenarios/magnum/utils.py @@ -20,17 +20,18 @@ from rally.task import atomic from rally.task import utils MAGNUM_BENCHMARK_OPTS = [ - cfg.FloatOpt("magnum_bay_create_prepoll_delay", + cfg.FloatOpt("magnum_cluster_create_prepoll_delay", default=5.0, help="Time(in sec) to sleep after creating a resource before " "polling for the status."), - cfg.FloatOpt("magnum_bay_create_timeout", + cfg.FloatOpt("magnum_cluster_create_timeout", default=1200.0, - help="Time(in sec) to wait for magnum bay to be created."), - cfg.FloatOpt("magnum_bay_create_poll_interval", + help="Time(in sec) to wait for magnum cluster to be " + "created."), + cfg.FloatOpt("magnum_cluster_create_poll_interval", default=1.0, help="Time interval(in sec) between checks when waiting for " - "bay creation."), + "cluster creation."), ] CONF = cfg.CONF @@ -41,76 +42,78 @@ CONF.register_opts(MAGNUM_BENCHMARK_OPTS, group=benchmark_group) class MagnumScenario(scenario.OpenStackScenario): """Base class for Magnum scenarios with basic atomic actions.""" - @atomic.action_timer("magnum.list_baymodels") - def _list_baymodels(self, **kwargs): - """Return list of baymodels. + @atomic.action_timer("magnum.list_cluster_templates") + def _list_cluster_templates(self, **kwargs): + """Return list of cluster_templates. :param limit: (Optional) The maximum number of results to return per request, if: - 1) limit > 0, the maximum number of baymodels to return. + 1) limit > 0, the maximum number of cluster_templates to return. 2) limit param is NOT specified (None), the number of items returned respect the maximum imposed by the Magnum API (see Magnum's api.max_limit option). - :param kwargs: Optional additional arguments for baymodels listing + :param kwargs: Optional additional arguments for cluster_templates + listing - :returns: baymodels list + :returns: cluster_templates list """ - return self.clients("magnum").baymodels.list(**kwargs) + return self.clients("magnum").cluster_templates.list(**kwargs) - @atomic.action_timer("magnum.create_baymodel") - def _create_baymodel(self, **kwargs): - """Create a baymodel + @atomic.action_timer("magnum.create_cluster_template") + def _create_cluster_template(self, **kwargs): + """Create a cluster_template - :param kwargs: optional additional arguments for baymodel creation - :returns: magnum baymodel + :param kwargs: optional additional arguments for cluster_template + creation + :returns: magnum cluster_template """ kwargs["name"] = self.generate_random_name() - return self.clients("magnum").baymodels.create(**kwargs) + return self.clients("magnum").cluster_templates.create(**kwargs) - @atomic.action_timer("magnum.list_bays") - def _list_bays(self, limit=None, **kwargs): - """Return list of bays. + @atomic.action_timer("magnum.list_clusters") + def _list_clusters(self, limit=None, **kwargs): + """Return list of clusters. :param limit: (Optional) the maximum number of results to return per request, if: - 1) limit > 0, the maximum number of bays to return. + 1) limit > 0, the maximum number of clusters to return. 2) limit param is NOT specified (None), the number of items returned respect the maximum imposed by the Magnum API (see Magnum's api.max_limit option). - :param kwargs: Optional additional arguments for bays listing + :param kwargs: Optional additional arguments for clusters listing - :returns: bays list + :returns: clusters list """ - return self.clients("magnum").bays.list(limit=limit, **kwargs) + return self.clients("magnum").clusters.list(limit=limit, **kwargs) - @atomic.action_timer("magnum.create_bay") - def _create_bay(self, baymodel, node_count, **kwargs): - """Create a bay + @atomic.action_timer("magnum.create_cluster") + def _create_cluster(self, cluster_template, node_count, **kwargs): + """Create a cluster - :param baymodel: baymodel for the bay - :param node_count: the bay node count - :param kwargs: optional additional arguments for bay creation - :returns: magnum bay + :param cluster_template: cluster_template for the cluster + :param node_count: the cluster node count + :param kwargs: optional additional arguments for cluster creation + :returns: magnum cluster """ name = self.generate_random_name() - bay = self.clients("magnum").bays.create( - name=name, baymodel_id=baymodel, + cluster = self.clients("magnum").clusters.create( + name=name, cluster_template_id=cluster_template, node_count=node_count, **kwargs) common_utils.interruptable_sleep( - CONF.benchmark.magnum_bay_create_prepoll_delay) - bay = utils.wait_for_status( - bay, + CONF.benchmark.magnum_cluster_create_prepoll_delay) + cluster = utils.wait_for_status( + cluster, ready_statuses=["CREATE_COMPLETE"], update_resource=utils.get_from_manager(), - timeout=CONF.benchmark.magnum_bay_create_timeout, - check_interval=CONF.benchmark.magnum_bay_create_poll_interval, + timeout=CONF.benchmark.magnum_cluster_create_timeout, + check_interval=CONF.benchmark.magnum_cluster_create_poll_interval, id_attr="uuid" ) - return bay + return cluster diff --git a/samples/tasks/scenarios/magnum/create-and-list-clusters.json b/samples/tasks/scenarios/magnum/create-and-list-clusters.json new file mode 100644 index 00000000..2f6078a9 --- /dev/null +++ b/samples/tasks/scenarios/magnum/create-and-list-clusters.json @@ -0,0 +1,78 @@ +{ + "MagnumClusters.create_and_list_clusters": [ + { + "runner": { + "type": "constant", + "concurrency": 1, + "times": 1 + }, + "args": { + "node_count": 1 + }, + "context": { + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "docker_volume_size": 5, + "coe": "kubernetes", + "image_id": "fedora-atomic-latest", + "network_driver": "flannel" + }, + "users": { + "users_per_tenant": 1, + "tenants": 1 + } + } + }, + { + "runner": { + "type": "constant", + "concurrency": 1, + "times": 1 + }, + "args": { + "node_count": 1 + }, + "context": { + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "docker_volume_size": 5, + "coe": "swarm", + "image_id": "fedora-atomic-latest", + "network_driver": "docker" + }, + "users": { + "users_per_tenant": 1, + "tenants": 1 + } + } + }, + { + "runner": { + "type": "constant", + "concurrency": 1, + "times": 1 + }, + "args": { + "node_count": 1 + }, + "context": { + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "coe": "mesos", + "image_id": "ubuntu-mesos", + "network_driver": "docker" + }, + "users": { + "users_per_tenant": 1, + "tenants": 1 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/magnum/create-and-list-clusters.yaml b/samples/tasks/scenarios/magnum/create-and-list-clusters.yaml new file mode 100644 index 00000000..0ed7fbc3 --- /dev/null +++ b/samples/tasks/scenarios/magnum/create-and-list-clusters.yaml @@ -0,0 +1,58 @@ +--- + MagnumClusters.create_and_list_clusters: + - + args: + node_count: 1 + runner: + type: "constant" + times: 1 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + cluster_templates: + image_id: "fedora-atomic-latest" + external_network_id: "public" + dns_nameserver: "8.8.8.8" + flavor_id: "m1.small" + docker_volume_size: 5 + network_driver: "flannel" + coe: "kubernetes" + - + args: + node_count: 1 + runner: + type: "constant" + times: 1 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + cluster_templates: + image_id: "fedora-atomic-latest" + external_network_id: "public" + dns_nameserver: "8.8.8.8" + flavor_id: "m1.small" + docker_volume_size: 5 + network_driver: "docker" + coe: "swarm" + - + args: + node_count: 1 + runner: + type: "constant" + times: 1 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + cluster_templates: + image_id: "ubuntu-mesos" + external_network_id: "public" + dns_nameserver: "8.8.8.8" + flavor_id: "m1.small" + network_driver: "docker" + coe: "mesos" diff --git a/samples/tasks/scenarios/magnum/list-cluster-templates.json b/samples/tasks/scenarios/magnum/list-cluster-templates.json new file mode 100644 index 00000000..d2d0b703 --- /dev/null +++ b/samples/tasks/scenarios/magnum/list-cluster-templates.json @@ -0,0 +1,69 @@ +{ + "MagnumClusterTemplates.list_cluster_templates": [ + { + "runner": { + "type": "constant", + "concurrency": 1, + "times": 1 + }, + "context": { + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "docker_volume_size": 5, + "coe": "kubernetes", + "image_id": "fedora-atomic-latest", + "network_driver": "flannel" + }, + "users": { + "users_per_tenant": 1, + "tenants": 1 + } + } + }, + { + "runner": { + "type": "constant", + "concurrency": 1, + "times": 1 + }, + "context": { + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "docker_volume_size": 5, + "coe": "swarm", + "image_id": "fedora-atomic-latest", + "network_driver": "docker" + }, + "users": { + "users_per_tenant": 1, + "tenants": 1 + } + } + }, + { + "runner": { + "type": "constant", + "concurrency": 1, + "times": 1 + }, + "context": { + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "coe": "mesos", + "image_id": "ubuntu-mesos", + "network_driver": "docker" + }, + "users": { + "users_per_tenant": 1, + "tenants": 1 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/magnum/list-cluster-templates.yaml b/samples/tasks/scenarios/magnum/list-cluster-templates.yaml new file mode 100644 index 00000000..decbe756 --- /dev/null +++ b/samples/tasks/scenarios/magnum/list-cluster-templates.yaml @@ -0,0 +1,52 @@ +--- + MagnumClusterTemplates.list_cluster_templates: + - + runner: + type: "constant" + times: 1 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + cluster_templates: + image_id: "fedora-atomic-latest" + external_network_id: "public" + dns_nameserver: "8.8.8.8" + flavor_id: "m1.small" + docker_volume_size: 5 + network_driver: "flannel" + coe: "kubernetes" + - + runner: + type: "constant" + times: 1 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + cluster_templates: + image_id: "fedora-atomic-latest" + external_network_id: "public" + dns_nameserver: "8.8.8.8" + flavor_id: "m1.small" + docker_volume_size: 5 + network_driver: "docker" + coe: "swarm" + - + runner: + type: "constant" + times: 1 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + cluster_templates: + image_id: "ubuntu-mesos" + external_network_id: "public" + dns_nameserver: "8.8.8.8" + flavor_id: "m1.small" + network_driver: "docker" + coe: "mesos" diff --git a/samples/tasks/scenarios/magnum/list-clusters.json b/samples/tasks/scenarios/magnum/list-clusters.json new file mode 100644 index 00000000..950ab2ae --- /dev/null +++ b/samples/tasks/scenarios/magnum/list-clusters.json @@ -0,0 +1,78 @@ +{ + "MagnumClusters.list_clusters": [ + { + "runner": { + "type": "constant", + "concurrency": 1, + "times": 1 + }, + "context": { + "clusters": { + "node_count": 2 + }, + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "docker_volume_size": 5, + "coe": "kubernetes", + "image_id": "fedora-atomic-latest", + "network_driver": "flannel" + }, + "users": { + "users_per_tenant": 1, + "tenants": 1 + } + } + }, + { + "runner": { + "type": "constant", + "concurrency": 1, + "times": 1 + }, + "context": { + "clusters": { + "node_count": 2 + }, + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "docker_volume_size": 5, + "coe": "swarm", + "image_id": "fedora-atomic-latest", + "network_driver": "docker" + }, + "users": { + "users_per_tenant": 1, + "tenants": 1 + } + } + }, + { + "runner": { + "type": "constant", + "concurrency": 1, + "times": 1 + }, + "context": { + "clusters": { + "node_count": 2 + }, + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "coe": "mesos", + "image_id": "ubuntu-mesos", + "network_driver": "docker" + }, + "users": { + "users_per_tenant": 1, + "tenants": 1 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/magnum/list-clusters.yaml b/samples/tasks/scenarios/magnum/list-clusters.yaml new file mode 100644 index 00000000..fd28a613 --- /dev/null +++ b/samples/tasks/scenarios/magnum/list-clusters.yaml @@ -0,0 +1,58 @@ +--- + MagnumClusters.list_clusters: + - + runner: + type: "constant" + times: 1 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + cluster_templates: + image_id: "fedora-atomic-latest" + external_network_id: "public" + dns_nameserver: "8.8.8.8" + flavor_id: "m1.small" + docker_volume_size: 5 + network_driver: "flannel" + coe: "kubernetes" + clusters: + node_count: 2 + - + runner: + type: "constant" + times: 1 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + cluster_templates: + image_id: "fedora-atomic-latest" + external_network_id: "public" + dns_nameserver: "8.8.8.8" + flavor_id: "m1.small" + docker_volume_size: 5 + network_driver: "docker" + coe: "swarm" + clusters: + node_count: 2 + - + runner: + type: "constant" + times: 1 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 + cluster_templates: + image_id: "ubuntu-mesos" + external_network_id: "public" + dns_nameserver: "8.8.8.8" + flavor_id: "m1.small" + network_driver: "docker" + coe: "mesos" + clusters: + node_count: 2 diff --git a/tests/ci/osresources.py b/tests/ci/osresources.py index b260c99d..134a95d2 100755 --- a/tests/ci/osresources.py +++ b/tests/ci/osresources.py @@ -96,26 +96,26 @@ class Magnum(ResourceManager): REQUIRED_SERVICE = consts.Service.MAGNUM - def list_baymodels(self): + def list_cluster_templates(self): result = [] marker = None while True: - baymodels = self.client.baymodels.list(marker=marker) - if not baymodels: + ct_list = self.client.cluster_templates.list(marker=marker) + if not ct_list: break - result.extend(baymodels) - marker = baymodels[-1].uuid + result.extend(ct_list) + marker = ct_list[-1].uuid return result - def list_bays(self): + def list_clusters(self): result = [] marker = None while True: - bays = self.client.bays.list(marker=marker) - if not bays: + clusters = self.client.clusters.list(marker=marker) + if not clusters: break - result.extend(bays) - marker = bays[-1].uuid + result.extend(clusters) + marker = clusters[-1].uuid return result diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index 4c195b6c..007c4339 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -322,7 +322,7 @@ class FakeObject(FakeResource): pass -class FakeBaymodel(FakeResource): +class FakeClusterTemplate(FakeResource): pass @@ -518,12 +518,12 @@ class FakeKeypairManager(FakeManager): self.resources_order.remove(resource) -class FakeBaymodelManager(FakeManager): +class FakeClusterTemplateManager(FakeManager): def create(self, name): - baymodel = FakeBaymodel(self) - baymodel.name = name or baymodel.name - return self._cache(baymodel) + cluster_template = FakeClusterTemplate(self) + cluster_template.name = name or cluster_template.name + return self._cache(cluster_template) def delete(self, resource): if not isinstance(resource, six.string_types): @@ -1533,7 +1533,7 @@ class FakeSenlinClient(object): class FakeMagnumClient(object): def __init__(self): - self.baymodels = FakeBaymodelManager() + self.cluster_templates = FakeClusterTemplateManager() class FakeWatcherClient(object): diff --git a/tests/unit/plugins/openstack/context/magnum/test_cluster_templates.py b/tests/unit/plugins/openstack/context/magnum/test_cluster_templates.py new file mode 100644 index 00000000..8aa572bb --- /dev/null +++ b/tests/unit/plugins/openstack/context/magnum/test_cluster_templates.py @@ -0,0 +1,108 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock + +from rally.plugins.openstack.context.magnum import cluster_templates +from tests.unit import fakes +from tests.unit import test + + +BASE_CTX = "rally.task.context" +CTX = "rally.plugins.openstack.context" +BASE_SCN = "rally.task.scenarios" +SCN = "rally.plugins.openstack.scenarios" + + +class ClusterTemplatesGeneratorTestCase(test.ScenarioTestCase): + + """Generate tenants.""" + def _gen_tenants(self, count): + tenants = {} + for id_ in range(count): + tenants[str(id_)] = dict(name=str(id_)) + return tenants + + @mock.patch("%s.magnum.utils.MagnumScenario." + "_create_cluster_template" % SCN, + return_value=fakes.FakeClusterTemplate(id="uuid")) + @mock.patch("%s.nova.utils.NovaScenario._create_keypair" % SCN, + return_value="key1") + def test_setup(self, mock_nova_scenario__create_keypair, + mock__create_cluster_template): + tenants_count = 2 + users_per_tenant = 5 + + tenants = self._gen_tenants(tenants_count) + users = [] + for ten_id in tenants: + for i in range(users_per_tenant): + users.append({"id": i, "tenant_id": ten_id, + "credential": mock.MagicMock()}) + + self.context.update({ + "config": { + "users": { + "tenants": tenants_count, + "users_per_tenant": users_per_tenant, + "concurrent": 10, + }, + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "docker_volume_size": 5, + "coe": "kubernetes", + "image_id": "fedora-atomic-latest", + "network_driver": "flannel" + } + }, + "users": users, + "tenants": tenants + }) + + ct_ctx = cluster_templates.ClusterTemplateGenerator(self.context) + ct_ctx.setup() + + ct_ctx_config = self.context["config"]["cluster_templates"] + image_id = ct_ctx_config.get("image_id") + external_network_id = ct_ctx_config.get( + "external_network_id") + dns_nameserver = ct_ctx_config.get("dns_nameserver") + flavor_id = ct_ctx_config.get("flavor_id") + docker_volume_size = ct_ctx_config.get("docker_volume_size") + network_driver = ct_ctx_config.get("network_driver") + coe = ct_ctx_config.get("coe") + mock_calls = [mock.call(image_id=image_id, keypair_id="key1", + external_network_id=external_network_id, + dns_nameserver=dns_nameserver, + flavor_id=flavor_id, + docker_volume_size=docker_volume_size, + network_driver=network_driver, coe=coe) + for i in range(tenants_count)] + mock__create_cluster_template.assert_has_calls(mock_calls) + + # check that stack ids have been saved in context + for ten_id in self.context["tenants"].keys(): + self.assertIsNotNone( + self.context["tenants"][ten_id]["cluster_template"]) + + @mock.patch("%s.magnum.cluster_templates.resource_manager.cleanup" % CTX) + def test_cleanup(self, mock_cleanup): + self.context.update({ + "users": mock.MagicMock() + }) + ct_ctx = cluster_templates.ClusterTemplateGenerator(self.context) + ct_ctx.cleanup() + mock_cleanup.assert_called_once_with(names=["magnum.cluster_templates", + "nova.keypairs"], + users=self.context["users"]) diff --git a/tests/unit/plugins/openstack/context/magnum/test_clusters.py b/tests/unit/plugins/openstack/context/magnum/test_clusters.py new file mode 100644 index 00000000..c777e148 --- /dev/null +++ b/tests/unit/plugins/openstack/context/magnum/test_clusters.py @@ -0,0 +1,150 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +import copy + +import mock + +from rally.plugins.openstack.context.magnum import clusters +from tests.unit import test + +CTX = "rally.plugins.openstack.context.magnum" +SCN = "rally.plugins.openstack.scenarios" + + +class ClustersGeneratorTestCase(test.ScenarioTestCase): + + def _gen_tenants(self, count): + tenants = {} + for id_ in range(count): + tenants[str(id_)] = {"name": str(id_)} + return tenants + + def _gen_tenants_with_cluster_template(self, count): + tenants = {} + for id_ in range(count): + tenants[str(id_)] = {"name": str(id_)} + tenants[str(id_)]["cluster_template"] = "rally_ct_uuid" + return tenants + + @mock.patch("%s.magnum.utils.MagnumScenario._create_cluster" % SCN, + return_value=mock.Mock()) + def test_setup_using_existing_cluster_template(self, mock__create_cluster): + tenants_count = 2 + users_per_tenant = 5 + + tenants = self._gen_tenants(tenants_count) + users = [] + for ten_id in tenants: + for i in range(users_per_tenant): + users.append({"id": i, "tenant_id": ten_id, + "credential": mock.MagicMock()}) + + self.context.update({ + "config": { + "users": { + "tenants": tenants_count, + "users_per_tenant": users_per_tenant, + "concurrent": 10, + }, + "clusters": { + "cluster_template_uuid": "123456789", + "node_count": 2 + } + }, + "users": users, + "tenants": tenants + }) + + mock_cluster = mock__create_cluster.return_value + new_context = copy.deepcopy(self.context) + for id_ in new_context["tenants"]: + new_context["tenants"][id_]["cluster"] = mock_cluster.uuid + + cluster_ctx = clusters.ClusterGenerator(self.context) + cluster_ctx.setup() + + self.assertEqual(new_context, self.context) + cluster_ctx_config = self.context["config"]["clusters"] + node_count = cluster_ctx_config.get("node_count") + cluster_template_uuid = cluster_ctx_config.get("cluster_template_uuid") + mock_calls = [mock.call(cluster_template=cluster_template_uuid, + node_count=node_count) + for i in range(tenants_count)] + mock__create_cluster.assert_has_calls(mock_calls) + + @mock.patch("%s.magnum.utils.MagnumScenario._create_cluster" % SCN, + return_value=mock.Mock()) + def test_setup(self, mock__create_cluster): + tenants_count = 2 + users_per_tenant = 5 + + tenants = self._gen_tenants_with_cluster_template(tenants_count) + users = [] + for ten_id in tenants: + for i in range(users_per_tenant): + users.append({"id": i, "tenant_id": ten_id, + "credential": mock.MagicMock()}) + + self.context.update({ + "config": { + "users": { + "tenants": tenants_count, + "users_per_tenant": users_per_tenant, + "concurrent": 10, + }, + "cluster_templates": { + "dns_nameserver": "8.8.8.8", + "external_network_id": "public", + "flavor_id": "m1.small", + "docker_volume_size": 5, + "coe": "kubernetes", + "image_id": "fedora-atomic-latest", + "network_driver": "flannel" + }, + "clusters": { + "node_count": 2 + } + }, + "users": users, + "tenants": tenants + }) + + mock_cluster = mock__create_cluster.return_value + new_context = copy.deepcopy(self.context) + for id_ in new_context["tenants"]: + new_context["tenants"][id_]["cluster"] = mock_cluster.uuid + + cluster_ctx = clusters.ClusterGenerator(self.context) + cluster_ctx.setup() + + self.assertEqual(new_context, self.context) + cluster_ctx_config = self.context["config"]["clusters"] + node_count = cluster_ctx_config.get("node_count") + mock_calls = [mock.call(cluster_template="rally_ct_uuid", + node_count=node_count) + for i in range(tenants_count)] + mock__create_cluster.assert_has_calls(mock_calls) + + @mock.patch("%s.cluster_templates.resource_manager.cleanup" % CTX) + def test_cleanup(self, mock_cleanup): + self.context.update({ + "users": mock.MagicMock() + }) + clusters_ctx = clusters.ClusterGenerator(self.context) + clusters_ctx.cleanup() + mock_cleanup.assert_called_once_with( + names=["magnum.clusters"], + users=self.context["users"]) diff --git a/tests/unit/plugins/openstack/scenarios/magnum/test_cluster_templates.py b/tests/unit/plugins/openstack/scenarios/magnum/test_cluster_templates.py new file mode 100644 index 00000000..b837c0c3 --- /dev/null +++ b/tests/unit/plugins/openstack/scenarios/magnum/test_cluster_templates.py @@ -0,0 +1,35 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import ddt +import mock + +from rally.plugins.openstack.scenarios.magnum import cluster_templates +from tests.unit import test + + +@ddt.ddt +class MagnumClusterTemplatesTestCase(test.TestCase): + + @ddt.data( + {"kwargs": {}}, + {"kwargs": {"fakearg": "f"}}) + @ddt.unpack + def test_list_cluster_templates(self, kwargs): + scenario = cluster_templates.ListClusterTemplates() + scenario._list_cluster_templates = mock.Mock() + + scenario.run(**kwargs) + + scenario._list_cluster_templates.assert_called_once_with(**kwargs) diff --git a/tests/unit/plugins/openstack/scenarios/magnum/test_clusters.py b/tests/unit/plugins/openstack/scenarios/magnum/test_clusters.py new file mode 100644 index 00000000..037106a6 --- /dev/null +++ b/tests/unit/plugins/openstack/scenarios/magnum/test_clusters.py @@ -0,0 +1,73 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import ddt +import mock + +from rally.plugins.openstack.scenarios.magnum import clusters +from tests.unit import test + + +@ddt.ddt +class MagnumClustersTestCase(test.ScenarioTestCase): + + @staticmethod + def _get_context(): + context = test.get_test_context() + context.update({ + "tenant": { + "id": "rally_tenant_id", + "cluster_template": "rally_cluster_template_uuid" + } + }) + return context + + @ddt.data( + {"kwargs": {}}, + {"kwargs": {"fakearg": "f"}}) + def test_list_clusters(self, kwargs): + scenario = clusters.ListClusters() + scenario._list_clusters = mock.Mock() + + scenario.run(**kwargs) + + scenario._list_clusters.assert_called_once_with(**kwargs) + + def test_create_cluster_with_existing_ct_and_list_clusters(self): + scenario = clusters.CreateAndListClusters() + kwargs = {"cluster_template_uuid": "existing_cluster_template_uuid", + "fakearg": "f"} + fake_cluster = mock.Mock() + scenario._create_cluster = mock.Mock(return_value=fake_cluster) + scenario._list_clusters = mock.Mock() + + scenario.run(2, **kwargs) + + scenario._create_cluster.assert_called_once_with( + "existing_cluster_template_uuid", 2, **kwargs) + scenario._list_clusters.assert_called_once_with(**kwargs) + + def test_create_and_list_clusters(self): + context = self._get_context() + scenario = clusters.CreateAndListClusters(context) + fake_cluster = mock.Mock() + kwargs = {"fakearg": "f"} + scenario._create_cluster = mock.Mock(return_value=fake_cluster) + scenario._list_clusters = mock.Mock() + + scenario.run(2, **kwargs) + + scenario._create_cluster.assert_called_once_with( + "rally_cluster_template_uuid", 2, **kwargs) + scenario._list_clusters.assert_called_once_with(**kwargs) diff --git a/tests/unit/plugins/openstack/scenarios/magnum/test_utils.py b/tests/unit/plugins/openstack/scenarios/magnum/test_utils.py index d9248de9..dad6c9f1 100644 --- a/tests/unit/plugins/openstack/scenarios/magnum/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/magnum/test_utils.py @@ -23,28 +23,28 @@ CONF = utils.CONF class MagnumScenarioTestCase(test.ScenarioTestCase): def setUp(self): super(MagnumScenarioTestCase, self).setUp() - self.baymodel = mock.Mock() - self.bay = mock.Mock() + self.cluster_template = mock.Mock() + self.cluster = mock.Mock() self.scenario = utils.MagnumScenario(self.context) - def test_list_baymodels(self): - fake_baymodel_list = [self.baymodel] + def test_list_cluster_templates(self): + fake_list = [self.cluster_template] - self.clients("magnum").baymodels.list.return_value = fake_baymodel_list - return_baymodels_list = self.scenario._list_baymodels() - self.assertEqual(fake_baymodel_list, return_baymodels_list) + self.clients("magnum").cluster_templates.list.return_value = fake_list + return_ct_list = self.scenario._list_cluster_templates() + self.assertEqual(fake_list, return_ct_list) - self.clients("magnum").baymodels.list.assert_called_once_with() + self.clients("magnum").cluster_templates.list.assert_called_once_with() self._test_atomic_action_timer(self.scenario.atomic_actions(), - "magnum.list_baymodels") + "magnum.list_cluster_templates") - def test_create_baymodel(self): + def test_create_cluster_template(self): self.scenario.generate_random_name = mock.Mock( return_value="generated_name") - fake_baymodel = self.baymodel - self.clients("magnum").baymodels.create.return_value = fake_baymodel + fake_ct = self.cluster_template + self.clients("magnum").cluster_templates.create.return_value = fake_ct - return_baymodel = self.scenario._create_baymodel( + return_cluster_template = self.scenario._create_cluster_template( image="test_image", keypair="test_key", external_network="public", @@ -54,40 +54,41 @@ class MagnumScenarioTestCase(test.ScenarioTestCase): network_driver="docker", coe="swarm") - self.assertEqual(fake_baymodel, return_baymodel) - args, kwargs = self.clients("magnum").baymodels.create.call_args + self.assertEqual(fake_ct, return_cluster_template) + _, kwargs = self.clients("magnum").cluster_templates.create.call_args self.assertEqual("generated_name", kwargs["name"]) self._test_atomic_action_timer(self.scenario.atomic_actions(), - "magnum.create_baymodel") + "magnum.create_cluster_template") - def test_list_bays(self): - return_bays_list = self.scenario._list_bays(limit="foo1") - self.clients("magnum").bays.list.assert_called_once_with(limit="foo1") - self.assertEqual(self.clients("magnum").bays.list.return_value, - return_bays_list) + def test_list_clusters(self): + return_clusters_list = self.scenario._list_clusters(limit="foo1") + client = self.clients("magnum") + client.clusters.list.assert_called_once_with(limit="foo1") + self.assertEqual(client.clusters.list.return_value, + return_clusters_list) self._test_atomic_action_timer( - self.scenario.atomic_actions(), "magnum.list_bays") + self.scenario.atomic_actions(), "magnum.list_clusters") - def test_create_bay(self): + def test_create_cluster(self): self.scenario.generate_random_name = mock.Mock( return_value="generated_name") - self.clients("magnum").bays.create.return_value = self.bay - return_bay = self.scenario._create_bay( - baymodel="generated_uuid", node_count=2) + self.clients("magnum").clusters.create.return_value = self.cluster + return_cluster = self.scenario._create_cluster( + cluster_template="generated_uuid", node_count=2) self.mock_wait_for_status.mock.assert_called_once_with( - self.bay, + self.cluster, ready_statuses=["CREATE_COMPLETE"], update_resource=self.mock_get_from_manager.mock.return_value, check_interval=CONF.benchmark. - magnum_bay_create_poll_interval, - timeout=CONF.benchmark.magnum_bay_create_timeout, + magnum_cluster_create_poll_interval, + timeout=CONF.benchmark.magnum_cluster_create_timeout, id_attr="uuid") - args, kwargs = self.clients("magnum").bays.create.call_args + _, kwargs = self.clients("magnum").clusters.create.call_args self.assertEqual("generated_name", kwargs["name"]) - self.assertEqual("generated_uuid", kwargs["baymodel_id"]) + self.assertEqual("generated_uuid", kwargs["cluster_template_id"]) self.mock_get_from_manager.mock.assert_called_once_with() self.assertEqual( - self.mock_wait_for_status.mock.return_value, return_bay) + self.mock_wait_for_status.mock.return_value, return_cluster) self._test_atomic_action_timer( - self.scenario.atomic_actions(), "magnum.create_bay") + self.scenario.atomic_actions(), "magnum.create_cluster")