Merge "Add dns_nameservers option to network context"

This commit is contained in:
Jenkins 2016-07-08 10:54:18 +00:00 committed by Gerrit Code Review
commit 011fbbe813
3 changed files with 36 additions and 7 deletions

View File

@ -623,6 +623,9 @@
network: network:
start_cidr: "10.2.0.0/24" start_cidr: "10.2.0.0/24"
networks_per_tenant: 2 networks_per_tenant: 2
dns_nameservers:
- "8.8.8.8"
- "8.8.4.4"
sla: sla:
failure_rate: failure_rate:
max: 0 max: 0
@ -740,4 +743,5 @@
users: users:
tenants: 1 tenants: 1
users_per_tenant: 1 users_per_tenant: 1
network: {} network:
dns_nameservers: []

View File

@ -53,6 +53,11 @@ class Network(context.Context):
"network_create_args": { "network_create_args": {
"type": "object", "type": "object",
"additionalProperties": True "additionalProperties": True
},
"dns_nameservers": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": True
} }
}, },
"additionalProperties": False "additionalProperties": False
@ -62,7 +67,8 @@ class Network(context.Context):
"start_cidr": "10.2.0.0/24", "start_cidr": "10.2.0.0/24",
"networks_per_tenant": 1, "networks_per_tenant": 1,
"subnets_per_network": 1, "subnets_per_network": 1,
"network_create_args": {} "network_create_args": {},
"dns_nameservers": None
} }
@logging.log_task_wrapper(LOG.info, _("Enter context: `network`")) @logging.log_task_wrapper(LOG.info, _("Enter context: `network`"))
@ -74,6 +80,9 @@ class Network(context.Context):
net_wrapper = network_wrapper.wrap( net_wrapper = network_wrapper.wrap(
osclients.Clients(self.context["admin"]["credential"]), osclients.Clients(self.context["admin"]["credential"]),
self, config=self.config) self, config=self.config)
kwargs = {}
if self.config["dns_nameservers"] is not None:
kwargs["dns_nameservers"] = self.config["dns_nameservers"]
for user, tenant_id in (utils.iterate_per_tenants( for user, tenant_id in (utils.iterate_per_tenants(
self.context.get("users", []))): self.context.get("users", []))):
self.context["tenants"][tenant_id]["networks"] = [] self.context["tenants"][tenant_id]["networks"] = []
@ -85,7 +94,8 @@ class Network(context.Context):
tenant_id, tenant_id,
add_router=True, add_router=True,
subnets_num=self.config["subnets_per_network"], subnets_num=self.config["subnets_per_network"],
network_create_args=network_create_args) network_create_args=network_create_args,
**kwargs)
self.context["tenants"][tenant_id]["networks"].append(network) self.context["tenants"][tenant_id]["networks"].append(network)
@logging.log_task_wrapper(LOG.info, _("Exit context: `network`")) @logging.log_task_wrapper(LOG.info, _("Exit context: `network`"))

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import ddt
import mock import mock
import netaddr import netaddr
@ -22,6 +23,7 @@ from tests.unit import test
NET = "rally.plugins.openstack.wrappers.network." NET = "rally.plugins.openstack.wrappers.network."
@ddt.ddt
class NetworkTestCase(test.TestCase): class NetworkTestCase(test.TestCase):
def get_context(self, **kwargs): def get_context(self, **kwargs):
return {"task": {"uuid": "foo_task"}, return {"task": {"uuid": "foo_task"},
@ -42,22 +44,30 @@ class NetworkTestCase(test.TestCase):
self.assertEqual(context.config["networks_per_tenant"], 1) self.assertEqual(context.config["networks_per_tenant"], 1)
self.assertEqual(context.config["start_cidr"], self.assertEqual(context.config["start_cidr"],
network_context.Network.DEFAULT_CONFIG["start_cidr"]) network_context.Network.DEFAULT_CONFIG["start_cidr"])
self.assertIsNone(context.config["dns_nameservers"])
@mock.patch("rally.osclients.Clients") @mock.patch("rally.osclients.Clients")
@mock.patch(NET + "wrap", return_value="foo_service") @mock.patch(NET + "wrap", return_value="foo_service")
def test__init__explicit(self, mock_wrap, mock_clients): def test__init__explicit(self, mock_wrap, mock_clients):
context = network_context.Network( context = network_context.Network(
self.get_context(start_cidr="foo_cidr", networks_per_tenant=42, self.get_context(start_cidr="foo_cidr", networks_per_tenant=42,
network_create_args={"fakearg": "fake"})) network_create_args={"fakearg": "fake"},
dns_nameservers=["1.2.3.4", "5.6.7.8"]))
self.assertEqual(context.config["networks_per_tenant"], 42) self.assertEqual(context.config["networks_per_tenant"], 42)
self.assertEqual(context.config["start_cidr"], "foo_cidr") self.assertEqual(context.config["start_cidr"], "foo_cidr")
self.assertDictEqual(context.config["network_create_args"], self.assertDictEqual(context.config["network_create_args"],
{"fakearg": "fake"}) {"fakearg": "fake"})
self.assertEqual(context.config["dns_nameservers"],
("1.2.3.4", "5.6.7.8"))
@ddt.data({},
{"dns_nameservers": []},
{"dns_nameservers": ["1.2.3.4", "5.6.7.8"]})
@ddt.unpack
@mock.patch(NET + "wrap") @mock.patch(NET + "wrap")
@mock.patch("rally.plugins.openstack.context.network.networks.utils") @mock.patch("rally.plugins.openstack.context.network.networks.utils")
@mock.patch("rally.osclients.Clients") @mock.patch("rally.osclients.Clients")
def test_setup(self, mock_clients, mock_utils, mock_wrap): def test_setup(self, mock_clients, mock_utils, mock_wrap, **dns_kwargs):
mock_utils.iterate_per_tenants.return_value = [ mock_utils.iterate_per_tenants.return_value = [
("foo_user", "foo_tenant"), ("foo_user", "foo_tenant"),
("bar_user", "bar_tenant")] ("bar_user", "bar_tenant")]
@ -67,13 +77,18 @@ class NetworkTestCase(test.TestCase):
nets_per_tenant = 2 nets_per_tenant = 2
net_context = network_context.Network( net_context = network_context.Network(
self.get_context(networks_per_tenant=nets_per_tenant, self.get_context(networks_per_tenant=nets_per_tenant,
network_create_args={"fakearg": "fake"})) network_create_args={"fakearg": "fake"},
**dns_kwargs))
net_context.setup() net_context.setup()
if "dns_nameservers" in dns_kwargs:
dns_kwargs["dns_nameservers"] = tuple(
dns_kwargs["dns_nameservers"])
create_calls = [ create_calls = [
mock.call(tenant, add_router=True, mock.call(tenant, add_router=True,
subnets_num=1, network_create_args={"fakearg": "fake"}) subnets_num=1, network_create_args={"fakearg": "fake"},
**dns_kwargs)
for user, tenant in mock_utils.iterate_per_tenants.return_value] for user, tenant in mock_utils.iterate_per_tenants.return_value]
mock_create.assert_has_calls(create_calls) mock_create.assert_has_calls(create_calls)