Magnum: Move keypair handling at the cluster level
Also fix a small bug to allow the use of an existing template in create_and_list_clusters scenario. Change-Id: I7dd84bcd54abcfe5c0af5eb6825c0fb0a52ff4cf
This commit is contained in:
@@ -19,7 +19,6 @@ from rally.common import validation
|
||||
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
|
||||
|
||||
|
||||
@@ -108,15 +107,6 @@ class ClusterTemplateGenerator(context.Context):
|
||||
for user, tenant_id in rutils.iterate_per_tenants(
|
||||
self.context["users"]):
|
||||
|
||||
nova_scenario = nova_utils.NovaScenario({
|
||||
"user": user,
|
||||
"task": self.context["task"],
|
||||
"owner_id": self.context["owner_id"],
|
||||
"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"],
|
||||
@@ -126,18 +116,13 @@ class ClusterTemplateGenerator(context.Context):
|
||||
})
|
||||
|
||||
cluster_template = magnum_scenario._create_cluster_template(
|
||||
keypair_id=keypair, **self.config)
|
||||
**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=["nova.keypairs"],
|
||||
users=self.context.get("users", []),
|
||||
superclass=nova_utils.NovaScenario,
|
||||
task_id=self.get_owner_id())
|
||||
resource_manager.cleanup(
|
||||
names=["magnum.cluster_templates"],
|
||||
users=self.context.get("users", []),
|
||||
|
||||
@@ -19,6 +19,7 @@ from rally.common import validation
|
||||
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
|
||||
|
||||
|
||||
@@ -52,6 +53,14 @@ class ClusterGenerator(context.Context):
|
||||
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"],
|
||||
@@ -67,13 +76,13 @@ class ClusterGenerator(context.Context):
|
||||
ct_uuid = ctx.get("cluster_template")
|
||||
cluster = magnum_scenario._create_cluster(
|
||||
cluster_template=ct_uuid,
|
||||
node_count=self.config.get("node_count"))
|
||||
node_count=self.config.get("node_count"), keypair=keypair)
|
||||
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"],
|
||||
names=["magnum.clusters", "nova.keypairs"],
|
||||
users=self.context.get("users", []),
|
||||
superclass=magnum_utils.MagnumScenario,
|
||||
task_id=self.get_owner_id())
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
from rally import consts
|
||||
from rally.plugins.openstack import scenario
|
||||
from rally.plugins.openstack.scenarios.magnum import utils
|
||||
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
||||
from rally.task import validation
|
||||
|
||||
"""Scenarios for Magnum clusters."""
|
||||
@@ -45,8 +46,7 @@ class ListClusters(utils.MagnumScenario):
|
||||
|
||||
@validation.required_services(consts.Service.MAGNUM)
|
||||
@validation.add("required_platform", platform="openstack", users=True)
|
||||
@validation.required_contexts("cluster_templates")
|
||||
@scenario.configure(context={"cleanup": ["magnum.clusters"]},
|
||||
@scenario.configure(context={"cleanup": ["magnum.clusters", "nova.keypairs"]},
|
||||
name="MagnumClusters.create_and_list_clusters")
|
||||
class CreateAndListClusters(utils.MagnumScenario):
|
||||
|
||||
@@ -61,8 +61,19 @@ class CreateAndListClusters(utils.MagnumScenario):
|
||||
cluster_template_uuid = kwargs.get("cluster_template_uuid", None)
|
||||
if cluster_template_uuid is None:
|
||||
cluster_template_uuid = self.context["tenant"]["cluster_template"]
|
||||
new_cluster = self._create_cluster(cluster_template_uuid,
|
||||
node_count, **kwargs)
|
||||
else:
|
||||
del kwargs["cluster_template_uuid"]
|
||||
|
||||
nova_scenario = nova_utils.NovaScenario({
|
||||
"user": self.context["user"],
|
||||
"task": self.context["task"],
|
||||
"config": {"api_versions": self.context["config"].get(
|
||||
"api_versions", [])}
|
||||
})
|
||||
keypair = nova_scenario._create_keypair()
|
||||
|
||||
new_cluster = self._create_cluster(cluster_template_uuid, node_count,
|
||||
keypair=keypair, **kwargs)
|
||||
self.assertTrue(new_cluster, "Failed to create new cluster")
|
||||
clusters = self._list_clusters(**kwargs)
|
||||
self.assertIn(new_cluster.uuid, [cluster.uuid for cluster in clusters],
|
||||
|
||||
@@ -14,7 +14,6 @@ import mock
|
||||
|
||||
from rally.plugins.openstack.context.magnum import cluster_templates
|
||||
from rally.plugins.openstack.scenarios.magnum import utils as magnum_utils
|
||||
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
@@ -37,10 +36,7 @@ class ClusterTemplatesGeneratorTestCase(test.ScenarioTestCase):
|
||||
@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):
|
||||
def test_setup(self, mock__create_cluster_template):
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
|
||||
@@ -84,7 +80,7 @@ class ClusterTemplatesGeneratorTestCase(test.ScenarioTestCase):
|
||||
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",
|
||||
mock_calls = [mock.call(image_id=image_id,
|
||||
external_network_id=external_network_id,
|
||||
dns_nameserver=dns_nameserver,
|
||||
flavor_id=flavor_id,
|
||||
@@ -105,14 +101,8 @@ class ClusterTemplatesGeneratorTestCase(test.ScenarioTestCase):
|
||||
})
|
||||
ct_ctx = cluster_templates.ClusterTemplateGenerator(self.context)
|
||||
ct_ctx.cleanup()
|
||||
mock_cleanup.assert_has_calls((
|
||||
mock.call(
|
||||
names=["nova.keypairs"],
|
||||
users=self.context["users"],
|
||||
superclass=nova_utils.NovaScenario,
|
||||
task_id=self.context["owner_id"]),
|
||||
mock.call(
|
||||
names=["magnum.cluster_templates"],
|
||||
users=self.context["users"],
|
||||
superclass=magnum_utils.MagnumScenario,
|
||||
task_id=self.context["owner_id"])))
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["magnum.cluster_templates"],
|
||||
users=self.context["users"],
|
||||
superclass=magnum_utils.MagnumScenario,
|
||||
task_id=self.context["owner_id"])
|
||||
|
||||
@@ -42,7 +42,10 @@ class ClustersGeneratorTestCase(test.ScenarioTestCase):
|
||||
|
||||
@mock.patch("%s.magnum.utils.MagnumScenario._create_cluster" % SCN,
|
||||
return_value=mock.Mock())
|
||||
def test_setup_using_existing_cluster_template(self, mock__create_cluster):
|
||||
@mock.patch("%s.nova.utils.NovaScenario._create_keypair" % SCN,
|
||||
return_value="key1")
|
||||
def test_setup_using_existing_cluster_template(
|
||||
self, mock__create_keypair, mock__create_cluster):
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
|
||||
@@ -82,13 +85,15 @@ class ClustersGeneratorTestCase(test.ScenarioTestCase):
|
||||
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)
|
||||
keypair="key1", 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):
|
||||
@mock.patch("%s.nova.utils.NovaScenario._create_keypair" % SCN,
|
||||
return_value="key1")
|
||||
def test_setup(self, mock__create_keypair, mock__create_cluster):
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
|
||||
@@ -135,7 +140,7 @@ class ClustersGeneratorTestCase(test.ScenarioTestCase):
|
||||
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)
|
||||
keypair="key1", node_count=node_count)
|
||||
for i in range(tenants_count)]
|
||||
mock__create_cluster.assert_has_calls(mock_calls)
|
||||
|
||||
@@ -147,7 +152,7 @@ class ClustersGeneratorTestCase(test.ScenarioTestCase):
|
||||
clusters_ctx = clusters.ClusterGenerator(self.context)
|
||||
clusters_ctx.cleanup()
|
||||
mock_cleanup.assert_called_once_with(
|
||||
names=["magnum.clusters"],
|
||||
names=["magnum.clusters", "nova.keypairs"],
|
||||
users=self.context["users"],
|
||||
superclass=magnum_utils.MagnumScenario,
|
||||
task_id=self.context["owner_id"])
|
||||
|
||||
@@ -28,9 +28,11 @@ class MagnumClustersTestCase(test.ScenarioTestCase):
|
||||
context = test.get_test_context()
|
||||
context.update({
|
||||
"tenant": {
|
||||
"id": "rally_tenant_id",
|
||||
"cluster_template": "rally_cluster_template_uuid"
|
||||
}
|
||||
"id": "rally_tenant_id"
|
||||
},
|
||||
"user": {"id": "fake_user_id",
|
||||
"credential": mock.MagicMock()},
|
||||
"config": {}
|
||||
})
|
||||
return context
|
||||
|
||||
@@ -46,9 +48,9 @@ class MagnumClustersTestCase(test.ScenarioTestCase):
|
||||
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"}
|
||||
context = self._get_context()
|
||||
scenario = clusters.CreateAndListClusters(context)
|
||||
kwargs = {"fakearg": "f"}
|
||||
fake_cluster1 = mock.Mock(uuid="a")
|
||||
fake_cluster2 = mock.Mock(uuid="b")
|
||||
fake_cluster3 = mock.Mock(uuid="c")
|
||||
@@ -57,30 +59,38 @@ class MagnumClustersTestCase(test.ScenarioTestCase):
|
||||
fake_cluster2,
|
||||
fake_cluster3])
|
||||
|
||||
run_kwargs = kwargs.copy()
|
||||
run_kwargs["cluster_template_uuid"] = "existing_cluster_template_uuid"
|
||||
# Positive case
|
||||
scenario.run(2, **kwargs)
|
||||
scenario.run(2, **run_kwargs)
|
||||
|
||||
scenario._create_cluster.assert_called_once_with(
|
||||
"existing_cluster_template_uuid", 2, **kwargs)
|
||||
"existing_cluster_template_uuid", 2, keypair=mock.ANY, **kwargs)
|
||||
scenario._list_clusters.assert_called_once_with(**kwargs)
|
||||
|
||||
# Negative case1: cluster isn't created
|
||||
scenario._create_cluster.return_value = None
|
||||
self.assertRaises(exceptions.RallyAssertionError,
|
||||
scenario.run, 2, **kwargs)
|
||||
scenario.run, 2, **run_kwargs)
|
||||
scenario._create_cluster.assert_called_with(
|
||||
"existing_cluster_template_uuid", 2, **kwargs)
|
||||
"existing_cluster_template_uuid", 2, keypair=mock.ANY, **kwargs)
|
||||
|
||||
# Negative case2: created cluster not in the list of available clusters
|
||||
scenario._create_cluster.return_value = mock.Mock(uuid="foo")
|
||||
self.assertRaises(exceptions.RallyAssertionError,
|
||||
scenario.run, 2, **kwargs)
|
||||
scenario.run, 2, **run_kwargs)
|
||||
scenario._create_cluster.assert_called_with(
|
||||
"existing_cluster_template_uuid", 2, **kwargs)
|
||||
"existing_cluster_template_uuid", 2, keypair=mock.ANY, **kwargs)
|
||||
scenario._list_clusters.assert_called_with(**kwargs)
|
||||
|
||||
def test_create_and_list_clusters(self):
|
||||
context = self._get_context()
|
||||
context.update({
|
||||
"tenant": {
|
||||
"cluster_template": "rally_cluster_template_uuid"
|
||||
}
|
||||
})
|
||||
|
||||
scenario = clusters.CreateAndListClusters(context)
|
||||
fake_cluster1 = mock.Mock(uuid="a")
|
||||
fake_cluster2 = mock.Mock(uuid="b")
|
||||
@@ -95,7 +105,7 @@ class MagnumClustersTestCase(test.ScenarioTestCase):
|
||||
scenario.run(2, **kwargs)
|
||||
|
||||
scenario._create_cluster.assert_called_once_with(
|
||||
"rally_cluster_template_uuid", 2, **kwargs)
|
||||
"rally_cluster_template_uuid", 2, keypair=mock.ANY, **kwargs)
|
||||
scenario._list_clusters.assert_called_once_with(**kwargs)
|
||||
|
||||
# Negative case1: cluster isn't created
|
||||
@@ -103,12 +113,12 @@ class MagnumClustersTestCase(test.ScenarioTestCase):
|
||||
self.assertRaises(exceptions.RallyAssertionError,
|
||||
scenario.run, 2, **kwargs)
|
||||
scenario._create_cluster.assert_called_with(
|
||||
"rally_cluster_template_uuid", 2, **kwargs)
|
||||
"rally_cluster_template_uuid", 2, keypair=mock.ANY, **kwargs)
|
||||
|
||||
# Negative case2: created cluster not in the list of available clusters
|
||||
scenario._create_cluster.return_value = mock.Mock(uuid="foo")
|
||||
self.assertRaises(exceptions.RallyAssertionError,
|
||||
scenario.run, 2, **kwargs)
|
||||
scenario._create_cluster.assert_called_with(
|
||||
"rally_cluster_template_uuid", 2, **kwargs)
|
||||
"rally_cluster_template_uuid", 2, keypair=mock.ANY, **kwargs)
|
||||
scenario._list_clusters.assert_called_with(**kwargs)
|
||||
|
||||
Reference in New Issue
Block a user